From patchwork Mon Jan 13 20:01:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 13938020 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 25E481C760D for ; Mon, 13 Jan 2025 20:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736798545; cv=none; b=IyvckdhQ/Hs7iM8MqdKjWywy0oJpGpCi6SJhdjmMoACKb4Ue2LoSePLcSX+tU7wptgUiGoTjjz3NQ4zw9lYCJLqtPQqtR+/1lcePCgvEzW0gTXZmYxMbN0ENBRNrpakPNDkDMK5TchvmyEZbj2+p0aplmS1rzS1YDf3kifRlMHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736798545; c=relaxed/simple; bh=YTs1dpjXQrZJaO2PwxhJPmloP3yUD+EWIBykta6id/w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bUY6YY99poV+eqvh+NdOe9BvcfgpObvJxeBWB97bGMsd2oRLmnspyXvjuiiKXOLbsQbgjjd9RJUFUeNJipExXTdebjKsfXa9spAfpk6XuSd8VvR/wpCrLkxgA5l7V7zTWgUQMKTeJWDhonWdvS2uF4iU7DTkgXDcx5Q3Sz3rm0Y= 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=t4f2V5Zr; arc=none smtp.client-ip=209.85.216.73 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="t4f2V5Zr" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2eebfd6d065so12204101a91.3 for ; Mon, 13 Jan 2025 12:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736798542; x=1737403342; 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=jtdiVJ+ztNcHT3qzoC9fhmElHCLjwxZM/dCdTnmBzy4=; b=t4f2V5Zr4iBGFF9WlJe0/K6br7MzjYP3IYzlAVFP+74J1puELYyJGrCNyAjIaaUGAA uyqnenenPXmxIkCpx7MC4J9I90ryL8A1v7w5eXLhyLXkkxtH7JED76uukqOYoDsdEcoH Sjzsshod8jpm7VTySOo3y9mUZ9bfGHmb4bGUgnbKc32VJO6ZBASa7BgXZ5xjny/RwBs5 NIUlkSwlvmop6wYCkFZbRuHEs2Y2HWC1uHAfmcr8LES13N5+UVrek6kjxmwWGsoPM7TZ 4Qt3fJbdk6AwkcgPYzCD1e4Aja2wy408gQhRMa4i6/l1UI26ItfnPy2zXd5vDc6s0xOG 5CbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736798542; x=1737403342; 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=jtdiVJ+ztNcHT3qzoC9fhmElHCLjwxZM/dCdTnmBzy4=; b=i5KUkGcxSfnwc9l1FdAbWsWbTNfWYn1p10dAxTvA+KY5c6CF2auCBRMm20eoPSVDXY fmqlwMDdbUoEAGKWJt4m4xkEZaL8Yzbl2d6wObp8KX99jBP392YyCMrom3zqXQokAHXQ jruN2r0kQU3iyqraslEPOTmJz0SnovPfV0KIXpzg/4NPf2GGSh2OWi+p7SymVQfkC8tM Uql7Qyxa3+igk/TqG2zByp8FVSYD8jGb4QLyoHgIiYhnFV0JCtqW7wPi+kKY3GccGjn4 RpVkRjHaYwUbjmmIvGlUcYOcmphtY1hTWcqa0v6k3O07lWM6qBzvd6KgKPwj/VoZ0Bui cL6Q== X-Forwarded-Encrypted: i=1; AJvYcCWgJ4PhNw1dv1mK+j9ZWe2kf99VxcLWamA/3xBUpfwxJ/Wedb3xsf6utj8NclWCKtGtCMk=@vger.kernel.org X-Gm-Message-State: AOJu0YzcOlQBcOhE+GbKI6/vrHzobjQn3Zl5CChnfoV3x4EWAB4GfJTo CrqUJ1cMejJkvx1gmazJWaitr8emJDN2iCeLLSCjtzW9CkObgavWFzMKd/jRLA1m5R+PZ8hEGVf kv6iN30cC7g== X-Google-Smtp-Source: AGHT+IGRDP+dLbZYnL6SPBzmcxG2KKCHdES/kfIarY6JU5nffIgg/+20LS/dSG2aIOK4rzFmwsSpg55z3V3Ilw== X-Received: from pfiy3.prod.google.com ([2002:a05:6a00:1903:b0:72b:ccb:c99b]) (user=jmattson job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4fd3:b0:72a:83ec:b1c9 with SMTP id d2e1a72fcca58-72d21f35ae3mr31398282b3a.6.1736798542485; Mon, 13 Jan 2025 12:02:22 -0800 (PST) Date: Mon, 13 Jan 2025 12:01:43 -0800 In-Reply-To: <20250113200150.487409-1-jmattson@google.com> Precedence: bulk X-Mailing-List: kvm@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-2-jmattson@google.com> Subject: [PATCH 1/2] KVM: x86: Introduce kvm_set_mp_state() 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 Replace all open-coded assignments to vcpu->arch.mp_state with calls to a new helper, kvm_set_mp_state(), to centralize all changes to mp_state. No functional change intended. Signed-off-by: Jim Mattson --- arch/x86/kvm/lapic.c | 6 +++--- arch/x86/kvm/svm/nested.c | 2 +- arch/x86/kvm/svm/sev.c | 4 ++-- arch/x86/kvm/vmx/nested.c | 4 ++-- arch/x86/kvm/x86.c | 17 ++++++++--------- arch/x86/kvm/x86.h | 5 +++++ arch/x86/kvm/xen.c | 4 ++-- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 3c83951c619e..bfbc4bc70595 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -3392,9 +3392,9 @@ int kvm_apic_accept_events(struct kvm_vcpu *vcpu) if (test_and_clear_bit(KVM_APIC_INIT, &apic->pending_events)) { kvm_vcpu_reset(vcpu, true); if (kvm_vcpu_is_bsp(apic->vcpu)) - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); else - vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_INIT_RECEIVED); } if (test_and_clear_bit(KVM_APIC_SIPI, &apic->pending_events)) { if (vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) { @@ -3403,7 +3403,7 @@ int kvm_apic_accept_events(struct kvm_vcpu *vcpu) sipi_vector = apic->sipi_vector; kvm_x86_call(vcpu_deliver_sipi_vector)(vcpu, sipi_vector); - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); } } return 0; diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index b708bdf7eaff..f47906fd9b03 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -994,7 +994,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm) kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu); /* in case we halted in L2 */ - svm->vcpu.arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); /* Give the current vmcb to the guest */ diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 943bd074a5d3..b4d9efd7537d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3831,7 +3831,7 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu) /* Mark the vCPU as offline and not runnable */ vcpu->arch.pv.pv_unhalted = false; - vcpu->arch.mp_state = KVM_MP_STATE_HALTED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED); /* Clear use of the VMSA */ svm->vmcb->control.vmsa_pa = INVALID_PAGE; @@ -3870,7 +3870,7 @@ static int __sev_snp_update_protected_guest_state(struct kvm_vcpu *vcpu) /* Mark the vCPU as runnable */ vcpu->arch.pv.pv_unhalted = false; - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); svm->sev_es.snp_vmsa_gpa = INVALID_PAGE; diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index aa78b6f38dfe..d53bf4a5ad99 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3791,7 +3791,7 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch) break; case GUEST_ACTIVITY_WAIT_SIPI: vmx->nested.nested_run_pending = 0; - vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_INIT_RECEIVED); break; default: break; @@ -5055,7 +5055,7 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason, vmx->nested.need_vmcs12_to_shadow_sync = true; /* in case we halted in L2 */ - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); if (likely(!vmx->fail)) { if (vm_exit_reason != -1) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c79a8cc57ba4..d6679df95a75 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11208,8 +11208,7 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu) case KVM_MP_STATE_HALTED: case KVM_MP_STATE_AP_RESET_HOLD: vcpu->arch.pv.pv_unhalted = false; - vcpu->arch.mp_state = - KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); fallthrough; case KVM_MP_STATE_RUNNABLE: vcpu->arch.apf.halted = false; @@ -11288,7 +11287,7 @@ static int __kvm_emulate_halt(struct kvm_vcpu *vcpu, int state, int reason) if (kvm_vcpu_has_events(vcpu)) vcpu->arch.pv.pv_unhalted = false; else - vcpu->arch.mp_state = state; + kvm_set_mp_state(vcpu, state); return 1; } else { vcpu->run->exit_reason = reason; @@ -11804,10 +11803,10 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, goto out; if (mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED) { - vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_INIT_RECEIVED); set_bit(KVM_APIC_SIPI, &vcpu->arch.apic->pending_events); } else - vcpu->arch.mp_state = mp_state->mp_state; + kvm_set_mp_state(vcpu, mp_state->mp_state); kvm_make_request(KVM_REQ_EVENT, vcpu); ret = 0; @@ -11934,7 +11933,7 @@ static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs, if (kvm_vcpu_is_bsp(vcpu) && kvm_rip_read(vcpu) == 0xfff0 && sregs->cs.selector == 0xf000 && sregs->cs.base == 0xffff0000 && !is_protmode(vcpu)) - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); return 0; } @@ -12237,9 +12236,9 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) kvm_gpc_init(&vcpu->arch.pv_time, vcpu->kvm); if (!irqchip_in_kernel(vcpu->kvm) || kvm_vcpu_is_reset_bsp(vcpu)) - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); else - vcpu->arch.mp_state = KVM_MP_STATE_UNINITIALIZED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_UNINITIALIZED); r = kvm_mmu_create(vcpu); if (r < 0) @@ -13459,7 +13458,7 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu, } vcpu->arch.apf.halted = false; - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); } void kvm_arch_async_page_present_queued(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index ec623d23d13d..bc3b5a9490c6 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -121,6 +121,11 @@ static inline bool kvm_vcpu_has_run(struct kvm_vcpu *vcpu) return vcpu->arch.last_vmentry_cpu != -1; } +static inline void kvm_set_mp_state(struct kvm_vcpu *vcpu, int mp_state) +{ + vcpu->arch.mp_state = mp_state; +} + static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu) { return vcpu->arch.exception.pending || diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index a909b817b9c0..f65ca27888e9 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1480,7 +1480,7 @@ static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool longmode, set_bit(vcpu->vcpu_idx, vcpu->kvm->arch.xen.poll_mask); if (!wait_pending_event(vcpu, sched_poll.nr_ports, ports)) { - vcpu->arch.mp_state = KVM_MP_STATE_HALTED; + kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED); if (sched_poll.timeout) mod_timer(&vcpu->arch.xen.poll_timer, @@ -1491,7 +1491,7 @@ static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool longmode, if (sched_poll.timeout) del_timer(&vcpu->arch.xen.poll_timer); - vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE; + kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE); } vcpu->arch.xen.poll_evtchn = 0; From patchwork Mon Jan 13 20:01:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 13938021 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 743721CDFCE 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=1736798547; cv=none; b=TDCAI0gJ+CbWYNOVKqrLYWLywgTry329C9qR2tY1ZjJjoDVkrmsL91lp7dDm4hkjrpiCRgEW5uq9F+CrU8T1i71BIJJAeUApMsyUb5EnjT7o2fA2HNeREQmd3e9a+JrELbcwZSBjFDPUZWxTBf8n89P1IIlNVGLO1UoqJ5pCntM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736798547; c=relaxed/simple; bh=6tUCQvz9TjrZUWVa2jhKNO+tcEn/Q8cjiHQwaA3jo7E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qb45bxSFDE4Wu526a+BI0KUVYIRRoIOENQYLXEKzGyif0U/TK72z81JcQnbHEsa8Lf+E7DA+XnH4yBnsdhvEBKnm9xIoCmYDFZAbHSpY3MxzZow2R4maIwMi7BsmlCbZ1kox4m5kEnbOvkhDTG2JDNYUCnlYofGz1MTSwjM1QRY= 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-2ee46799961so12207903a91.2 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=HPAA55J4QanVRtBrMybOZV+O+2ukEqCCPMAP4AtrwLGDFGAJmdIfPQmLplUed8w8Yo VVx0et/5CX8oUuEJ0gBQBJ3dhCD+5GrHnix0LS5VuOEbR0ssgJTifTD3yo61T8WhmWkh heb6ugci+oq+qulu9gbQ+Ww3NwksVYON7SdGWOh/XcW2INWmjawkl2bka1Bys/zastVA Q9odR9nHRHr6jA/MGkoHwFQKvScvow/nmeBZ2Yn784zeX9tXbqIXTfJ6Isjxrph8S15M B5gzAcHt3kPriGD4S0cKOXYqbW7WiJUi5qrdnZckrK+w5LnGVD3Ndu1IREUcgmgdz5Xy dgCA== X-Forwarded-Encrypted: i=1; AJvYcCXUg8VV3Btp4vDYX0Cga82E0xVPZvekU20903QFNPhhlsfiHfwCb/zpVYFIkqjfUkLxw70=@vger.kernel.org X-Gm-Message-State: AOJu0YxmsAed7ogEJPBZFDbuI55MNx+KowDkLqwihAvdKra2JliFi0d+ STEIqXVVsAVFy2pJKDJ761d4WkYtswd29lbtGsh5Y5o2vmdW9cIuVKxGNM83yM7ycqRMdROOpdF 3rWZDGjJpFQ== 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: kvm@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 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(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 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 = 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 *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)