From: Joerg Roedel <[email protected]>

When there are IRQs or events pending for plane0, make sure it can
handle it.

Signed-off-by: Joerg Roedel <[email protected]>
---
 arch/x86/kvm/x86.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 08fe65b8d57d..60b34bd4da9d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10962,6 +10962,20 @@ static int kvm_check_and_inject_events(struct kvm_vcpu 
*vcpu,
        return r;
 }
 
+static inline bool kvm_check_plane0_events(struct kvm_vcpu *vcpu)
+{
+       struct kvm_vcpu *vcpu_plane0;
+
+       if (vcpu->plane_level == 0)
+               return false;
+
+       vcpu_plane0 = vcpu->common->vcpus[0];
+
+       return kvm_cpu_has_injectable_intr(vcpu_plane0) ||
+               vcpu_plane0->arch.nmi_pending ||
+               vcpu_plane0->arch.smi_pending;
+}
+
 static void process_nmi(struct kvm_vcpu *vcpu)
 {
        unsigned int limit;
@@ -11410,12 +11424,19 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
                                goto out;
                        }
                }
+       }
 
-               if (kvm_check_request(KVM_REQ_PLANE_RESCHED, vcpu)) {
-                       vcpu->common->plane_switch = true;
-                       r = 0;
-                       goto out;
-               }
+       if (kvm_check_plane0_events(vcpu)) {
+               kvm_vcpu_set_plane_runnable(vcpu->common->vcpus[0]);
+
+               kvm_make_request(KVM_REQ_EVENT, vcpu);
+               kvm_make_request(KVM_REQ_PLANE_RESCHED, vcpu);
+       }
+
+       if (kvm_check_request(KVM_REQ_PLANE_RESCHED, vcpu)) {
+               vcpu->common->plane_switch = true;
+               r = 0;
+               goto out;
        }
 
        if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win ||
@@ -11737,6 +11758,9 @@ bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
        if (kvm_test_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, vcpu))
                return true;
 
+       if (kvm_test_request(KVM_REQ_PLANE_RESCHED, vcpu))
+               return true;
+
        if (kvm_arch_interrupt_allowed(vcpu) && kvm_cpu_has_interrupt(vcpu))
                return true;
 
-- 
2.53.0


Reply via email to