Skip to contentSkip to conversation

Rework Arm64 exception mask helpers

PATCH New Liao Chang 1 participant 3 messages May 22, 2025

Subsystems (2)
lore
Share & tools
lore

Liao Chang

author
#0 lore raw

v5 cover Rework Arm64 exception mask helpers

This patch series is a significant rework of the exception mask helpers, building upon the discussions from a year ago [1]. The need for this reworking has become increasingly apparent with the emerging platform and virtualization support for FEAT_NMI [2], and Mark Brown's FEAT_NMI patch series [3] really highlighted the existing "hacking style" approach to DAIF management that needed addressing before NMI functionality could be properly integrated.

Furthermore, with Jonathan has platform that now support FEAT_NMI, there's a strong desire to see Mark Brown's FEAT_NMI patchset merged soon. All of these factors emphasize the importance of a robust and clean exception mask rework. Therefore, I'm pushing this patchset again and would greatly appreciate your review.

This series broadly follows the suggestions made by Mark Rutland in response [4] to Mark Brown's FEAT_NMI patchset. To summarize his thoughts on DAIF + PMR + ALLINT management:

(a) Adding entry-specific helpers to manipulate abstract exception masks covering DAIF + PMR + ALLINT. Those need unmask-at-entry and mask-at-exit behaviour, and today only need to manage DAIF + PMR.

It should be possible to do this ahead of ALLINT / NMI support.

(b) Adding new "logical exception mask" helpers that treat DAIF + PMR + ALLINT as separate elements.

While attempting to follow Mark Rutland's guidance, I may have initially misunderstood some nuances, leading to a complete redesign and recoding of this patchset. As a result, it looks rather different from the previous revision.

In short summary, to reduce the complexity of a single, monolithic function trying to handle every scenario, this patchset now introduces two distinct series of logical exception mask helpers. Each series is tailored for a specific kernel configuration and use case. I believe this policy makes the behavior of each exception mask helper much more explicit for any given situation, and simplifies the future integration of FEAT_NMI support without introducing further complexity.

Thanks,

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/linux-arm-kernel/[email protected]/
[4] https://lore.kernel.org/linux-arm-kernel/Y5c9SLeJacLYHmP7@FVFF77S0Q05N/

v5->v4:
1. The rework has been fully redesigned, you'll find all the details in the first patch.
2. The rework focus on replacing the helpers defined in daifflags.h, so less patches in this series, it will be easier to review and discuss.

v4->v3:
General Enhancements
--------------------
Commit messages of [PATCH 04/05/06] have been enriched to outline the implementation details, motivations and potential effects. This might improve develper understanding and review efficiency.

Specific Changes
----------------
1. [PATCH 01] new utilize the existing helper maco in sysregs.h to generate the "MSR ALLLINT, #Imm1" instruction. Additionally, helper names have been renamed to start with msr_pstate_ for better discoverability (as suggested by Mark Brown).

2. For [PATCH 04], due to the barrier side-effect of writing to PSTATE fields, it is unnecessary to call pmr_sync() in __pmr_local_allint_restore(). Add a table in comments to depict the relationship between the type of interrupt masking and hardware register configuration.

3. For [PATCH 05/06], function names have been revised to better reflect their purpose:

local_errint_enable() -> local_irq_serror_enable()
local_errint_disable() -> local_nmi_serror_disable()
local_allint_mark_enabled() -> local_irq_mark_enabled()
local_allint_disable() -> local_nmi_disable()
local_errnmi_enable() -> local_nmi_serror_enable()

4. For [PATCH 07], A bug in local_nmi_enable() has been fixed. The v3 version is overly complex and included an unnecessary write operation to PSTATE.DAIF.

5. [PATCH 09] introduce a slight optimization for NMI handling. Since the intermediate step of marking IRQ TO-BE enabled is no longer required, dropping PMR before acknowledge PSEUDO_NMI is also unnecessary.

6. [PATCH 10] migrates CPU idle contex save/restore operation to the newly introduced logical interrupt masking helper functions.

v3->v2:
1. Squash two commits that address two minor issues into Mark Brown's origin patch for detecting FEAT_NMI.
2. Add one patch resolves the kprobe reenter panic while testing FEAT_NMI on QEMU.

v2->v1:
Add SoB tags following the origin author's SoBs.

