Skip to content

Commit 8d474de

Browse files
wensMarc Zyngier
authored andcommitted
irqchip/gic-v3: Fix priority comparison when non-secure priorities are used
When non-secure priorities are used, compared to the raw priority set, the value read back from RPR is also right-shifted by one and the highest bit set. Add a macro to do the modifications to the raw priority when doing the comparison against the RPR value. This corrects the pseudo-NMI behavior when non-secure priorities in the GIC are used. Tested on 5.10 with the "IPI as pseudo-NMI" series [1] applied on MT8195. [1] https://lore.kernel.org/linux-arm-kernel/[email protected]/ Fixes: 3367805 ("irqchip/gic-v3: Support pseudo-NMIs when SCR_EL3.FIQ == 0") Reviewed-by: Alexandru Elisei <[email protected]> Signed-off-by: Chen-Yu Tsai <[email protected]> [maz: Added comment contributed by Alex] Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 60a1cd1 commit 8d474de

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/irqchip/irq-gic-v3.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ EXPORT_SYMBOL(gic_pmr_sync);
100100
DEFINE_STATIC_KEY_FALSE(gic_nonsecure_priorities);
101101
EXPORT_SYMBOL(gic_nonsecure_priorities);
102102

103+
/*
104+
* When the Non-secure world has access to group 0 interrupts (as a
105+
* consequence of SCR_EL3.FIQ == 0), reading the ICC_RPR_EL1 register will
106+
* return the Distributor's view of the interrupt priority.
107+
*
108+
* When GIC security is enabled (GICD_CTLR.DS == 0), the interrupt priority
109+
* written by software is moved to the Non-secure range by the Distributor.
110+
*
111+
* If both are true (which is when gic_nonsecure_priorities gets enabled),
112+
* we need to shift down the priority programmed by software to match it
113+
* against the value returned by ICC_RPR_EL1.
114+
*/
115+
#define GICD_INT_RPR_PRI(priority) \
116+
({ \
117+
u32 __priority = (priority); \
118+
if (static_branch_unlikely(&gic_nonsecure_priorities)) \
119+
__priority = 0x80 | (__priority >> 1); \
120+
\
121+
__priority; \
122+
})
123+
103124
/* ppi_nmi_refs[n] == number of cpus having ppi[n + 16] set as NMI */
104125
static refcount_t *ppi_nmi_refs;
105126

@@ -687,7 +708,7 @@ static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs
687708
return;
688709

689710
if (gic_supports_nmi() &&
690-
unlikely(gic_read_rpr() == GICD_INT_NMI_PRI)) {
711+
unlikely(gic_read_rpr() == GICD_INT_RPR_PRI(GICD_INT_NMI_PRI))) {
691712
gic_handle_nmi(irqnr, regs);
692713
return;
693714
}

0 commit comments

Comments
 (0)