Re: [PATCH] KVM: VMX: add memory clobber to asm for VMX instructions
From: Sean Christopherson
Date: Tue Jul 21 2026 - 13:13:04 EST
On Tue, Jul 21, 2026, Paolo Bonzini wrote:
> VMCLEAR/VMREAD/VMWRITE/VMPTRLD access the internal VMCS cache, which
> is not visible to the compiler; without a memory clobber, the compiler
> can reorder them in troublesome ways because "asm volatile" and "asm goto"
> only protect against removal of the asm. For example, placing a VMWRITE
> before the corresponding VMCS pointer is loaded can lead to corruption.
> While none of this has been observed, it is better to prevent than cure.
>
> Likewise, INVEPT and INVVPID access the TLB and, even though in their
> case the effect is only visible to the next VMLAUNCH/VMRESUME, it is
> technically correct to add the clobber there too. So avoid any urge to
> special case them, and simply hardcode "memory" into the clobber list
> of vmx_asm1() and vmx_asm2(). __vmcs_readl() open-codes its own asm,
> so add the clobber there as well.
>
> Link: https://lore.kernel.org/kvm/CABgObfbL3t21yVeSwiLSjjOUER+rTYDPHYAH9YU4TWGRjx6XHg@xxxxxxxxxxxxxx/
> Cc: Sean Christopherson <seanjc@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
Reviewed-by: Sean Christopherson <seanjc@xxxxxxxxxx>