---

Liao Chang (2):
arm64: New exception mask helpers to manage DAIF, PMR and ALLINT
arm64: Deprecate the old daifflags helpers

 arch/arm64/include/asm/daifflags.h      | 144 -------------------
 arch/arm64/include/asm/exception_mask.h | 137 ++++++++++++++++++
 arch/arm64/include/asm/kvm_host.h       |   2 +-
 arch/arm64/include/asm/mmu_context.h    |   2 +-
 arch/arm64/kernel/Makefile              |   2 +-
 arch/arm64/kernel/acpi.c                |  10 +-
 arch/arm64/kernel/cpufeature.c          |   3 +
 arch/arm64/kernel/debug-monitors.c      |   6 +-
 arch/arm64/kernel/entry-common.c        |  81 +++++------
 arch/arm64/kernel/exception_mask.c      | 177 ++++++++++++++++++++++++
 arch/arm64/kernel/hibernate.c           |   6 +-
 arch/arm64/kernel/irq.c                 |   4 +-
 arch/arm64/kernel/machine_kexec.c       |   4 +-
 arch/arm64/kernel/probes/kprobes.c      |   2 +-
 arch/arm64/kernel/setup.c               |   4 +-
 arch/arm64/kernel/signal.c              |   2 +-
 arch/arm64/kernel/smp.c                 |  10 +-
 arch/arm64/kernel/suspend.c             |   6 +-
 arch/arm64/kernel/traps.c               |   2 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c         |   4 +-
 arch/arm64/kvm/hyp/vhe/switch.c         |   4 +-
 arch/arm64/mm/fault.c                   |   2 +-
 arch/arm64/mm/mmu.c                     |   6 +-
 23 files changed, 397 insertions(+), 223 deletions(-)
 delete mode 100644 arch/arm64/include/asm/daifflags.h
 create mode 100644 arch/arm64/include/asm/exception_mask.h
 create mode 100644 arch/arm64/kernel/exception_mask.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/2 arm64: New exception mask helpers to manage DAIF, PMR and ALLINT

This patch refactors the arm64 exception masking helpers to reduce complexity without any function changes, especially with the upcoming FEAT_NMI support [1]. Currently, managing differnt hardware contexts (DAIF, PMR, ALLINT) within a single set of exception mask/save/unmask/restore helpers is becoming error-prone and adds more conditional branching overhead.

To adderss this problem, this patch introduces:

1. Using a single 64bit integer to manage all hardware contexts involved in masking exceptions, maskable and non-maskable interrupts. Field 'pmr' stores a software generated value that will be written to the SYS_ICC_PMR_EL1 register when kernel uses PSEUDO_NMI. Field 'daif' stores the value of PSTATE.DAIF. It indicates any exception or interrupt is masked. Field 'allint' stores PSTATE.A when kernel uses PSEUDO_NMI, Alternatively, it stores PSTATE.ALLINT when kernel uses FEAT_NMI to indicate that arm64 superpriority interrupt(NMI) is masked.

2. Instead of one complicated function trying to handle every situation, it now has two distinct series of specialized logical exception mask helpers. Each set is designed for a specific scenario based on how the kernel is configured.

For examples:

- When NMI is not supported (CONFIG_ARM64_PSEUDO_NMI and CONFIG_ARM64_NMI [1] are not 'y'), the kernel uses the default daif_handler to manipulate DAIF only.

- With PSEUDO_NMI enabled (CONFIG_ARM64_PSEUDO_NMI=y and irqchip.gicv3_pseudo_nmi=1), the kernel uses the pmr_handler to manage both PMR and DAIF for interrupt masking. The most trick part is masking NMI mentioned above.

- For hardware NMI support (CONFIG_ARM64_NMI=y and pseudo_nmi disabled), a new cpu_exception_mask_handler could be added to manage DAIF and ALLINT for interrupt masking.

This changes make exception mask helpers more obvious what's happening in each situation. And it's easier to add support for new CPU feature in the future without adding code complexity.

With these refactor, this patch also replace the local_daif_xxx helpers used at exception entry and exit with a series abstract exception masks helpers.

[1] https://lore.kernel.org/linux-arm-kernel/Y4sH5qX5bK9xfEBp@lpieralisi/

