[PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError

Dan Carpenter dan at pereq.eu
Wed Nov 25 04:26:47 PST 2026


Oliver's commit bfb7a30b1986 ("KVM: arm64: Don't retire MMIO instruction
w/ pending (emulated) SError") established the rule that when userspace
injects an SError that we drop the MMIO.  An MMIO access dropped this way
runs again when the guest returns from the SError.

However, since commit 3bd107ed6b23 ("KVM: arm64: Only emulate an SError's
entry for vCPUs with NV"), a vcpu without EL2 pends the SError through
HCR_EL2.VSE instead.  The next KVM_RUN completes the access, and then
the guest takes the SError.  So the behavior is not consistent depending
on whether the vcpu has EL2 (MMIO dropped) or not (MMIO completes).

To make things consistent, drop the pending MMIO access in the non-EL2
case as well.

This change only affects unmasked SErrors, if they are masked the MMIO
always completes.  Protected vcpus are left alone, because the host's
copy of their PSTATE can't be trusted.

I discovered this inconsistency while writing a selftest and I don't
believe real life users have noticed it.

Fixes: 3bd107ed6b23 ("KVM: arm64: Only emulate an SError's entry for vCPUs with NV")
Signed-off-by: Dan Carpenter <dan at pereq.eu>
---
I think this patch is correct but it's also easy enough to modify my
selftest to accept the current behavior.
---
 arch/arm64/kvm/inject_fault.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
index 1d5dfd4b9e00..91b835bc939b 100644
--- a/arch/arm64/kvm/inject_fault.c
+++ b/arch/arm64/kvm/inject_fault.c
@@ -396,6 +396,14 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)
 		return 1;
 	}
 
+	/*
+	 * Like the emulated entry above, an unmasked SError cancels the MMIO
+	 * access the vcpu exited on.  The host's copy of a protected vcpu's
+	 * PSTATE is stale so checking serror_is_masked() doesn't make sense.
+	 */
+	if (!vcpu_is_protected(vcpu) && !serror_is_masked(vcpu))
+		vcpu->mmio_needed = false;
+
 	vcpu_set_vsesr(vcpu, esr & ESR_ELx_ISS_MASK);
 	*vcpu_hcr(vcpu) |= HCR_EL2_VSE;
 	return 1;

---
base-commit: 4a1b7259e337e8a2ea999436b47151a75c7572dc
change-id: 20261125-serror-drop-mmio-1bf42dd8841c

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




More information about the linux-arm-kernel mailing list