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 1/4] KVM: arm64: Track IRQ and FIQ exceptions separately
Date: Tue, 1 Dec 2026 12:44:59 -0800 [thread overview]
Message-ID: <20261201204502.1813335-2-oupton@kernel.org> (raw)
In-Reply-To: <20261201204502.1813335-1-oupton@kernel.org>
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
next prev parent reply other threads:[~2026-12-01 20:45 UTC|newest]
Thread overview: 6+ 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 ` Oliver Upton [this message]
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
2026-12-01 20:51 ` [PATCH 0/4] KVM: arm64: Fixes for guest-only PMU event overflows on Apple Silicon sashiko-bot
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-2-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