Re: [PATCH 3/5] alpha/perf: implement ProfileMe sampling
From: Matt Turner
Date: Thu Oct 29 2026 - 23:59:36 EST
On Thu, Oct 29, 2026 at 11:18 AM Magnus Lindholm <linmag7@xxxxxxxxx> wrote:
> > + pm_regs = *regs;
>
> On Alpha, perf_reg_value(SP) derives kernel SP from regs + 1.
> I think passing this copy therefore reports an address past the local copy,
> rather than past the original interrupt frame.
[...]
> If PMPC is in userspace but the interrupt arrived in kernel mode,
> this also makes perf_sample_regs_user() select the copied kernel
> registers as user registers, bypassing perf_get_regs_user().
[...]
> Could we preserve the original frame for register/stack capture
> and supply the profiled IP and mode separately?
Right on both counts. sashiko caught the same thing, and v2 drops the
copy. perf core takes the sample IP and mode from regs
(perf_instruction_pointer() and perf_misc_flags()), so there is no way
to pass them separately. Instead v2 sets the PC and mode bit in a real
frame for the overflow call and restores them afterwards:
- interrupt taken in the instruction's mode: regs
- user instruction, interrupt taken in the kernel: task_pt_regs(current)
- kernel instruction, interrupt taken after the return to user mode: a
per-CPU pt_regs holding only the PC, since the kernel state is gone.
It is not on the stack, so perf_reg_value() reports no SP for it, and
the user frame is left alone for perf_get_regs_user().
So SP comes from the right frame, and a user sample gets the real user
frame.