KVM: VMX: Use posted interrupt to deliver virtual interrupt
authorYang Zhang <yang.z.zhang@Intel.com>
Thu, 11 Apr 2013 11:25:16 +0000 (19:25 +0800)
committerMarcelo Tosatti <mtosatti@redhat.com>
Tue, 16 Apr 2013 19:32:41 +0000 (16:32 -0300)
If posted interrupt is avaliable, then uses it to inject virtual
interrupt to guest.

Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
Reviewed-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/lapic.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c

index dbf74c922aa13510d00e80deecaeb07a00e7965b..e29883c604ff02c232a769663cf33a4d6f80379c 100644 (file)
@@ -353,6 +353,7 @@ static inline int apic_find_highest_irr(struct kvm_lapic *apic)
        if (!apic->irr_pending)
                return -1;
 
+       kvm_x86_ops->sync_pir_to_irr(apic->vcpu);
        result = apic_search_irr(apic);
        ASSERT(result == -1 || result >= 16);
 
@@ -683,18 +684,25 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
                if (dest_map)
                        __set_bit(vcpu->vcpu_id, dest_map);
 
-               result = !apic_test_and_set_irr(vector, apic);
-               trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode,
-                                         trig_mode, vector, !result);
-               if (!result) {
-                       if (trig_mode)
-                               apic_debug("level trig mode repeatedly for "
-                                               "vector %d", vector);
-                       break;
-               }
+               if (kvm_x86_ops->deliver_posted_interrupt) {
+                       result = 1;
+                       kvm_x86_ops->deliver_posted_interrupt(vcpu, vector);
+               } else {
+                       result = !apic_test_and_set_irr(vector, apic);
 
-               kvm_make_request(KVM_REQ_EVENT, vcpu);
-               kvm_vcpu_kick(vcpu);
+                       if (!result) {
+                               if (trig_mode)
+                                       apic_debug("level trig mode repeatedly "
+                                               "for vector %d", vector);
+                               goto out;
+                       }
+
+                       kvm_make_request(KVM_REQ_EVENT, vcpu);
+                       kvm_vcpu_kick(vcpu);
+               }
+out:
+               trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode,
+                               trig_mode, vector, !result);
                break;
 
        case APIC_DM_REMRD:
index 3a14d8a0ee462853d86448fd824d7cc56de2fa7a..5a87a58af49dc75b61de4f89b1886d74f86dd3a7 100644 (file)
@@ -84,7 +84,7 @@ module_param(vmm_exclusive, bool, S_IRUGO);
 static bool __read_mostly fasteoi = 1;
 module_param(fasteoi, bool, S_IRUGO);
 
-static bool __read_mostly enable_apicv;
+static bool __read_mostly enable_apicv = 1;
 module_param(enable_apicv, bool, S_IRUGO);
 
 /*
index 276b4a9a5605de065f95743a77dd16f1ddba1db8..50e2e10b80416b85a9356f017b1eff347c368d0e 100644 (file)
@@ -2692,6 +2692,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu,
                                    struct kvm_lapic_state *s)
 {
+       kvm_x86_ops->sync_pir_to_irr(vcpu);
        memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s);
 
        return 0;