KVM: Set TMR when programming ioapic entry
authorYang Zhang <yang.z.zhang@Intel.com>
Thu, 11 Apr 2013 11:25:14 +0000 (19:25 +0800)
committerMarcelo Tosatti <mtosatti@redhat.com>
Tue, 16 Apr 2013 19:32:40 +0000 (16:32 -0300)
We already know the trigger mode of a given interrupt when programming
the ioapice entry. So it's not necessary to set it in each interrupt
delivery.

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
arch/x86/kvm/x86.c
virt/kvm/ioapic.c
virt/kvm/ioapic.h

index 34a8ca845280b3120b1afc0a651600b4115a8c27..d197579435d00bf8e78703d4e454e05f8b4b1cbe 100644 (file)
@@ -468,6 +468,15 @@ static inline int apic_find_highest_isr(struct kvm_lapic *apic)
        return result;
 }
 
+void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr)
+{
+       struct kvm_lapic *apic = vcpu->arch.apic;
+       int i;
+
+       for (i = 0; i < 8; i++)
+               apic_set_reg(apic, APIC_TMR + 0x10 * i, tmr[i]);
+}
+
 static void apic_update_ppr(struct kvm_lapic *apic)
 {
        u32 tpr, isrv, ppr, old_ppr;
@@ -661,12 +670,6 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
                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);
-               } else
-                       apic_clear_vector(vector, apic->regs + APIC_TMR);
-
                result = !apic_test_and_set_irr(vector, apic);
                trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode,
                                          trig_mode, vector, !result);
index 16304b1a8cba22dd253e4139301e36c6d14fff4a..7fe0c9180ea1f962947e72e23b5f003728a64d40 100644 (file)
@@ -53,6 +53,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value);
 u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
 void kvm_apic_set_version(struct kvm_vcpu *vcpu);
 
+void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
 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,
index 87a05df3eae4a381e0537af3a227a5034b06827f..276b4a9a5605de065f95743a77dd16f1ddba1db8 100644 (file)
@@ -5664,14 +5664,17 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
 static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 {
        u64 eoi_exit_bitmap[4];
+       u32 tmr[8];
 
        if (!kvm_apic_hw_enabled(vcpu->arch.apic))
                return;
 
        memset(eoi_exit_bitmap, 0, 32);
+       memset(tmr, 0, 32);
 
-       kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap);
+       kvm_ioapic_scan_entry(vcpu, eoi_exit_bitmap, tmr);
        kvm_x86_ops->load_eoi_exitmap(vcpu, eoi_exit_bitmap);
+       kvm_apic_update_tmr(vcpu, tmr);
 }
 
 static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
index f2157a985a1f9ded86be0169ac28bab03cc8d947..2d682977ce82656bd29a9a915fced16174163db3 100644 (file)
@@ -193,7 +193,8 @@ static void update_handled_vectors(struct kvm_ioapic *ioapic)
        smp_wmb();
 }
 
-void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
+void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+                       u32 *tmr)
 {
        struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
        union kvm_ioapic_redirect_entry *e;
@@ -207,8 +208,13 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
                         kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC,
                                 index) || index == RTC_GSI)) {
                        if (kvm_apic_match_dest(vcpu, NULL, 0,
-                               e->fields.dest_id, e->fields.dest_mode))
-                               __set_bit(e->fields.vector, (unsigned long *)eoi_exit_bitmap);
+                               e->fields.dest_id, e->fields.dest_mode)) {
+                               __set_bit(e->fields.vector,
+                                       (unsigned long *)eoi_exit_bitmap);
+                               if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG)
+                                       __set_bit(e->fields.vector,
+                                               (unsigned long *)tmr);
+                       }
                }
        }
        spin_unlock(&ioapic->lock);
index 674a388612b42204c68a9e6680daaa3d15fb6aa9..615d8c995c3c1fec2bdfc4f875bcad477bee9e53 100644 (file)
@@ -97,6 +97,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
 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_vcpu_request_scan_ioapic(struct kvm *kvm);
-void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
+void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap,
+                       u32 *tmr);
 
 #endif