Skip to content

Commit 8dfe804

Browse files
jma123456willdeacon
authored andcommitted
arm64: perf: Report the PC value in REGS_ABI_32 mode
A 32-bit perf querying the registers of a compat task using REGS_ABI_32 will receive zeroes from w15, when it expects to find the PC. Return the PC value for register dwarf register 15 when returning register values for a compat task to perf. Cc: <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Jiping Ma <[email protected]> Link: https://lore.kernel.org/r/[email protected] [will: Shuffled code and added a comment] Signed-off-by: Will Deacon <[email protected]>
1 parent cb944f0 commit 8dfe804

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

arch/arm64/kernel/perf_regs.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
1515
return 0;
1616

1717
/*
18-
* Compat (i.e. 32 bit) mode:
19-
* - PC has been set in the pt_regs struct in kernel_entry,
20-
* - Handle SP and LR here.
18+
* Our handling of compat tasks (PERF_SAMPLE_REGS_ABI_32) is weird, but
19+
* we're stuck with it for ABI compatability reasons.
20+
*
21+
* For a 32-bit consumer inspecting a 32-bit task, then it will look at
22+
* the first 16 registers (see arch/arm/include/uapi/asm/perf_regs.h).
23+
* These correspond directly to a prefix of the registers saved in our
24+
* 'struct pt_regs', with the exception of the PC, so we copy that down
25+
* (x15 corresponds to SP_hyp in the architecture).
26+
*
27+
* So far, so good.
28+
*
29+
* The oddity arises when a 64-bit consumer looks at a 32-bit task and
30+
* asks for registers beyond PERF_REG_ARM_MAX. In this case, we return
31+
* SP_usr, LR_usr and PC in the positions where the AArch64 SP, LR and
32+
* PC registers would normally live. The initial idea was to allow a
33+
* 64-bit unwinder to unwind a 32-bit task and, although it's not clear
34+
* how well that works in practice, somebody might be relying on it.
35+
*
36+
* At the time we make a sample, we don't know whether the consumer is
37+
* 32-bit or 64-bit, so we have to cater for both possibilities.
2138
*/
2239
if (compat_user_mode(regs)) {
2340
if ((u32)idx == PERF_REG_ARM64_SP)
2441
return regs->compat_sp;
2542
if ((u32)idx == PERF_REG_ARM64_LR)
2643
return regs->compat_lr;
44+
if (idx == 15)
45+
return regs->pc;
2746
}
2847

2948
if ((u32)idx == PERF_REG_ARM64_SP)

0 commit comments

Comments
 (0)