[PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow
Oliver Upton
oupton at kernel.org
Tue Dec 1 12:45:02 PST 2026
Apple's PMU appears to behave strangely in that the FIQ line level is
dependent on the event filter bits as well as the value of HCR_EL2.TGE.
This manifests as an FIQ storm when using the vPMU in sampling mode
inside of a KVM guest. Those FIQs are no longer pending by the time KVM
unmasks interrupts after changing TGE as the host event filters are
cleared.
Work around the issue by leaning into the crappiness of the underlying
hardware: pend an FIQ that will actually be taken by queueing a
self-IPI for the current CPU.
Signed-off-by: Oliver Upton <oupton at kernel.org>
---
drivers/irqchip/irq-apple-aic.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c
index 4a3141d9f914..9d658a6e21c3 100644
--- a/drivers/irqchip/irq-apple-aic.c
+++ b/drivers/irqchip/irq-apple-aic.c
@@ -554,6 +554,14 @@ static void aic_fiq_eoi(struct irq_data *d)
ARCH_TIMER_CTRL_IT_STAT)) == \
(ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_STAT))
+static bool aic_cpu_pmu_fiq_firing(void)
+{
+ u64 pmcr0 = read_sysreg_s(SYS_IMP_APL_PMCR0_EL1);
+
+ return FIELD_GET(PMCR0_IMODE, pmcr0) == PMCR0_IMODE_FIQ &&
+ pmcr0 & PMCR0_IACT;
+}
+
static void __exception_irq_entry aic_handle_fiq(struct pt_regs *regs)
{
/*
@@ -597,8 +605,7 @@ static void __exception_irq_entry aic_handle_fiq(struct pt_regs *regs)
AIC_FIQ_HWIRQ(AIC_TMR_EL02_VIRT));
}
- if ((read_sysreg_s(SYS_IMP_APL_PMCR0_EL1) & (PMCR0_IMODE | PMCR0_IACT)) ==
- (FIELD_PREP(PMCR0_IMODE, PMCR0_IMODE_FIQ) | PMCR0_IACT))
+ if (aic_cpu_pmu_fiq_firing())
generic_handle_domain_irq(aic_irqc->hw_domain,
AIC_FIQ_HWIRQ(AIC_CPU_PMU_P));
@@ -925,6 +932,25 @@ static struct gic_kvm_info vgic_info __initdata = {
.no_hw_deactivation = true,
};
+static void aic_fixup_guest_fiq_exception(void)
+{
+ lockdep_assert_irqs_disabled();
+
+ /*
+ * The line level of the PMU appears to evaluate the event filter bits
+ * (dependent on HCR_EL2.TGE) in addition to the counter overflow state.
+ * So for PMU events that exclude the host, such as those used for a vPMU,
+ * the CPU takes an FIQ exception to EL2 which is no longer pending by the
+ * time KVM unmasks interrupts.
+ *
+ * Abuse the absence of a proper irqchip behind the FIQ line and queue a
+ * self-IPI. aic_handle_fiq() will walk all FIQ sources and detect the
+ * overflowed PMU.
+ */
+ if (aic_cpu_pmu_fiq_firing())
+ aic_ipi_send_fast(smp_processor_id());
+}
+
static void build_fiq_affinity(struct aic_irq_chip *ic, struct device_node *aff)
{
int i, n;
@@ -1112,6 +1138,9 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *p
vgic_info.maint_irq = irq_create_fwspec_mapping(&mi);
WARN_ON(!vgic_info.maint_irq);
+
+ if (static_branch_likely(&use_fast_ipi))
+ vgic_info.fixup_fiq_exception = aic_fixup_guest_fiq_exception;
}
vgic_set_kvm_info(&vgic_info);
--
2.47.3
More information about the linux-arm-kernel
mailing list