From nobody Thu Dec 18 11:45:15 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 743D41CEAA3 for ; Mon, 13 Jan 2025 20:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736798545; cv=none; b=CmVHNrw3koFXR4f7fcGKYEKvrVugE+NKpRQwE/omFFWXhtAFdGZND3FEtSximW8tm8tfa05y7uDnZJafCyOKGzY35YSvbb1/+lhTa4+aiEmczN6JRjEQQX8s1aA0VvG7ZUg7ajCyfPqSGkIvjrIx8OxD8XkH68T+Crz4k+4uydg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736798545; c=relaxed/simple; bh=6tUCQvz9TjrZUWVa2jhKNO+tcEn/Q8cjiHQwaA3jo7E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=YevhUOL0grEw5XQ9Yx51rU7EEgeQiBrMff2ojYMZ34FrphiZ+suHl5Dv5IizCxQ526z+37dNOzMiIikAYIdpdBW3cp6atoSOY6xpqd57YsN0awU13IJTrgczvyqio3vEs+CgqzQbE6HhZqF9hfSEyV5/5JkJc1FYa5sK0e2IuD8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jmattson.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pixZwTrs; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jmattson.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pixZwTrs" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef79d9c692so12251699a91.0 for ; Mon, 13 Jan 2025 12:02:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736798544; x=1737403344; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yat4B4+GPlhs7xbLK2dbkAhGVvRnl7DFK3afM4k4FTA=; b=pixZwTrsA1WlyZUhPncDTf50t5EKC+Tm2H9/2JoUsgYJZPaNV5gh7+XswFWqkKSSEO 5ibZHjtqZezP2CYmBm7bWIJS6Z2NbdhGbEeYJls9a24ymVd1gfVIMRTZL4fF/VcRP4vs 74a3Vzi2n5aEoqwrBseW9wWjkXFTNOb4a8E8pRXhe/EzEZCoQBwiCn5A+CnuRwiV0wvM foW3XayESceU7VXuKRGxyVz9iOduzI0hBuBg9lARbPK4ROQgIEB/iPSDDBQwwImitFWE /n5G2jE15vERfpo2B2xWhrc7zWdepAQ9Hvi1FMPGI/PJTVQuy0HOzRnM+gSMPctRSEfQ /uhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736798544; x=1737403344; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yat4B4+GPlhs7xbLK2dbkAhGVvRnl7DFK3afM4k4FTA=; b=kfgU/p0PWdNAPW16Fpy3JzGXgy4C1c7tks2/nOgr/ijMicN3LdpPJt5S8rr8mDdQie 6KN5EoubsXKz6C68s2Nx40ueOvr7WUXeU7yTYBpagfldEtdXjP6fADOKxorv3oclbsbJ Te1mvC5YKy8wBtsL00jnuYlDsUpAZd1TSTZm0qq7mzjPog1EoWCQKWU5aDl2HDFrVvqM lkxt56th6Oz532F9jF/TCWhmle0pjtj4LUdNuWsyF7IDuAj5tV0R00wnK41dXu5Lf94I MHiOR+65QgKJPeLSO6IA9ni8CA5o2my5f69qH+zOftMwRZ8lOuvASIFHz+sGl8rmOxA2 iNxg== X-Forwarded-Encrypted: i=1; AJvYcCWY5bYHbl0dV9nohhSrTaDrhEGow9Td0XRUihROY0CcQdDtzOWqwmUA7O7LvoL8XuBYTzu65UvvKI+W/lU=@vger.kernel.org X-Gm-Message-State: AOJu0YxZKfzSXw+ufqYCXC/FKzcaZvxkG7mMfzpHgVl6VkgdcW+8YF92 LZtfZ92E+iLeRAaX7s4cq0iFrshn8N+0DONVtbKKRXUynvJf25P9rJsSGpvfy4FsHwsOj4gZECE RK3i28d94BQ== X-Google-Smtp-Source: AGHT+IEmWiATVThH7bgQ/hnlvDunJgeyGf7yLM6TQhUanGNHhy3W7K/gBGEus6U+L8kLklUfWVVO1PSxA30F+g== X-Received: from pjbsg6.prod.google.com ([2002:a17:90b:5206:b0:2e9:5043:f55b]) (user=jmattson job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:c2c8:b0:2ee:70cb:a500 with SMTP id 98e67ed59e1d1-2f548e9a4c9mr28634548a91.1.1736798543960; Mon, 13 Jan 2025 12:02:23 -0800 (PST) Date: Mon, 13 Jan 2025 12:01:44 -0800 In-Reply-To: <20250113200150.487409-1-jmattson@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250113200150.487409-1-jmattson@google.com> X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250113200150.487409-3-jmattson@google.com> Subject: [PATCH 2/2] KVM: x86: Clear pv_unhalted on all transitions to KVM_MP_STATE_RUNNABLE From: Jim Mattson To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , David Woodhouse , Paul Durrant , Gleb Natapov , Raghavendra K T , Suzuki Poulose , Srivatsa Vaddagiri , Jan Kiszka , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jim Mattson Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. The "fixes" list may be incompplete. 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") Signed-off-by: Jim Mattson --- arch/x86/kvm/svm/sev.c | 1 - arch/x86/kvm/x86.c | 1 - arch/x86/kvm/x86.h | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index b4d9efd7537d..73e15e7658c2 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3869,7 +3869,6 @@ static int __sev_snp_update_protected_guest_state(str= uct kvm_vcpu *vcpu) svm->vmcb->control.vmsa_pa =3D pfn_to_hpa(pfn); =20 /* Mark the vCPU as runnable */ - vcpu->arch.pv.pv_unhalted =3D false; kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); =20 svm->sev_es.snp_vmsa_gpa =3D INVALID_PAGE; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d6679df95a75..4b21ed6803c6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11207,7 +11207,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 =3D 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 bc3b5a9490c6..cc06631027bd 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 *vc= pu) static inline void kvm_set_mp_state(struct kvm_vcpu *vcpu, int mp_state) { vcpu->arch.mp_state =3D mp_state; + if (mp_state =3D=3D KVM_MP_STATE_RUNNABLE) + vcpu->arch.pv.pv_unhalted =3D false; } =20 static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu) --=20 2.47.1.688.g23fc6f90ad-goog