On Tue, Nov 17, 2026 at 11:11 AM Tanushree Shah <[email protected]>
wrote:> One question: the callchain still walks from regs (gpr[1],
link), but
> its first entry now comes from SIAR. Can SIAR and the interrupted PC
> end up on opposite sides of user/kernel? If so, would the callchain
> be affected? Something like perf record -g on a workload that switches
> between user and kernel often might show it.
Yes, it happens. I ran perf record -g -e cycles -c 1000000 on a loop
that does a little work in user space and then calls getppid(). Of
16953 samples, 3022 had SIAR and the interrupted PC in different
modes.
2193 had SIAR in the syscall exit path (__kuep_unlock,
ret_from_syscall, syscall_exit_finish, syscall_exit_prepare) and the
interrupted PC in user space. The exception is held off while MSR[EE]
is clear, so it's taken just after the rfi. The sample is marked as a
kernel sample, but the callchain is a user callchain that starts with
a kernel address, so perf can't resolve that entry, and the actual
user PC (in libc's syscall()) is missing.
801 had SIAR in the system call vector at 0xc00. That code runs with
translation off, so SIAR holds a real address. The interrupted PC was
in the kernel, but these were marked as user samples at a bogus
address.
The other 28 had SIAR in user space and the interrupted PC in the
kernel.
In v2 I'll use SIAR only when it's in the same mode as the
interrupted context and fall back to regs->nip otherwise, which is
what the code did before this patch:
static inline void perf_read_regs(struct pt_regs *regs)
{
unsigned long siar = mfspr(SPRN_SIAR);
regs->result = siar && is_kernel_addr(siar) == !user_mode(regs);
}
A real-mode vector address isn't a kernel address, so this covers the
0xc00 case too, and perf_get_misc_flags() no longer needs to look at
SIAR. With that change the same test had no mismatched samples out
of 18069. The share of samples in the kernel went from 44% to 46%
(perf stat puts it at 57% of cycles), so falling back to regs->nip
near the transitions doesn't lose anything.
Good catch, thanks.