Use eoi to track RTC interrupt delivery status
v6 cover Use eoi to track RTC interrupt delivery status
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, the pending_eoi set to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.
Changes from v5 to v6
* Move set dest_map logic into __apic_accept_irq().
* Use RTC_GSI to distinguish different platform, and drop all CONFIG_X86.
* Rebase on top of KVM.
Changes from v4 to v5
* Calculate destination vcpu on interrupt injection not hook into ioapic modification.
* Rebase on top of KVM.
Changes from v3 to v4
* Call kvm_apic_match_dest() to check destination vcpu.
* Update RTC interrrupt's destination vcpu map when ioapic entry of RTC or apic register (id, ldr, dfr) is changed.
Changes from v2 to v3:
* Remove unused viarable irq_ack_notifier.
* Acquire ioapic->lock before calculte destination vcpu map.
* Copy vcpu_map to expected_eoi_timap on each RTC irq and clear it on eoi.
Yang Zhang (6):
KVM: Add vcpu info to ioapic_update_eoi()
KVM: Introduce struct rtc_status
KVM : Return destination vcpu on interrupt injection
KVM: Add reset/restore rtc_status support KVM : Force vmexit with virtual interrupt delivery
KVM: Use eoi to track RTC interrupt delivery status
arch/x86/kvm/lapic.c | 35 +++++++++++++++------ arch/x86/kvm/lapic.h | 7 +++- virt/kvm/ioapic.c | 82 +++++++++++++++++++++++++++++++++++++++++++++----- virt/kvm/ioapic.h | 17 +++++++++- virt/kvm/irq_comm.c | 12 ++++---- 5 files changed, 125 insertions(+), 28 deletions(-)
PATCH v6 1/6 KVM: Add vcpu info to ioapic_update_eoi()
From: Yang Zhang <[email protected]>
Add vcpu info to ioapic_update_eoi, so we can know which vcpu issued this EOI.
--- arch/x86/kvm/lapic.c | 2 +- virt/kvm/ioapic.c | 12 ++++++------ virt/kvm/ioapic.h | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-)
arch/x86/kvm/lapic.c +1 -1
@@ -786,7 +786,7 @@ static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector) trigger_mode =IOAPIC_LEVEL_TRIG ; else trigger_mode =IOAPIC_EDGE_TRIG ; -kvm_ioapic_update_eoi (apic->vcpu->kvm, vector, trigger_mode); +kvm_ioapic_update_eoi (apic->vcpu, vector, trigger_mode); } }
virt/kvm/ioapic.c +6 -6
@@ -267,8 +267,8 @@ void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id)spin_unlock (&ioapic->lock); } -static void __kvm_ioapic_update_eoi (struct kvm_ioapic *ioapic,int vector, -int trigger_mode) +static void __kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, +struct kvm_ioapic *ioapic,int vector,int trigger_mode) {int i;
@@ -307,12 +307,12 @@ bool kvm_ioapic_handles_vector(struct kvm *kvm, int vector)return test_bit (vector, ioapic->handled_vectors); } -void kvm_ioapic_update_eoi (struct kvm *kvm,int vector,int trigger_mode) +void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector,int trigger_mode) { -struct kvm_ioapic *ioapic = kvm->arch.vioapic; +struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;spin_lock (&ioapic->lock); -__kvm_ioapic_update_eoi (ioapic, vector, trigger_mode); +__kvm_ioapic_update_eoi (vcpu, ioapic, vector, trigger_mode);spin_unlock (&ioapic->lock); }
@@ -410,7 +410,7 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len,break ;#ifdef CONFIG_IA64 case IOAPIC_REG_EOI : -__kvm_ioapic_update_eoi (ioapic, data,IOAPIC_LEVEL_TRIG ); +__kvm_ioapic_update_eoi (NULL , ioapic, data,IOAPIC_LEVEL_TRIG );break ;#endif
virt/kvm/ioapic.h +2 -1
@@ -70,7 +70,8 @@ static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm)int kvm_apic_match_dest (struct kvm_vcpu *vcpu,struct kvm_lapic *source,int short_hand,int dest,int dest_mode);int kvm_apic_compare_prio (struct kvm_vcpu *vcpu1,struct kvm_vcpu *vcpu2); -void kvm_ioapic_update_eoi (struct kvm *kvm,int vector,int trigger_mode); +void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu,int vector, +int trigger_mode);bool kvm_ioapic_handles_vector (struct kvm *kvm,int vector);int kvm_ioapic_init (struct kvm *kvm);void kvm_ioapic_destroy (struct kvm *kvm);
Signature · 1 line
1.7.1
PATCH v6 2/6 KVM: Introduce struct rtc_status
In reply to Yang ZhangFrom: Yang Zhang <[email protected]>
--- virt/kvm/ioapic.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
virt/kvm/ioapic.h +12 -0
@@ -34,6 +34,17 @@ struct kvm_vcpu;#define IOAPIC_INIT 0x5#define IOAPIC_EXTINT 0x7 +#ifdef CONFIG_X86 +#define RTC_GSI 8 +#else +#define RTC_GSI 255 +#endif + +struct rtc_status { +int pending_eoi; + DECLARE_BITMAP(dest_map, KVM_MAX_VCPUS); +}; +struct kvm_ioapic {u64 base_address;u32 ioregsel;
@@ -47,6 +58,7 @@ struct kvm_ioapic {void (*ack_notifier)(void *opaque,int irq);spinlock_t lock;DECLARE_BITMAP (handled_vectors,256 ); +struct rtc_status rtc_status; };#ifdef DEBUG
Signature · 1 line
1.7.1
PATCH v6 3/6 KVM : Return destination vcpu on interrupt injection
In reply to Yang ZhangFrom: Yang Zhang <[email protected]>
Add a new parameter to know vcpus who received the interrupt.
--- arch/x86/kvm/lapic.c | 25 ++++++++++++++++--------- arch/x86/kvm/lapic.h | 5 +++-- virt/kvm/ioapic.c | 2 +- virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 12 ++++++------ 5 files changed, 27 insertions(+), 19 deletions(-)
arch/x86/kvm/lapic.c +16 -9
@@ -431,14 +431,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)
@@ -611,7 +613,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 ;
@@ -622,7 +624,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; }
@@ -667,7 +669,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;
@@ -681,7 +683,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;
@@ -694,6 +697,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 );
@@ -852,7 +858,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)
@@ -1488,7 +1494,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 ; }
arch/x86/kvm/lapic.h +3 -2
@@ -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);
virt/kvm/ioapic.c +1 -1
@@ -220,7 +220,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,
virt/kvm/ioapic.h +1 -1
@@ -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);
virt/kvm/irq_comm.c +6 -6
@@ -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 ;
Signature · 1 line
1.7.1
Re: [PATCH v6 3/6] KVM : Return destination vcpu on interrupt injection
Quoted 75 lines · Yang Zhang
From: Yang Zhang <[email protected]>
Add a new parameter to know vcpus who received the interrupt.
Signed-off-by Yang Zhang <[email protected]>--- arch/x86/kvm/lapic.c | 25 ++++++++++++++++--------- arch/x86/kvm/lapic.h | 5 +++-- virt/kvm/ioapic.c | 2 +- virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 12 ++++++------ 5 files changed, 27 insertions(+), 19 deletions(-)arch/x86/kvm/lapic.c +10
-7@@ -431,14 +431,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)@@ -611,7 +613,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 ;@@ -622,7 +624,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; }@@ -667,7 +669,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;@@ -681,7 +683,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;
arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, · line 702
Quoted 6 lines
arch/x86/kvm/lapic.c +3
-0@@ -694,6 +697,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); +
__set_bit()
Quoted 127 lines
arch/x86/kvm/lapic.c +3
-2if (trig_mode) {apic_debug ("level trig mode for vector %d" , vector);apic_set_vector (vector, apic->regs +APIC_TMR );@@ -852,7 +858,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)@@ -1488,7 +1494,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 ; }arch/x86/kvm/lapic.h +3
-2@@ -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);virt/kvm/ioapic.c +1
-1@@ -220,7 +220,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,virt/kvm/ioapic.h +1
-1@@ -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);virt/kvm/irq_comm.c +6
-6@@ -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 ;Signature · 1 line
1.7.1
--
Gleb.
RE: [PATCH v6 3/6] KVM : Return destination vcpu on interrupt injection
Gleb Natapov wrote on 2013-03-22:
Quoted 79 lines · Yang Zhang
arch/x86/kvm/lapic.c int kvm_lapic_find_highest_irr(struct kvm_vcpu
Quoted 17 lines
From: Yang Zhang <[email protected]>
Add a new parameter to know vcpus who received the interrupt.
Signed-off-by Yang Zhang <[email protected]>--- arch/x86/kvm/lapic.c | 25 ++++++++++++++++--------- arch/x86/kvm/lapic.h | 5 +++-- virt/kvm/ioapic.c | 2 +- virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 12 ++++++------ 5 files changed, 27 insertions(+), 19 deletions(-)arch/x86/kvm/lapic.c +0
-0@@ -431,14 +431,16 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu*vcpu)
arch/x86/kvm/lapic.c int kvm_apic_match_dest(struct kvm_vcpu *vcpu,
Quoted 20 lines
arch/x86/kvm/lapic.c +5
-3}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)@@ -611,7 +613,7 @@ int kvm_apic_match_dest(struct kvm_vcpu *vcpu,struct
kvm_lapic*source,arch/x86/kvm/lapic.c bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,
Quoted 9 lines
arch/x86/kvm/lapic.c +1
-1}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 ;@@ -622,7 +624,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,struct
kvm_lapic*src,arch/x86/kvm/lapic.c bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,
Quoted 8 lines
arch/x86/kvm/lapic.c +1
-1*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; }@@ -667,7 +669,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,struct
kvm_lapic*src,arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int
Quoted 19 lines
arch/x86/kvm/lapic.c +3
-2continue ;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;@@ -681,7 +683,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;@@ -694,6 +697,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int
delivery_mode,
Quoted 6 lines
arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, · line 702
Quoted 5 lines
arch/x86/kvm/lapic.c +3
-0if (unlikely (!apic_enabled (apic)))break ; +if (dest_map) +set_bit (vcpu->vcpu_id, dest_map); +
__set_bit()
no, __apic_accept_irq() may be called to deliver interrupt from IOAPIC and LAPIC interrupt.
Though the dest_map is only used by RTC interrupt now, it may be use by LAPIC interrupt in future. So it's better to use set_bit not __set_bit.
Quoted 121 lines
arch/x86/kvm/lapic.c int kvm_apic_local_deliver(struct kvm_lapic *apic, int
Quoted 11 lines
arch/x86/kvm/lapic.c +0
-0if (trig_mode) {apic_debug ("level trig mode for vector %d" , vector); apic_set_vector(vector, apic->regs + APIC_TMR); @@ -852,7 +858,7 @@ static void apic_send_ipi(struct kvm_lapic *apic) irq.trig_mode, irq.level, irq.dest_mode, irq.delivery_mode,irq.vector);
arch/x86/kvm/lapic.c +1
-1-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)@@ -1488,7 +1494,8 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, int
lvt_type)virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 33 lines
arch/x86/kvm/lapic.c +2
-1vector = 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 ; }arch/x86/kvm/lapic.h +3
-2@@ -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);virt/kvm/ioapic.c +0
-0@@ -220,7 +220,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.h int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq,
Quoted 12 lines
virt/kvm/ioapic.c +1
-1irqe.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,virt/kvm/ioapic.h +0
-0@@ -92,7 +92,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq,int
irq_source_id,virt/kvm/irq_comm.c inline static bool kvm_is_dm_lowest_prio(struct
Quoted 13 lines
virt/kvm/ioapic.h +1
-1void 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);virt/kvm/irq_comm.c +0
-0@@ -63,7 +63,7 @@ inline static bool kvm_is_dm_lowest_prio(struct
kvm_lapic_irq*irq)virt/kvm/irq_comm.c int kvm_irq_delivery_to_apic(struct kvm *kvm, struct
Quoted 9 lines
virt/kvm/irq_comm.c +1
-1}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,virt/kvm/irq_comm.c int kvm_irq_delivery_to_apic(struct kvm *kvm, struct
Quoted 8 lines
virt/kvm/irq_comm.c +1
-1irq->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,virt/kvm/irq_comm.c int kvm_irq_delivery_to_apic(struct kvm *kvm, struct
Quoted 9 lines
virt/kvm/irq_comm.c +1
-1if (!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,Quoted 19 lines
virt/kvm/irq_comm.c +2
-2}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,
Quoted 11 lines
Quoted 8 lines
virt/kvm/irq_comm.c +1
-2kvm_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 ; --1.7.1
--
Gleb.
Best regards,
Yang
Re: [PATCH v6 3/6] KVM : Return destination vcpu on interrupt injection
Quoted 80 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 79 lines · Yang Zhang
arch/x86/kvm/lapic.c int kvm_lapic_find_highest_irr(struct kvm_vcpu
Quoted 17 lines
From: Yang Zhang <[email protected]>
Add a new parameter to know vcpus who received the interrupt.
Signed-off-by Yang Zhang <[email protected]>--- arch/x86/kvm/lapic.c | 25 ++++++++++++++++--------- arch/x86/kvm/lapic.h | 5 +++-- virt/kvm/ioapic.c | 2 +- virt/kvm/ioapic.h | 2 +- virt/kvm/irq_comm.c | 12 ++++++------ 5 files changed, 27 insertions(+), 19 deletions(-)arch/x86/kvm/lapic.c +0
-0@@ -431,14 +431,16 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu*vcpu)
arch/x86/kvm/lapic.c int kvm_apic_match_dest(struct kvm_vcpu *vcpu,
Quoted 20 lines
arch/x86/kvm/lapic.c +5
-3}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)@@ -611,7 +613,7 @@ int kvm_apic_match_dest(struct kvm_vcpu *vcpu,struct
kvm_lapic*source,arch/x86/kvm/lapic.c bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,
Quoted 9 lines
arch/x86/kvm/lapic.c +1
-1}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 ;@@ -622,7 +624,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,struct
kvm_lapic*src,arch/x86/kvm/lapic.c bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,
Quoted 8 lines
arch/x86/kvm/lapic.c +1
-1*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; }@@ -667,7 +669,7 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm,struct
kvm_lapic*src,arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int
Quoted 19 lines
arch/x86/kvm/lapic.c +3
-2continue ;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;@@ -681,7 +683,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;@@ -694,6 +697,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int
delivery_mode,
Quoted 8 lines
Quoted 6 lines
arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, · line 702
Quoted 5 lines
arch/x86/kvm/lapic.c +3
-0if (unlikely (!apic_enabled (apic)))break ; +if (dest_map) +set_bit (vcpu->vcpu_id, dest_map); +
__set_bit()no,
__apic_accept_irq()may be called to deliver interrupt from IOAPIC and LAPIC interrupt.
Though thedest_mapis only used by RTC interrupt now, it may be use by LAPIC interrupt in future. So it's better to useset_bitnot__set_bit.
It is a caller responsibility to not provide pointer to the same memory to concurrent function invocations.
--
Gleb.
PATCH v6 4/6 KVM: Add reset/restore rtc_status support
In reply to Yang ZhangFrom: Yang Zhang <[email protected]>
--- arch/x86/kvm/lapic.c | 8 ++++++++ arch/x86/kvm/lapic.h | 2 ++ virt/kvm/ioapic.c | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 0 deletions(-)
arch/x86/kvm/lapic.c +8 -0
@@ -94,6 +94,14 @@ static inline int apic_test_vector(int vec, void *bitmap)return test_bit (VEC_POS (vec), (bitmap) +REG_POS (vec)); } +bool kvm_apic_pending_eoi (struct kvm_vcpu *vcpu,int vector) +{ +struct kvm_lapic *apic = vcpu->arch.apic; + +return apic_test_vector (vector, apic->regs +APIC_ISR ) || +apic_test_vector (vector, apic->regs +APIC_IRR ); +} +static inline void apic_set_vector (int vec,void *bitmap) {set_bit (VEC_POS (vec), (bitmap) +REG_POS (vec));
arch/x86/kvm/lapic.h +2 -0
@@ -170,4 +170,6 @@ static inline bool kvm_apic_has_events(struct kvm_vcpu *vcpu) return vcpu->arch.apic->pending_events; } +bool kvm_apic_pending_eoi (struct kvm_vcpu *vcpu,int vector); +#endif
virt/kvm/ioapic.c +26 -0
@@ -90,6 +90,30 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,return result; } +static void rtc_irq_reset (struct kvm_ioapic *ioapic) +{ + ioapic->rtc_status.pending_eoi =0 ; +bitmap_zero (ioapic->rtc_status.dest_map,KVM_MAX_VCPUS ); +} + +static void rtc_irq_restore (struct kvm_ioapic *ioapic) +{ +struct kvm_vcpu *vcpu; +int vector, i, pending_eoi =0 ; + +if (RTC_GSI !=8 ) +return ; + + vector = ioapic->redirtbl[RTC_GSI ].fields.vector; +kvm_for_each_vcpu (i, vcpu, ioapic->kvm) { +if (kvm_apic_pending_eoi (vcpu, vector)) { + pending_eoi++; +set_bit (vcpu->vcpu_id, ioapic->rtc_status.dest_map); + } + } + ioapic->rtc_status.pending_eoi = pending_eoi; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;
@@ -431,6 +455,7 @@ void kvm_ioapic_reset(struct kvm_ioapic *ioapic) ioapic->ioregsel =0 ; ioapic->irr =0 ; ioapic->id =0 ; +rtc_irq_reset (ioapic);update_handled_vectors (ioapic); }
@@ -496,6 +521,7 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)spin_lock (&ioapic->lock);memcpy (ioapic, state,sizeof (struct kvm_ioapic_state ));update_handled_vectors (ioapic); +rtc_irq_restore (ioapic);kvm_ioapic_make_eoibitmap_request (kvm);spin_unlock (&ioapic->lock);return 0 ;
Signature · 1 line
1.7.1
Paolo Bonzini
maintainerRe: [PATCH v6 4/6] KVM: Add reset/restore rtc_status support
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, · line 104
Quoted 6 lines
virt/kvm/ioapic.c +6
-0+static void rtc_irq_restore (struct kvm_ioapic *ioapic) +{ +struct kvm_vcpu *vcpu; +int vector, i, pending_eoi =0 ; + +if (RTC_GSI !=8 )
Please set it to -1U if not x86, and do
if (RTC_GSI >= IOAPIC_NUM_PINS)
return;
here.
Paolo
Quoted 2 lines
(quoted diff) +2
-0+ return; +
RE: [PATCH v6 4/6] KVM: Add reset/restore rtc_status support
Paolo Bonzini wrote on 2013-03-26:
Quoted 10 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, · line 104
Quoted 6 lines
virt/kvm/ioapic.c +6
-0+static void rtc_irq_restore (struct kvm_ioapic *ioapic) +{ +struct kvm_vcpu *vcpu; +int vector, i, pending_eoi =0 ; + +if (RTC_GSI !=8 )Please set it to -1U if not x86, and do
Quoted 3 lines
if (
RTC_GSI>=IOAPIC_NUM_PINS)return;here.
Sure. It is more reasonable.
Best regards,
Yang
Paolo Bonzini
maintainerRe: [PATCH v6 4/6] KVM: Add reset/restore rtc_status support
In reply to Yang ZhangIl 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, · line 111
Quoted 5 lines
virt/kvm/ioapic.c +5
-0+ vector = ioapic->redirtbl[RTC_GSI ].fields.vector; +kvm_for_each_vcpu (i, vcpu, ioapic->kvm) { +if (kvm_apic_pending_eoi (vcpu, vector)) { + pending_eoi++; +set_bit (vcpu->vcpu_id, ioapic->rtc_status.dest_map);
Also, __set_bit. If I understand correctly, dest_map is protected by the ioapic spinlock.
Paolo
Quoted 3 lines
virt/kvm/ioapic.c +3
-0+ } + } + ioapic->rtc_status.pending_eoi = pending_eoi;
RE: [PATCH v6 4/6] KVM: Add reset/restore rtc_status support
Paolo Bonzini wrote on 2013-03-26:
Quoted 9 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic, · line 111
Quoted 5 lines
virt/kvm/ioapic.c +5
-0+ vector = ioapic->redirtbl[RTC_GSI ].fields.vector; +kvm_for_each_vcpu (i, vcpu, ioapic->kvm) { +if (kvm_apic_pending_eoi (vcpu, vector)) { + pending_eoi++; +set_bit (vcpu->vcpu_id, ioapic->rtc_status.dest_map);Also,
__set_bit. If I understand correctly,dest_mapis protected by the ioapic spinlock.
Yes, I already see it and changed it in version 7.
Best regards,
Yang
PATCH v6 5/6 KVM : Force vmexit with virtual interrupt delivery
In reply to Yang ZhangFrom: Yang Zhang <[email protected]>
Need the EOI to track interrupt deliver status, so force vmexit on EOI for rtc interrupt when enabling virtual interrupt delivery.
--- virt/kvm/ioapic.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +1 -1
@@ -158,7 +158,7 @@ void kvm_ioapic_calculate_eoi_exitmap(struct kvm_vcpu *vcpu,if (!e->fields.mask && (e->fields.trig_mode ==IOAPIC_LEVEL_TRIG ||kvm_irq_has_notifier (ioapic->kvm,KVM_IRQCHIP_IOAPIC , - index))) { + index) || index ==RTC_GSI )) { irqe.dest_id = e->fields.dest_id; irqe.vector = e->fields.vector; irqe.dest_mode = e->fields.dest_mode;
Signature · 1 line
1.7.1
PATCH v6 6/6 KVM: Use eoi to track RTC interrupt delivery status
In reply to Yang ZhangFrom: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, the pending_eoi set to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.
--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +39 -1
@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic *ioapic) ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;
@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) {union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",
@@ -244,7 +268,14 @@ 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,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret; + }else + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); + +return ret; } int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
@@ -268,6 +299,11 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, ret =1 ; }else {int edge = (entry.fields.trig_mode ==IOAPIC_EDGE_TRIG ); + +if (rtc_irq_check (ioapic, irq)) { + ret =0 ;/* coalesced */ + goto out; + } ioapic->irr |= mask;if ((edge && old_irr != ioapic->irr) || (!edge && !entry.fields.remote_irr))
@@ -275,6 +311,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,else ret =0 ;/* report coalesced interrupt */ } +out:trace_kvm_ioapic_set_irq (entry.bits, irq, ret ==0 );spin_unlock (&ioapic->lock);
@@ -302,6 +339,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; +rtc_irq_ack_eoi (vcpu, &ioapic->rtc_status, i);/* * We are dropping lock while calling ack notifiers because ack * notifier callbacks for assigned devices call into IOAPIC
Signature · 1 line
1.7.1
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 58 lines · Yang Zhang
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +24
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic *ioapic) ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) {union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 8 lines
virt/kvm/ioapic.c +4
-1@@ -244,7 +268,14 @@ 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,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;
We should track status only if IRQ_STATUS ioctl was used to inject an interrupt.
Quoted 37 lines
virt/kvm/ioapic.c +11
-0+ }else + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); + +return ret; } int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,@@ -268,6 +299,11 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, ret =1 ; }else {int edge = (entry.fields.trig_mode ==IOAPIC_EDGE_TRIG ); + +if (rtc_irq_check (ioapic, irq)) { + ret =0 ;/* coalesced */ + goto out; + } ioapic->irr |= mask;if ((edge && old_irr != ioapic->irr) || (!edge && !entry.fields.remote_irr))@@ -275,6 +311,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,else ret =0 ;/* report coalesced interrupt */ } +out:trace_kvm_ioapic_set_irq (entry.bits, irq, ret ==0 );spin_unlock (&ioapic->lock);@@ -302,6 +339,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu,if (ent->fields.vector != vector)continue ; +rtc_irq_ack_eoi (vcpu, &ioapic->rtc_status, i);/* * We are dropping lock while calling ack notifiers because ack * notifier callbacks for assigned devices call into IOAPIC Signature · 1 line
1.7.1
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-03-22:
Quoted 59 lines · Yang Zhang
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 48 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +23
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic *ioapic) ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
Quoted 9 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
We already know RTC will use IRQ_STATUS ioctl. Why check it again?
Quoted 27 lines
virt/kvm/ioapic.c int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ }else + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); + +return ret; } int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,@@ -268,6 +299,11 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, intirq, int
irq_source_id,virt/kvm/ioapic.c int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq,
Quoted 12 lines
virt/kvm/ioapic.c +5
-0ret =1 ; }else {int edge = (entry.fields.trig_mode ==IOAPIC_EDGE_TRIG ); + +if (rtc_irq_check (ioapic, irq)) { + ret =0 ;/* coalesced */ + goto out; + } ioapic->irr |= mask;if ((edge && old_irr != ioapic->irr) || (!edge && !entry.fields.remote_irr))@@ -275,6 +311,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq,int
irq_source_id,virt/kvm/ioapic.c static void __kvm_ioapic_update_eoi(struct kvm_vcpu
Quoted 4 lines
virt/kvm/ioapic.c +0
-0else ret = 0; /* report coalesced interrupt */ } +out:trace_kvm_ioapic_set_irq (entry.bits, irq, ret ==0 );spin_unlock (&ioapic->lock);@@ -302,6 +339,7 @@ static void __kvm_ioapic_update_eoi(struct kvm_vcpu*vcpu,
Quoted 15 lines
Quoted 8 lines
virt/kvm/ioapic.c +1
-1if (ent->fields.vector != vector)continue ; +rtc_irq_ack_eoi (vcpu, &ioapic->rtc_status, i);/* * We are dropping lock while calling ack notifiers because ack * notifier callbacks for assigned devices call into IOAPIC -- 1.7.1
--
Gleb.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 69 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 59 lines · Yang Zhang
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 48 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +23
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic *ioapic) ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
Quoted 9 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?
QEMU does. QEMU is not the only userspace.
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-03-22:
Quoted 72 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 9 lines
Quoted 9 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 9 lines
Signed-off-by Yang Zhang <[email protected]>---
virt/kvm/ioapic.c| 40 +++++++++++++++++++++++++++++++++++++++- 1
files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 30 lines
Quoted 30 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 29 lines
virt/kvm/ioapic.c +23
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 73 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 72 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 9 lines
Quoted 9 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 9 lines
Signed-off-by Yang Zhang <[email protected]>---
virt/kvm/ioapic.c| 40 +++++++++++++++++++++++++++++++++++++++- 1
files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 30 lines
Quoted 30 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 29 lines
virt/kvm/ioapic.c +23
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ + +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-03-22:
Quoted 75 lines · Yang Z
Quoted 45 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 44 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 9 lines
Quoted 9 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 9 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
If other userspace has the reinjection logic for RTC, but it not uses IRQ_STATUS, then it cannot get the right coalescing info. If it also use IRQ_STATUS to get coalescing info, then we don't need the IRQ_STATUS check.
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 76 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 75 lines · Yang Z
Quoted 45 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 44 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt.
This patch introduces a new mechinism to use eoi to track interrupt:
When delivering an interrupt to vcpu, thepending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 9 lines
Quoted 9 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 9 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, · line 273
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
If other userspace has the reinjection logic for RTC, but it not uses
IRQ_STATUS, then it cannot get the right coalescing info. If it also useIRQ_STATUSto get coalescing info, then we don't need theIRQ_STATUScheck.
If userspace does not care about irq status it does not use IRQ_STATUS ioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-03-22:
Quoted 85 lines · Yang Z
Quoted 48 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 47 lines · Yang Z
Quoted 46 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 45 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt. This patch introduces a new mechinism to use eoi to track interrupt: When delivering an interrupt to vcpu, the
pending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 10 lines
Quoted 10 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 10 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40+++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 10 lines
Quoted 10 lines
int
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c
Quoted 7 lines
virt/kvm/ioapic.c +0
-1irqe.level =1 ; irqe.shorthand =0 ; - return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,NULL); + if (irq ==
RTC_GSI) { + ret =
kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,virt/kvm/ioapic.c +2
-0+ ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
How?
If other userspace has the reinjection logic for RTC, but it not uses
IRQ_STATUS,then it cannot get the right coalescing info. If it also use
IRQ_STATUSto get coalescing info, then we don't need theIRQ_STATUScheck.Quoted 1 line
If userspace does not care about irq status it does not use
IRQ_STATUSioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.
I see your point. But if no windows guest running, RTC is hardly used by other guests and the overheard can be ignore.
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 87 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 86 lines · Yang Z
Quoted 48 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 47 lines · Yang Z
Quoted 46 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 45 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt. This patch introduces a new mechinism to use eoi to track interrupt: When delivering an interrupt to vcpu, the
pending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 10 lines
Quoted 10 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 10 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40+++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 10 lines
Quoted 10 lines
int
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 17 lines
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c
Quoted 7 lines
virt/kvm/ioapic.c +0
-1irqe.level =1 ; irqe.shorthand =0 ; - return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,NULL); + if (irq ==
RTC_GSI) { + ret =
kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,virt/kvm/ioapic.c +2
-0+ ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
Quoted 9 lines
Quoted 7 lines
Quoted 1 line
If other userspace has the reinjection logic for RTC, but it not uses
IRQ_STATUS,then it cannot get the right coalescing info. If it also use
IRQ_STATUSto get coalescing info, then we don't need theIRQ_STATUScheck.Quoted 1 line
If userspace does not care about irq status it does not use
IRQ_STATUSioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.I see your point. But if no windows guest running, RTC is hardly used by other guests and the overheard can be ignore.
Anyone can use RTC is Linux guest. Don't know about others.
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-03-22:
Quoted 93 lines · Yang Z
Quoted 88 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 87 lines · Yang Z
Quoted 48 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 47 lines · Yang Z
Quoted 46 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 45 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt. This patch introduces a new mechinism to use eoi to track interrupt: When delivering an interrupt to vcpu, the
pending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 10 lines
Quoted 10 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 10 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40+++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 10 lines
Quoted 10 lines
int
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c
Quoted 7 lines
virt/kvm/ioapic.c +0
-1irqe.level =1 ; irqe.shorthand =0 ; - return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,NULL); + if (irq ==
RTC_GSI) { + ret =
kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,virt/kvm/ioapic.c +2
-0+ ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
If other userspace has the reinjection logic for RTC, but it not uses
IRQ_STATUS,Quoted 3 lines
Quoted 3 lines
then it cannot get the right coalescing info. If it also use
IRQ_STATUSto get coalescing info, then we don't need theIRQ_STATUScheck.Quoted 1 line
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
If userspace does not care about irq status it does not use
IRQ_STATUSioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.I see your point. But if no windows guest running, RTC is hardly used by other guests and the overheard can be ignore.
Anyone can use RTC is Linux guest. Don't know about others.
I see.
Since pass IRQ_STATUS to ioapic need to change many functions, how about add a variable in rtc_status:
struct rtc_status {
bool IRQ_STATUS
};
And set it in kvm_vm_ioctl():
case KVM_IRQ_LINE_STATUS:
if(irq == RTC_GSI && ioapic) ioapic->rtc_status.IRQ_STATUS = true;
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 107 lines · Yang Z
Gleb Natapov wrote on 2013-03-22:
Quoted 93 lines · Yang Z
Quoted 88 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 87 lines · Yang Z
Quoted 48 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 47 lines · Yang Z
Quoted 46 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 45 lines · Yang Z
Quoted 12 lines
Gleb Natapov wrote on 2013-03-22:
Quoted 11 lines · Yang Zhang
Quoted 10 lines
From: Yang Zhang <[email protected]>
Current interrupt coalescing logci which only used by RTC has conflict with Posted Interrupt. This patch introduces a new mechinism to use eoi to track interrupt: When delivering an interrupt to vcpu, the
pending_eoiset to number of vcpu that received the interrupt. And decrease it when each vcpu writing eoi. No subsequent RTC interrupt can deliver to vcpu until all vcpus write eoi.Quoted 10 lines
Quoted 10 lines
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic
Quoted 10 lines
Signed-off-by Yang Zhang <[email protected]>--- virt/kvm/ioapic.c | 40+++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-)
virt/kvm/ioapic.c +0
-0@@ -114,6 +114,29 @@ static void rtc_irq_restore(struct kvm_ioapic*ioapic)
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
virt/kvm/ioapic.c +19
-0ioapic->rtc_status.pending_eoi = pending_eoi; } +static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +} + +static bool rtc_irq_check (struct kvm_ioapic *ioapic,int irq) +{ +if (irq !=RTC_GSI ) +return false; + +if (ioapic->rtc_status.pending_eoi >0 ) +return true;/* coalesced */ Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +4
-0+ +return false; +} +static int ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) {union kvm_ioapic_redirect_entry *pent;@@ -229,6 +252,7 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 10 lines
Quoted 10 lines
int
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic
Quoted 8 lines
virt/kvm/ioapic.c +1
-0{union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];struct kvm_lapic_irq irqe; +int ret; ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n",@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic*ioapic,
Quoted 18 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
int
Quoted 10 lines
Quoted 10 lines
irq)
virt/kvm/ioapic.c
Quoted 7 lines
virt/kvm/ioapic.c +0
-1irqe.level =1 ; irqe.shorthand =0 ; - return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,NULL); + if (irq ==
RTC_GSI) { + ret =
kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,virt/kvm/ioapic.c +2
-0+ ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;We should track status only if
IRQ_STATUSioctl was used to inject an interrupt.Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
We already know RTC will use
IRQ_STATUSioctl. Why check it again?QEMU does. QEMU is not the only userspace.
And this will break other userspace.
How?
If other userspace has the reinjection logic for RTC, but it not uses
IRQ_STATUS,Quoted 3 lines
Quoted 3 lines
then it cannot get the right coalescing info. If it also use
IRQ_STATUSto get coalescing info, then we don't need theIRQ_STATUScheck.Quoted 1 line
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
If userspace does not care about irq status it does not use
IRQ_STATUSioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.I see your point. But if no windows guest running, RTC is hardly used by other guests and the overheard can be ignore.
Anyone can use RTC is Linux guest. Don't know about others.
I see.
Since passIRQ_STATUSto ioapic need to change many functions, how about add a variable inrtc_status:
structrtc_status{
boolIRQ_STATUS
};
Quoted 5 lines
And set it in
kvm_vm_ioctl():
caseKVM_IRQ_LINE_STATUS:if(irq == RTC_GSI && ioapic) ioapic->rtc_status.IRQ_STATUS = true;
I do not like that kind of hacks. Just put functions change in separate, easy to review patch.
--
Gleb.
Paolo Bonzini
maintainerRe: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
In reply to Gleb NatapovIl 22/03/2013 09:54, Gleb Natapov ha scritto:
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
If userspace does not care about irq status it does not use
IRQ_STATUSioctl and we should not go extra mile to provide one. Not everyone cares about running Windows as a guest.I see your point. But if no windows guest running, RTC is hardly used by other guests and the overheard can be ignore.
Anyone can use RTC is Linux guest. Don't know about others.
I do not think the additional code complexity is worth the speedup.
The KVM Userspace That Won't Be Merged doesn't even emulate the RTC interrupt at all.
Paolo
Paolo Bonzini
maintainerRe: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
In reply to Yang ZhangIl 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}
This is the only case where you're passing the struct rtc_status instead of the struct kvm_ioapic. Please use the latter, and make it the first argument.
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 9 lines
virt/kvm/ioapic.c +4
-1@@ -244,7 +268,14 @@ 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,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;
I think you should either add a
BUG_ON(ioapic->rtc_status.pending_eoi != 0);
or use "ioapic->rtc_status.pending_eoi += ret" (or both).
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 279
Quoted 5 lines
virt/kvm/ioapic.c +4
-0+ }else + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); + +return ret; }
Paolo
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Paolo Bonzini wrote on 2013-03-26:
Quoted 29 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Review static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
Quoted 3 lines
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).
There may malicious guest to write EOI more than once. And the pending_eoi will be negative. But it should not be a bug. Just WARN_ON is enough. And we already do it in ack_eoi. So don't need to do duplicated thing here.
Best regards,
Yang
Paolo Bonzini
maintainerRe: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Il 29/03/2013 04:25, Zhang, Yang Z ha scritto:
Quoted 30 lines
Paolo Bonzini wrote on 2013-03-26:
Quoted 29 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Review static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
Quoted 7 lines
Quoted 3 lines
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).There may malicious guest to write EOI more than once. And the
pending_eoiwill be negative. But it should not be a bug. JustWARN_ONis enough. And we already do it inack_eoi. So don't need to do duplicated thing here.
Even WARN_ON is too much if it is guest-triggerable. But then it is better to make it "+=", I think.
Paolo
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Paolo Bonzini wrote on 2013-03-29:
Quoted 34 lines
Il 29/03/2013 04:25, Zhang, Yang Z ha scritto:
Quoted 33 lines
Paolo Bonzini wrote on 2013-03-26:
Quoted 32 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Review static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).
Quoted 7 lines
Quoted 4 lines
There may malicious guest to write EOI more than once. And the
pending_eoiwill be negative. But it should not be a bug. JustWARN_ONis enough. And we already do it inack_eoi. So don't need to do duplicated thing here.Even
WARN_ONis too much if it is guest-triggerable. But then it is better to make it "+=", I think.
No. If the above case happened, you will always hit the WARN_ON with "+=".
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
In reply to Zhang, Yang ZQuoted 30 lines · Yang Z
Paolo Bonzini wrote on 2013-03-26:
Quoted 29 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Review static int ioapic_deliver(struct kvm_ioapic *ioapic, int
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, intirq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
Quoted 5 lines
Quoted 3 lines
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).There may malicious guest to write EOI more than once. And the
pending_eoiwill be negative. But it should not be a bug. JustWARN_ONis enough. And we already do it inack_eoi. So don't need to do duplicated thing here.
Since we track vcpus that already called EOI and decrement pending_eoi only once for each vcpu malicious guest cannot trigger it, but we already do WARN_ON() in rtc_irq_ack_eoi(), so I am not sure we need another one here. += will be correct (since pending_eoi == 0 here), but confusing since it makes an impression that pending_eoi may not be zero.
--
Gleb.
RE: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Gleb Natapov wrote on 2013-04-02:
Quoted 36 lines · Yang Z
Quoted 18 lines
Paolo Bonzini wrote on 2013-03-26:
Quoted 17 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Quoted 1 line
Quoted 1 line
Review static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 11 lines
Quoted 11 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
Quoted 4 lines
Quoted 3 lines
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).There may malicious guest to write EOI more than once. And the
pending_eoi
Quoted 8 lines
will be negative. But it should not be a bug. Just
WARN_ONis enough. And we already do it inack_eoi. So don't need to do duplicated thing here.Quoted 1 line
Since we track vcpus that already called EOI and decrement
pending_eoionly once for each vcpu malicious guest cannot trigger it, but we already doWARN_ON()inrtc_irq_ack_eoi(), so I am not sure we need another one here. += will be correct (sincepending_eoi== 0 here), but confusing since it makes an impression thatpending_eoimay not be zero.
Yes, I also make the wrong impression.
With previous implementation, the pening_eoi may not be zero: Calculate the destination vcpu via parse IOAPIC entry, and if using lowest priority deliver mode, set all possible vcpus in dest_map even it doesn't receive it finally. At same time, a malicious guest can send IPI with same vector of RTC to those vcpus who is in dest_map but not have RTC interrupt. Then the pending_eoi will be negative. Now, we set the dest_map with the vcpus who really received the interrupt. The above case cannot happen. So as you and Paolo suggested, it is better to use +=.
Best regards,
Yang
Re: [PATCH v6 6/6] KVM: Use eoi to track RTC interrupt delivery status
Quoted 40 lines · Yang Z
Gleb Natapov wrote on 2013-04-02:
Quoted 39 lines · Yang Z
Quoted 18 lines
Paolo Bonzini wrote on 2013-03-26:
Quoted 17 lines
Il 22/03/2013 06:24, Yang Zhang ha scritto:
virt/kvm/ioapic.c static void rtc_irq_restore(struct kvm_ioapic *ioapic) · line 127
Quoted 11 lines
virt/kvm/ioapic.c +11
-0+static void rtc_irq_ack_eoi (struct kvm_vcpu *vcpu, +struct rtc_status *rtc_status,int irq) +{ +if (irq !=RTC_GSI ) +return ; + +if (test_and_clear_bit (vcpu->vcpu_id, rtc_status->dest_map)) + --rtc_status->pending_eoi; + +WARN_ON (rtc_status->pending_eoi <0 ); +}This is the only case where you're passing the struct
rtc_statusinstead of the structkvm_ioapic. Please use the latter, and make it the first argument.Quoted 1 line
Quoted 1 line
Review static int ioapic_deliver(struct kvm_ioapic *ioapic,
Quoted 1 line
(quoted diff) +0
-0@@ -244,7 +268,14 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic,int
Quoted 11 lines
Quoted 11 lines
irq)
virt/kvm/ioapic.c static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) · line 274
Quoted 7 lines
virt/kvm/ioapic.c +4
-1irqe.level =1 ; irqe.shorthand =0 ; -return kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe,NULL ); +if (irq ==RTC_GSI ) { + ret =kvm_irq_delivery_to_apic (ioapic->kvm,NULL , &irqe, + ioapic->rtc_status.dest_map); + ioapic->rtc_status.pending_eoi = ret;I think you should either add a
Quoted 4 lines
Quoted 3 lines
BUG_ON(ioapic->rtc_status.pending_eoi != 0);or use "
ioapic->rtc_status.pending_eoi+= ret" (or both).There may malicious guest to write EOI more than once. And the
pending_eoiwill be negative. But it should not be a bug. Just
WARN_ONis enough. And we already do it inack_eoi. So don't need to do duplicated thing here.Quoted 1 line
Quoted 9 lines
Quoted 5 lines
Since we track vcpus that already called EOI and decrement
pending_eoionly once for each vcpu malicious guest cannot trigger it, but we already doWARN_ON()inrtc_irq_ack_eoi(), so I am not sure we need another one here. += will be correct (sincepending_eoi== 0 here), but confusing since it makes an impression thatpending_eoimay not be zero.Yes, I also make the wrong impression.
With previous implementation, thepening_eoimay not be zero: Calculate the destination vcpu via parse IOAPIC entry, and if using lowest priority deliver mode, set all possible vcpus indest_mapeven it doesn't receive it finally. At same time, a malicious guest can send IPI with same vector of RTC to those vcpus who is indest_mapbut not have RTC interrupt. Then thepending_eoiwill be negative. Now, we set thedest_mapwith the vcpus who really received the interrupt. The above case cannot happen. So as you and Paolo suggested, it is better to use +=.
I am not suggesting that it is better to use +=. We can add BUG_ON(ioapic->rtc_status.pending_eoi != 0); but no need to resend patches just for that.
--
Gleb.