[PATCH v18 04/14] KVM: arm64: Ensure GCS memory effects are visible
Yao Yuan
yaoyuan at linux.alibaba.com
Thu Aug 6 01:25:16 PDT 2026
On Mon, Aug 03, 2026 at 11:56:49PM +0800, 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.
>
Reviewed-by: Yuan Yao <yaoyuan at linux.alibaba.com>
> Signed-off-by: Mark Brown <broonie at kernel.org>
> ---
> arch/arm64/kvm/hyp/nvhe/switch.c | 13 +++++++++++++
> arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 14 ++++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
> index 7318e3e6a5f3..fe8727bf2833 100644
> --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> @@ -301,6 +301,12 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> */
> dsb(nsh);
>
> + /*
> + * Ensure any GCS memory effects are visible to this CPU.
> + */
> + if (ctxt_has_gcs(guest_ctxt))
> + gcsb_dsync();
> +
> __kvm_adjust_pc(vcpu);
>
> /*
> @@ -345,6 +351,13 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> */
> dsb(nsh);
>
> + /*
> + * Ensure any GCS memory effects from the outgoing vCPU are
> + * visible elsewhere.
> + */
> + if (ctxt_has_gcs(guest_ctxt))
> + gcsb_dsync();
> +
> __deactivate_traps(vcpu);
> __load_host_stage2();
>
> diff --git a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
> index 2431c18f5792..4594992b008c 100644
> --- a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
> +++ b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
> @@ -239,6 +239,13 @@ void __vcpu_load_switch_sysregs(struct kvm_vcpu *vcpu)
> if (vcpu_has_nv(vcpu))
> dsb(nsh);
>
> + /*
> + * Ensure any GCS memory effects are visible to the incoming
> + * vCPU.
> + */
> + if (ctxt_has_gcs(guest_ctxt))
> + gcsb_dsync();
> +
> /*
> * Load guest EL1 and user state
> *
> @@ -299,5 +306,12 @@ void __vcpu_put_switch_sysregs(struct kvm_vcpu *vcpu)
> /* Restore host user state */
> __sysreg_restore_user_state(host_ctxt);
>
> + /*
> + * Ensure any GCS memory effects from the outgoing vCPU are
> + * visible elsewhere.
> + */
> + if (ctxt_has_gcs(guest_ctxt))
> + gcsb_dsync();
> +
> vcpu_clear_flag(vcpu, SYSREGS_ON_CPU);
> }
>
> --
> 2.47.3
>
More information about the linux-arm-kernel
mailing list