Re: [PATCH] riscv: Fix 32-bit call_on_irq_stack() frame pointer ABI

From: Paul Walmsley

Date: Thu Jun 25 2026 - 15:51:32 EST


On Thu, 25 Jun 2026, Nam Cao wrote:

> Michael Ellerman <mpe@xxxxxxxxxx> writes:
> > On 24/6/26 9:31 pm, Rui Qi wrote:
> >> call_on_irq_stack() uses struct member offsets to set up its link in the
> >> frame record list. On riscv32, struct stackframe is the wrong size to
> >> maintain stack pointer alignment, so STACKFRAME_SIZE_ON_STACK includes
> >> padding. However, the ABI requires the frame record to be placed
> >> immediately below the address stored in s0, so the padding must come
> >> before the struct members.
> >>
> >> Fix the layout by making STACKFRAME_FP and STACKFRAME_RA the negative
> >> offsets from s0, instead of the positive offsets from sp.
> >
> > The fact that all uses of the defines need to add back STACKFRAME_SIZE_ON_STACK
> > makes me think the defines don't have the most useful values.
> >
> > If the values were offset + padding then the uses could be left unchanged.
>
> At the moment we only have only one user which has nothing except the
> stack frame on the stack. Other potential users do not necessarily add back
> STACKFRAME_SIZE_ON_STACK.
>
> The offset value depends on the function. So I think it's better to
> leave that offset calculation to users.

Since it's a fix, I queued Rui's resend of Samuel's patch for v7.2-rc,
after cleaning it up along the lines of Nam's suggestions.

Michael, if you think those changes are worth a followup patch for the
list to consider, maybe you can send it as a separate patch?


- Paul