Skip to content

Commit 8f48c06

Browse files
wildea01ctmarinas
authored andcommitted
arm64: hw_breakpoint: use target state to determine ABI behaviour
The arm64 hw_breakpoint interface is slightly less flexible than its 32-bit counterpart, thanks to some changes in the architecture rendering unaligned watchpoint addresses obselete for AArch64. However, in a multi-arch environment (i.e. debugging a 32-bit target with a 64-bit GDB under a 64-bit kernel), we need to provide a feature compatible interface to GDB in order for debugging to function correctly. This patch adds a new helper, is_compat_bp, to our hw_breakpoint implementation which changes the interface behaviour based on the architecture of the debug target as opposed to the debugger itself. This allows debugged to function as expected for multi-arch configurations without relying on deprecated architectural behaviours when debugging native applications. Cc: Yao Qi <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 120798d commit 8f48c06

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arch/arm64/kernel/hw_breakpoint.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ enum hw_breakpoint_ops {
163163
HW_BREAKPOINT_RESTORE
164164
};
165165

166+
static int is_compat_bp(struct perf_event *bp)
167+
{
168+
struct task_struct *tsk = bp->hw.target;
169+
170+
/*
171+
* tsk can be NULL for per-cpu (non-ptrace) breakpoints.
172+
* In this case, use the native interface, since we don't have
173+
* the notion of a "compat CPU" and could end up relying on
174+
* deprecated behaviour if we use unaligned watchpoints in
175+
* AArch64 state.
176+
*/
177+
return tsk && is_compat_thread(task_thread_info(tsk));
178+
}
179+
166180
/**
167181
* hw_breakpoint_slot_setup - Find and setup a perf slot according to
168182
* operations
@@ -420,7 +434,7 @@ static int arch_build_bp_info(struct perf_event *bp)
420434
* Watchpoints can be of length 1, 2, 4 or 8 bytes.
421435
*/
422436
if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE) {
423-
if (is_compat_task()) {
437+
if (is_compat_bp(bp)) {
424438
if (info->ctrl.len != ARM_BREAKPOINT_LEN_2 &&
425439
info->ctrl.len != ARM_BREAKPOINT_LEN_4)
426440
return -EINVAL;
@@ -477,7 +491,7 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp)
477491
* AArch32 tasks expect some simple alignment fixups, so emulate
478492
* that here.
479493
*/
480-
if (is_compat_task()) {
494+
if (is_compat_bp(bp)) {
481495
if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
482496
alignment_mask = 0x7;
483497
else

0 commit comments

Comments
 (0)