KVM: SVM: Update cr3_lm_rsvd_bits for AMD SEV guests
authorBabu Moger <babu.moger@amd.com>
Thu, 12 Nov 2020 22:18:03 +0000 (16:18 -0600)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 13 Nov 2020 11:31:14 +0000 (06:31 -0500)
For AMD SEV guests, update the cr3_lm_rsvd_bits to mask
the memory encryption bit in reserved bits.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Message-Id: <160521948301.32054.5783800787423231162.stgit@bmoger-ubuntu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/svm.c

index 2f32fd0..1e81cfe 100644 (file)
@@ -3741,6 +3741,7 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
 static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
+       struct kvm_cpuid_entry2 *best;
 
        vcpu->arch.xsaves_enabled = guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
                                    boot_cpu_has(X86_FEATURE_XSAVE) &&
@@ -3753,6 +3754,13 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
        /* Check again if INVPCID interception if required */
        svm_check_invpcid(svm);
 
+       /* For sev guests, the memory encryption bit is not reserved in CR3.  */
+       if (sev_guest(vcpu->kvm)) {
+               best = kvm_find_cpuid_entry(vcpu, 0x8000001F, 0);
+               if (best)
+                       vcpu->arch.cr3_lm_rsvd_bits &= ~(1UL << (best->ebx & 0x3f));
+       }
+
        if (!kvm_vcpu_apicv_active(vcpu))
                return;