CC Mark Brown <[email protected]>
CC Mark Rutland <[email protected]>
CC Marc Zyngier <[email protected]>
CC Jonathan Cameron <[email protected]>
---
 arch/arm64/include/asm/exception_mask.h | 137 ++++++++++++++++++
 arch/arm64/kernel/Makefile              |   2 +-
 arch/arm64/kernel/cpufeature.c          |   3 +
 arch/arm64/kernel/entry-common.c        |  79 +++++------
 arch/arm64/kernel/exception_mask.c      | 177 ++++++++++++++++++++++++
 5 files changed, 358 insertions(+), 40 deletions(-)
 create mode 100644 arch/arm64/include/asm/exception_mask.h
 create mode 100644 arch/arm64/kernel/exception_mask.c
arch/arm64/include/asm/exception_mask.h new file +137 -0
new file mode 100644
index 000000000000..46e85e4ac70d
@@ -0,0 +1,137 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2025 Huawei Ltd.
+ */
+#ifndef __ASM_EXCEPTION_MASK_H
+#define __ASM_EXCEPTION_MASK_H
+
+#include <asm/ptrace.h>
+#include <asm/sysreg.h>
+
+#define DAIF_PROCCTX		0
+#define DAIF_PROCCTX_NOIRQ	(PSR_I_BIT | PSR_F_BIT)
+#define DAIF_ERRCTX		(PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
+#define DAIF_MASK		(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
+
+union cpu_exception_mask {
+	unsigned long flags;
+	struct {
+		unsigned long pmr : 8;		// SYS_ICC_PMR_EL1
+		unsigned long daif : 10;	// PSTATE.DAIF at bits[6-9]
+		unsigned long allint : 14;	// PSTATE.ALLINT at bits[13]
+	} fields;
+};
+
+struct cpu_exception_mask_handler {
+	void (*mask)(void);             // mask all exception and interrupt
+	unsigned long (*save)(void);    // save exception and interrupt masks
+	void (*restore)(unsigned long flags); // restore exception from given masks
+};
+
+extern const union cpu_exception_mask procctx;
+extern const union cpu_exception_mask procctx_noirq;
+extern const union cpu_exception_mask errctx;
+extern struct cpu_exception_mask_handler *cpu_exception;
+int set_exception_mask_handler(int type);
+
+/*
+ * The exception masking steps for exception entry and exit:
+ *
+ * [EL0 Sync]
+ *	el0_sync_entry_exception_mask()
+ *	...
+ *	do_resume_notify()
+ *	el0_common_exit_exception_mask()
+ *
+ * [EL0 IRQ & FIQ]
+ *	irq_common_entry_exception_mask()
+ *	...
+ *	do_resume_notify()
+ *	el0_common_exit_exception_mask()
+ *
+ * [EL0 serror]
+ *	serror_entry_exception_mask()
+ *	...
+ *	el0_serror_exit_exception_mask()
+ *	do_resume_notify()
+ *	el0_exit_common_exception_mask()
+ *
+ * [EL1 Sync]
+ *	el1_sync_entry_exception_mask()
+ *	...
+ *	el1_sync_exit_exception_mask()
+ *
+ * [EL1 IRQ & FIQ]
+ *	irq_common_entry_exception_mask()
+ *
+ * [EL1 Serror]
+ *	serror_entry_exception_mask()
+ */
+static inline void el0_sync_entry_exception_mask(void)
+{
+	cpu_exception->restore(procctx.flags);
+}
+
+static inline void irq_common_entry_exception_mask(void)
+{
+	/* only mask normal interrupts and NMIs*/
+	asm volatile ("msr daifclr, #0xc" : : : "memory");
+}
+
+static inline void serror_entry_exception_mask(void)
+{
+	cpu_exception->restore(errctx.flags);
+}
+
+static inline void el0_serror_exit_exception_mask(void)
+{
+	cpu_exception->restore(procctx.flags);
+}
+
+static inline void el0_common_exit_exception_mask(void)
+{
+	cpu_exception->mask();
+}
+
+static inline void el1_sync_entry_exception_mask(struct pt_regs *regs)
+{
+	union cpu_exception_mask mask;
+
+	mask.fields.pmr = regs->pmr;
+	mask.fields.daif = regs->pstate & DAIF_MASK;
+
+	cpu_exception->restore(mask.flags);
+}
+
+static inline void el1_sync_exit_exception_mask(void)
+{
+	cpu_exception->mask();
+}
+
+static inline unsigned long local_exception_save(void)
+{
+	unsigned long flags;
+
+	flags = cpu_exception->save();
+	cpu_exception->mask();
+
+	return flags;
+}
+
+static inline unsigned long local_exception_save_flags(void)
+{
+	return cpu_exception->save();
+}
+
+/* mask/save/unmask/restore all exceptions, including interrupts. */
+static inline void local_exception_mask(void)
+{
+	cpu_exception->mask();
+}
+
+static inline void local_exception_restore(unsigned long flags)
+{
+	cpu_exception->restore(flags);
+}
+
+#endif
arch/arm64/kernel/Makefile +1 -1
index 71c29a2a2f19..b88c0f2af796 100644
@@ -34,7 +34,7 @@ obj-y			:= debug-monitors.o entry.o irq.o fpsimd.o		\
 			   cpufeature.o alternative.o cacheinfo.o		\
 			   smp.o smp_spin_table.o topology.o smccc-call.o	\
 			   syscall.o proton-pack.o idle.o patching.o pi/	\
