Skip to content

Commit e42c682

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: SVM: avoid emulation with stale next_rip
svm->next_rip is reset in svm_vcpu_run() only after calling svm_exit_handlers_fastpath(), which will cause SVM's skip_emulated_instruction() to write a stale RIP. We can move svm_exit_handlers_fastpath towards the end of svm_vcpu_run(). To align VMX with SVM, keep svm_complete_interrupts() close as well. Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com> Cc: Paul K. <kronenpj@kronenpj.dyndns.org> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Wanpeng Li <wanpengli@tencent.com> [Also move vmcb_mark_all_clean before any possible write to the VMCB. - Paolo]
1 parent d831de1 commit e42c682

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,8 +2938,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
29382938
if (npt_enabled)
29392939
vcpu->arch.cr3 = svm->vmcb->save.cr3;
29402940

2941-
svm_complete_interrupts(svm);
2942-
29432941
if (is_guest_mode(vcpu)) {
29442942
int vmexit;
29452943

@@ -3504,7 +3502,6 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
35043502
stgi();
35053503

35063504
/* Any pending NMI will happen here */
3507-
exit_fastpath = svm_exit_handlers_fastpath(vcpu);
35083505

35093506
if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI))
35103507
kvm_after_interrupt(&svm->vcpu);
@@ -3518,6 +3515,7 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
35183515
}
35193516

35203517
svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
3518+
vmcb_mark_all_clean(svm->vmcb);
35213519

35223520
/* if exit due to PF check for async PF */
35233521
if (svm->vmcb->control.exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR)
@@ -3537,7 +3535,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
35373535
SVM_EXIT_EXCP_BASE + MC_VECTOR))
35383536
svm_handle_mce(svm);
35393537

3540-
vmcb_mark_all_clean(svm->vmcb);
3538+
svm_complete_interrupts(svm);
3539+
exit_fastpath = svm_exit_handlers_fastpath(vcpu);
35413540
return exit_fastpath;
35423541
}
35433542

0 commit comments

Comments
 (0)