summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2025-11-14 02:14:17 +0300
committerSean Christopherson <seanjc@google.com>2026-03-03 23:23:26 +0300
commit089af84641b574990da97d4674706a0303abca34 (patch)
tree4dbe3157b73b8b60c259e3a7a5f989a5453eb26c
parentf35043d0f973504e5f199be6287159dc5b373deb (diff)
downloadlinux-089af84641b574990da97d4674706a0303abca34.tar.xz
KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as present
Don't bother reading the OSVW MSRs if osvw_len is already zero, i.e. if KVM is already treating all errata as present, in which case the positive path of the if-statement is one giant nop. Opportunistically update the comment to more thoroughly explain how the MSRs work and why the code does what it does. Link: https://patch.msgid.link/20251113231420.1695919-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r--arch/x86/kvm/svm/svm.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 9d611bfbcc8c..695cebf8d724 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -543,15 +543,25 @@ static int svm_enable_virtualization_cpu(void)
/*
- * Get OSVW bits.
+ * Get OS-Visible Workarounds (OSVW) bits.
*
* Note that it is possible to have a system with mixed processor
* revisions and therefore different OSVW bits. If bits are not the same
* on different processors then choose the worst case (i.e. if erratum
* is present on one processor and not on another then assume that the
* erratum is present everywhere).
+ *
+ * Note #2! The OSVW MSRs are used to communciate that an erratum is
+ * NOT present! Software must assume erratum as present if its bit is
+ * set in OSVW_STATUS *or* the bit number exceeds OSVW_ID_LENGTH. If
+ * either RDMSR fails, simply zero out the length to treat all errata
+ * as being present. Similarly, use the *minimum* length across all
+ * CPUs, not the maximum length.
+ *
+ * If the length is zero, then is KVM already treating all errata as
+ * being present and there's nothing left to do.
*/
- if (cpu_has(&boot_cpu_data, X86_FEATURE_OSVW)) {
+ if (osvw_len && cpu_has(&boot_cpu_data, X86_FEATURE_OSVW)) {
u64 len, status = 0;
int err;