mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] arm64: Return early when break handler is found on linked-list
@ 2024-08-27 11:00 Liao Chang
  2024-08-27 12:30 ` Will Deacon
  2024-08-27 12:50 ` Mark Rutland
  0 siblings, 2 replies; 8+ messages in thread
From: Liao Chang @ 2024-08-27 11:00 UTC (permalink / raw)
  To: catalin.marinas, will, ptosi, liaochang1, oliver.upton
  Cc: linux-arm-kernel, linux-kernel

The search for breakpoint handlers iterate through the entire
linked list. Given that all registered hook has a valid fn field, and no
registered hooks share the same mask and imm. This commit optimize the
efficiency slightly by returning early as a matching handler is found.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 arch/arm64/kernel/debug-monitors.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index 024a7b245056..fc998956f44c 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -281,6 +281,7 @@ static LIST_HEAD(kernel_break_hook);
 
 void register_user_break_hook(struct break_hook *hook)
 {
+	WARN_ON(!hook->fn);
 	register_debug_hook(&hook->node, &user_break_hook);
 }
 
@@ -291,6 +292,7 @@ void unregister_user_break_hook(struct break_hook *hook)
 
 void register_kernel_break_hook(struct break_hook *hook)
 {
+	WARN_ON(!hook->fn);
 	register_debug_hook(&hook->node, &kernel_break_hook);
 }
 
@@ -303,7 +305,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
 {
 	struct break_hook *hook;
 	struct list_head *list;
-	int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
 
 	list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
 
@@ -313,10 +314,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
 	 */
 	list_for_each_entry_rcu(hook, list, node) {
 		if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
-			fn = hook->fn;
+			return hook->fn(regs, esr);
 	}
 
-	return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
+	return DBG_HOOK_ERROR;
 }
 NOKPROBE_SYMBOL(call_break_hook);
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-10-24  3:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-27 11:00 [PATCH] arm64: Return early when break handler is found on linked-list Liao Chang
2024-08-27 12:30 ` Will Deacon
2024-08-29  3:29   ` Liao, Chang
2024-08-27 12:50 ` Mark Rutland
2024-08-29  3:29   ` Liao, Chang
2024-10-23  1:52   ` Liao, Chang
2024-10-23 16:40     ` Will Deacon
2024-10-24  3:54       ` Liao, Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®