Skip to contentSkip to conversation

KVM: SVM: Move svm_complete_interrupts() into svm_vcpu_run()

PATCH Superseded Wanpeng Li 3 participants 5 messages Sep 9, 2020 – Sep 14, 2020

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 2/3 KVM: SVM: Move svm_complete_interrupts() into svm_vcpu_run()

From: Wanpeng Li <[email protected]>

Moving svm_complete_interrupts() into svm_vcpu_run() which can align VMX and SVM with respect to completing interrupts.

---
 arch/x86/kvm/svm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +2 -2
index c61bc3b..74bcf0a 100644
@@ -2938,8 +2938,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
 	if (npt_enabled)
 		vcpu->arch.cr3 = svm->vmcb->save.cr3;
 
-	svm_complete_interrupts(svm);
-
 	if (is_guest_mode(vcpu)) {
 		int vmexit;
 
@@ -3530,6 +3528,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
 		     SVM_EXIT_EXCP_BASE + MC_VECTOR))
 		svm_handle_mce(svm);
 
+	svm_complete_interrupts(svm);
+
 	vmcb_mark_all_clean(svm->vmcb);
 	return exit_fastpath;
 }
Signature · 1 line
2.7.4
Reviewed-by on v1 2/3
#1 lore raw
Quoted 26 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Moving svm_complete_interrupts() into svm_vcpu_run() which can align VMX and SVM with respect to completing interrupts.

---
 arch/x86/kvm/svm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +0 -2
index c61bc3b..74bcf0a 100644
@@ -2938,8 +2938,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
 	if (npt_enabled)
 		vcpu->arch.cr3 = svm->vmcb->save.cr3;
 
-	svm_complete_interrupts(svm);
-
 	if (is_guest_mode(vcpu)) {
 		int vmexit;
 

arch/x86/kvm/svm/svm.c static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) · line 3535

Quoted 8 lines
arch/x86/kvm/svm/svm.c +2 -0
@@ -3530,6 +3528,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
 		     SVM_EXIT_EXCP_BASE + MC_VECTOR))
 		svm_handle_mce(svm);
 
+	svm_complete_interrupts(svm);
+
 	vmcb_mark_all_clean(svm->vmcb);
 	return exit_fastpath;
 }

This seems to be the right thing to do, however, the amount of code between kvm_x86_ops.run() and kvm_x86_ops.handle_exit() is non-trivial, hope it won't blow up in testing...

One more thing:

VMX version does

        vmx_complete_interrupts(vmx);
        if (is_guest_mode(vcpu))
                return EXIT_FASTPATH_NONE;

and on SVM we analyze is_guest_mode() inside svm_exit_handlers_fastpath() - should we also change that for conformity?

Signature · 1 line
Vitaly
author
#2 lore raw
Quoted 48 lines · Vitaly Kuznetsov
Quoted 26 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Moving svm_complete_interrupts() into svm_vcpu_run() which can align VMX and SVM with respect to completing interrupts.

---
 arch/x86/kvm/svm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/svm.c +0 -2
index c61bc3b..74bcf0a 100644
@@ -2938,8 +2938,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
      if (npt_enabled)
              vcpu->arch.cr3 = svm->vmcb->save.cr3;
 
-     svm_complete_interrupts(svm);
-
      if (is_guest_mode(vcpu)) {
              int vmexit;
 

arch/x86/kvm/svm/svm.c static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) · line 3535

Quoted 8 lines
arch/x86/kvm/svm/svm.c +2 -0
@@ -3530,6 +3528,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
                   SVM_EXIT_EXCP_BASE + MC_VECTOR))
              svm_handle_mce(svm);
 
+     svm_complete_interrupts(svm);
+
      vmcb_mark_all_clean(svm->vmcb);
      return exit_fastpath;
 }

This seems to be the right thing to do, however, the amount of code between kvm_x86_ops.run() and kvm_x86_ops.handle_exit() is non-trivial, hope it won't blow up in testing...

One more thing:

VMX version does

Quoted 7 lines
        vmx_complete_interrupts(vmx);
        if (is_guest_mode(vcpu))
                return EXIT_FASTPATH_NONE;

and on SVM we analyze is_guest_mode() inside svm_exit_handlers_fastpath() - should we also change that for conformity?

Agreed, will do in v2.

Wanpeng

maintainer
#3 lore raw
Quoted 8 lines · Wanpeng Li
Quoted 8 lines

One more thing:

VMX version does

        vmx_complete_interrupts(vmx);
        if (is_guest_mode(vcpu))
                return EXIT_FASTPATH_NONE;
Quoted 5 lines
Quoted 3 lines

and on SVM we analyze is_guest_mode() inside svm_exit_handlers_fastpath() - should we also change that for conformity?

Agreed, will do in v2.

Please just send an incremental patch. Thanks!

Paolo

author
#4 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines · Wanpeng Li
Quoted 8 lines

One more thing:

VMX version does

        vmx_complete_interrupts(vmx);
        if (is_guest_mode(vcpu))
                return EXIT_FASTPATH_NONE;
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

and on SVM we analyze is_guest_mode() inside svm_exit_handlers_fastpath() - should we also change that for conformity?

Agreed, will do in v2.

Please just send an incremental patch. Thanks!

Just sent out a patch to do it. :)

Wanpeng