Skip to content

Commit 096586f

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: nSVM: Correctly set the shadow NPT root level in its MMU role
Move the initialization of shadow NPT MMU's shadow_root_level into kvm_init_shadow_npt_mmu() and explicitly set the level in the shadow NPT MMU's role to be the TDP level. This ensures the role and MMU levels are synchronized and also initialized before __kvm_mmu_new_pgd(), which consumes the level when attempting a fast PGD switch. Cc: Vitaly Kuznetsov <[email protected]> Fixes: 9fa7211 ("kvm: x86: Introduce kvm_mmu_calc_root_page_role()") Fixes: a506fdd ("KVM: nSVM: implement nested_svm_load_cr3() and use it for host->guest switch") Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Tested-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9c2475f commit 096586f

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4963,6 +4963,9 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, u32 cr0, u32 cr4, u32 efer,
49634963
union kvm_mmu_role new_role =
49644964
kvm_calc_shadow_mmu_root_page_role(vcpu, false);
49654965

4966+
new_role.base.level = vcpu->arch.tdp_level;
4967+
context->shadow_root_level = new_role.base.level;
4968+
49664969
__kvm_mmu_new_pgd(vcpu, nested_cr3, new_role.base, false, false);
49674970

49684971
if (new_role.as_u64 != context->mmu_role.as_u64)

arch/x86/kvm/svm/nested.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ static void nested_svm_init_mmu_context(struct kvm_vcpu *vcpu)
8585
vcpu->arch.mmu->get_guest_pgd = nested_svm_get_tdp_cr3;
8686
vcpu->arch.mmu->get_pdptr = nested_svm_get_tdp_pdptr;
8787
vcpu->arch.mmu->inject_page_fault = nested_svm_inject_npf_exit;
88-
vcpu->arch.mmu->shadow_root_level = vcpu->arch.tdp_level;
8988
reset_shadow_zero_bits_mask(vcpu, vcpu->arch.mmu);
9089
vcpu->arch.walk_mmu = &vcpu->arch.nested_mmu;
9190
}

0 commit comments

Comments
 (0)