[PATCH v4 13/21] arm64: entry: sdei: Make 'tsk' available
Vladimir Murzin
vladimir.murzin at arm.com
Thu Sep 10 06:06:14 PDT 2026
On 9/8/26 16:17, Mark Rutland wrote:
> For regular entry/exit sequences, we use 'tsk' (x28) to hold the current
> task pointer, allowing this to be used by various assembly macros. The
> SDEI entry/exit sequence uses x28 to hold the value of the interrupted
> sp_el0, and doesn't retain the current task pointer in a register.
>
> These differences makes it awkward to share assembly macros across
> regular entry/exit and SDEI entry/exit, and risk surprises.
>
> Align the SDEI entry/exit sequence with regular entry/exit, keeping the
> current task pointer in 'tsk', and preserving the interrupted sp_el0 in
> another (callee-saved) register. I've used x20 as x19 was already in
> used for the relevant sdei_registered_event, and these are the
> lowest-numbered registers above x18 (which we must preserve for shadow
> call stack).
>
> Signed-off-by: Mark Rutland <mark.rutland at arm.com>
> Tested-by: Muhammad Usama Anjum <usama.anjum at arm.com>
> Cc: Ada Couprie Diaz <ada.coupriediaz at arm.com>
> Cc: Ard Biesheuvel <ardb at kernel.org>
> Cc: Catalin Marinas <catalin.marinas at arm.com>
> Cc: James Morse <james.morse at arm.com>
> Cc: Jinjie Ruan <ruanjinjie at huawei.com>
> Cc: Marc Zyngier <maz at kernel.org>
> Cc: Peter Zijlstra <peterz at infradead.org>
> Cc: Vladimir Murzin <vladimir.murzin at arm.com>
> Cc: Will Deacon <will at kernel.org>
> Cc: Yang Shi <yang at os.amperecomputing.com>
> ---
> arch/arm64/kernel/entry.S | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index a6ec5c5a2d29c..0902c1bd9dd3d 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -1023,11 +1023,12 @@ SYM_CODE_START(__sdei_asm_handler)
>
> /*
> * We may have interrupted userspace, or a guest, or exit-from or
> - * return-to either of these. We can't trust sp_el0, restore it.
> + * return-to either of these. Preserve the interrupted sp_el0, and
> + * initialize sp_el0 to the current task.
> */
> - mrs x28, sp_el0
> - ldr_this_cpu dst=x0, sym=__entry_task, tmp=x1
> - msr sp_el0, x0
> + mrs x20, sp_el0
> + ldr_this_cpu dst=tsk, sym=__entry_task, tmp=x1
> + msr sp_el0, tsk
>
> /* If we interrupted the kernel point to the previous stack/frame. */
> and x0, x3, #0xc
> @@ -1043,7 +1044,7 @@ SYM_CODE_START(__sdei_asm_handler)
> mov x1, x19
> bl __sdei_handler
>
> - msr sp_el0, x28
> + msr sp_el0, x20
> /* restore regs >x17 that firmware won't restore */
> mov x4, x19 // keep x4 for __sdei_asm_exit_trampoline
> ldp x18, x19, [x4, #SDEI_EVENT_INTREGS + 16 * 9]
> -- 2.30.2
>
I'm sure you are already pretty much aware that Will's series touches
this code as well... :)
FWIW,
Reviewed-by: Vladimir Murzin <vladimir.murzin at arm.com>
More information about the linux-arm-kernel
mailing list