-			   rsi.o
+			   rsi.o exception_mask.o
 
 obj-$(CONFIG_COMPAT)			+= sys32.o signal32.o			\
 					   sys_compat.o
arch/arm64/kernel/cpufeature.c +3 -0
index 9c4d6d552b25..792f599f5c4d 100644
@@ -93,6 +93,7 @@
 #include <asm/traps.h>
 #include <asm/vectors.h>
 #include <asm/virt.h>
+#include <asm/exception_mask.h>
 
 /* Kernel representation of AT_HWCAP and AT_HWCAP2 */
 static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
@@ -2290,6 +2291,8 @@ static bool can_use_gic_priorities(const struct arm64_cpu_capabilities *entry,
 	if (!cpus_have_cap(ARM64_HAS_GIC_CPUIF_SYSREGS))
 		return false;
 
+	set_exception_mask_handler(enable_pseudo_nmi ? 1 : 0);
+
 	return enable_pseudo_nmi;
 }
 
arch/arm64/kernel/entry-common.c +40 -39

281 lines not on this page · raw message

arch/arm64/kernel/exception_mask.c new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v5 2/2 arm64: Deprecate the old daifflags helpers

In reply to Liao Chang

Replacing all of the daifflags helpers used in the arm64 architecture code with the counterparts defined in exception_mask.h

CC Mark Brown <[email protected]>
CC Mark Rutland <[email protected]>
CC Marc Zyngier <[email protected]>
CC Jonathan Cameron <[email protected]>
---
 arch/arm64/include/asm/daifflags.h   | 144 ---------------------------
 arch/arm64/include/asm/kvm_host.h    |   2 +-
 arch/arm64/include/asm/mmu_context.h |   2 +-
 arch/arm64/kernel/acpi.c             |  10 +-
 arch/arm64/kernel/debug-monitors.c   |   6 +-
 arch/arm64/kernel/entry-common.c     |   2 +-
 arch/arm64/kernel/hibernate.c        |   6 +-
 arch/arm64/kernel/irq.c              |   4 +-
 arch/arm64/kernel/machine_kexec.c    |   4 +-
 arch/arm64/kernel/probes/kprobes.c   |   2 +-
 arch/arm64/kernel/setup.c            |   4 +-
 arch/arm64/kernel/signal.c           |   2 +-
 arch/arm64/kernel/smp.c              |  10 +-
 arch/arm64/kernel/suspend.c          |   6 +-
 arch/arm64/kernel/traps.c            |   2 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c      |   4 +-
 arch/arm64/kvm/hyp/vhe/switch.c      |   4 +-
 arch/arm64/mm/fault.c                |   2 +-
 arch/arm64/mm/mmu.c                  |   6 +-
 19 files changed, 39 insertions(+), 183 deletions(-)
 delete mode 100644 arch/arm64/include/asm/daifflags.h
