* [PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError
@ 2026-11-25 12:26 Dan Carpenter
2026-11-25 13:52 ` Fuad Tabba
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2026-11-25 12:26 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Fuad Tabba, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
Mark Rutland
Cc: Karthik Bhargavan, Clément Blaudeau, linux-arm-kernel,
kvmarm, Dan Carpenter
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@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@pereq.eu>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError
2026-11-25 12:26 [PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError Dan Carpenter
@ 2026-11-25 13:52 ` Fuad Tabba
2026-11-27 16:23 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Fuad Tabba @ 2026-11-25 13:52 UTC (permalink / raw)
To: Dan Carpenter
Cc: Marc Zyngier, Oliver Upton, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
Mark Rutland, Karthik Bhargavan, Clément Blaudeau,
linux-arm-kernel, kvmarm
Hi Dan,
On Wed, 25 Nov 2026 12:26:47 +0000, Dan Carpenter <dan@pereq.eu> wrote:
[...]
> diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
> index 1d5dfd4b9e00..91b835bc939b 100644
[...]
> @@ -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;
Could you check PSTATE.A directly instead of calling
serror_is_masked()? That helper treats SCTLR2_EL1.NMEA=1 as unmasked,
but NMEA doesn't affect a virtual SError. With NMEA and PSTATE.A both
set, the patch would drop the access while the SError stays pending.
Checking PSTATE.A also covers protected vCPUs, since EL2 always sets A
in the host's copy of a protected vCPU's PSTATE (pvm_host_pstate()).
You can then drop the vcpu_is_protected() check. Something like:
if (!(*vcpu_cpsr(vcpu) & PSR_A_BIT))
vcpu->mmio_needed = false;
Cheers,
/fuad
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError
2026-11-25 13:52 ` Fuad Tabba
@ 2026-11-27 16:23 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2026-11-27 16:23 UTC (permalink / raw)
To: Fuad Tabba
Cc: Marc Zyngier, Oliver Upton, Joey Gouly, Steffen Eiden,
Suzuki K Poulose, Zenghui Yu, Catalin Marinas, Will Deacon,
Mark Rutland, Karthik Bhargavan, Clément Blaudeau,
linux-arm-kernel, kvmarm
On Wed, Nov 25, 2026 at 01:52:53PM +0000, Fuad Tabba wrote:
> Hi Dan,
>
> On Wed, 25 Nov 2026 12:26:47 +0000, Dan Carpenter <dan@pereq.eu> wrote:
> [...]
> > diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
> > index 1d5dfd4b9e00..91b835bc939b 100644
> [...]
> > @@ -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;
>
> Could you check PSTATE.A directly instead of calling
> serror_is_masked()? That helper treats SCTLR2_EL1.NMEA=1 as unmasked,
> but NMEA doesn't affect a virtual SError. With NMEA and PSTATE.A both
> set, the patch would drop the access while the SError stays pending.
>
> Checking PSTATE.A also covers protected vCPUs, since EL2 always sets A
> in the host's copy of a protected vCPU's PSTATE (pvm_host_pstate()).
> You can then drop the vcpu_is_protected() check. Something like:
>
> if (!(*vcpu_cpsr(vcpu) & PSR_A_BIT))
> vcpu->mmio_needed = false;
>
That obviously works. I'll send it. I wonder if it would be prettier
inside a wrapper like if (!vserror_is_masked(vcpu)) instead?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 16:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 12:26 [PATCH] KVM: arm64: Drop a pending MMIO access when injecting an unmasked SError Dan Carpenter
2026-11-25 13:52 ` Fuad Tabba
2026-11-27 16:23 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox