KVM: Return destination vcpu on interrupt injection
authorYang Zhang <yang.z.zhang@Intel.com>
Thu, 11 Apr 2013 11:21:37 +0000 (19:21 +0800)
committerMarcelo Tosatti <mtosatti@redhat.com>
Tue, 16 Apr 2013 02:20:34 +0000 (23:20 -0300)
Add a new parameter to know vcpus who received the interrupt.

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/lapic.h
virt/kvm/ioapic.c
virt/kvm/ioapic.h
virt/kvm/irq_comm.c

index 3e22536a703175f23875371865deda2e811262e1..0b734025fc87fe64526eb5e22eaca349479ac475 100644 (file)
@@ -384,14 +384,16 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
 }
 
 static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
-                            int vector, int level, int trig_mode);
+                            int vector, int level, int trig_mode,
+                            unsigned long *dest_map);
 
-int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq)
+int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
+               unsigned long *dest_map)
 {
        struct kvm_lapic *apic = vcpu->arch.apic;
 
        return __apic_accept_irq(apic, irq->delivery_mode, irq->vector,
-                       irq->level, irq->trig_mode);
+                       irq->level, irq->trig_mode, dest_map);
 }
 
 static int pv_eoi_put_user(struct kvm_vcpu *vcpu, u8 val)
@@ -564,7 +566,7 @@ int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
 }
 
 bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
-               struct kvm_lapic_irq *irq, int *r)
+               struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map)
 {
        struct kvm_apic_map *map;
        unsigned long bitmap = 1;
@@ -575,7 +577,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
        *r = -1;
 
        if (irq->shorthand == APIC_DEST_SELF) {
-               *r = kvm_apic_set_irq(src->vcpu, irq);
+               *r = kvm_apic_set_irq(src->vcpu, irq, dest_map);
                return true;
        }
 
@@ -620,7 +622,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
                        continue;
                if (*r < 0)
                        *r = 0;
-               *r += kvm_apic_set_irq(dst[i]->vcpu, irq);
+               *r += kvm_apic_set_irq(dst[i]->vcpu, irq, dest_map);
        }
 
        ret = true;
@@ -634,7 +636,8 @@ out:
  * Return 1 if successfully added and 0 if discarded.
  */
 static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
-                            int vector, int level, int trig_mode)
+                            int vector, int level, int trig_mode,
+                            unsigned long *dest_map)
 {
        int result = 0;
        struct kvm_vcpu *vcpu = apic->vcpu;
@@ -647,6 +650,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
                if (unlikely(!apic_enabled(apic)))
                        break;
 
+               if (dest_map)
+                       __set_bit(vcpu->vcpu_id, dest_map);
+
                if (trig_mode) {
                        apic_debug("level trig mode for vector %d", vector);
                        apic_set_vector(vector, apic->regs + APIC_TMR);
@@ -805,7 +811,7 @@ static void apic_send_ipi(struct kvm_lapic *apic)
                   irq.trig_mode, irq.level, irq.dest_mode, irq.delivery_mode,
                   irq.vector);
 
-       kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq);
+       kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq, NULL);
 }
 
 static u32 apic_get_tmcct(struct kvm_lapic *apic)
@@ -1441,7 +1447,8 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type)
                vector = reg & APIC_VECTOR_MASK;
                mode = reg & APIC_MODE_MASK;
                trig_mode = reg & APIC_LVT_LEVEL_TRIGGER;
-               return __apic_accept_irq(apic, mode, vector, 1, trig_mode);
+               return __apic_accept_irq(apic, mode, vector, 1, trig_mode,
+                                       NULL);
        }
        return 0;
 }
index baa20cfb95ae36db337e3aca6f66b4699fd701d7..3e5a43160cb7888becf2b087c8da48286e0278a2 100644 (file)
@@ -55,11 +55,12 @@ void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
 int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
 int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda);
-int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq);
+int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
+               unsigned long *dest_map);
 int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type);
 
 bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
-               struct kvm_lapic_irq *irq, int *r);
+               struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map);
 
 u64 kvm_get_apic_base(struct kvm_vcpu *vcpu);
 void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data);
index 1d8906d39214d96b0003ef7196cd23f1b27fed58..27ae8dd64e29c150dd1b8e6db960547714d32cee 100644 (file)
@@ -217,7 +217,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
        irqe.level = 1;
        irqe.shorthand = 0;
 
-       return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe);
+       return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
 }
 
 int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
index 87cd94bae372a25694c05793a375a39b8a2199d9..761e5b57099ea2d434880d765e8c2653fb4e6e0f 100644 (file)
@@ -92,7 +92,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
 void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id);
 void kvm_ioapic_reset(struct kvm_ioapic *ioapic);
 int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
-               struct kvm_lapic_irq *irq);
+               struct kvm_lapic_irq *irq, unsigned long *dest_map);
 int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
 int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state);
 void kvm_ioapic_make_eoibitmap_request(struct kvm *kvm);
index e9073cf4d0406c0faaec2faf0d87015f962494ad..2f07d2e59a2ddf3d36ed7d882aebbfdd70541819 100644 (file)
@@ -63,7 +63,7 @@ inline static bool kvm_is_dm_lowest_prio(struct kvm_lapic_irq *irq)
 }
 
 int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
-               struct kvm_lapic_irq *irq)
+               struct kvm_lapic_irq *irq, unsigned long *dest_map)
 {
        int i, r = -1;
        struct kvm_vcpu *vcpu, *lowest = NULL;
@@ -74,7 +74,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
                irq->delivery_mode = APIC_DM_FIXED;
        }
 
-       if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r))
+       if (kvm_irq_delivery_to_apic_fast(kvm, src, irq, &r, dest_map))
                return r;
 
        kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -88,7 +88,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
                if (!kvm_is_dm_lowest_prio(irq)) {
                        if (r < 0)
                                r = 0;
-                       r += kvm_apic_set_irq(vcpu, irq);
+                       r += kvm_apic_set_irq(vcpu, irq, dest_map);
                } else if (kvm_lapic_enabled(vcpu)) {
                        if (!lowest)
                                lowest = vcpu;
@@ -98,7 +98,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
        }
 
        if (lowest)
-               r = kvm_apic_set_irq(lowest, irq);
+               r = kvm_apic_set_irq(lowest, irq, dest_map);
 
        return r;
 }
@@ -130,7 +130,7 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
 
        kvm_set_msi_irq(e, &irq);
 
-       return kvm_irq_delivery_to_apic(kvm, NULL, &irq);
+       return kvm_irq_delivery_to_apic(kvm, NULL, &irq, NULL);
 }
 
 
@@ -142,7 +142,7 @@ static int kvm_set_msi_inatomic(struct kvm_kernel_irq_routing_entry *e,
 
        kvm_set_msi_irq(e, &irq);
 
-       if (kvm_irq_delivery_to_apic_fast(kvm, NULL, &irq, &r))
+       if (kvm_irq_delivery_to_apic_fast(kvm, NULL, &irq, &r, NULL))
                return r;
        else
                return -EWOULDBLOCK;