arch/arm64/include/asm/daifflags.h deleted +0 -144
deleted file mode 100644
index fbb5c99eb2f9..000000000000
@@ -1,144 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2017 ARM Ltd.
- */
-#ifndef __ASM_DAIFFLAGS_H
-#define __ASM_DAIFFLAGS_H
-
-#include <linux/irqflags.h>
-
-#include <asm/arch_gicv3.h>
-#include <asm/barrier.h>
-#include <asm/cpufeature.h>
-#include <asm/ptrace.h>
-
-#define DAIF_PROCCTX		0
-#define DAIF_PROCCTX_NOIRQ	(PSR_I_BIT | PSR_F_BIT)
-#define DAIF_ERRCTX		(PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
-#define DAIF_MASK		(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
-
-
-/* mask/save/unmask/restore all exceptions, including interrupts. */
-static inline void local_daif_mask(void)
-{
-	WARN_ON(system_has_prio_mask_debugging() &&
-		(read_sysreg_s(SYS_ICC_PMR_EL1) == (GIC_PRIO_IRQOFF |
-						    GIC_PRIO_PSR_I_SET)));
-
-	asm volatile(
-		"msr	daifset, #0xf		// local_daif_mask\n"
-		:
-		:
-		: "memory");
-
-	/* Don't really care for a dsb here, we don't intend to enable IRQs */
-	if (system_uses_irq_prio_masking())
-		gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
-
-	trace_hardirqs_off();
-}
-
-static inline unsigned long local_daif_save_flags(void)
-{
-	unsigned long flags;
-
-	flags = read_sysreg(daif);
-
-	if (system_uses_irq_prio_masking()) {
-		/* If IRQs are masked with PMR, reflect it in the flags */
-		if (read_sysreg_s(SYS_ICC_PMR_EL1) != GIC_PRIO_IRQON)
-			flags |= PSR_I_BIT | PSR_F_BIT;
-	}
-
-	return flags;
-}
-
-static inline unsigned long local_daif_save(void)
-{
-	unsigned long flags;
-
-	flags = local_daif_save_flags();
-
-	local_daif_mask();
-
-	return flags;
-}
-
-static inline void local_daif_restore(unsigned long flags)
-{
-	bool irq_disabled = flags & PSR_I_BIT;
-
-	WARN_ON(system_has_prio_mask_debugging() &&
-		(read_sysreg(daif) & (PSR_I_BIT | PSR_F_BIT)) != (PSR_I_BIT | PSR_F_BIT));
-
-	if (!irq_disabled) {
-		trace_hardirqs_on();
-
-		if (system_uses_irq_prio_masking()) {
-			gic_write_pmr(GIC_PRIO_IRQON);
-			pmr_sync();
-		}
-	} else if (system_uses_irq_prio_masking()) {
-		u64 pmr;
-
-		if (!(flags & PSR_A_BIT)) {
-			/*
-			 * If interrupts are disabled but we can take
-			 * asynchronous errors, we can take NMIs
-			 */
-			flags &= ~(PSR_I_BIT | PSR_F_BIT);
-			pmr = GIC_PRIO_IRQOFF;
-		} else {
-			pmr = GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET;
-		}
-
-		/*
-		 * There has been concern that the write to daif
-		 * might be reordered before this write to PMR.
-		 * From the ARM ARM DDI 0487D.a, section D1.7.1
-		 * "Accessing PSTATE fields":
-		 *   Writes to the PSTATE fields have side-effects on
-		 *   various aspects of the PE operation. All of these
-		 *   side-effects are guaranteed:
-		 *     - Not to be visible to earlier instructions in
-		 *       the execution stream.
-		 *     - To be visible to later instructions in the
-		 *       execution stream
-		 *
-		 * Also, writes to PMR are self-synchronizing, so no
-		 * interrupts with a lower priority than PMR is signaled
-		 * to the PE after the write.
-		 *
-		 * So we don't need additional synchronization here.
-		 */
-		gic_write_pmr(pmr);
-	}
-
-	write_sysreg(flags, daif);
-
-	if (irq_disabled)
-		trace_hardirqs_off();
-}
-
-/*
- * Called by synchronous exception handlers to restore the DAIF bits that were
- * modified by taking an exception.
- */
-static inline void local_daif_inherit(struct pt_regs *regs)
-{
-	unsigned long flags = regs->pstate & DAIF_MASK;
-
-	if (interrupts_enabled(regs))
-		trace_hardirqs_on();
-
-	if (system_uses_irq_prio_masking())
-		gic_write_pmr(regs->pmr);
-
-	/*
-	 * We can't use local_daif_restore(regs->pstate) here as
-	 * system_has_prio_mask_debugging() won't restore the I bit if it can
-	 * use the pmr instead.
-	 */
-	write_sysreg(flags, daif);
-}
-#endif
arch/arm64/include/asm/kvm_host.h +1 -1
index 08ba91e6fb03..0af825f11efc 100644
@@ -23,7 +23,7 @@
 #include <asm/barrier.h>
 #include <asm/cpufeature.h>
 #include <asm/cputype.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/fpsimd.h>
 #include <asm/kvm.h>
 #include <asm/kvm_asm.h>
