Re: [PATCH 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
From: Vladimir Murzin
Date: Wed Nov 18 2026 - 04:58:42 EST
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@xxxxxxx/
> Fixes: 133d05186325 ("arm64: Make PMR part of task context")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@xxxxxxx>
> ---
> 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
>