[PATCH 05/17] arm64: Introduce helpers for restoring standard exception masks

From: Jinjie Ruan

Date: Fri Jul 03 2026 - 06:04:28 EST


Several non-entry call sites construct and restore standard exception
masks by open-coding patterns like

local_exception_restore(arm64_make_noirq_mask());
local_exception_restore(arm64_make_procctx_mask());
local_exception_restore(arm64_make_errctx_mask());

These scattered calls directly manipulate DAIF and are blind to the
ongoing rework of exception mask management (DAIF + PMR + future
ALLINT). Encapsulate each pattern into a dedicated helper:

local_exception_restore_noirq()
local_exception_restore_procctx()
local_exception_restore_errctx()

This centralises the mask construction, avoids open-coding of
arch-specific mask details, and prepares for the entry-specific
exception mask framework that will manage DAIF, PMR and eventually
ALLINT in a consistent way.

Callers in ACPI, IRQ setup, SMP, KVM VHE switch and elsewhere are
converted to use the new helpers. No functional change.

No functional change.

Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
arch/arm64/include/asm/exception_masks.h | 15 +++++++++++++++
arch/arm64/kernel/acpi.c | 4 ++--
arch/arm64/kernel/irq.c | 2 +-
arch/arm64/kernel/setup.c | 2 +-
arch/arm64/kernel/smp.c | 2 +-
arch/arm64/kvm/hyp/vhe/switch.c | 2 +-
6 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/include/asm/exception_masks.h b/arch/arm64/include/asm/exception_masks.h
index 2c87f7c90f62..fbbba769ca03 100644
--- a/arch/arm64/include/asm/exception_masks.h
+++ b/arch/arm64/include/asm/exception_masks.h
@@ -196,4 +196,19 @@ static __always_inline void exception_exit_restore_mask(struct exception_mask ma
{
write_sysreg(mask.daif, daif);
}
+
+static inline void local_exception_restore_noirq(void)
+{
+ local_exception_restore(arm64_make_noirq_mask());
+}
+
+static inline void local_exception_restore_errctx(void)
+{
+ local_exception_restore(arm64_make_errctx_mask());
+}
+
+static inline void local_exception_restore_procctx(void)
+{
+ local_exception_restore(arm64_make_procctx_mask());
+}
#endif /* __ASM_EXCEPTION_MASKS_H */
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 4d413419309d..88883d074ecd 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -407,7 +407,7 @@ int apei_claim_sea(struct pt_regs *regs)
* SEA can interrupt SError, mask it and describe this as an NMI so
* that APEI defers the handling.
*/
- local_exception_restore(arm64_make_errctx_mask());
+ local_exception_restore_errctx();
nmi_enter();
err = ghes_notify_sea();
nmi_exit();
@@ -418,7 +418,7 @@ int apei_claim_sea(struct pt_regs *regs)
*/
if (!err) {
if (return_to_irqs_enabled) {
- local_exception_restore(arm64_make_noirq_mask());
+ local_exception_restore_noirq();
__irq_enter();
irq_work_run();
__irq_exit();
diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c
index 9e7fb0d22586..fff0efd5a195 100644
--- a/arch/arm64/kernel/irq.c
+++ b/arch/arm64/kernel/irq.c
@@ -130,6 +130,6 @@ void __init init_IRQ(void)
* the PMR/PSR pair to a consistent state.
*/
WARN_ON(read_sysreg(daif) & PSR_A_BIT);
- local_exception_restore(arm64_make_noirq_mask());
+ local_exception_restore_noirq();
}
}
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 10507e55e2ce..bd7aa8263ebe 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -311,7 +311,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
* IRQ and FIQ will be unmasked after the root irqchip has been
* detected and initialized.
*/
- local_exception_restore(arm64_make_noirq_mask());
+ local_exception_restore_noirq();

/*
* TTBR0 is only used for the identity mapping at this stage. Make it
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index d153ff77d25c..a94ebb1bb6d7 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -263,7 +263,7 @@ asmlinkage notrace void secondary_start_kernel(void)
* as the root irqchip has already been detected and initialized we can
* unmask IRQ and FIQ at the same time.
*/
- local_exception_restore(arm64_make_procctx_mask());
+ local_exception_restore_procctx();

/*
* OK, it's off to the idle thread for us
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 024876efe0c3..d11fb05e558b 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -650,7 +650,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
* local_exception_restore() takes care to properly restore PSTATE.DAIF
* and the GIC PMR if the host is using IRQ priorities.
*/
- local_exception_restore(arm64_make_noirq_mask());
+ local_exception_restore_noirq();

return ret;
}
--
2.34.1