Skip to content

Commit d82aaef

Browse files
vittyvkbonzini
authored andcommitted
KVM: nSVM: use nested_svm_load_cr3() on guest->host switch
Make nSVM code resemble nVMX where nested_vmx_load_cr3() is used on both guest->host and host->guest transitions. Also, we can now eliminate unconditional kvm_mmu_reset_context() and speed things up. Note, nVMX has two different paths: load_vmcs12_host_state() and nested_vmx_restore_host_state() and the later is used to restore from 'partial' switch to L2, it always uses kvm_mmu_reset_context(). nSVM doesn't have this yet. Also, nested_svm_vmexit()'s return value is almost always ignored nowadays. Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a506fdd commit d82aaef

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm)
342342
}
343343

344344
/*
345-
* Load guest's cr3 at nested entry. @nested_npt is true if we are
346-
* emulating VM-Entry into a guest with NPT enabled.
345+
* Load guest's/host's cr3 on nested vmentry or vmexit. @nested_npt is true
346+
* if we are emulating VM-Entry into a guest with NPT enabled.
347347
*/
348348
static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
349349
bool nested_npt)
@@ -676,15 +676,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
676676

677677
nested_svm_uninit_mmu_context(&svm->vcpu);
678678

679-
if (npt_enabled) {
680-
svm->vmcb->save.cr3 = hsave->save.cr3;
681-
svm->vcpu.arch.cr3 = hsave->save.cr3;
682-
} else {
683-
(void)kvm_set_cr3(&svm->vcpu, hsave->save.cr3);
684-
}
679+
rc = nested_svm_load_cr3(&svm->vcpu, hsave->save.cr3, false);
680+
if (rc)
681+
return 1;
685682

686-
kvm_mmu_reset_context(&svm->vcpu);
687-
kvm_mmu_load(&svm->vcpu);
683+
if (npt_enabled)
684+
svm->vmcb->save.cr3 = hsave->save.cr3;
688685

689686
/*
690687
* Drop what we picked up for L2 via svm_complete_interrupts() so it

0 commit comments

Comments
 (0)