[PATCH] KVM: arm64: nv: Reset MMIO state when committing a nested exception

Dan Carpenter dan at pereq.eu
Mon Nov 23 01:47:42 PST 2026


KVM has two ways to commit a pending exception, commit_pending_events()
which also resets the MMIO emulation state, and a direct call to
__kvm_adjust_pc() which doesn't.  The EL1 to EL2 path in
kvm_inject_nested() uses __kvm_adjust_pc(), but it needs to use
commit_pending_events() instead.

The scenario is: the vcpu exits to userspace for an MMIO access and
userspace then injects a synchronous external abort or an SError using
the KVM_SET_VCPU_EVENTS ioctl.  If the vcpu is in L2 context and L1 has
asked for the exception, then kvm_inject_nested() enters the exception
straight away and vcpu->mmio_needed stays set.  On the next KVM_RUN,
kvm_handle_mmio_return() completes the access in L1's context so it
skips the first instruction of L1's exception vector and writes the
MMIO data to one of L1's registers.

Replace the __kvm_adjust_pc() with commit_pending_events() so that the
MMIO emulation state is cleared.

Reported-by: Sashiko <sashiko-bot at kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-221074@kernel.org/
Fixes: 9aba641b9ec2 ("KVM: arm64: nv: Respect exception routing rules for SEAs")
Fixes: 77ee70a07357 ("KVM: arm64: nv: Honor SError exception routing / masking")
Cc: stable at vger.kernel.org
Signed-off-by: Dan Carpenter <dan at pereq.eu>
---
 arch/arm64/include/asm/kvm_host.h | 1 +
 arch/arm64/kvm/emulate-nested.c   | 2 +-
 arch/arm64/kvm/guest.c            | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 0614c3b3a40d..c75b0c623824 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1354,6 +1354,7 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 
 int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
 			      struct kvm_vcpu_events *events);
+void commit_pending_events(struct kvm_vcpu *vcpu);
 
 void kvm_arm_halt_guest(struct kvm *kvm);
 void kvm_arm_resume_guest(struct kvm *kvm);
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index 39136a89d74b..5a7019bb719b 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -2921,7 +2921,7 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
 	 * Make sure the exception actually took place before we load
 	 * the new context.
 	 */
-	__kvm_adjust_pc(vcpu);
+	commit_pending_events(vcpu);
 
 	kvm_arch_vcpu_load(vcpu, smp_processor_id());
 	vcpu_clear_flag(vcpu, IN_NESTED_EXCEPTION);
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index ba4570c52a91..b7d36c2abfdf 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -770,7 +770,7 @@ int __kvm_arm_vcpu_get_events(struct kvm_vcpu *vcpu,
 	return 0;
 }
 
-static void commit_pending_events(struct kvm_vcpu *vcpu)
+void commit_pending_events(struct kvm_vcpu *vcpu)
 {
 	if (!vcpu_get_flag(vcpu, PENDING_EXCEPTION))
 		return;

---
base-commit: 5a7235e9adff42aa043ac9473dbeb0354dca0967
change-id: 20261120-stale_mmio-a33a67733b65

Best regards,
--  
Dan Carpenter <dan at pereq.eu>




More information about the linux-arm-kernel mailing list