Skip to content

Commit b291db5

Browse files
Binbin Wusean-jc
authored andcommitted
KVM: x86: Use KVM-governed feature framework to track "LAM enabled"
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>
1 parent 6ef90ee commit b291db5

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

arch/x86/kvm/cpuid.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ static __always_inline bool guest_can_use(struct kvm_vcpu *vcpu,
276276

277277
static inline bool kvm_vcpu_is_legal_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
278278
{
279-
if (kvm_cpu_cap_has(X86_FEATURE_LAM) &&
280-
guest_cpuid_has(vcpu, X86_FEATURE_LAM))
279+
if (guest_can_use(vcpu, X86_FEATURE_LAM))
281280
cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57);
282281

283282
return kvm_vcpu_is_legal_gpa(vcpu, cr3);

arch/x86/kvm/governed_features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ KVM_GOVERNED_X86_FEATURE(PAUSEFILTER)
1616
KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD)
1717
KVM_GOVERNED_X86_FEATURE(VGIF)
1818
KVM_GOVERNED_X86_FEATURE(VNMI)
19+
KVM_GOVERNED_X86_FEATURE(LAM)
1920

2021
#undef KVM_GOVERNED_X86_FEATURE
2122
#undef KVM_GOVERNED_FEATURE

arch/x86/kvm/mmu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ static inline unsigned long kvm_get_active_pcid(struct kvm_vcpu *vcpu)
148148

149149
static inline unsigned long kvm_get_active_cr3_lam_bits(struct kvm_vcpu *vcpu)
150150
{
151-
if (!kvm_cpu_cap_has(X86_FEATURE_LAM) ||
152-
!guest_cpuid_has(vcpu, X86_FEATURE_LAM))
151+
if (!guest_can_use(vcpu, X86_FEATURE_LAM))
153152
return 0;
154153

155154
return kvm_read_cr3(vcpu) & (X86_CR3_LAM_U48 | X86_CR3_LAM_U57);

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7764,6 +7764,7 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
77647764
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_XSAVES);
77657765

77667766
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_VMX);
7767+
kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LAM);
77677768

77687769
vmx_setup_uret_msrs(vmx);
77697770

0 commit comments

Comments
 (0)