Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@kernel.org>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Sven Peter <sven@kernel.org>,
	Janne Grunau <j@jannau.net>, Thomas Gleixner <tglx@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Mark Rutland <mark.rutland@arm.com>, Neal Gompa <neal@gompa.dev>,
	Radu Rendec <radu@rendec.net>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, asahi@lists.linux.dev,
	linux-perf-users@vger.kernel.org
Subject: [PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow
Date: Tue,  1 Dec 2026 12:45:02 -0800	[thread overview]
Message-ID: <20261201204502.1813335-5-oupton@kernel.org> (raw)
In-Reply-To: <20261201204502.1813335-1-oupton@kernel.org>

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@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



      parent reply	other threads:[~2026-12-01 20:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 20:44 [PATCH 0/4] KVM: arm64: Fixes for guest-only PMU event overflows on Apple Silicon Oliver Upton
2026-12-01 20:44 ` [PATCH 1/4] KVM: arm64: Track IRQ and FIQ exceptions separately Oliver Upton
2026-12-01 20:45 ` [PATCH 2/4] perf kvm stat: Add new 'ARM_EXCEPTION_FIQ' exception type Oliver Upton
2026-12-01 20:45 ` [PATCH 3/4] KVM: arm64: Let the irqchip provide a fixup for FIQs taken to EL2 Oliver Upton
2026-12-01 20:45 ` Oliver Upton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201204502.1813335-5-oupton@kernel.org \
    --to=oupton@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=asahi@lists.linux.dev \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=irogers@google.com \
    --cc=j@jannau.net \
    --cc=james.clark@linaro.org \
    --cc=joey.gouly@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=neal@gompa.dev \
    --cc=peterz@infradead.org \
    --cc=radu@rendec.net \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=sven@kernel.org \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox