From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796157912; b=T8Zw0KmESX9i0TXxVq5gQVFpJxmiGq42StgJ1PYQwofBeLjr6lHnD0vaRFZV6A2r2x8q xnYaXLIX9jTmFWtKKqNH7zH/c4upn39bLMvDK34nBcJXRpu/k92eEnahSpat2S9eJ22Yf TFuNiNmKAUVsWm9Xiu5B1gCloSeeQ01Mcc/+tBl2qH+aM+bd1NE2UTpLOH8Hj+JIZMRVI 7+KUQDos0prF4ua4eMpfq8IxGiObmYvr91jbEmIt09sGtSarTa4A5tM3/ydNQPtUtD8Cc aW6cXbYM6wjGntm2hrPrx3m1aSVdQxOLngKcQi4n1ZQQT/d5SDQcwWdZiylY8WaEThA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796157912; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=CbeKPdHQv8EExWQdgxCtrY5t1SX0qIcrzsKuN0OPn68=; b=eyW2thC2YSASYDMh+2joprsSGcj+pNX/ekodPsgWc4gr5vIDi1vH8lAzy46QlB13+jYG 3FVc57T4iOaQJxxdeTBlaD4fJxgHWgOEHbVxT4z64NMHE4LVC8h16EHyn3ROyM/v0oI1R iBEIV2OfJNNYnClNQghaeeh490RbY9n2suWMPBUvcoflbHBNWxcG+sbuzAY+NVgWju9U3 LDHhlwiYNMJeqb1sl77Uea1Vxrp75MofFoImPKBswNOeiePYPxM6lds0knCs7gNWWRz1n h5XBCgFH6syEWW/UEK8V/VeAXI8U94s27pnMeIbM9LyZObFPsYWLZEgrOwuXdd7LmCA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DupJUu39; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AAEE606A6A8; Tue, 1 Dec 2026 20:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DupJUu39 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7700E1F0089A; Tue, 1 Dec 2026 20:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796157911; bh=CbeKPdHQv8EExWQdgxCtrY5t1SX0qIcrzsKuN0OPn68=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DupJUu39ZvV6ZJ6an+tU7wupaLAvKu0Ts2+18Jb/xyBceA5bWs1WO1Mi0u9ZBd/Ua TJ6TJuagvLgtIo4sca1e+Wta4V8E3RivT87OqCwPyJj3dbqPKtGhFvZBwn6aPddWWh xg4oS1tgXJ8vDCRTjdZ2feXiY4gEjiiLIhtOXIOU/dSO0UY7UcqagURLEGQ+ZMTajq XwM7XoTQzFc1kKaSNqcu5kmETLSi2xgjKqKHOCi9N7VoSlpmmmzdfBpGkS092+2snB Z1b4CWTUkEqf9R/r6RhdZTKtNAIecq3aBXuEDn5SzpnLZKKYxtIlxtWdjYkiWIK0eq hnsVl3IWcWVAQ== From: Oliver Upton To: Marc Zyngier , Oliver Upton , Catalin Marinas , Will Deacon , Sven Peter , Janne Grunau , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim Cc: Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Neal Gompa , Radu Rendec , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , 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 Message-ID: <20261201204502.1813335-5-oupton@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201204502.1813335-1-oupton@kernel.org> References: <20261201204502.1813335-1-oupton@kernel.org> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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