Skip to content

Commit bf7dea4

Browse files
vittyvkbonzini
authored andcommitted
KVM: nSVM: move kvm_set_cr3() after nested_svm_uninit_mmu_context()
kvm_mmu_new_pgd() refers to arch.mmu and at this point it still references arch.guest_mmu while arch.root_mmu is expected. Note, the change is effectively a nop: when !npt_enabled, nested_svm_uninit_mmu_context() does nothing (as we don't do nested_svm_init_mmu_context()) and with npt_enabled we don't do kvm_set_cr3(). However, it will matter when we move the call to kvm_mmu_new_pgd into nested_svm_load_cr3(). No functional change intended. Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 62156f6 commit bf7dea4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
636636
svm_set_efer(&svm->vcpu, hsave->save.efer);
637637
svm_set_cr0(&svm->vcpu, hsave->save.cr0 | X86_CR0_PE);
638638
svm_set_cr4(&svm->vcpu, hsave->save.cr4);
639-
if (npt_enabled) {
640-
svm->vmcb->save.cr3 = hsave->save.cr3;
641-
svm->vcpu.arch.cr3 = hsave->save.cr3;
642-
} else {
643-
(void)kvm_set_cr3(&svm->vcpu, hsave->save.cr3);
644-
}
645639
kvm_rax_write(&svm->vcpu, hsave->save.rax);
646640
kvm_rsp_write(&svm->vcpu, hsave->save.rsp);
647641
kvm_rip_write(&svm->vcpu, hsave->save.rip);
@@ -661,6 +655,14 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
661655
kvm_vcpu_unmap(&svm->vcpu, &map, true);
662656

663657
nested_svm_uninit_mmu_context(&svm->vcpu);
658+
659+
if (npt_enabled) {
660+
svm->vmcb->save.cr3 = hsave->save.cr3;
661+
svm->vcpu.arch.cr3 = hsave->save.cr3;
662+
} else {
663+
(void)kvm_set_cr3(&svm->vcpu, hsave->save.cr3);
664+
}
665+
664666
kvm_mmu_reset_context(&svm->vcpu);
665667
kvm_mmu_load(&svm->vcpu);
666668

0 commit comments

Comments
 (0)