Skip to content

Commit 80691d3

Browse files
Ada Couprie Diazwilldeacon
authored andcommitted
arm64: debug: refactor reinstall_suspended_bps()
`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 <[email protected]> Tested-by: Luis Claudio R. Goncalves <[email protected]> Reviewed-by: Anshuman Khandual <[email protected]> Reviewed-by: Will Deacon <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 43e2ae7 commit 80691d3

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

arch/arm64/include/asm/debug-monitors.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ void kernel_rewind_single_step(struct pt_regs *regs);
8484
void kernel_fastforward_single_step(struct pt_regs *regs);
8585

8686
#ifdef CONFIG_HAVE_HW_BREAKPOINT
87-
int reinstall_suspended_bps(struct pt_regs *regs);
87+
bool try_step_suspended_breakpoints(struct pt_regs *regs);
8888
#else
89-
static inline int reinstall_suspended_bps(struct pt_regs *regs)
89+
static inline bool try_step_suspended_breakpoints(struct pt_regs *regs)
9090
{
91-
return -ENODEV;
91+
return false;
9292
}
9393
#endif
9494

arch/arm64/kernel/debug-monitors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int single_step_handler(unsigned long unused, unsigned long esr,
195195
* If we are stepping a pending breakpoint, call the hw_breakpoint
196196
* handler first.
197197
*/
198-
if (!reinstall_suspended_bps(regs))
198+
if (try_step_suspended_breakpoints(regs))
199199
return 0;
200200

201201
if (call_step_hook(regs, esr) == DBG_HOOK_HANDLED)

arch/arm64/kernel/hw_breakpoint.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,36 +847,35 @@ NOKPROBE_SYMBOL(watchpoint_handler);
847847
/*
848848
* Handle single-step exception.
849849
*/
850-
int reinstall_suspended_bps(struct pt_regs *regs)
850+
bool try_step_suspended_breakpoints(struct pt_regs *regs)
851851
{
852852
struct debug_info *debug_info = &current->thread.debug;
853-
int handled_exception = 0, *kernel_step;
854-
855-
kernel_step = this_cpu_ptr(&stepping_kernel_bp);
853+
int *kernel_step = this_cpu_ptr(&stepping_kernel_bp);
854+
bool handled_exception = false;
856855

857856
/*
858857
* Called from single-step exception handler.
859-
* Return 0 if execution can resume, 1 if a SIGTRAP should be
860-
* reported.
858+
* Return true if we stepped a breakpoint and can resume execution,
859+
* false if we need to handle a single-step.
861860
*/
862861
if (user_mode(regs)) {
863862
if (debug_info->bps_disabled) {
864863
debug_info->bps_disabled = 0;
865864
toggle_bp_registers(AARCH64_DBG_REG_BCR, DBG_ACTIVE_EL0, 1);
866-
handled_exception = 1;
865+
handled_exception = true;
867866
}
868867

869868
if (debug_info->wps_disabled) {
870869
debug_info->wps_disabled = 0;
871870
toggle_bp_registers(AARCH64_DBG_REG_WCR, DBG_ACTIVE_EL0, 1);
872-
handled_exception = 1;
871+
handled_exception = true;
873872
}
874873

875874
if (handled_exception) {
876875
if (debug_info->suspended_step) {
877876
debug_info->suspended_step = 0;
878877
/* Allow exception handling to fall-through. */
879-
handled_exception = 0;
878+
handled_exception = false;
880879
} else {
881880
user_disable_single_step(current);
882881
}
@@ -890,17 +889,17 @@ int reinstall_suspended_bps(struct pt_regs *regs)
890889

891890
if (*kernel_step != ARM_KERNEL_STEP_SUSPEND) {
892891
kernel_disable_single_step();
893-
handled_exception = 1;
892+
handled_exception = true;
894893
} else {
895-
handled_exception = 0;
894+
handled_exception = false;
896895
}
897896

898897
*kernel_step = ARM_KERNEL_STEP_NONE;
899898
}
900899

901-
return !handled_exception;
900+
return handled_exception;
902901
}
903-
NOKPROBE_SYMBOL(reinstall_suspended_bps);
902+
NOKPROBE_SYMBOL(try_step_suspended_breakpoints);
904903

905904
/*
906905
* Context-switcher for restoring suspended breakpoints.

0 commit comments

Comments
 (0)