From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] KVM: SVM: Serialize updates to global OS-Visible Workarounds variables
Date: Thu, 13 Nov 2025 15:14:16 -0800 [thread overview]
Message-ID: <20251113231420.1695919-2-seanjc@google.com> (raw)
In-Reply-To: <20251113231420.1695919-1-seanjc@google.com>
Guard writes to the global osvw_status and osvw_len variables with a
spinlock to ensure enabling virtualization on multiple CPUs in parallel
doesn't effectively drop any writes due to writing back stale data. Don't
bother taking the lock when the boot CPU doesn't support the feature, as
that check is constant for all CPUs, i.e. racing writes will always write
the same value (zero).
Note, the bug was inadvertently "fixed" by commit 9a798b1337af ("KVM:
Register cpuhp and syscore callbacks when enabling hardware"), which
effectively serialized calls to enable virtualization due to how the cpuhp
framework "brings up" CPU. But KVM shouldn't rely on the mechanics of
cphup to provide serialization.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/svm.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index fc42bcdbb520..5612e46e481c 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -77,6 +77,7 @@ static bool erratum_383_found __read_mostly;
* are published and we know what the new status bits are
*/
static uint64_t osvw_len = 4, osvw_status;
+static DEFINE_SPINLOCK(osvw_lock);
static DEFINE_PER_CPU(u64, current_tsc_ratio);
@@ -554,16 +555,19 @@ static int svm_enable_virtualization_cpu(void)
if (!err)
err = native_read_msr_safe(MSR_AMD64_OSVW_STATUS, &status);
- if (err)
+ guard(spinlock)(&osvw_lock);
+
+ if (err) {
osvw_status = osvw_len = 0;
- else {
+ } else {
if (len < osvw_len)
osvw_len = len;
osvw_status |= status;
osvw_status &= (1ULL << osvw_len) - 1;
}
- } else
+ } else {
osvw_status = osvw_len = 0;
+ }
svm_init_erratum_383();
--
2.52.0.rc1.455.g30608eb744-goog
next prev parent reply other threads:[~2025-11-13 23:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 23:14 [PATCH 0/5] KVM: SVM: Fix and clean up OSVW handling Sean Christopherson
2025-11-13 23:14 ` Sean Christopherson [this message]
2025-11-13 23:14 ` [PATCH 2/5] KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as present Sean Christopherson
2025-11-13 23:14 ` [PATCH 3/5] KVM: SVM: Extract OS-visible workarounds setup to helper function Sean Christopherson
2025-11-13 23:14 ` [PATCH 4/5] KVM: SVM: Skip OSVW variable updates if current CPU's errata are a subset Sean Christopherson
2025-11-13 23:14 ` [PATCH 5/5] KVM: SVM: Skip OSVW MSR reads if current CPU doesn't support the feature Sean Christopherson
2026-03-05 17:08 ` [PATCH 0/5] KVM: SVM: Fix and clean up OSVW handling Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251113231420.1695919-2-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®