[PATCH 2/7] KVM: arm64: Move OUTSIDE_GUEST_MODE publication past context being saved

Marc Zyngier maz at kernel.org
Thu Oct 15 06:52:05 PDT 2026


On Thu, 15 Oct 2026 13:57:13 +0100,
Fuad Tabba <fuad.tabba at linux.dev> wrote:
> 
> Hi Marc,
> 
> On Thu, 15 Oct 2026 11:05:34 +0100, Marc Zyngier <maz at kernel.org> wrote:
> [...]
> > However, code that uses OUTSIDE_GUEST_MODE as a synchronisation point
> > relies on the vcpu state to have been written back to the in-memory
> > structures. Clearly, this is not what is happening
> 
> nit: missing full stop.
> 
> [...]
> > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> [...]
> > @@ -1390,6 +1389,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
> >
> >  		kvm_arch_vcpu_ctxsync_fp(vcpu);
> >
> > +		/*
> > +		 * All the state has been synchronised, let advertise
> > +		 * we're outside of the guest.
> > +		 */
> > +		smp_store_release(&vcpu->mode, OUTSIDE_GUEST_MODE);
> 
> nit: could this say the vgic state rather than all the state? In pKVM,
> a non-protected guest's context comes back later, in
> handle_exit_pkvm_state() or on demand, and with VHE the EL1 sysregs
> stay on the CPU until vcpu_put(). Also "let's advertise".

I don't really want to make this vgic specific, as there could be
more. But I can more precisely describe what state were talking about:

diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 8b46fafdd3494..7ce9f3bfa7fff 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -1390,8 +1390,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
 		kvm_arch_vcpu_ctxsync_fp(vcpu);
 
 		/*
-		 * All the state has been synchronised, let advertise
-		 * we're outside of the guest.
+		 * The state that was pushed into the CPU on entering
+		 * the guest has been synchronised back, let's
+		 * advertise we're outside of the guest.
 		 */
 		smp_store_release(&vcpu->mode, OUTSIDE_GUEST_MODE);
 

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list