From: Matt Turner <mattst88@gmail.com>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Paul Mackerras <paulus@ozlabs.org>
Cc: Tanushree Shah <tshah@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 7/8] powerpc/perf: Use SIAR for kernel sample addresses on 32-bit
Date: Wed, 18 Nov 2026 11:17:06 -0500 [thread overview]
Message-ID: <20261118161706.2454031-1-mattst88@gmail.com> (raw)
In-Reply-To: <20261117-ppc32-perf-v2-7-2072e9b90009@gmail.com>
On 32-bit, perf_read_regs() sets regs->result to 0, so regs_use_siar()
is always false and every sample is attributed to the interrupted PC.
The MPC7450 family's SIAR holds the address of the last instruction to
complete before the performance monitor exception is generated
(MPC7450UM Rev. 5, section 11.3.7). The exception can be generated
with MSR[EE] = 0 and is taken once EE is set again (section 11.2), so
when interrupts are disabled the interrupted PC is wherever they are
re-enabled, while SIAR still points into the disabled region.
On a 7448, sampling cycles system-wide with --intr-regs=nip during dd,
perf bench sched pipe and find, 46% of the kernel samples have SIAR and
the interrupted PC in different functions. 13270 samples have their PC
on the instruction after the mtmsr that restores interrupts in
ata_scsi_queuecmd(), and 11661 of those have SIAR in udelay().
With interrupts enabled SIAR helps less. Sampling a 32-instruction
loop with one store and one branch with -c 10007, 99.8% of the samples
land at:
event interrupted PC SIAR
r122 (branches) br + 13 br + 9
r014 (stores) stw + 21 stw + 17
Because the exception is held off, it can also be taken on the other
side of a user/kernel transition from the instruction in SIAR, e.g.
just after the rfi at the end of a system call. Recording a loop that
alternates user work with getppid() with perf record -g -c 1000000,
3022 of 16953 samples had SIAR in a different mode from the
interrupted PC. The callchain is walked from regs, so taking its first
entry from SIAR there starts a user callchain with a kernel address.
SIAR also holds a real address while translation is off, and a real
address looks like a user address. The hash_page() fast path on
CONFIG_PPC_BOOK3S_604 runs with translation off and EE clear and
returns straight to user space, so an exception generated there is
taken at a user PC with SIAR holding a kernel real address. Reading
one word from each of 2048 pages after an mprotect() round trip has
flushed their hash PTEs, with -c 10007, 1674 of 2659 user samples land
on the real addresses of DataAccess, hash_page() and
fast_hash_page_return when SIAR is used whenever its address matches
the mode of the interrupted context.
A user SIAR cannot be told apart from a kernel real address, and the
table above shows user samples gain little from SIAR. Use SIAR for PMU
exceptions only when the interrupted context is the kernel and SIAR is
a kernel address, and the interrupted PC otherwise. With that, neither
test has user samples at kernel addresses or callchains with mixed
modes, and 99.9% of the kernel samples in the mprotect() test still
take their address from SIAR.
Suggested-by: Tanushree Shah <tshah@linux.ibm.com>
Signed-off-by: Matt Turner <mattst88@gmail.com>
---
Changes in v3:
- Use SIAR only for kernel samples, and only when it is a kernel
address. A real-mode SIAR from the hash_page() fast path looks like a
user address and was used for user samples taken after its rfi
(Tanushree Shah).
- Retitled from "Use SIAR for sample addresses on 32-bit".
- Link to v2: https://patch.msgid.link/20261117-ppc32-perf-v2-7-2072e9b90009@gmail.com
arch/powerpc/perf/core-book3s.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
index 10ded865583c..aab18f4dda94 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -112,9 +112,28 @@ static inline u32 perf_get_misc_flags(struct pt_regs *regs)
{
return 0;
}
+
+/*
+ * The MPC7450 family's SIAR holds the address of the last instruction to
+ * complete before the performance monitor exception was generated, so for
+ * a PMU exception it is closer to the event than the interrupted PC. The
+ * exception is held off while MSR[EE] is clear, so with interrupts
+ * disabled the interrupted PC is wherever they are re-enabled.
+ *
+ * Because it is held off, the exception can also be taken on the other
+ * side of a user/kernel transition from the instruction in SIAR, e.g.
+ * just after the rfi at the end of a system call. SIAR also holds a real
+ * address for code running with translation off, and a real address
+ * looks like a user address. The hash_page() fast path runs with
+ * translation off and returns straight to user space, so a user SIAR
+ * cannot be trusted. Use SIAR only for kernel samples, and only when it
+ * is a kernel address.
+ */
static inline void perf_read_regs(struct pt_regs *regs)
{
- regs->result = 0;
+ unsigned long siar = mfspr(SPRN_SIAR);
+
+ regs->result = siar && !user_mode(regs) && is_kernel_addr(siar);
}
static inline int siar_valid(struct pt_regs *regs)
--
2.56.1
next prev parent reply other threads:[~2026-11-18 16:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:43 [PATCH v2 0/8] powerpc/perf: mpc7450: Event fixes, SIAR sampling and sysfs event names Matt Turner
2026-11-17 17:43 ` [PATCH v2 1/8] powerpc/perf: mpc7450: Event 0x30d does not use the threshold Matt Turner
2026-11-17 17:43 ` [PATCH v2 2/8] powerpc/perf: mpc7450: Event 0x634 counts L2 prefetches, not L1I Matt Turner
2026-11-17 17:43 ` [PATCH v2 3/8] powerpc/perf: mpc7450: Remove the snoop retry alternatives Matt Turner
2026-11-17 17:43 ` [PATCH v2 4/8] powerpc/perf: mpc7450: Fill in the L1 data cache events Matt Turner
2026-11-17 17:43 ` [PATCH v2 5/8] powerpc/perf: mpc7450: Add the PMC6 L3 events to the alternatives table Matt Turner
2026-11-17 17:43 ` [PATCH v2 6/8] powerpc/perf: mpc7450: Export the event format in sysfs Matt Turner
2026-11-17 17:43 ` [PATCH v2 7/8] powerpc/perf: Use SIAR for sample addresses on 32-bit Matt Turner
[not found] ` <53a68daf-e694-4c88-b99e-fb8a4c17c1a7@linux.ibm.com>
2026-11-18 16:01 ` Matt Turner
2026-11-18 16:17 ` Matt Turner [this message]
2026-11-17 17:43 ` [PATCH v2 8/8] powerpc/perf: mpc7450: Export event names in sysfs Matt Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118161706.2454031-1-mattst88@gmail.com \
--to=mattst88@gmail.com \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=paulus@ozlabs.org \
--cc=ritesh.list@gmail.com \
--cc=sshegde@linux.ibm.com \
--cc=tshah@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®