arch/arm64/include/asm/mmu_context.h +1 -1
index 0dbe3b29049b..6284ce3fd3b4 100644
@@ -19,7 +19,7 @@
 
 #include <asm/cacheflush.h>
 #include <asm/cpufeature.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/gcs.h>
 #include <asm/proc-fns.h>
 #include <asm/cputype.h>
arch/arm64/kernel/acpi.c +5 -5
index b9a66fc146c9..3f3a4ff95d5d 100644
@@ -33,7 +33,7 @@
 #include <acpi/processor.h>
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/smp_plat.h>
 
 int acpi_noirq = 1;		/* skip ACPI IRQ initialization */
@@ -397,7 +397,7 @@ int apei_claim_sea(struct pt_regs *regs)
 	if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
 		return err;
 
-	current_flags = local_daif_save_flags();
+	current_flags = local_exception_save_flags();
 
 	/* current_flags isn't useful here as daif doesn't tell us about pNMI */
 	return_to_irqs_enabled = !irqs_disabled_flags(arch_local_save_flags());
@@ -409,7 +409,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_daif_restore(DAIF_ERRCTX);
+	serror_entry_exception_mask();
 	nmi_enter();
 	err = ghes_notify_sea();
 	nmi_exit();
@@ -420,7 +420,7 @@ int apei_claim_sea(struct pt_regs *regs)
 	 */
 	if (!err) {
 		if (return_to_irqs_enabled) {
-			local_daif_restore(DAIF_PROCCTX_NOIRQ);
+			local_exception_restore(procctx_noirq.flags);
 			__irq_enter();
 			irq_work_run();
 			__irq_exit();
@@ -430,7 +430,7 @@ int apei_claim_sea(struct pt_regs *regs)
 		}
 	}
 
-	local_daif_restore(current_flags);
+	local_exception_restore(current_flags);
 
 	return err;
 }
arch/arm64/kernel/debug-monitors.c +3 -3
index 58f047de3e1c..97dc7cafccd6 100644
@@ -19,7 +19,7 @@
 
 #include <asm/cpufeature.h>
 #include <asm/cputype.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/system_misc.h>
 #include <asm/traps.h>
@@ -37,9 +37,9 @@ u8 debug_monitors_arch(void)
 static void mdscr_write(u32 mdscr)
 {
 	unsigned long flags;
-	flags = local_daif_save();
+	flags = local_exception_save();
 	write_sysreg(mdscr, mdscr_el1);
-	local_daif_restore(flags);
+	local_exception_restore(flags);
 }
 NOKPROBE_SYMBOL(mdscr_write);
 
arch/arm64/kernel/entry-common.c +1 -1
index 528d1bfbb5ed..221df3937da6 100644
@@ -16,7 +16,7 @@
 #include <linux/thread_info.h>
 
 #include <asm/cpufeature.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/esr.h>
 #include <asm/exception.h>
 #include <asm/irq_regs.h>
arch/arm64/kernel/hibernate.c +3 -3
index 18749e9a6c2d..cb1c9d00d840 100644
@@ -20,7 +20,7 @@
 #include <asm/barrier.h>
 #include <asm/cacheflush.h>
 #include <asm/cputype.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/irqflags.h>
 #include <asm/kexec.h>
 #include <asm/memory.h>
@@ -341,7 +341,7 @@ int swsusp_arch_suspend(void)
 		return -EBUSY;
 	}
 
-	flags = local_daif_save();
+	flags = local_exception_save();
 
 	if (__cpu_suspend_enter(&state)) {
 		/* make the crash dump kernel image visible/saveable */
@@ -391,7 +391,7 @@ int swsusp_arch_suspend(void)
 		spectre_v4_enable_mitigation(NULL);
 	}
 
