Skip to content

Commit 382e6e1

Browse files
author
Marc Zyngier
committed
irqchip/gic-v3: Workaround inconsistent PMR setting on NMI entry
The arm64 entry code suffers from an annoying issue on taking a NMI, as it sets PMR to a value that actually allows IRQs to be acknowledged. This is done for consistency with other parts of the code, and is in the process of being fixed. This shouldn't be a problem, as we are not enabling interrupts whilst in NMI context. However, in the infortunate scenario that we took a spurious NMI (retired before the read of IAR) *and* that there is an IRQ pending at the same time, we'll ack the IRQ in NMI context. Too bad. In order to avoid deadlocks while running something like perf, teach the GICv3 driver about this situation: if we were in a context where no interrupt should have fired, transiently set PMR to a value that only allows NMIs before acking the pending interrupt, and restore the original value after that. This papers over the core issue for the time being, and makes NMIs great again. Sort of. Fixes: 4d6a38d ("arm64: entry: always set GIC_PRIO_PSR_I_SET during entry") Co-developed-by: Mark Rutland <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]
1 parent d07f6ca commit 382e6e1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

drivers/irqchip/irq-gic-v3.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,45 @@ static inline void gic_handle_nmi(u32 irqnr, struct pt_regs *regs)
642642
nmi_exit();
643643
}
644644

645+
static u32 do_read_iar(struct pt_regs *regs)
646+
{
647+
u32 iar;
648+
649+
if (gic_supports_nmi() && unlikely(!interrupts_enabled(regs))) {
650+
u64 pmr;
651+
652+
/*
653+
* We were in a context with IRQs disabled. However, the
654+
* entry code has set PMR to a value that allows any
655+
* interrupt to be acknowledged, and not just NMIs. This can
656+
* lead to surprising effects if the NMI has been retired in
657+
* the meantime, and that there is an IRQ pending. The IRQ
658+
* would then be taken in NMI context, something that nobody
659+
* wants to debug twice.
660+
*
661+
* Until we sort this, drop PMR again to a level that will
662+
* actually only allow NMIs before reading IAR, and then
663+
* restore it to what it was.
664+
*/
665+
pmr = gic_read_pmr();
666+
gic_pmr_mask_irqs();
667+
isb();
668+
669+
iar = gic_read_iar();
670+
671+
gic_write_pmr(pmr);
672+
} else {
673+
iar = gic_read_iar();
674+
}
675+
676+
return iar;
677+
}
678+
645679
static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
646680
{
647681
u32 irqnr;
648682

649-
irqnr = gic_read_iar();
683+
irqnr = do_read_iar(regs);
650684

651685
/* Check for special IDs first */
652686
if ((irqnr >= 1020 && irqnr <= 1023))

0 commit comments

Comments
 (0)