]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
KVM: SVM: Add MSR-based feature support for serializing LFENCE
authorTom Lendacky <thomas.lendacky@amd.com>
Fri, 23 Feb 2018 23:18:20 +0000 (00:18 +0100)
committerBrian Maly <brian.maly@oracle.com>
Tue, 19 Feb 2019 18:43:48 +0000 (13:43 -0500)
In order to determine if LFENCE is a serializing instruction on AMD
processors, MSR 0xc0011029 (MSR_F10H_DECFG) must be read and the state
of bit 1 checked.  This patch will add support to allow a guest to
properly make this determination.

Add the MSR feature callback operation to svm.c and add MSR 0xc0011029
to the list of MSR-based features.  If LFENCE is serializing, then the
feature is supported, allowing the hypervisor to set the value of the
MSR that guest will see.  Support is also added to write (hypervisor only)
and read the MSR value for the guest.  A write by the guest will result in
a #GP.  A read by the guest will return the value as set by the host.  In
this way, the support to expose the feature to the guest is controlled by
the hypervisor.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
(cherry picked from commit d1d93fa90f1afa926cb060b7f78ab01a65705b4d)

Orabug: 29335274

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Signed-off-by: Brian Maly <brian.maly@oracle.com>
Conflicts:
arch/x86/kvm/svm.c
arch/x86/kvm/x86.c
Contextual

Signed-off-by: Brian Maly <brian.maly@oracle.com>
arch/x86/kvm/svm.c
arch/x86/kvm/x86.c

index 2694d18319a7cde36a94d93452a4dbad70fe5af4..ec7251565d6c79b5d3b189a2848bf5c0733fa421 100644 (file)
@@ -137,6 +137,8 @@ struct vcpu_svm {
        uint64_t sysenter_esp;
        uint64_t sysenter_eip;
 
+       u64 msr_decfg;
+
        u64 next_rip;
 
        u64 host_user_msrs[NR_HOST_SAVE_USER_MSRS];
@@ -3109,7 +3111,18 @@ static u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
 
 static int svm_get_msr_feature(struct kvm_msr_entry *msr)
 {
-       return 1;
+       msr->data = 0;
+
+       switch (msr->index) {
+       case MSR_F10H_DECFG:
+               if (boot_cpu_has(X86_FEATURE_LFENCE_RDTSC))
+                       msr->data |= BIT_ULL(MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT);
+               break;
+       default:
+               return 1;
+       }
+
+       return 0;
 }
 
 static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
@@ -3189,6 +3202,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
        case MSR_IA32_UCODE_REV:
                msr_info->data = 0x01000065;
                break;
+       case MSR_F10H_DECFG:
+               msr_info->data = svm->msr_decfg;
+               break;
        default:
                return kvm_get_msr_common(vcpu, msr_info);
        }
@@ -3357,6 +3373,24 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 
                svm->virt_spec_ctrl = data;
                break;
+       case MSR_F10H_DECFG: {
+               struct kvm_msr_entry msr_entry;
+
+               msr_entry.index = msr->index;
+               if (svm_get_msr_feature(&msr_entry))
+                       return 1;
+
+               /* Check the supported bits */
+               if (data & ~msr_entry.data)
+                       return 1;
+
+               /* Don't allow the guest to change a bit, #GP */
+               if (!msr->host_initiated && (data ^ msr_entry.data))
+                       return 1;
+
+               svm->msr_decfg = data;
+               break;
+       }
        default:
                return kvm_set_msr_common(vcpu, msr);
        }
index 76299d88381d8bd4bf2e16adcaa3b052386a8c08..65c6e6f17cb97c33a21b38d32fa2c39a4b22bb82 100644 (file)
@@ -972,6 +972,7 @@ static const u32 emulated_msrs[] = {
  */
 static u32 msr_based_features[] = {
        MSR_IA32_ARCH_CAPABILITIES,
+       MSR_F10H_DECFG,
 };
 
 static unsigned int num_msr_based_features;