]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arm64: debug: refactor reinstall_suspended_bps()
authorAda Couprie Diaz <ada.coupriediaz@arm.com>
Mon, 7 Jul 2025 11:41:04 +0000 (12:41 +0100)
committerWill Deacon <will@kernel.org>
Tue, 8 Jul 2025 12:27:42 +0000 (13:27 +0100)
`reinstall_suspended_bps()` plays a key part in the stepping process
when we have hardware breakpoints and watchpoints enabled.
It checks if we need to step one, will re-enable it if it has
been handled and will return whether or not we need to proceed with
a single-step.

However, the current naming and return values make it harder to understand
the logic and goal of the function.

Rename it `try_step_suspended_breakpoints()` and change the return value
to a boolean, aligning it with similar functions used in
`do_el0_undef()` like `try_emulate_mrs()`, and making its behaviour
more obvious.

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

index caee1d923f9c7e2eadd8ab6cbaac248bb51acf4d..586290e95d874f2b3acdb18f5fa1feba240e211a 100644 (file)
@@ -84,11 +84,11 @@ void kernel_rewind_single_step(struct pt_regs *regs);
 void kernel_fastforward_single_step(struct pt_regs *regs);
 
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
-int reinstall_suspended_bps(struct pt_regs *regs);
+bool try_step_suspended_breakpoints(struct pt_regs *regs);
 #else
-static inline int reinstall_suspended_bps(struct pt_regs *regs)
+static inline bool try_step_suspended_breakpoints(struct pt_regs *regs)
 {
-       return -ENODEV;
+       return false;
 }
 #endif
 
index 46fb9359a554034e2329f19eeb04d9bac7f8063f..89264d1a9d65299ecbc06647df09e496e69c8149 100644 (file)
@@ -195,7 +195,7 @@ static int single_step_handler(unsigned long unused, unsigned long esr,
         * If we are stepping a pending breakpoint, call the hw_breakpoint
         * handler first.
         */
-       if (!reinstall_suspended_bps(regs))
+       if (try_step_suspended_breakpoints(regs))
                return 0;
 
        if (call_step_hook(regs, esr) == DBG_HOOK_HANDLED)
index d7eede5d869c2ba6188409195d2c28ba9132a51b..309ae24d4548059ed9be0257af47b5db2c48a986 100644 (file)
@@ -847,36 +847,35 @@ NOKPROBE_SYMBOL(watchpoint_handler);
 /*
  * Handle single-step exception.
  */
-int reinstall_suspended_bps(struct pt_regs *regs)
+bool try_step_suspended_breakpoints(struct pt_regs *regs)
 {
        struct debug_info *debug_info = &current->thread.debug;
-       int handled_exception = 0, *kernel_step;
-
-       kernel_step = this_cpu_ptr(&stepping_kernel_bp);
+       int *kernel_step = this_cpu_ptr(&stepping_kernel_bp);
+       bool handled_exception = false;
 
        /*
         * Called from single-step exception handler.
-        * Return 0 if execution can resume, 1 if a SIGTRAP should be
-        * reported.
+        * Return true if we stepped a breakpoint and can resume execution,
+        * false if we need to handle a single-step.
         */
        if (user_mode(regs)) {
                if (debug_info->bps_disabled) {
                        debug_info->bps_disabled = 0;
                        toggle_bp_registers(AARCH64_DBG_REG_BCR, DBG_ACTIVE_EL0, 1);
-                       handled_exception = 1;
+                       handled_exception = true;
                }
 
                if (debug_info->wps_disabled) {
                        debug_info->wps_disabled = 0;
                        toggle_bp_registers(AARCH64_DBG_REG_WCR, DBG_ACTIVE_EL0, 1);
-                       handled_exception = 1;
+                       handled_exception = true;
                }
 
                if (handled_exception) {
                        if (debug_info->suspended_step) {
                                debug_info->suspended_step = 0;
                                /* Allow exception handling to fall-through. */
-                               handled_exception = 0;
+                               handled_exception = false;
                        } else {
                                user_disable_single_step(current);
                        }
@@ -890,17 +889,17 @@ int reinstall_suspended_bps(struct pt_regs *regs)
 
                if (*kernel_step != ARM_KERNEL_STEP_SUSPEND) {
                        kernel_disable_single_step();
-                       handled_exception = 1;
+                       handled_exception = true;
                } else {
-                       handled_exception = 0;
+                       handled_exception = false;
                }
 
                *kernel_step = ARM_KERNEL_STEP_NONE;
        }
 
-       return !handled_exception;
+       return handled_exception;
 }
-NOKPROBE_SYMBOL(reinstall_suspended_bps);
+NOKPROBE_SYMBOL(try_step_suspended_breakpoints);
 
 /*
  * Context-switcher for restoring suspended breakpoints.