[PATCH v4 07/10] irqchip/gic-v3: Improve the maintainability of NMI masking in GIC driver

From: Liao Chang
Date: Thu Jun 13 2024 - 23:53:52 EST


It has a better maintainability to use the local_nmi_enable() in GIC
driver to unmask NMI and keep regular IRQ and FIQ maskable, instead of
writing raw value into DAIF, PMR and ALLINT directly.

Signed-off-by: Liao Chang <liaochang1@xxxxxxxxxx>
---
arch/arm64/include/asm/daifflags.h | 14 ++++++++++++++
drivers/irqchip/irq-gic-v3.c | 6 ++----
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h
index b19dfd948704..4eb97241a58f 100644
--- a/arch/arm64/include/asm/daifflags.h
+++ b/arch/arm64/include/asm/daifflags.h
@@ -332,4 +332,18 @@ static inline void local_nmi_serror_enable(void)
irqflags.fields.allint = 0;
local_allint_restore_notrace(irqflags);
}
+
+/*
+ * local_nmi_enable - Enable NMI with or without superpriority.
+ */
+static inline void local_nmi_enable(void)
+{
+ if (system_uses_irq_prio_masking()) {
+ gic_pmr_mask_irqs();
+ asm volatile ("msr daifclr, #3" : : : "memory");
+ } else if (system_uses_nmi()) {
+ asm volatile ("msr daifset, #3" : : : "memory");
+ msr_pstate_allint(0);
+ }
+}
#endif
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 6fb276504bcc..ed7d8d87768f 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -33,6 +33,7 @@
#include <asm/exception.h>
#include <asm/smp_plat.h>
#include <asm/virt.h>
+#include <asm/daifflags.h>

#include "irq-gic-common.h"

@@ -813,10 +814,7 @@ static void __gic_handle_irq_from_irqson(struct pt_regs *regs)
nmi_exit();
}

- if (gic_prio_masking_enabled()) {
- gic_pmr_mask_irqs();
- gic_arch_enable_irqs();
- }
+ local_nmi_enable();

if (!is_nmi)
__gic_handle_irq(irqnr, regs);
--
2.34.1