Skip to content

Commit ba50bb4

Browse files
committed
KVM: x86: Ensure vcpu->mode is loaded from memory in kvm_vcpu_exit_request()
Wrap kvm_vcpu_exit_request()'s load of vcpu->mode with READ_ONCE() to ensure the variable is re-loaded from memory, as there is no guarantee the caller provides the necessary annotations to ensure KVM sees a fresh value, e.g. the VM-Exit fastpath could theoretically reuse the pre-VM-Enter value. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://lore.kernel.org/r/20240828232013.768446-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8eada24 commit ba50bb4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,8 +2144,9 @@ EXPORT_SYMBOL_GPL(kvm_emulate_monitor);
21442144
static inline bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu)
21452145
{
21462146
xfer_to_guest_mode_prepare();
2147-
return vcpu->mode == EXITING_GUEST_MODE || kvm_request_pending(vcpu) ||
2148-
xfer_to_guest_mode_work_pending();
2147+
2148+
return READ_ONCE(vcpu->mode) == EXITING_GUEST_MODE ||
2149+
kvm_request_pending(vcpu) || xfer_to_guest_mode_work_pending();
21492150
}
21502151

21512152
/*

0 commit comments

Comments
 (0)