Skip to content

KVM: SVM: Fix and clean up OSVW handling

Sean Christopherson kvm lkml 1 version Applied

Status from this message: Applied to kvm-x86 svm, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/5KVM: SVM: Serialize updates to global OS-Visible Workarounds variablesarch/x86/kvm/svm/svm.c+7 -30 replies
2/5KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as presentarch/x86/kvm/svm/svm.c+12 -20 replies
3/5KVM: SVM: Extract OS-visible workarounds setup to helper functionarch/x86/kvm/svm/svm.c+49 -410 replies
4/5KVM: SVM: Skip OSVW variable updates if current CPU's errata are a subsetarch/x86/kvm/svm/svm.c+10 -120 replies
5/5KVM: SVM: Skip OSVW MSR reads if current CPU doesn't support the featurearch/x86/kvm/svm/svm.c+2 -60 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] KVM: SVM: Fix and clean up OSVW handling

Fix a long-standing bug where KVM could clobber its OS-visible workarounds handling (not that anyone would notice), and then clean up the code to make it easier understand and maintain (I didn't even know what "osvw" stood for until I ran into this code when trying to moving actual SVM pieces of svm_enable_virtualization_cpu() out of KVM (for TDX purposes)).

Tested by running in a VM and generating unique per-vCPU MSR values in the host (see below), and verifying KVM ended up with the right values.

arch/x86/kvm/x86.c +8 -0
index c9c2aa6f4705..d8b8eff733d8 100644
@@ -4631,12 +4631,20 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
        case MSR_AMD64_OSVW_ID_LENGTH:
                if (!guest_cpu_cap_has(vcpu, X86_FEATURE_OSVW))
                        return 1;
+
+               if (vcpu->vcpu_idx == 64)
+                       return 1;
+
                msr_info->data = vcpu->arch.osvw.length;
+               if (vcpu->vcpu_idx < 64)
+                       msr_info->data = max(vcpu->vcpu_idx, 8);
                break;
        case MSR_AMD64_OSVW_STATUS:
                if (!guest_cpu_cap_has(vcpu, X86_FEATURE_OSVW))
                        return 1;
                msr_info->data = vcpu->arch.osvw.status;
+               if (vcpu->vcpu_idx < 64)
+                       msr_info->data |= BIT_ULL(vcpu->vcpu_idx);
                break;
        case MSR_PLATFORM_INFO:
                if (!msr_info->host_initiated &&

Sean Christopherson (5):
KVM: SVM: Serialize updates to global OS-Visible Workarounds variables
KVM: SVM: Skip OSVW MSR reads if KVM is treating all errata as present
KVM: SVM: Extract OS-visible workarounds setup to helper function
KVM: SVM: Skip OSVW variable updates if current CPU's errata are a
subset
KVM: SVM: Skip OSVW MSR reads if current CPU doesn't support the
feature

 arch/x86/kvm/svm/svm.c | 72 ++++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 28 deletions(-)

base-commit: 16ec4fb4ac95d878b879192d280db2baeec43272

Signature · 1 line
2.52.0.rc1.455.g30608eb744-goog