Skip to content

Commit 8301305

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Specify max TDP level via kvm_configure_mmu()
Capture the max TDP level during kvm_configure_mmu() instead of using a kvm_x86_ops hook to do it at every vCPU creation. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 1d92d2e commit 8301305

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ struct kvm_x86_ops {
11331133
int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu);
11341134
int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
11351135
int (*set_identity_map_addr)(struct kvm *kvm, u64 ident_addr);
1136-
int (*get_max_tdp_level)(void);
11371136
u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
11381137

11391138
void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, unsigned long pgd,
@@ -1509,7 +1508,8 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid);
15091508
void kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd, bool skip_tlb_flush,
15101509
bool skip_mmu_sync);
15111510

1512-
void kvm_configure_mmu(bool enable_tdp, int tdp_page_level);
1511+
void kvm_configure_mmu(bool enable_tdp, int tdp_max_root_level,
1512+
int tdp_huge_page_level);
15131513

15141514
static inline u16 kvm_read_ldt(void)
15151515
{

arch/x86/kvm/mmu/mmu.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module_param_named(flush_on_reuse, force_flush_and_sync_on_reuse, bool, 0644);
9393
bool tdp_enabled = false;
9494

9595
static int max_huge_page_level __read_mostly;
96+
static int max_tdp_level __read_mostly;
9697

9798
enum {
9899
AUDIT_PRE_PAGE_FAULT,
@@ -4849,10 +4850,10 @@ static union kvm_mmu_role kvm_calc_mmu_role_common(struct kvm_vcpu *vcpu,
48494850
static inline int kvm_mmu_get_tdp_level(struct kvm_vcpu *vcpu)
48504851
{
48514852
/* Use 5-level TDP if and only if it's useful/necessary. */
4852-
if (vcpu->arch.max_tdp_level == 5 && cpuid_maxphyaddr(vcpu) <= 48)
4853+
if (max_tdp_level == 5 && cpuid_maxphyaddr(vcpu) <= 48)
48534854
return 4;
48544855

4855-
return vcpu->arch.max_tdp_level;
4856+
return max_tdp_level;
48564857
}
48574858

48584859
static union kvm_mmu_role
@@ -5580,9 +5581,11 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid)
55805581
}
55815582
EXPORT_SYMBOL_GPL(kvm_mmu_invpcid_gva);
55825583

5583-
void kvm_configure_mmu(bool enable_tdp, int tdp_huge_page_level)
5584+
void kvm_configure_mmu(bool enable_tdp, int tdp_max_root_level,
5585+
int tdp_huge_page_level)
55845586
{
55855587
tdp_enabled = enable_tdp;
5588+
max_tdp_level = tdp_max_root_level;
55865589

55875590
/*
55885591
* max_huge_page_level reflects KVM's MMU capabilities irrespective

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ static __init int svm_hardware_setup(void)
885885
if (npt_enabled && !npt)
886886
npt_enabled = false;
887887

888-
kvm_configure_mmu(npt_enabled, PG_LEVEL_1G);
888+
kvm_configure_mmu(npt_enabled, get_max_npt_level(), PG_LEVEL_1G);
889889
pr_info("kvm: Nested Paging %sabled\n", npt_enabled ? "en" : "dis");
890890

891891
if (nrips) {
@@ -4109,7 +4109,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
41094109

41104110
.set_tss_addr = svm_set_tss_addr,
41114111
.set_identity_map_addr = svm_set_identity_map_addr,
4112-
.get_max_tdp_level = get_max_npt_level,
41134112
.get_mt_mask = svm_get_mt_mask,
41144113

41154114
.get_exit_info = svm_get_exit_info,

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7959,7 +7959,6 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = {
79597959

79607960
.set_tss_addr = vmx_set_tss_addr,
79617961
.set_identity_map_addr = vmx_set_identity_map_addr,
7962-
.get_max_tdp_level = vmx_get_max_tdp_level,
79637962
.get_mt_mask = vmx_get_mt_mask,
79647963

79657964
.get_exit_info = vmx_get_exit_info,
@@ -8110,7 +8109,7 @@ static __init int hardware_setup(void)
81108109
ept_lpage_level = PG_LEVEL_2M;
81118110
else
81128111
ept_lpage_level = PG_LEVEL_4K;
8113-
kvm_configure_mmu(enable_ept, ept_lpage_level);
8112+
kvm_configure_mmu(enable_ept, vmx_get_max_tdp_level(), ept_lpage_level);
81148113

81158114
/*
81168115
* Only enable PML when hardware supports PML feature, and both EPT

arch/x86/kvm/x86.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9520,7 +9520,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
95209520
fx_init(vcpu);
95219521

95229522
vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
9523-
vcpu->arch.max_tdp_level = kvm_x86_ops.get_max_tdp_level();
95249523

95259524
vcpu->arch.pat = MSR_IA32_CR_PAT_DEFAULT;
95269525

0 commit comments

Comments
 (0)