]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
KVM: x86: Use KVM-governed feature framework to track "LAM enabled"
authorBinbin Wu <binbin.wu@linux.intel.com>
Wed, 13 Sep 2023 12:42:24 +0000 (20:42 +0800)
committerSean Christopherson <seanjc@google.com>
Wed, 29 Nov 2023 01:54:09 +0000 (17:54 -0800)
Use the governed feature framework to track if Linear Address Masking (LAM)
is "enabled", i.e. if LAM can be used by the guest.

Using the framework to avoid the relative expensive call guest_cpuid_has()
during cr3 and vmexit handling paths for LAM.

No functional change intended.

Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
Tested-by: Xuelian Guo <xuelian.guo@intel.com>
Link: https://lore.kernel.org/r/20230913124227.12574-14-binbin.wu@linux.intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/cpuid.h
arch/x86/kvm/governed_features.h
arch/x86/kvm/mmu.h
arch/x86/kvm/vmx/vmx.c

index e4bd59c15a2cacf985d704be8f197e4b8e5d48a1..856e3037e74f3ffc7fdeb72f2067812080d71910 100644 (file)
@@ -276,8 +276,7 @@ static __always_inline bool guest_can_use(struct kvm_vcpu *vcpu,
 
 static inline bool kvm_vcpu_is_legal_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
 {
-       if (kvm_cpu_cap_has(X86_FEATURE_LAM) &&
-           guest_cpuid_has(vcpu, X86_FEATURE_LAM))
+       if (guest_can_use(vcpu, X86_FEATURE_LAM))
                cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57);
 
        return kvm_vcpu_is_legal_gpa(vcpu, cr3);
index 423a73395c102ca908453016e416dbdfb7fc2b5b..ad463b1ed4e4a87c29aa9d5af3842fbd4e039e41 100644 (file)
@@ -16,6 +16,7 @@ KVM_GOVERNED_X86_FEATURE(PAUSEFILTER)
 KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
 KVM_GOVERNED_X86_FEATURE(VGIF)
 KVM_GOVERNED_X86_FEATURE(VNMI)
+KVM_GOVERNED_X86_FEATURE(LAM)
 
 #undef KVM_GOVERNED_X86_FEATURE
 #undef KVM_GOVERNED_FEATURE
index 580e2414b88c79e6dbdf39abf4032938670e1bbe..60f21bb4c27b196d7da820a304771b31b700899f 100644 (file)
@@ -148,8 +148,7 @@ static inline unsigned long kvm_get_active_pcid(struct kvm_vcpu *vcpu)
 
 static inline unsigned long kvm_get_active_cr3_lam_bits(struct kvm_vcpu *vcpu)
 {
-       if (!kvm_cpu_cap_has(X86_FEATURE_LAM) ||
-           !guest_cpuid_has(vcpu, X86_FEATURE_LAM))
+       if (!guest_can_use(vcpu, X86_FEATURE_LAM))
                return 0;
 
        return kvm_read_cr3(vcpu) & (X86_CR3_LAM_U48 | X86_CR3_LAM_U57);
index 3825ab316be9f4ab0548bf9190852d8a16b605c7..d30df9b3fe3e52012634fafd305a267103b14eb7 100644 (file)
@@ -7763,6 +7763,7 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
                kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_XSAVES);
 
        kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VMX);
+       kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LAM);
 
        vmx_setup_uret_msrs(vmx);