]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arm64: debug: call step handlers statically
authorAda Couprie Diaz <ada.coupriediaz@arm.com>
Mon, 7 Jul 2025 11:41:00 +0000 (12:41 +0100)
committerWill Deacon <will@kernel.org>
Tue, 8 Jul 2025 12:27:41 +0000 (13:27 +0100)
Software stepping checks for the correct handler by iterating over a list
of dynamically registered handlers and calling all of them until one
handles the exception.

This is the only generic way to handle software stepping handlers in arm64
as the exception does not provide an immediate that could be checked,
contrary to software breakpoints.

However, the registration mechanism is not exported and has only
two current users : the KGDB stepping handler, and the uprobe single step
handler.
Given that one comes from user mode and the other from kernel mode, call
the appropriate one by checking the source EL of the exception.
Add a stand-in that returns DBG_HOOK_ERROR when the configuration
options are not enabled.

Remove `arch_init_uprobes()` as it is not useful anymore and is
specific to arm64.

Unify the naming of the handler to XXX_single_step_handler(), making it
clear they are related.

Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
Tested-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
Reviewed-by: Will Deacon <will@kernel.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20250707114109.35672-5-ada.coupriediaz@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/kgdb.h
arch/arm64/include/asm/uprobes.h
arch/arm64/kernel/debug-monitors.c
arch/arm64/kernel/kgdb.c
arch/arm64/kernel/probes/uprobes.c

index 82a76b2102fb613ab556de46acd10f90ac82c388..3184f5d1e3ae490d44ed75b01e583abe14050a37 100644 (file)
@@ -26,6 +26,15 @@ extern int kgdb_fault_expected;
 
 int kgdb_brk_handler(struct pt_regs *regs, unsigned long esr);
 int kgdb_compiled_brk_handler(struct pt_regs *regs, unsigned long esr);
+#ifdef CONFIG_KGDB
+int kgdb_single_step_handler(struct pt_regs *regs, unsigned long esr);
+#else
+static inline int kgdb_single_step_handler(struct pt_regs *regs,
+       unsigned long esr)
+{
+       return DBG_HOOK_ERROR;
+}
+#endif
 
 #endif /* !__ASSEMBLY__ */
 
index 3659a79a9f325fa442578d351e4cc37daefea84a..89bfb0213a500c497a3be7af9bd097cd23bd6195 100644 (file)
@@ -29,5 +29,14 @@ struct arch_uprobe {
 };
 
 int uprobe_brk_handler(struct pt_regs *regs, unsigned long esr);
+#ifdef CONFIG_UPROBES
+int uprobe_single_step_handler(struct pt_regs *regs, unsigned long esr);
+#else
+static inline int uprobe_single_step_handler(struct pt_regs *regs,
+       unsigned long esr)
+{
+       return DBG_HOOK_ERROR;
+}
+#endif
 
 #endif
index 15d7158a7548b0259e5b7bc89dcc55ba0280b4c4..26c71b7edc261acb006b8895f6b49edca8d0e156 100644 (file)
@@ -200,30 +200,17 @@ void unregister_kernel_step_hook(struct step_hook *hook)
 }
 
 /*
- * Call registered single step handlers
+ * Call single step handlers
  * There is no Syndrome info to check for determining the handler.
- * So we call all the registered handlers, until the right handler is
- * found which returns zero.
+ * However, there is only one possible handler for user and kernel modes, so
+ * check and call the appropriate one.
  */
 static int call_step_hook(struct pt_regs *regs, unsigned long esr)
 {
-       struct step_hook *hook;
-       struct list_head *list;
-       int retval = DBG_HOOK_ERROR;
+       if (user_mode(regs))
+               return uprobe_single_step_handler(regs, esr);
 
-       list = user_mode(regs) ? &user_step_hook : &kernel_step_hook;
-
-       /*
-        * Since single-step exception disables interrupt, this function is
-        * entirely not preemptible, and we can use rcu list safely here.
-        */
-       list_for_each_entry_rcu(hook, list, node)       {
-               retval = hook->fn(regs, esr);
-               if (retval == DBG_HOOK_HANDLED)
-                       break;
-       }
-
-       return retval;
+       return kgdb_single_step_handler(regs, esr);
 }
 NOKPROBE_SYMBOL(call_step_hook);
 
index b5a3b9c85a6565af8647cdf8fe0f7b66537c7a1c..968324a79a89725f59ee74bd7d6a76e81aca03d2 100644 (file)
@@ -250,7 +250,7 @@ int kgdb_compiled_brk_handler(struct pt_regs *regs, unsigned long esr)
 }
 NOKPROBE_SYMBOL(kgdb_compiled_brk_handler);
 
-static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned long esr)
+int kgdb_single_step_handler(struct pt_regs *regs, unsigned long esr)
 {
        if (!kgdb_single_step)
                return DBG_HOOK_ERROR;
@@ -258,11 +258,7 @@ static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned long esr)
        kgdb_handle_exception(0, SIGTRAP, 0, regs);
        return DBG_HOOK_HANDLED;
 }
-NOKPROBE_SYMBOL(kgdb_step_brk_fn);
-
-static struct step_hook kgdb_step_hook = {
-       .fn             = kgdb_step_brk_fn
-};
+NOKPROBE_SYMBOL(kgdb_single_step_handler);
 
 static int __kgdb_notify(struct die_args *args, unsigned long cmd)
 {
@@ -301,13 +297,7 @@ static struct notifier_block kgdb_notifier = {
  */
 int kgdb_arch_init(void)
 {
-       int ret = register_die_notifier(&kgdb_notifier);
-
-       if (ret != 0)
-               return ret;
-
-       register_kernel_step_hook(&kgdb_step_hook);
-       return 0;
+       return register_die_notifier(&kgdb_notifier);
 }
 
 /*
@@ -317,7 +307,6 @@ int kgdb_arch_init(void)
  */
 void kgdb_arch_exit(void)
 {
-       unregister_kernel_step_hook(&kgdb_step_hook);
        unregister_die_notifier(&kgdb_notifier);
 }
 
index ad68b4a5974d4e83b919716edd317c2bf06b36b7..1f91fd2a818798616635cd0490b4f40dc4be6da1 100644 (file)
@@ -182,7 +182,7 @@ int uprobe_brk_handler(struct pt_regs *regs,
        return DBG_HOOK_ERROR;
 }
 
-static int uprobe_single_step_handler(struct pt_regs *regs,
+int uprobe_single_step_handler(struct pt_regs *regs,
                                      unsigned long esr)
 {
        struct uprobe_task *utask = current->utask;
@@ -194,16 +194,3 @@ static int uprobe_single_step_handler(struct pt_regs *regs,
        return DBG_HOOK_ERROR;
 }
 
-/* uprobe single step handler hook */
-static struct step_hook uprobes_step_hook = {
-       .fn = uprobe_single_step_handler,
-};
-
-static int __init arch_init_uprobes(void)
-{
-       register_user_step_hook(&uprobes_step_hook);
-
-       return 0;
-}
-
-device_initcall(arch_init_uprobes);