Re: [PATCH v20 04/14] KVM: arm64: Ensure GCS memory effects are visible
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Date: 2026-09-04 12:16:45
Also in:
kvmarm, linux-doc, linux-kselftest, lkml
On Tue, Sep 01, 2026 at 10:47:02PM +0100, Mark Brown wrote:
In order to allow efficient implementation of GCS implementations are permitted to do GCS specific caching, with barriers implicit in stack switch operations and GCSB DSYNC as an explicit barrier. Since we do not use GCS in the hypervisor or host kernel the hypervisor cannot rely on any barriers being present in vCPU context switches other than those it explicitly inserts. Add explicit barriers when loading and saving vCPU state. Signed-off-by: Mark Brown <broonie@kernel.org>
LGTM so: Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
quoted hunk ↗ jump to hunk
Reviewed-by: Yuan Yao <redacted> --- arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 7 +++++++ 2 files changed, 14 insertions(+)diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 8b080804bc90..52f53f682e6a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c@@ -755,6 +755,13 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
So this seems to be where -> vCPU unscheduled so the right place to do it.
vcpu_set_flag(vcpu, PKVM_HOST_STATE_DIRTY); } + /* + * Ensure any GCS memory effects from the outgoing vCPU are + * visible elsewhere. + */ + if (kvm_has_gcs(vcpu->kvm)) + gcsb_dsync();
Makes sense.
I did notice the curious:
static inline void gcsb_dsync(void)
{
asm volatile(".inst 0xd503227f" : : : "memory");
}
And various sludging around suggests this is HINT #19 and guaranteed to be a nop
on arches that don't implement the feature :)
quoted hunk ↗ jump to hunk
+ kvm_vcpu_put_debug(vcpu); kvm_arch_vcpu_put_fp(vcpu); if (has_vhe())diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 9a3b92e626ad..534db037c5f6 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c@@ -261,6 +261,13 @@ static void sync_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
And here similar for pKVM.
fpsimd_sve_sync(&hyp_vcpu->vcpu);
sync_debug_state(hyp_vcpu);
+ /*
+ * Ensure any GCS memory effects from the outgoing vCPU are
+ * visible elsewhere even if the host skips syncing.
+ */
+ if (kvm_has_gcs(hyp_vcpu->vcpu.kvm))
+ gcsb_dsync();
+
if (pkvm_hyp_vcpu_is_protected(hyp_vcpu)) {
host_vcpu->arch.ctxt = hyp_vcpu->vcpu.arch.ctxt;
} else {
--
2.47.3
-- Cheers, Lorenzo