[PATCH 1/4] KVM: arm64: Track IRQ and FIQ exceptions separately

Oliver Upton oupton at kernel.org
Tue Dec 1 12:44:59 PST 2026


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




More information about the linux-arm-kernel mailing list