kvm/x86: split ioapic-handled and EOI exit bitmaps
authorAndrey Smetanin <asmetanin@virtuozzo.com>
Tue, 10 Nov 2015 12:36:32 +0000 (15:36 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 25 Nov 2015 16:24:21 +0000 (17:24 +0100)
The function to determine if the vector is handled by ioapic used to
rely on the fact that only ioapic-handled vectors were set up to
cause vmexits when virtual apic was in use.

We're going to break this assumption when introducing Hyper-V
synthetic interrupts: they may need to cause vmexits too.

To achieve that, introduce a new bitmap dedicated specifically for
ioapic-handled vectors, and populate EOI exit bitmap from it for now.

Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Gleb Natapov <gleb@kernel.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Roman Kagan <rkagan@virtuozzo.com>
CC: Denis V. Lunev <den@openvz.org>
CC: qemu-devel@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/ioapic.c
arch/x86/kvm/ioapic.h
arch/x86/kvm/irq_comm.c
arch/x86/kvm/lapic.c
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c

index 30cfd64295a0075ab9c4727721c0fc8c8b607f46..f6d8894f25b4c0c2959a9b469d1c42bd0b985001 100644 (file)
@@ -400,7 +400,7 @@ struct kvm_vcpu_arch {
        u64 efer;
        u64 apic_base;
        struct kvm_lapic *apic;    /* kernel irqchip context */
-       u64 eoi_exit_bitmap[4];
+       DECLARE_BITMAP(ioapic_handled_vectors, 256);
        unsigned long apic_attention;
        int32_t apic_arb_prio;
        int mp_state;
@@ -834,7 +834,7 @@ struct kvm_x86_ops {
        int (*cpu_uses_apicv)(struct kvm_vcpu *vcpu);
        void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
        void (*hwapic_isr_update)(struct kvm *kvm, int isr);
-       void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu);
+       void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
        void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set);
        void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu, hpa_t hpa);
        void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector);
index 88d0a92d3f94676d2e68cdb19b2bdd35b49a7d15..1facfd60b04ac5eed05112b0cc3412396c8aa86d 100644 (file)
@@ -233,7 +233,7 @@ static void kvm_ioapic_inject_all(struct kvm_ioapic *ioapic, unsigned long irr)
 }
 
 
-void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
+void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors)
 {
        struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
        union kvm_ioapic_redirect_entry *e;
@@ -250,7 +250,7 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
                            (e->fields.trig_mode == IOAPIC_EDGE_TRIG &&
                             kvm_apic_pending_eoi(vcpu, e->fields.vector)))
                                __set_bit(e->fields.vector,
-                                       (unsigned long *)eoi_exit_bitmap);
+                                         ioapic_handled_vectors);
                }
        }
        spin_unlock(&ioapic->lock);
index 084617d37c74d0264926cdb26bef3fb57c06965e..2d16dc251d81a45cff53ae2a9d629e8ee7ecb732 100644 (file)
@@ -121,7 +121,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
                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_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
-void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
-
+void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu,
+                          ulong *ioapic_handled_vectors);
+void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
+                           ulong *ioapic_handled_vectors);
 #endif
index e39768ca8285e42a147317cb4151b05807c4f3b9..ece901c293513eac3a4c9a68e1a8bef2e3cd3dee 100644 (file)
@@ -339,7 +339,8 @@ void kvm_arch_post_irq_routing_update(struct kvm *kvm)
        kvm_make_scan_ioapic_request(kvm);
 }
 
-void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
+void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu,
+                           ulong *ioapic_handled_vectors)
 {
        struct kvm *kvm = vcpu->kvm;
        struct kvm_kernel_irq_routing_entry *entry;
@@ -369,7 +370,7 @@ void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
                                u32 vector = entry->msi.data & 0xff;
 
                                __set_bit(vector,
-                                         (unsigned long *) eoi_exit_bitmap);
+                                         ioapic_handled_vectors);
                        }
                }
        }
index 4d30b865be30641f4964a3279939020e9f1a057a..9469d453abc8026746e58b37f6a3f2e1057bf3b6 100644 (file)
@@ -932,7 +932,7 @@ int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2)
 
 static bool kvm_ioapic_handles_vector(struct kvm_lapic *apic, int vector)
 {
-       return test_bit(vector, (ulong *)apic->vcpu->arch.eoi_exit_bitmap);
+       return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors);
 }
 
 static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
index 83a1c643f9a50fd3fa0ffc041c40d9f4d25aa5b5..ebb76e8a91e1a447460deff5cd7c441ebc865bf5 100644 (file)
@@ -3564,7 +3564,7 @@ static int svm_cpu_uses_apicv(struct kvm_vcpu *vcpu)
        return 0;
 }
 
-static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu)
+static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
 {
        return;
 }
index af823a388c1994ba244e3ef0098f1a578408101e..c8a87c94dc81f35062ea19e48b1819d27ff91ee9 100644 (file)
@@ -8257,9 +8257,8 @@ static void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr)
        }
 }
 
-static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu)
+static void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
 {
-       u64 *eoi_exit_bitmap = vcpu->arch.eoi_exit_bitmap;
        if (!vmx_cpu_uses_apicv(vcpu))
                return;
 
index eed32283d22cc0cafbff75e8f2a246887d4cbb5f..9c69337a3d61494ddb1b1a19781c40810898c390 100644 (file)
@@ -6301,15 +6301,16 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
        if (!kvm_apic_hw_enabled(vcpu->arch.apic))
                return;
 
-       memset(vcpu->arch.eoi_exit_bitmap, 0, 256 / 8);
+       bitmap_zero(vcpu->arch.ioapic_handled_vectors, 256);
 
        if (irqchip_split(vcpu->kvm))
-               kvm_scan_ioapic_routes(vcpu, vcpu->arch.eoi_exit_bitmap);
+               kvm_scan_ioapic_routes(vcpu, vcpu->arch.ioapic_handled_vectors);
        else {
                kvm_x86_ops->sync_pir_to_irr(vcpu);
-               kvm_ioapic_scan_entry(vcpu, vcpu->arch.eoi_exit_bitmap);
+               kvm_ioapic_scan_entry(vcpu, vcpu->arch.ioapic_handled_vectors);
        }
-       kvm_x86_ops->load_eoi_exitmap(vcpu);
+       kvm_x86_ops->load_eoi_exitmap(vcpu,
+                                     (u64 *)vcpu->arch.ioapic_handled_vectors);
 }
 
 static void kvm_vcpu_flush_tlb(struct kvm_vcpu *vcpu)
@@ -6417,7 +6418,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
                if (kvm_check_request(KVM_REQ_IOAPIC_EOI_EXIT, vcpu)) {
                        BUG_ON(vcpu->arch.pending_ioapic_eoi > 255);
                        if (test_bit(vcpu->arch.pending_ioapic_eoi,
-                                    (void *) vcpu->arch.eoi_exit_bitmap)) {
+                                    vcpu->arch.ioapic_handled_vectors)) {
                                vcpu->run->exit_reason = KVM_EXIT_IOAPIC_EOI;
                                vcpu->run->eoi.vector =
                                                vcpu->arch.pending_ioapic_eoi;