Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] KVM: arm64: Fixes for guest-only PMU event overflows on Apple Silicon
@ 2026-12-01 20:44 Oliver Upton
  2026-12-01 20:44 ` [PATCH 1/4] KVM: arm64: Track IRQ and FIQ exceptions separately Oliver Upton
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Oliver Upton @ 2026-12-01 20:44 UTC (permalink / raw)
  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, kvmarm, linux-kernel, asahi,
	linux-perf-users

A rather annoying detail of the Apple CPU PMU is that the FIQ appears to
depend on the event filter configuration / value of HCR_EL2.TGE. Events
that filter out the host ELs do not appear to drive the FIQ line when
HCR_EL2.TGE=1.

This manifests when using the vPMU for sampling inside of a KVM guest,
as the overflowed PMU generates a storm of FIQs that are no longer
pending by the time interrupts are unmasked.

This series performs a rather disgusting hack to work around the issue,
forcing a pending FIQ by performing a self-IPI when exiting due to a FIQ
and the PMU is in an interrupt condition. The mitigation works on all
implementations that support PMUv3 traps as the 'fast' IPI feature (IPIs
taken as a FIQ) long predates vPMU support.

Applies to 7.4-rc3, tested with various perf record invocations in an L1
KVM guest.

Oliver Upton (4):
  KVM: arm64: Track IRQ and FIQ exceptions separately
  perf kvm stat: Add new 'ARM_EXCEPTION_FIQ' exception type
  KVM: arm64: Let the irqchip provide a fixup for FIQs taken to EL2
  irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow

 arch/arm64/include/asm/kvm_asm.h              | 12 ++++---
 arch/arm64/kvm/arm.c                          |  5 ++-
 arch/arm64/kvm/handle_exit.c                  |  1 +
 arch/arm64/kvm/hyp/entry.S                    |  6 ++++
 arch/arm64/kvm/hyp/hyp-entry.S                |  6 +++-
 arch/arm64/kvm/hyp/include/hyp/switch.h       |  4 +--
 arch/arm64/kvm/hyp/nvhe/hyp-main.c            |  2 ++
 arch/arm64/kvm/vgic/vgic-init.c               |  6 ++++
 arch/arm64/kvm/vgic/vgic.h                    |  9 +++++
 drivers/irqchip/irq-apple-aic.c               | 33 +++++++++++++++++--
 include/kvm/arm_vgic.h                        |  4 +++
 include/linux/irqchip/arm-vgic-info.h         |  3 ++
 .../kvm-stat-arch/arm64_exception_types.h     |  2 ++
 13 files changed, 83 insertions(+), 10 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.47.3



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] KVM: arm64: Track IRQ and FIQ exceptions separately
  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 ` Oliver Upton
  2026-12-01 20:45 ` [PATCH 2/4] perf kvm stat: Add new 'ARM_EXCEPTION_FIQ' exception type Oliver Upton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2026-12-01 20:44 UTC (permalink / raw)
  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, kvmarm, linux-kernel, asahi,
	linux-perf-users

Use separate exception codes for IRQs and FIQs so KVM can apply an
FIQ-specific workaround on broken hardware.

Signed-off-by: Oliver Upton <oupton@kernel.org>
---
 arch/arm64/include/asm/kvm_asm.h        | 12 ++++++++----
 arch/arm64/kvm/arm.c                    |  2 +-
 arch/arm64/kvm/handle_exit.c            |  1 +
 arch/arm64/kvm/hyp/entry.S              |  6 ++++++
 arch/arm64/kvm/hyp/hyp-entry.S          |  6 +++++-
 arch/arm64/kvm/hyp/include/hyp/switch.h |  4 ++--
 arch/arm64/kvm/hyp/nvhe/hyp-main.c      |  2 ++
 7 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index abda476e023d..6c9103e29e9e 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -12,15 +12,18 @@
 #include <asm/virt.h>
 #include <asm/sysreg.h>
 
-#define ARM_EXIT_WITH_SERROR_BIT  31
-#define ARM_EXCEPTION_CODE(x)	  ((x) & ~(1U << ARM_EXIT_WITH_SERROR_BIT))
-#define ARM_EXCEPTION_IS_TRAP(x)  (ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_TRAP)
-#define ARM_SERROR_PENDING(x)	  !!((x) & (1U << ARM_EXIT_WITH_SERROR_BIT))
+#define ARM_EXIT_WITH_SERROR_BIT  	31
+#define ARM_EXCEPTION_CODE(x)	  	((x) & ~(1U << ARM_EXIT_WITH_SERROR_BIT))
+#define ARM_EXCEPTION_IS_TRAP(x)  	(ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_TRAP)
+#define ARM_EXCEPTION_IS_INTERRUPT(x)	((ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_IRQ) || \
+					 (ARM_EXCEPTION_CODE((x)) == ARM_EXCEPTION_FIQ))
+#define ARM_SERROR_PENDING(x)	  	!!((x) & (1U << ARM_EXIT_WITH_SERROR_BIT))
 
 #define ARM_EXCEPTION_IRQ	  0
 #define ARM_EXCEPTION_EL1_SERROR  1
 #define ARM_EXCEPTION_TRAP	  2
 #define ARM_EXCEPTION_IL	  3
+#define ARM_EXCEPTION_FIQ	  4
 /* The hyp-stub will return this for any kvm_call_hyp() call */
 #define ARM_EXCEPTION_HYP_GONE	  HVC_STUB_ERR
 
@@ -28,6 +31,7 @@
 	{ARM_EXCEPTION_IRQ,		"IRQ"		},	\
 	{ARM_EXCEPTION_EL1_SERROR, 	"SERROR"	},	\
 	{ARM_EXCEPTION_TRAP, 		"TRAP"		},	\
+	{ARM_EXCEPTION_FIQ,		"FIQ"		},	\
 	{ARM_EXCEPTION_HYP_GONE,	"HYP_GONE"	}
 
 /*
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 157bf4b81202..a6123defd7e6 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1547,7 +1547,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		 * context synchronization event) is necessary to ensure that
 		 * pending interrupts are taken.
 		 */
-		if (ARM_EXCEPTION_CODE(ret) == ARM_EXCEPTION_IRQ) {
+		if (ARM_EXCEPTION_IS_INTERRUPT(ret)) {
 			local_irq_enable();
 			isb();
 			local_irq_disable();
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index 9931192735d4..c0b5c6460ded 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -459,6 +459,7 @@ int handle_exit(struct kvm_vcpu *vcpu, int exception_index)
 
 	switch (exception_index) {
 	case ARM_EXCEPTION_IRQ:
+	case ARM_EXCEPTION_FIQ:
 		return 1;
 	case ARM_EXCEPTION_EL1_SERROR:
 		return 1;
diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S
index 9709905f21b5..7d38bae49d31 100644
--- a/arch/arm64/kvm/hyp/entry.S
+++ b/arch/arm64/kvm/hyp/entry.S
@@ -48,7 +48,13 @@ alternative_else_nop_endif
 	// synchronization event so that callers don't need ISBs for anything
 	// that would usually be synchronized by the ERET.
 	isb
+
+	// Both a FIQ and IRQ could be pending. Arbitrarily give precedence
+	// to reporting a pending FIQ.
 	mov	x0, #ARM_EXCEPTION_IRQ
+	mov	x2, #ARM_EXCEPTION_FIQ
+	tst	x1, #ISR_EL1_F
+	csel	x0, x2, x0, ne
 	ret
 
 1:
diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S
index 03f97d71984c..66fd9e78ad25 100644
--- a/arch/arm64/kvm/hyp/hyp-entry.S
+++ b/arch/arm64/kvm/hyp/hyp-entry.S
@@ -80,11 +80,15 @@ el1_trap:
 	b	__guest_exit
 
 el1_irq:
-el1_fiq:
 	get_vcpu_ptr	x1, x0
 	mov	x0, #ARM_EXCEPTION_IRQ
 	b	__guest_exit
 
+el1_fiq:
+	get_vcpu_ptr	x1, x0
+	mov	x0, #ARM_EXCEPTION_FIQ
+	b	__guest_exit
+
 el1_error:
 	get_vcpu_ptr	x1, x0
 	mov	x0, #ARM_EXCEPTION_EL1_SERROR
diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index e0c55644224c..900515ac99cb 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -923,11 +923,11 @@ static inline void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu)
 static inline bool __fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code,
 				      const exit_handler_fn *handlers)
 {
-	if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ)
+	if (!ARM_EXCEPTION_IS_INTERRUPT(*exit_code))
 		vcpu->arch.fault.esr_el2 = read_sysreg_el2(SYS_ESR);
 
 	if (ARM_SERROR_PENDING(*exit_code) &&
-	    ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ) {
+	    !ARM_EXCEPTION_IS_INTERRUPT(*exit_code)) {
 		u8 esr_ec = kvm_vcpu_trap_get_class(vcpu);
 
 		/*
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 179d7c8277b8..c12a0d68862f 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -732,6 +732,7 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
 
 	switch (ARM_EXCEPTION_CODE(hyp_vcpu->exit_code)) {
 	case ARM_EXCEPTION_IRQ:
+	case ARM_EXCEPTION_FIQ:
 	case ARM_EXCEPTION_EL1_SERROR:
 	case ARM_EXCEPTION_IL:
 		break;
@@ -787,6 +788,7 @@ static void sync_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu, u32 exit_reason)
 
 	switch (ARM_EXCEPTION_CODE(exit_reason)) {
 	case ARM_EXCEPTION_IRQ:
+	case ARM_EXCEPTION_FIQ:
 		break;
 	case ARM_EXCEPTION_TRAP:
 		/* SError pending: not handled at EL2, the guest replays it. */
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] perf kvm stat: Add new 'ARM_EXCEPTION_FIQ' exception type
  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 ` 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 ` [PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow Oliver Upton
  3 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2026-12-01 20:45 UTC (permalink / raw)
  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, kvmarm, linux-kernel, asahi,
	linux-perf-users

Align the tools definition with the corresponding kernel definition.

Signed-off-by: Oliver Upton <oupton@kernel.org>
---
 tools/perf/util/kvm-stat-arch/arm64_exception_types.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/kvm-stat-arch/arm64_exception_types.h b/tools/perf/util/kvm-stat-arch/arm64_exception_types.h
index bf827f19ace0..7dafd0fc941e 100644
--- a/tools/perf/util/kvm-stat-arch/arm64_exception_types.h
+++ b/tools/perf/util/kvm-stat-arch/arm64_exception_types.h
@@ -10,6 +10,7 @@
 #define ARM_EXCEPTION_EL1_SERROR	1
 #define ARM_EXCEPTION_TRAP		2
 #define ARM_EXCEPTION_IL		3
+#define ARM_EXCEPTION_FIQ		4
 /* The hyp-stub will return this for any kvm_call_hyp() call */
 #define ARM_EXCEPTION_HYP_GONE		HVC_STUB_ERR
 
@@ -18,6 +19,7 @@
 	{ARM_EXCEPTION_EL1_SERROR,	"SERROR"	},	\
 	{ARM_EXCEPTION_TRAP,		"TRAP"		},	\
 	{ARM_EXCEPTION_IL,		"ILLEGAL"	},	\
+	{ARM_EXCEPTION_FIQ,		"FIQ"		},	\
 	{ARM_EXCEPTION_HYP_GONE,	"HYP_GONE"	}
 
 /* Per asm/esr.h */
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] KVM: arm64: Let the irqchip provide a fixup for FIQs taken to EL2
  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 ` Oliver Upton
  2026-12-01 20:45 ` [PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow Oliver Upton
  3 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2026-12-01 20:45 UTC (permalink / raw)
  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, kvmarm, linux-kernel, asahi,
	linux-perf-users

Certain implementations suffer from disappearing FIQs which are no
longer pending by the time KVM unmasks interrupts. That's no good; give
the irqchip a hook to intervene on FIQ exceptions taken from the guest.

Signed-off-by: Oliver Upton <oupton@kernel.org>
---
 arch/arm64/kvm/arm.c                  | 3 +++
 arch/arm64/kvm/vgic/vgic-init.c       | 6 ++++++
 arch/arm64/kvm/vgic/vgic.h            | 9 +++++++++
 include/kvm/arm_vgic.h                | 4 ++++
 include/linux/irqchip/arm-vgic-info.h | 3 +++
 5 files changed, 25 insertions(+)

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a6123defd7e6..e69e23b1541b 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1537,6 +1537,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		 */
 		smp_store_release(&vcpu->mode, OUTSIDE_GUEST_MODE);
 
+		/* Fixup a borked asynchronous exception before unmasking IRQs */
+		vgic_fixup_async_exception(ret);
+
 		/*
 		 * We must ensure that any pending interrupts are taken before
 		 * we exit guest timing so that timer ticks are accounted as
diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
index c9991e24cb6b..c44066d8419e 100644
--- a/arch/arm64/kvm/vgic/vgic-init.c
+++ b/arch/arm64/kvm/vgic/vgic-init.c
@@ -912,6 +912,12 @@ int kvm_vgic_hyp_init(void)
 		ret = -ENODEV;
 	}
 
+	if (gic_kvm_info->fixup_fiq_exception) {
+		kvm_vgic_global_state.fixup_fiq_exception = gic_kvm_info->fixup_fiq_exception;
+		static_branch_enable(&kvm_vgic_global_state.needs_fiq_exception_fixup);
+		kvm_info("irqchip requires FIQ exception fixup\n");
+	}
+
 	kvm_vgic_global_state.maint_irq = gic_kvm_info->maint_irq;
 
 out_free:
diff --git a/arch/arm64/kvm/vgic/vgic.h b/arch/arm64/kvm/vgic/vgic.h
index 97fc3bdf520e..d4fcc6f2fe97 100644
--- a/arch/arm64/kvm/vgic/vgic.h
+++ b/arch/arm64/kvm/vgic/vgic.h
@@ -536,4 +536,13 @@ static inline bool vgic_supports_direct_irqs(struct kvm *kvm)
 int vgic_its_debug_init(struct kvm_device *dev);
 void vgic_its_debug_destroy(struct kvm_device *dev);
 
+static inline void vgic_fixup_async_exception(int ret)
+{
+	if (!static_branch_unlikely(&kvm_vgic_global_state.needs_fiq_exception_fixup))
+		return;
+
+	if (ARM_EXCEPTION_CODE(ret) == ARM_EXCEPTION_FIQ)
+		kvm_vgic_global_state.fixup_fiq_exception();
+}
+
 #endif
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index 4b2c41917b77..962ca522831c 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -202,6 +202,10 @@ struct vgic_global {
 	/* GICv3 system register CPU interface */
 	struct static_key_false gicv3_cpuif;
 
+	/* Hot garbage irqchip that loses FIQs */
+	struct static_key_false needs_fiq_exception_fixup;
+	void			(*fixup_fiq_exception)(void);
+
 	/* GICv3 compat mode on a GICv5 host */
 	bool			has_gcie_v3_compat;
 
diff --git a/include/linux/irqchip/arm-vgic-info.h b/include/linux/irqchip/arm-vgic-info.h
index f05370e2debf..67d36d4b6214 100644
--- a/include/linux/irqchip/arm-vgic-info.h
+++ b/include/linux/irqchip/arm-vgic-info.h
@@ -43,6 +43,9 @@ struct gic_kvm_info {
 		void __iomem	*base;
 		bool		non_coherent;
 	}		gicv5_irs;
+
+	/* Disappearing FIQs, need to rematerialize */
+	void		(*fixup_fiq_exception)(void);
 };
 
 #ifdef CONFIG_KVM
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow
  2026-12-01 20:44 [PATCH 0/4] KVM: arm64: Fixes for guest-only PMU event overflows on Apple Silicon Oliver Upton
                   ` (2 preceding siblings ...)
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2026-12-01 20:45 UTC (permalink / raw)
  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, kvmarm, linux-kernel, asahi,
	linux-perf-users

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 4/4] irqchip/apple-aic: Work around FIQ storms upon vPMU counter overflow Oliver Upton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox