Skip to content

Commit 3cf85f9

Browse files
vittyvkbonzini
authored andcommitted
KVM: x86: nSVM: fix switch to guest mmu
Recent optimizations in MMU code broke nested SVM with NPT in L1 completely: when we do nested_svm_{,un}init_mmu_context() we want to switch from TDP MMU to shadow MMU, both init_kvm_tdp_mmu() and kvm_init_shadow_mmu() check if re-configuration is needed by looking at cache source data. The data, however, doesn't change - it's only the type of the MMU which changes. We end up not re-initializing guest MMU as shadow and everything goes off the rails. The issue could have been fixed by putting MMU type into extended MMU role but this is not really needed. We can just split root and guest MMUs the exact same way we did for nVMX, their types never change in the lifetime of a vCPU. There is still room for improvement: currently, we reset all MMU roots when switching from L1 to L2 and back and this is not needed. Fixes: 7dcd575 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0e1b869 commit 3cf85f9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/x86/kvm/svm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,8 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
29372937
static void nested_svm_init_mmu_context(struct kvm_vcpu *vcpu)
29382938
{
29392939
WARN_ON(mmu_is_nested(vcpu));
2940+
2941+
vcpu->arch.mmu = &vcpu->arch.guest_mmu;
29402942
kvm_init_shadow_mmu(vcpu);
29412943
vcpu->arch.mmu->set_cr3 = nested_svm_set_tdp_cr3;
29422944
vcpu->arch.mmu->get_cr3 = nested_svm_get_tdp_cr3;
@@ -2949,6 +2951,7 @@ static void nested_svm_init_mmu_context(struct kvm_vcpu *vcpu)
29492951

29502952
static void nested_svm_uninit_mmu_context(struct kvm_vcpu *vcpu)
29512953
{
2954+
vcpu->arch.mmu = &vcpu->arch.root_mmu;
29522955
vcpu->arch.walk_mmu = &vcpu->arch.root_mmu;
29532956
}
29542957

@@ -3458,7 +3461,6 @@ static void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
34583461
svm->vcpu.arch.hflags &= ~HF_HIF_MASK;
34593462

34603463
if (nested_vmcb->control.nested_ctl & SVM_NESTED_CTL_NP_ENABLE) {
3461-
kvm_mmu_unload(&svm->vcpu);
34623464
svm->nested.nested_cr3 = nested_vmcb->control.nested_cr3;
34633465
nested_svm_init_mmu_context(&svm->vcpu);
34643466
}

0 commit comments

Comments
 (0)