From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA631606A32D for ; Tue, 1 Dec 2026 20:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=E0x1vLTQ; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DupJUu39 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=CbeKPdHQv8EExWQdgxCtrY5t1SX0qIcrzsKuN0OPn68=; b=E0x1vLTQY1rwYG +C9KT/UTuvLUnNEdG8sPMscs4qSxbSv+1bBjQR2Qn61XNjtA79LMZhZEKv+87b058nPUH/WcaD2Rh 6hb/VvydSgziut70PHy62d5Ehg9LZ63+CVcWgrCSGatVaqx4z3VDgVdsWhXNAsxEQQ35TDHi2wtpg HaVFSiY7/1Pqsw+y3OoSP8YMmwg62eNH4SD+WQvguevezazX5ES76xZd6IcKKf51HF7H2XWcj2PyC Tk1x3Z3UPmSoHilNz55tBkNHmQ5uvM3kBek6Aqbtfk2i9aHGODgRI3gkeIJlqTUUuQTWb+BXUAXWo RincC5oJIgTuO8BfOQGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYUix-00000009OHM-3Puo; Tue, 01 Dec 2026 20:45:15 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYUiu-00000009OEe-2z8c for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 20:45:12 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 2681D6194E; Tue, 1 Dec 2026 20:45:12 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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