* [PATCH 1/3] arm64: entry: sdei: always set VBAR_EL1 on SDEI entry
2026-11-17 17:48 [PATCH 0/3] arm64: sdei: fix entry edge cases, pseudo-NMI Ada Couprie Diaz
@ 2026-11-17 17:48 ` Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 3/3] arm64: head: set __entry_task along with task setup Ada Couprie Diaz
2 siblings, 0 replies; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-17 17:48 UTC (permalink / raw)
To: linux-arm-kernel, Will Deacon, Mark Rutland, Catalin Marinas
Cc: Kiryl Shutsemau, Thomas Huth, Vladimir Murzin, Peter Zijlstra,
Marc Zyngier, Jinjie Ruan, kernel-team, Doug Anderson, stable,
linux-kernel, mrigendrachaubey, Breno Leitao, Linus Walleij,
Dawei Li
SDEI can interrupt at any time, so we cannot guarantee that VBAR_EL1
points to the kernel vectors.
Unconditionally set VBAR_EL1 to the kernel vectors on SDEI entry so
the SDEI handler always runs on the correct vectors.
Commit 9bf6ee7952c7 ("arm64: sdei: Run the event handler on the kernel
vectors") sets VBAR_EL1 to the kernel vectors when KPTI is on
and it still points to the trampoline vectors.
This is only covers the KPTI case, as any other VBAR_EL1 value would
not be changed, while pointing to the wrong exception vectors.
KVM in VHE mode would be such a case as, in VHE, VBAR_EL1 is an alias for
VBAR_EL2, which KVM uses for the hypervisor vectors when running guests.
Fixes: 79e9aa59dc29 ("arm64: sdei: Add trampoline code for remapping the kernel")
Cc: stable@vger.kernel.org
Cc: Kiryl Shutsemau (Meta) <kas@kernel.org>
Cc: Breno Leitao <leitao@debian.org>
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
arch/arm64/kernel/entry-common.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index beb56891fc4f..cb122163a68d 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -1079,19 +1079,22 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
far = read_sysreg(far_el1);
/*
- * With KPTI, VBAR_EL1 holds the trampoline vectors from the return to
- * EL0 until the next exception from EL0 maps the kernel. They only
- * handle exceptions from EL0: an exception taken here would run their
- * empty current-EL half and never come back. Switch to the kernel
- * vectors. The IRQ-like resume keeps using the interrupted VBAR, so it
- * still goes through the trampoline.
+ * As an SDEI event can take over at any point, VBAR_EL1 might not allow
+ * us to take an exception safely :
+ * - With KPTI, VBAR_EL1 holds the trampoline vectors from the return to
+ * EL0 until the next exception from EL0 maps the kernel. They only
+ * handle exceptions from EL0: an exception taken here would run their
+ * empty current-EL half and never come back ;
+ * - With VHE, the kernel runs at EL2 and VBAR_EL1 accesses VBAR_EL2.
+ * KVM might be running a guest and switched VBAR_EL2 to the
+ * hypervisor vectors.
+ *
+ * Switch to the kernel vectors unconditionally and restore
+ * the interrupted VBAR_EL1 before returning.
*/
vbar = read_sysreg(vbar_el1);
- if (arm64_kernel_unmapped_at_el0() &&
- vbar == (unsigned long)raw_cpu_read(this_cpu_vector)) {
- write_sysreg((unsigned long)vectors, vbar_el1);
- isb();
- }
+ write_sysreg((unsigned long)vectors, vbar_el1);
+ isb();
state = irqentry_nmi_enter(regs);
ret = do_sdei_event(regs, arg, vbar);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
2026-11-17 17:48 [PATCH 0/3] arm64: sdei: fix entry edge cases, pseudo-NMI Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 1/3] arm64: entry: sdei: always set VBAR_EL1 on SDEI entry Ada Couprie Diaz
@ 2026-11-17 17:48 ` Ada Couprie Diaz
2026-11-18 9:58 ` Vladimir Murzin
2026-11-18 15:42 ` [PATCH v2 " Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 3/3] arm64: head: set __entry_task along with task setup Ada Couprie Diaz
2 siblings, 2 replies; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-17 17:48 UTC (permalink / raw)
To: linux-arm-kernel, Will Deacon, Mark Rutland, Catalin Marinas
Cc: Kiryl Shutsemau, Thomas Huth, Vladimir Murzin, Peter Zijlstra,
Marc Zyngier, Jinjie Ruan, kernel-team, Doug Anderson, stable,
linux-kernel, mrigendrachaubey, Breno Leitao, Linus Walleij,
Dawei Li
If using pseudo-NMI, PMR must be saved and restored on exception
entry/exit. We do so, and set it to a known value reflecting that DAIF
is masking all interrupts, in the regular entry path.
Do the same for SDEI, as it can interrupt the kernel at any point
and does not mandate firmware to touch PMR, but does mandate masking DAIF.
This avoids potentially returning with a different PMR than interrupted,
and SDEI having the DAIF/PMR pair in a unexpected state compared to
the rest of the kernel.
Fixes: 133d05186325 ("arm64: Make PMR part of task context")
Cc: stable@vger.kernel.org
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
arch/arm64/kernel/entry-common.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index cb122163a68d..17a14c55532c 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -1041,7 +1041,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs)
asmlinkage noinstr unsigned long
__sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
{
- unsigned long elr, spsr, esr, far, vbar;
+ unsigned long pmr, elr, spsr, esr, far, vbar;
irqentry_state_t state;
unsigned long ret;
@@ -1067,6 +1067,16 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
else if (cpu_has_pan())
set_pstate_pan(0);
+ /*
+ * Regular kernel entry saves and resets the PMR to align with DAIF,
+ * but __sdei_asm_handler() does not ; do it now.
+ */
+ if (system_uses_irq_prio_masking()) {
+ pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
+ write_sysreg_s(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET,
+ SYS_ICC_PMR_EL1);
+ }
+
/*
* Nothing saved the interrupted context's exception registers on the
* way in, and it may be in the middle of exception entry or return
@@ -1110,6 +1120,9 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
write_sysreg(far, far_el1);
write_sysreg(vbar, vbar_el1);
+ if (system_uses_irq_prio_masking())
+ write_sysreg_s(pmr, SYS_ICC_PMR_EL1);
+
return ret;
}
#endif /* CONFIG_ARM_SDE_INTERFACE */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
2026-11-17 17:48 ` [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
@ 2026-11-18 9:58 ` Vladimir Murzin
2026-11-18 15:43 ` Ada Couprie Diaz
2026-11-18 15:42 ` [PATCH v2 " Ada Couprie Diaz
1 sibling, 1 reply; 9+ messages in thread
From: Vladimir Murzin @ 2026-11-18 9:58 UTC (permalink / raw)
To: Ada Couprie Diaz, linux-arm-kernel, Will Deacon, Mark Rutland,
Catalin Marinas
Cc: Marc Zyngier, Kiryl Shutsemau, Breno Leitao, Jinjie Ruan,
Doug Anderson, Linus Walleij, Peter Zijlstra, Thomas Huth,
Dawei Li, mrigendrachaubey, kernel-team, linux-kernel, stable
Hi Ada,
On 11/17/26 17:48, Ada Couprie Diaz wrote:
> If using pseudo-NMI, PMR must be saved and restored on exception
> entry/exit. We do so, and set it to a known value reflecting that DAIF
> is masking all interrupts, in the regular entry path.
>
> Do the same for SDEI, as it can interrupt the kernel at any point
> and does not mandate firmware to touch PMR, but does mandate masking DAIF.
> This avoids potentially returning with a different PMR than interrupted,
> and SDEI having the DAIF/PMR pair in a unexpected state compared to
> the rest of the kernel.
>
I think we need to save/restore PMR into/from pt_regs similarly to regular
entry path, otherwise regs_irqs_disabled() is still broken, like it was
pointed in the thread [1] (and Sashiko has raised the same concern on
FEAT_NMI series)
Cheers
Vladimir
[1] https://lore.kernel.org/all/auzM-l40BLsT3clg@arm.com/
> Fixes: 133d05186325 ("arm64: Make PMR part of task context")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
> ---
> arch/arm64/kernel/entry-common.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index cb122163a68d..17a14c55532c 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c
> @@ -1041,7 +1041,7 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs)
> asmlinkage noinstr unsigned long
> __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
> {
> - unsigned long elr, spsr, esr, far, vbar;
> + unsigned long pmr, elr, spsr, esr, far, vbar;
> irqentry_state_t state;
> unsigned long ret;
>
> @@ -1067,6 +1067,16 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
> else if (cpu_has_pan())
> set_pstate_pan(0);
>
> + /*
> + * Regular kernel entry saves and resets the PMR to align with DAIF,
> + * but __sdei_asm_handler() does not ; do it now.
> + */
> + if (system_uses_irq_prio_masking()) {
> + pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
> + write_sysreg_s(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET,
> + SYS_ICC_PMR_EL1);
> + }
> +
> /*
> * Nothing saved the interrupted context's exception registers on the
> * way in, and it may be in the middle of exception entry or return
> @@ -1110,6 +1120,9 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
> write_sysreg(far, far_el1);
> write_sysreg(vbar, vbar_el1);
>
> + if (system_uses_irq_prio_masking())
> + write_sysreg_s(pmr, SYS_ICC_PMR_EL1);
> +
> return ret;
> }
> #endif /* CONFIG_ARM_SDE_INTERFACE */
> -- 2.43.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
2026-11-18 9:58 ` Vladimir Murzin
@ 2026-11-18 15:43 ` Ada Couprie Diaz
0 siblings, 0 replies; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-18 15:43 UTC (permalink / raw)
To: Vladimir Murzin, linux-arm-kernel, Will Deacon, Mark Rutland,
Catalin Marinas
Cc: Kiryl Shutsemau, Thomas Huth, Peter Zijlstra, Marc Zyngier,
Jinjie Ruan, kernel-team, Doug Anderson, stable, linux-kernel,
mrigendrachaubey, Breno Leitao, Linus Walleij, Dawei Li
Hi Vladimir,
On 18/11/2026 09:58, Vladimir Murzin wrote:
> Hi Ada,
>
> On 11/17/26 17:48, Ada Couprie Diaz wrote:
>> If using pseudo-NMI, PMR must be saved and restored on exception
>> entry/exit. We do so, and set it to a known value reflecting that DAIF
>> is masking all interrupts, in the regular entry path.
>>
>> Do the same for SDEI, as it can interrupt the kernel at any point
>> and does not mandate firmware to touch PMR, but does mandate masking DAIF.
>> This avoids potentially returning with a different PMR than interrupted,
>> and SDEI having the DAIF/PMR pair in a unexpected state compared to
>> the rest of the kernel.
>>
> I think we need to save/restore PMR into/from pt_regs similarly to regular
> entry path, otherwise regs_irqs_disabled() is still broken, like it was
> pointed in the thread [1] (and Sashiko has raised the same concern on
> FEAT_NMI series)
>
> Cheers
> Vladimir
>
> [1] https://lore.kernel.org/all/auzM-l40BLsT3clg@arm.com/
Thanks for checking, that's definitely what should be done, I was
a bit hasty...
Given it's a very simple code change (I rewrote the commit message
accordingly) I sent the proper fix as a reply to the patch directly.
Happy to send a full v2 if that would be better !
Kind regards,
Ada
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
2026-11-17 17:48 ` [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
2026-11-18 9:58 ` Vladimir Murzin
@ 2026-11-18 15:42 ` Ada Couprie Diaz
1 sibling, 0 replies; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-18 15:42 UTC (permalink / raw)
To: linux-arm-kernel, Will Deacon, Mark Rutland, Catalin Marinas
Cc: Kiryl Shutsemau, Thomas Huth, Vladimir Murzin, Peter Zijlstra,
Marc Zyngier, Jinjie Ruan, kernel-team, Doug Anderson, stable,
linux-kernel, mrigendrachaubey, Breno Leitao, Linus Walleij,
Dawei Li
When using pseudo-NMIs, the PMR affects if IRQs are disabled
and is not updated by the CPU on exception entry/exit. It must be saved
and restored to/from pt_regs, as the DAIF bits are, so that
`regs_irqs_disabled()` can reliably work with pseudo-NMIs.
We do so in the regular entry path, and set it to a known value
reflecting that DAIF is masking all interrupts.
Do the same for SDEI, as it can interrupt the kernel at any point
and does not mandate firmware to touch PMR, but does mandate masking DAIF.
This makes `regs_irqs_disabled()` reliable in the SDEI handler with
pseudo-NMIs enabled, which is critical as the return path to the kernel
depends on if the interrupted task had IRQs disabled or not.
This also avoids returning to the interrupted task with a different PMR
and a possible DAIF/PMR mismatch, as expected by the rest of the kernel.
Fixes: 133d05186325 ("arm64: Make PMR part of task context")
Cc: stable@vger.kernel.org
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
arch/arm64/kernel/entry-common.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index cb122163a68d..91afd1a36ec6 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -1067,6 +1067,16 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
else if (cpu_has_pan())
set_pstate_pan(0);
+ /*
+ * Regular kernel entry saves and resets the PMR to align with DAIF,
+ * but __sdei_asm_handler() does not ; do it now.
+ */
+ if (system_uses_irq_prio_masking()) {
+ regs->pmr = read_sysreg_s(SYS_ICC_PMR_EL1);
+ write_sysreg_s(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET,
+ SYS_ICC_PMR_EL1);
+ }
+
/*
* Nothing saved the interrupted context's exception registers on the
* way in, and it may be in the middle of exception entry or return
@@ -1110,6 +1120,9 @@ __sdei_handler(struct pt_regs *regs, struct sdei_registered_event *arg)
write_sysreg(far, far_el1);
write_sysreg(vbar, vbar_el1);
+ if (system_uses_irq_prio_masking())
+ write_sysreg_s(regs->pmr, SYS_ICC_PMR_EL1);
+
return ret;
}
#endif /* CONFIG_ARM_SDE_INTERFACE */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] arm64: head: set __entry_task along with task setup
2026-11-17 17:48 [PATCH 0/3] arm64: sdei: fix entry edge cases, pseudo-NMI Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 1/3] arm64: entry: sdei: always set VBAR_EL1 on SDEI entry Ada Couprie Diaz
2026-11-17 17:48 ` [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI Ada Couprie Diaz
@ 2026-11-17 17:48 ` Ada Couprie Diaz
2026-11-18 11:01 ` Vladimir Murzin
2 siblings, 1 reply; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-17 17:48 UTC (permalink / raw)
To: linux-arm-kernel, Will Deacon, Mark Rutland, Catalin Marinas
Cc: Kiryl Shutsemau, Thomas Huth, Vladimir Murzin, Peter Zijlstra,
Marc Zyngier, Jinjie Ruan, kernel-team, Doug Anderson, stable,
linux-kernel, mrigendrachaubey, Breno Leitao, Linus Walleij,
Dawei Li
`__entry_task` is only set after the first `switch_to()`, despite
a proper task being set up in SP_EL0 as soon as CPUs go through
`__{primary,secondary}_switched()`.
As SDEI can interrupt execution at any time, it can interrupt before
the first `switch_to()` and use a null `__entry_task` to set
its current task.
Set `__entry_task` as soon as we have a proper task set up in
`init_cpu_task()` in case we get interrupted before switching threads.
Remove the second paragraph of the comment on `__entry_task`, as it has
been incorrect since the introduction of SDEI, and even more so
with this change.
Fixes: f5df26961853 ("arm64: kernel: Add arch-specific SDEI entry code and CPU masking")
Cc: stable@vger.kernel.org
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
---
arch/arm64/kernel/head.S | 3 +++
arch/arm64/kernel/process.c | 3 ---
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index d6ba3c0af811..e53a9c6fec83 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -209,6 +209,9 @@ SYM_CODE_END(preserve_boot_args)
ldr w\tmp2, [\tsk, #TSK_TI_CPU]
ldr \tmp1, [\tmp1, \tmp2, lsl #3]
set_this_cpu_offset \tmp1
+
+ adr_l \tmp2, __entry_task
+ str \tsk, [\tmp2, \tmp1]
.endm
/*
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 42b15b0c069f..c3d194676efc 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -584,9 +584,6 @@ static void ssbs_thread_switch(struct task_struct *next)
/*
* We store our current task in sp_el0, which is clobbered by userspace. Keep a
* shadow copy so that we can restore this upon entry from userspace.
- *
- * This is *only* for exception entry from EL0, and is not valid until we
- * __switch_to() a user task.
*/
DEFINE_PER_CPU(struct task_struct *, __entry_task);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 3/3] arm64: head: set __entry_task along with task setup
2026-11-17 17:48 ` [PATCH 3/3] arm64: head: set __entry_task along with task setup Ada Couprie Diaz
@ 2026-11-18 11:01 ` Vladimir Murzin
2026-11-18 15:30 ` Ada Couprie Diaz
0 siblings, 1 reply; 9+ messages in thread
From: Vladimir Murzin @ 2026-11-18 11:01 UTC (permalink / raw)
To: Ada Couprie Diaz, linux-arm-kernel, Will Deacon, Mark Rutland,
Catalin Marinas
Cc: Marc Zyngier, Kiryl Shutsemau, Breno Leitao, Jinjie Ruan,
Doug Anderson, Linus Walleij, Peter Zijlstra, Thomas Huth,
Dawei Li, mrigendrachaubey, kernel-team, linux-kernel, stable
Hi Ada,
On 11/17/26 17:48, Ada Couprie Diaz wrote:
> `__entry_task` is only set after the first `switch_to()`, despite
> a proper task being set up in SP_EL0 as soon as CPUs go through
> `__{primary,secondary}_switched()`.
>
> As SDEI can interrupt execution at any time, it can interrupt before
> the first `switch_to()` and use a null `__entry_task` to set
> its current task.
>
TBH I do not know much about SDEI, but don't we need opt-in for
SDEI before we can get any SDEI events? If so, can we really
receive SDEI event before first switch_to()?
Cheers
Vladimir
> Set `__entry_task` as soon as we have a proper task set up in
> `init_cpu_task()` in case we get interrupted before switching threads.
>
> Remove the second paragraph of the comment on `__entry_task`, as it has
> been incorrect since the introduction of SDEI, and even more so
> with this change.
>
> Fixes: f5df26961853 ("arm64: kernel: Add arch-specific SDEI entry code and CPU masking")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
> ---
> arch/arm64/kernel/head.S | 3 +++
> arch/arm64/kernel/process.c | 3 ---
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index d6ba3c0af811..e53a9c6fec83 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -209,6 +209,9 @@ SYM_CODE_END(preserve_boot_args)
> ldr w\tmp2, [\tsk, #TSK_TI_CPU]
> ldr \tmp1, [\tmp1, \tmp2, lsl #3]
> set_this_cpu_offset \tmp1
> +
> + adr_l \tmp2, __entry_task
> + str \tsk, [\tmp2, \tmp1]
> .endm
>
> /*
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 42b15b0c069f..c3d194676efc 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -584,9 +584,6 @@ static void ssbs_thread_switch(struct task_struct *next)
> /*
> * We store our current task in sp_el0, which is clobbered by userspace. Keep a
> * shadow copy so that we can restore this upon entry from userspace.
> - *
> - * This is *only* for exception entry from EL0, and is not valid until we
> - * __switch_to() a user task.
> */
> DEFINE_PER_CPU(struct task_struct *, __entry_task);
>
> -- 2.43.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 3/3] arm64: head: set __entry_task along with task setup
2026-11-18 11:01 ` Vladimir Murzin
@ 2026-11-18 15:30 ` Ada Couprie Diaz
0 siblings, 0 replies; 9+ messages in thread
From: Ada Couprie Diaz @ 2026-11-18 15:30 UTC (permalink / raw)
To: Vladimir Murzin, linux-arm-kernel, Will Deacon, Mark Rutland,
Catalin Marinas
Cc: Marc Zyngier, Kiryl Shutsemau, Breno Leitao, Jinjie Ruan,
Doug Anderson, Linus Walleij, Peter Zijlstra, Thomas Huth,
Dawei Li, mrigendrachaubey, kernel-team, linux-kernel, stable
[Resending for the lists, as I forgot to disable sending HTML,
sorry for the noise !]
Hi Vladimir,
On 18/11/2026 11:01, Vladimir Murzin wrote:
> Hi Ada,
>
> On 11/17/26 17:48, Ada Couprie Diaz wrote:
>> `__entry_task` is only set after the first `switch_to()`, despite
>> a proper task being set up in SP_EL0 as soon as CPUs go through
>> `__{primary,secondary}_switched()`.
>>
>> As SDEI can interrupt execution at any time, it can interrupt before
>> the first `switch_to()` and use a null `__entry_task` to set
>> its current task.
>>
> TBH I do not know much about SDEI, but don't we need opt-in for
> SDEI before we can get any SDEI events? If so, can we really
> receive SDEI event before first switch_to()?
>
> Cheers
> Vladimir
I honestly do not know much either !
But, looking into the driver, we register the SDEI entrypoint
as part of the driver init in `arch_initcall`, with a few notifiers
(CPU hotplug among them).
If using SDEI NMI, we register an SDEI event callback within in this
driver init, in `device_initcall`.
Both of those are done in "late" in the boot process, in
rest_init()
-> kernel_init()
-> kernel_init_freeable()
-> do_basic_setup()
This is as part of the init task, before excve into userspace,
but after kthreadd is set up and has switched to the init task.
So, I think that it is not possible to be interrupted by SDEI
on the boot CPU before the first `switch_to`, as we would have
`switch_to()`'d the init task by immediately scheduling
from the idle task.
However, as far as I can tell this is not the case for secondaries :
their first task on boot is set to the idle task, which they go to
without switching until (and unless) something gets scheduled on the core.
This would be the same path taken for CPU hotplug.
Unless I am misunderstanding something, which would not surprise me
given the amount of things happening before getting to init, I think
that is is indeed impossible to get an SDEI interrupt before the first
`switch_to()` on the boot CPU, but that it is on secondaries
or after hotplug.
Hopefully this makes sense and, more importantly, is correct !
Thanks for bringing the question up.
Kind regards,
Ada
^ permalink raw reply [flat|nested] 9+ messages in thread