Re: [PATCH] powerpc/irq: Fix missing r2 clobber in PCREL inline assembly
From: Segher Boessenkool <hidden>
Date: 2026-07-20 10:25:54
Also in:
lkml
Hi! On Mon, Jul 20, 2026 at 12:43:47PM +0530, Saket Kumar Bhaskar wrote:
In CONFIG_PPC_KERNEL_PCREL mode, r2 is no longer reserved for the TOC pointer and is available as a caller-saved register [0].
Just like on many more ABIs. Yeah. It's the first that PowerPC Linux supports though :-)
Both call_do_irq() and call_do_softirq() use inline assembly to call functions with stack switching, but fail to list r2 in their clobber lists. This causes the compiler to assume r2 is preserved across these calls, leading to register corruption when the called functions (__do_irq and __do_softirq) clobber r2.
Yeah.
quoted hunk ↗ jump to hunk
index a0e8b998c9b5..26df38bdd334 100644--- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c@@ -218,7 +218,12 @@ static __always_inline void call_do_softirq(const void *sp) [callee] "i" (__do_softirq) : // Clobbers "lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6", - "cr7", "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", + "cr7", "r0", + /* r2 is clobbered in PCREL mode */
"Note that r2 may be clobbered in the call, when using the ELF V2 ABI"? PCREL has nothing to do with it. Well, not directly :-) And the clobber list does not specify registers that definitely *are* clobbered, but registers that *may be* clobbered, instead :-) Registers that *are* clobbered are in the output list (and given a name there so that the new value can be accessed, etc.)
quoted hunk ↗ jump to hunk
+#ifdef CONFIG_PPC_KERNEL_PCREL + "r2", +#endif + "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" ); }@@ -276,7 +281,12 @@ static __always_inline void call_do_irq(struct pt_regs *regs, void *sp) [callee] "i" (__do_irq) : // Clobbers "lr", "xer", "ctr", "memory", "cr0", "cr1", "cr5", "cr6", - "cr7", "r0", "r4", "r5", "r6", "r7", "r8", "r9", "r10", + "cr7", "r0", + /* r2 is clobbered in PCREL mode */ +#ifdef CONFIG_PPC_KERNEL_PCREL + "r2", +#endif + "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" ); }
Segher