Re: [PATCH] powerpc/irq: Fix missing r2 clobber in PCREL inline assembly
From: Saket Kumar Bhaskar
Date: Wed Jul 22 2026 - 06:49:09 EST
On Mon, Jul 20, 2026 at 05:25:18AM -0500, Segher Boessenkool wrote:
> 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.
>
> > 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.)
>
Thanks for the review. Will send v2 with updated comments as:
r2 may be clobbered by the callee when using the ELFv2 ABI.
-Saket
> > +#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