Skip to content

Commit 2a289ae

Browse files
committed
KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT
When emulating HLT and a wake event is already pending, explicitly mark the vCPU RUNNABLE (via kvm_set_mp_state()) instead of assuming the vCPU is already in the appropriate state. Barring a KVM bug, it should be impossible for the vCPU to be in a non-RUNNABLE state, but there is no advantage to relying on that to hold true, and ensuring the vCPU is made RUNNABLE avoids non-deterministic behavior with respect to pv_unhalted. E.g. if the vCPU is not already RUNNABLE, then depending on when pv_unhalted is set, KVM could either leave the vCPU in the non-RUNNABLE state (set before __kvm_emulate_halt()), or transition the vCPU to HALTED and then RUNNABLE (pv_unhalted set after the kvm_vcpu_has_events() check). Link: https://lore.kernel.org/r/20250224174156.2362059-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent b50cb2b commit 2a289ae

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11297,9 +11297,8 @@ static int __kvm_emulate_halt(struct kvm_vcpu *vcpu, int state, int reason)
1129711297
++vcpu->stat.halt_exits;
1129811298
if (lapic_in_kernel(vcpu)) {
1129911299
if (kvm_vcpu_has_events(vcpu))
11300-
vcpu->arch.pv.pv_unhalted = false;
11301-
else
11302-
kvm_set_mp_state(vcpu, state);
11300+
state = KVM_MP_STATE_RUNNABLE;
11301+
kvm_set_mp_state(vcpu, state);
1130311302
return 1;
1130411303
} else {
1130511304
vcpu->run->exit_reason = reason;

0 commit comments

Comments
 (0)