mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT
@ 2025-02-24 17:41 Sean Christopherson
  2025-03-05  1:05 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2025-02-24 17:41 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel

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).

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/x86.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 58b82d6fd77c..7f5abdaab935 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11310,9 +11310,8 @@ static int __kvm_emulate_halt(struct kvm_vcpu *vcpu, int state, int reason)
 	++vcpu->stat.halt_exits;
 	if (lapic_in_kernel(vcpu)) {
 		if (kvm_vcpu_has_events(vcpu))
-			vcpu->arch.pv.pv_unhalted = false;
-		else
-			kvm_set_mp_state(vcpu, state);
+			state = KVM_MP_STATE_RUNNABLE;
+		kvm_set_mp_state(vcpu, state);
 		return 1;
 	} else {
 		vcpu->run->exit_reason = reason;

base-commit: fed48e2967f402f561d80075a20c5c9e16866e53
-- 
2.48.1.658.g4767266eb4-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT
  2025-02-24 17:41 [PATCH] KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT Sean Christopherson
@ 2025-03-05  1:05 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2025-03-05  1:05 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel

On Mon, 24 Feb 2025 09:41:56 -0800, Sean Christopherson wrote:
> 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.
> 
> [...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT
      https://github.com/kvm-x86/linux/commit/2a289aed3fcd

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-05  1:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-24 17:41 [PATCH] KVM: x86: Always set mp_state to RUNNABLE on wakeup from HLT Sean Christopherson
2025-03-05  1:05 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®