-	local_daif_restore(flags);
+	local_exception_restore(flags);
 
 	return ret;
 }
arch/arm64/kernel/irq.c +2 -2
index 85087e2df564..f92497e9849d 100644
@@ -20,7 +20,7 @@
 #include <linux/seq_file.h>
 #include <linux/smp.h>
 #include <linux/vmalloc.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/exception.h>
 #include <asm/numa.h>
 #include <asm/softirq_stack.h>
@@ -132,6 +132,6 @@ void __init init_IRQ(void)
 		 * the PMR/PSR pair to a consistent state.
 		 */
 		WARN_ON(read_sysreg(daif) & PSR_A_BIT);
-		local_daif_restore(DAIF_PROCCTX_NOIRQ);
+		local_exception_restore(procctx_noirq.flags);
 	}
 }
arch/arm64/kernel/machine_kexec.c +2 -2
index 6f121a0164a4..e415d7a74269 100644
@@ -17,7 +17,7 @@
 
 #include <asm/cacheflush.h>
 #include <asm/cpu_ops.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/memory.h>
 #include <asm/mmu.h>
 #include <asm/mmu_context.h>
@@ -176,7 +176,7 @@ void machine_kexec(struct kimage *kimage)
 
 	pr_info("Bye!\n");
 
-	local_daif_mask();
+	local_exception_mask();
 
 	/*
 	 * Both restart and kernel_reloc will shutdown the MMU, disable data
arch/arm64/kernel/probes/kprobes.c +1 -1
index d9e462eafb95..9405d8110525 100644
@@ -23,7 +23,7 @@
 #include <linux/vmalloc.h>
 
 #include <asm/cacheflush.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/insn.h>
 #include <asm/irq.h>
arch/arm64/kernel/setup.c +2 -2
index 85104587f849..9e52c4649a43 100644
@@ -37,7 +37,7 @@
 #include <asm/fixmap.h>
 #include <asm/cpu.h>
 #include <asm/cputype.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/elf.h>
 #include <asm/cpufeature.h>
 #include <asm/cpu_ops.h>
@@ -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_daif_restore(DAIF_PROCCTX_NOIRQ);
+	local_exception_restore(procctx_noirq.flags);
 
 	/*
 	 * TTBR0 is only used for the identity mapping at this stage. Make it
arch/arm64/kernel/signal.c +1 -1
index a7c37afb4ebe..07c2950c3298 100644
@@ -21,7 +21,7 @@
 #include <linux/syscalls.h>
 #include <linux/pkeys.h>
 
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/elf.h>
 #include <asm/exception.h>
arch/arm64/kernel/smp.c +5 -5
index 3b3f6b56e733..86594601fe37 100644
@@ -42,7 +42,7 @@
 #include <asm/cpu.h>
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/kvm_mmu.h>
 #include <asm/mmu_context.h>
 #include <asm/numa.h>
@@ -271,7 +271,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_daif_restore(DAIF_PROCCTX);
+	local_exception_restore(procctx.flags);
 
 	/*
 	 * OK, it's off to the idle thread for us
@@ -378,7 +378,7 @@ void __noreturn cpu_die(void)
 
 	idle_task_exit();
 
-	local_daif_mask();
+	local_exception_mask();
 
 	/* Tell cpuhp_bp_sync_dead() that this CPU is now safe to dispose of */
 	cpuhp_ap_report_dead();
@@ -873,7 +873,7 @@ static void __noreturn local_cpu_stop(unsigned int cpu)
 {
 	set_cpu_online(cpu, false);
 
-	local_daif_mask();
+	local_exception_mask();
 	sdei_mask_local_cpu();
 	cpu_park_loop();
 }
@@ -899,7 +899,7 @@ static void __noreturn ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs
 	 * interrupt us. It's better to prevent the NMI and let the IRQ
 	 * finish since the pt_regs will be better.
 	 */
-	local_daif_mask();
+	local_exception_mask();
 
 	crash_save_cpu(regs, cpu);
 
