]> git.ipfire.org Git - thirdparty/linux.git/commit
KVM: VMX: add memory clobber to asm for VMX instructions
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 21 Jul 2026 16:31:49 +0000 (18:31 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 28 Jul 2026 15:43:28 +0000 (17:43 +0200)
commit0e65cd9e5d41c34f86b7c347967bedac54926041
treeed9d79a70023c654467b69f434108af1c31bfa20
parenta7fe52b5ab9e1fdb53a8a111a0f427bbff4cb91e
KVM: VMX: add memory clobber to asm for VMX instructions

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@mail.gmail.com/
Cc: Sean Christopherson <seanjc@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/vmx_ops.h