Commit d82aaef9 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

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: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20200710141157.1640173-9-vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent a506fdd2
...@@ -342,8 +342,8 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm) ...@@ -342,8 +342,8 @@ static inline bool nested_npt_enabled(struct vcpu_svm *svm)
} }
/* /*
* Load guest's cr3 at nested entry. @nested_npt is true if we are * Load guest's/host's cr3 on nested vmentry or vmexit. @nested_npt is true
* emulating VM-Entry into a guest with NPT enabled. * if we are emulating VM-Entry into a guest with NPT enabled.
*/ */
static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3, static int nested_svm_load_cr3(struct kvm_vcpu *vcpu, unsigned long cr3,
bool nested_npt) bool nested_npt)
...@@ -676,15 +676,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) ...@@ -676,15 +676,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
nested_svm_uninit_mmu_context(&svm->vcpu); nested_svm_uninit_mmu_context(&svm->vcpu);
if (npt_enabled) { rc = nested_svm_load_cr3(&svm->vcpu, hsave->save.cr3, false);
svm->vmcb->save.cr3 = hsave->save.cr3; if (rc)
svm->vcpu.arch.cr3 = hsave->save.cr3; return 1;
} else {
(void)kvm_set_cr3(&svm->vcpu, hsave->save.cr3);
}
kvm_mmu_reset_context(&svm->vcpu); if (npt_enabled)
kvm_mmu_load(&svm->vcpu); svm->vmcb->save.cr3 = hsave->save.cr3;
/* /*
* Drop what we picked up for L2 via svm_complete_interrupts() so it * Drop what we picked up for L2 via svm_complete_interrupts() so it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment