[PATCH v2 2/3] arm64: entry: sdei: save and restore PMR for pseudo-NMI
From: Ada Couprie Diaz
Date: Wed Nov 18 2026 - 10:43:59 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@xxxxxxx>
---
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