From: Jim Mattson Date: Mon, 13 Jan 2025 20:01:44 +0000 (-0800) Subject: KVM: x86: Clear pv_unhalted on all transitions to KVM_MP_STATE_RUNNABLE X-Git-Tag: v6.15-rc1~195^2~10^2~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9cb61055fee5f973984e2b98edd3bbc356f9c89;p=thirdparty%2Fkernel%2Flinux.git KVM: x86: Clear pv_unhalted on all transitions to KVM_MP_STATE_RUNNABLE In kvm_set_mp_state(), ensure that vcpu->arch.pv.pv_unhalted is always cleared on a transition to KVM_MP_STATE_RUNNABLE, so that the next HLT instruction will be respected. Fixes: 6aef266c6e17 ("kvm hypervisor : Add a hypercall to KVM hypervisor to support pv-ticketlocks") Fixes: b6b8a1451fc4 ("KVM: nVMX: Rework interception of IRQs and NMIs") Fixes: 38c0b192bd6d ("KVM: SVM: leave halted state on vmexit") Fixes: 1a65105a5aba ("KVM: x86/xen: handle PV spinlocks slowpath") Signed-off-by: Jim Mattson Link: https://lore.kernel.org/r/20250113200150.487409-3-jmattson@google.com [sean: add Xen PV spinlocks to the list of Fixes, tweak changelog] Signed-off-by: Sean Christopherson --- diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 87d2840da6af8..8bc62e9941389 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3883,7 +3883,6 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu) svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn); /* Mark the vCPU as runnable */ - vcpu->arch.pv.pv_unhalted = false; kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); svm->sev_es.snp_vmsa_gpa = INVALID_PAGE; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3041b8d8b59fa..0aca2a5dac7e0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11215,7 +11215,6 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu) switch(vcpu->arch.mp_state) { case KVM_MP_STATE_HALTED: case KVM_MP_STATE_AP_RESET_HOLD: - vcpu->arch.pv.pv_unhalted = false; kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); fallthrough; case KVM_MP_STATE_RUNNABLE: diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 34ca87049845e..5c1fd5230cee9 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -124,6 +124,8 @@ static inline bool kvm_vcpu_has_run(struct kvm_vcpu *vcpu) static inline void kvm_set_mp_state(struct kvm_vcpu *vcpu, int mp_state) { vcpu->arch.mp_state = mp_state; + if (mp_state == KVM_MP_STATE_RUNNABLE) + vcpu->arch.pv.pv_unhalted = false; } static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu)