Re: [RFC PATCH 06/36] arm64: irq: introduce a helper for GIC priority initialization
From: Vladimir Murzin <hidden>
Date: 2026-07-14 10:02:43
On 7/10/26 08:44, Jinjie Ruan wrote:
On 7/9/2026 8:13 PM, Vladimir Murzin wrote:quoted
From: Ada Couprie Diaz <redacted> Arm64's `init_IRQ()` calls `local_daif_restore()` to synchronize interrupt masking via DAIF and switch to masking via PMR. This depends on a very specific behaviour of `local_daif_restore()` which will clear DAIF if masking interrupts via PMR, which will get removed in the future. As `setup_arch()` cleared DA only earlier, introduce a dedicated helper that explicitly initializes the PMR to mask interrupts and clears DAIF, switching to IRQ priority masking. Given it is a dedicated helper, add a lockdep assertion as `setup_arch()` should always have called `trace_hardirqs_off()` when clearing DA, otherwise something bad happened. Signed-off-by: Ada Couprie Diaz <redacted> Signed-off-by: Vladimir Murzin <redacted> --- arch/arm64/include/asm/daifflags.h | 15 +++++++++++++++ arch/arm64/kernel/irq.c | 7 +++---- 2 files changed, 18 insertions(+), 4 deletions(-)diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h index 795b35128467..56341578e7e3 100644 --- a/arch/arm64/include/asm/daifflags.h +++ b/arch/arm64/include/asm/daifflags.h@@ -141,4 +141,19 @@ static __always_inline void local_daif_inherit(struct pt_regs *regs) */ write_sysreg(flags, daif); } + +/* + * During early boot, we unmask PSR.DA before the GIC has been set up. + * If we use IRQ priority masking, the PMR and PSR will be out of sync + * after the GIC is enabled : sync them up. + */ +static inline void local_interrupt_priority_init(void)Maybe switch_to_pmr_masking()?
I have no strong opinion on that, tbh. Having another look at the code made me think that this helper has only a single caller. Perhaps we should move the system_uses_irq_prio_masking() check from the caller into the helper, making it clear that the helper is specific to pNMI without having to inspect the call site. What do you reckon?
quoted
+{ + WARN_ON(read_sysreg(daif) & PSR_A_BIT); + lockdep_assert_irqs_disabled(); + + gic_write_pmr(GIC_PRIO_IRQOFF); + write_sysreg(DAIF_PROCCTX, daif);otherwise LGTM Reviewed-by: Jinjie Ruan <redacted>
Thanks! Vladimir
quoted
+} + #endifdiff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c index 9fafd826002b..c73faa30268d 100644 --- a/arch/arm64/kernel/irq.c +++ b/arch/arm64/kernel/irq.c@@ -126,10 +126,9 @@ void __init init_IRQ(void) if (system_uses_irq_prio_masking()) { /* - * Now that we have a stack for our IRQ handler, set - * the PMR/PSR pair to a consistent state. + * Now that we have a stack for our IRQ handler, + * let's mask interrupts via the PMR. */ - WARN_ON(read_sysreg(daif) & PSR_A_BIT); - local_daif_restore(DAIF_PROCCTX_NOIRQ); + local_interrupt_priority_init(); } }