arch/arm64/kernel/suspend.c +3 -3
index eaaff94329cd..754a56f08e66 100644
@@ -9,7 +9,7 @@
 #include <asm/cacheflush.h>
 #include <asm/cpufeature.h>
 #include <asm/cpuidle.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/exec.h>
 #include <asm/fpsimd.h>
@@ -122,7 +122,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
 	 * hardirqs should be firmly off by now. This really ought to use
 	 * something like raw_local_daif_save().
 	 */
-	flags = local_daif_save();
+	flags = local_exception_save();
 
 	/*
 	 * Function graph tracer state gets inconsistent when the kernel
@@ -168,7 +168,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
 	 * restored, so from this point onwards, debugging is fully
 	 * reenabled if it was enabled when core started shutdown.
 	 */
-	local_daif_restore(flags);
+	local_exception_restore(flags);
 
 	return ret;
 }
arch/arm64/kernel/traps.c +1 -1
index 529cff825531..62562e9fb4ba 100644
@@ -33,7 +33,7 @@
 #include <asm/atomic.h>
 #include <asm/bug.h>
 #include <asm/cpufeature.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/efi.h>
 #include <asm/esr.h>
arch/arm64/kvm/hyp/vgic-v3-sr.c +2 -2
index ed363aa3027e..2e60f61a094c 100644
@@ -437,7 +437,7 @@ u64 __vgic_v3_get_gic_config(void)
 	 * EL2.
 	 */
 	if (has_vhe())
-		flags = local_daif_save();
+		flags = local_exception_save();
 
 	/*
 	 * Table 11-2 "Permitted ICC_SRE_ELx.SRE settings" indicates
@@ -457,7 +457,7 @@ u64 __vgic_v3_get_gic_config(void)
 	isb();
 
 	if (has_vhe())
-		local_daif_restore(flags);
+		local_exception_restore(flags);
 
 	val  = (val & ICC_SRE_EL1_SRE) ? 0 : (1ULL << 63);
 	val |= read_gicreg(ICH_VTR_EL2);
arch/arm64/kvm/hyp/vhe/switch.c +2 -2
index 731a0378ed13..ea938b0d6920 100644
@@ -644,7 +644,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
 {
 	int ret;
 
-	local_daif_mask();
+	local_exception_mask();
 
 	/*
 	 * Having IRQs masked via PMR when entering the guest means the GIC
@@ -663,7 +663,7 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
 	 * local_daif_restore() takes care to properly restore PSTATE.DAIF
 	 * and the GIC PMR if the host is using IRQ priorities.
 	 */
-	local_daif_restore(DAIF_PROCCTX_NOIRQ);
+	local_exception_restore(procctx_noirq.flags);
 
 	/*
 	 * When we exit from the guest we change a number of CPU configuration
arch/arm64/mm/fault.c +1 -1
index ec0a337891dd..34441e023b58 100644
@@ -33,7 +33,7 @@
 #include <asm/cpufeature.h>
 #include <asm/efi.h>
 #include <asm/exception.h>
-#include <asm/daifflags.h>
+#include <asm/exception_mask.h>
 #include <asm/debug-monitors.h>
 #include <asm/esr.h>
 #include <asm/kprobes.h>
arch/arm64/mm/mmu.c +3 -3
index ea6695d53fb9..a712f9b02d58 100644
@@ -1533,7 +1533,7 @@ void __cpu_replace_ttbr1(pgd_t *pgdp, bool cnp)
 	typedef void (ttbr_replace_func)(phys_addr_t);
 	extern ttbr_replace_func idmap_cpu_replace_ttbr1;
 	ttbr_replace_func *replace_phys;
-	unsigned long daif;
+	unsigned long flags;
 
 	/* phys_to_ttbr() zeros lower 2 bits of ttbr with 52-bit PA */
 	phys_addr_t ttbr1 = phys_to_ttbr(virt_to_phys(pgdp));
@@ -1549,9 +1549,9 @@ void __cpu_replace_ttbr1(pgd_t *pgdp, bool cnp)
 	 * We really don't want to take *any* exceptions while TTBR1 is
 	 * in the process of being replaced so mask everything.
 	 */
-	daif = local_daif_save();
+	flags = local_exception_save();
 	replace_phys(ttbr1);
-	local_daif_restore(daif);
+	local_exception_restore(flags);
 
 	cpu_uninstall_idmap();
 }
Signature · 1 line
2.34.1