Optimize and unify IOAPIC/MSI delivery
v8 cover Optimize and unify IOAPIC/MSI delivery
This patchset based on MSI patch which changed deliver method to irq routing.
Thanks.
--
Yang, Sheng
PATCH v8 1/5 KVM: Split IOAPIC structure
Prepared for reuse ioapic_redir_entry for MSI.
--- include/linux/kvm_types.h | 17 +++++++++++++++++ virt/kvm/ioapic.c | 6 +++--- virt/kvm/ioapic.h | 17 +---------------- 3 files changed, 21 insertions(+), 19 deletions(-)
include/linux/kvm_types.h +17 -0
@@ -40,4 +40,21 @@ typedef unsigned long hfn_t;typedef hfn_t pfn_t ; +union kvm_ioapic_redirect_entry { +u64 bits; +struct { +u8 vector; +u8 delivery_mode:3 ; +u8 dest_mode:1 ; +u8 delivery_status:1 ; +u8 polarity:1 ; +u8 remote_irr:1 ; +u8 trig_mode:1 ; +u8 mask:1 ; +u8 reserve:7 ; +u8 reserved[4 ]; +u8 dest_id; + } fields; +}; +#endif /* __KVM_TYPES_H__ */
virt/kvm/ioapic.c +3 -3
@@ -85,7 +85,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,static void ioapic_service (struct kvm_ioapic *ioapic,unsigned int idx) { -union ioapic_redir_entry *pent; +union kvm_ioapic_redirect_entry *pent; pent = &ioapic->redirtbl[idx];
@@ -277,7 +277,7 @@ void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) {u32 old_irr = ioapic->irr;u32 mask =1 << irq; -union ioapic_redir_entry entry; +union kvm_ioapic_redirect_entry entry;if (irq >=0 && irq <IOAPIC_NUM_PINS ) { entry = ioapic->redirtbl[irq];
@@ -296,7 +296,7 @@ void kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level)static void __kvm_ioapic_update_eoi (struct kvm_ioapic *ioapic,int pin,int trigger_mode) { -union ioapic_redir_entry *ent; +union kvm_ioapic_redirect_entry *ent; ent = &ioapic->redirtbl[pin];
virt/kvm/ioapic.h +1 -16
@@ -40,22 +40,7 @@ struct kvm_ioapic {u32 id;u32 irr;u32 pad; -union ioapic_redir_entry { -u64 bits; -struct { -u8 vector; -u8 delivery_mode:3 ; -u8 dest_mode:1 ; -u8 delivery_status:1 ; -u8 polarity:1 ; -u8 remote_irr:1 ; -u8 trig_mode:1 ; -u8 mask:1 ; -u8 reserve:7 ; -u8 reserved[4 ]; -u8 dest_id; - } fields; - } redirtbl[IOAPIC_NUM_PINS ]; +union kvm_ioapic_redirect_entry redirtbl[IOAPIC_NUM_PINS ];struct kvm_io_device dev;struct kvm *kvm;void (*ack_notifier)(void *opaque,int irq);
Signature · 1 line
1.5.4.5
PATCH v8 2/5 KVM: Unified the delivery of IOAPIC and MSI
In reply to Sheng Yang--- include/linux/kvm_host.h | 3 ++ virt/kvm/ioapic.c | 84 ++++++++++++++++--------------------------- virt/kvm/irq_comm.c | 89 ++++++++++++++++++++++++++++----------------- 3 files changed, 89 insertions(+), 87 deletions(-)
include/linux/kvm_host.h +3 -0
@@ -351,6 +351,9 @@ void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, struct kvm_irq_mask_notifier *kimn);void kvm_fire_mask_notifiers (struct kvm *kvm,int irq,bool mask); +void kvm_get_intr_delivery_bitmask (struct kvm_ioapic *ioapic, +union kvm_ioapic_redirect_entry *entry, +unsigned long *deliver_bitmask);void kvm_set_irq (struct kvm *kvm,int irq_source_id,int irq,int level);void kvm_notify_acked_irq (struct kvm *kvm,unsigned irqchip,unsigned pin); void kvm_register_irq_ack_notifier(struct kvm *kvm,
virt/kvm/ioapic.c +31 -53
106 lines not on this page · raw message
virt/kvm/irq_comm.c +55 -34
105 lines not on this page · raw message
Signature · 1 line
1.5.4.5
PATCH v8 3/5 KVM: Change API of kvm_ioapic_get_delivery_bitmask
In reply to Sheng YangIn order to use with bit ops.
--- virt/kvm/ioapic.c | 17 ++++++++--------- virt/kvm/ioapic.h | 4 ++-- virt/kvm/irq_comm.c | 5 +++-- 3 files changed, 13 insertions(+), 13 deletions(-)
virt/kvm/ioapic.c +8 -9
@@ -158,22 +158,22 @@ static void ioapic_inj_nmi(struct kvm_vcpu *vcpu)kvm_vcpu_kick (vcpu); } -u32 kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, -u8 dest_mode) +void kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, +u8 dest_mode,u32 *mask) { -u32 mask =0 ;int i;struct kvm *kvm = ioapic->kvm;struct kvm_vcpu *vcpu;ioapic_debug ("dest %d dest_mode %d\n" , dest, dest_mode); + *mask =0 ;if (dest_mode ==0 ) {/* Physical mode. */ if (dest ==0xFF ) {/* Broadcast. */ for (i =0 ; i <KVM_MAX_VCPUS ; ++i)if (kvm->vcpus[i] && kvm->vcpus[i]->arch.apic) - mask |=1 << i; -return mask; + *mask |=1 << i; +return ; }for (i =0 ; i <KVM_MAX_VCPUS ; ++i) { vcpu = kvm->vcpus[i];
@@ -181,7 +181,7 @@ u32 kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,continue ;if (kvm_apic_match_physical_addr (vcpu->arch.apic, dest)) {if (vcpu->arch.apic) - mask =1 << i; + *mask =1 << i;break ; } }
@@ -192,10 +192,9 @@ u32 kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,continue ;if (vcpu->arch.apic &&kvm_apic_match_logical_addr (vcpu->arch.apic, dest)) - mask |=1 << vcpu->vcpu_id; + *mask |=1 << vcpu->vcpu_id; } -ioapic_debug ("mask %x\n" , mask); -return mask; +ioapic_debug ("mask %x\n" , *mask); }static int ioapic_deliver (struct kvm_ioapic *ioapic,int irq)
virt/kvm/ioapic.h +2 -2
@@ -70,7 +70,7 @@ void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode);int kvm_ioapic_init (struct kvm *kvm);void kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level);void kvm_ioapic_reset (struct kvm_ioapic *ioapic); -u32 kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, -u8 dest_mode); +void kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, +u8 dest_mode,u32 *mask);#endif
virt/kvm/irq_comm.c +3 -2
@@ -49,8 +49,9 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic, {struct kvm_vcpu *vcpu; - *deliver_bitmask =kvm_ioapic_get_delivery_bitmask (ioapic, - entry->fields.dest_id, entry->fields.dest_mode); +kvm_ioapic_get_delivery_bitmask (ioapic, entry->fields.dest_id, + entry->fields.dest_mode, + deliver_bitmask);switch (entry->fields.delivery_mode) {case IOAPIC_LOWEST_PRIORITY : vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm,
Signature · 1 line
1.5.4.5
PATCH v8 4/5 KVM: Update intr delivery func to accept unsigned long* bitmap
In reply to Sheng YangWould be used with bit ops, and would be easily extended if KVM_MAX_VCPUS is increased.
--- arch/x86/kvm/lapic.c | 8 ++++---- virt/kvm/ioapic.c | 4 ++-- virt/kvm/ioapic.h | 4 ++-- virt/kvm/irq_comm.c | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/kvm/lapic.c +4 -4
@@ -409,7 +409,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, }static struct kvm_lapic *kvm_apic_round_robin (struct kvm *kvm,u8 vector, -unsigned long bitmap) +unsigned long *bitmap) {int last;int next;
@@ -421,7 +421,7 @@ static struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector, do { if (++next == KVM_MAX_VCPUS) next = 0; - if (kvm->vcpus[next] == NULL || !test_bit(next, &bitmap)) + if (kvm->vcpus[next] == NULL || !test_bit(next, bitmap)) continue; apic = kvm->vcpus[next]->arch.apic; if (apic && apic_enabled(apic))
@@ -437,7 +437,7 @@ static struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector, }struct kvm_vcpu *kvm_get_lowest_prio_vcpu (struct kvm *kvm,u8 vector, -unsigned long bitmap) +unsigned long *bitmap) {struct kvm_lapic *apic;
@@ -508,7 +508,7 @@ static void apic_send_ipi(struct kvm_lapic *apic) }if (delivery_mode ==APIC_DM_LOWEST ) { - target =kvm_get_lowest_prio_vcpu (vcpu->kvm, vector, lpr_map); + target =kvm_get_lowest_prio_vcpu (vcpu->kvm, vector, &lpr_map);if (target !=NULL )__apic_accept_irq (target->arch.apic, delivery_mode, vector, level, trig_mode);
virt/kvm/ioapic.c +2 -2
@@ -159,7 +159,7 @@ static void ioapic_inj_nmi(struct kvm_vcpu *vcpu) }void kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, -u8 dest_mode,u32 *mask) +u8 dest_mode,unsigned long *mask) {int i;struct kvm *kvm = ioapic->kvm;
@@ -200,7 +200,7 @@ void kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,static int ioapic_deliver (struct kvm_ioapic *ioapic,int irq) {union kvm_ioapic_redirect_entry entry = ioapic->redirtbl[irq]; -u32 deliver_bitmask; +unsigned long deliver_bitmask;struct kvm_vcpu *vcpu;int vcpu_id, r =0 ;
virt/kvm/ioapic.h +2 -2
@@ -65,12 +65,12 @@ static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm) }struct kvm_vcpu *kvm_get_lowest_prio_vcpu (struct kvm *kvm,u8 vector, -unsigned long bitmap); +unsigned long *bitmap);void kvm_ioapic_update_eoi (struct kvm *kvm,int vector,int trigger_mode);int kvm_ioapic_init (struct kvm *kvm);void kvm_ioapic_set_irq (struct kvm_ioapic *ioapic,int irq,int level);void kvm_ioapic_reset (struct kvm_ioapic *ioapic);void kvm_ioapic_get_delivery_bitmask (struct kvm_ioapic *ioapic,u8 dest, -u8 dest_mode,u32 *mask); +u8 dest_mode,unsigned long *mask);#endif
virt/kvm/irq_comm.c +3 -3
@@ -45,7 +45,7 @@ static void kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,void kvm_get_intr_delivery_bitmask (struct kvm_ioapic *ioapic,union kvm_ioapic_redirect_entry *entry, -u32 *deliver_bitmask) +unsigned long *deliver_bitmask) {struct kvm_vcpu *vcpu;
@@ -55,7 +55,7 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,switch (entry->fields.delivery_mode) {case IOAPIC_LOWEST_PRIORITY : vcpu =kvm_get_lowest_prio_vcpu (ioapic->kvm, - entry->fields.vector, *deliver_bitmask); + entry->fields.vector, deliver_bitmask); *deliver_bitmask =1 << vcpu->vcpu_id;break ;case IOAPIC_FIXED :
@@ -76,7 +76,7 @@ static void kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,struct kvm_vcpu *vcpu;struct kvm_ioapic *ioapic =ioapic_irqchip (kvm);union kvm_ioapic_redirect_entry entry; -u32 deliver_bitmask; +unsigned long deliver_bitmask;BUG_ON (!ioapic);
Signature · 1 line
1.5.4.5
PATCH v8 5/5 KVM: bit ops for deliver_bitmap
In reply to Sheng YangIt's also convenient when we extend KVM supported vcpu number in the future.
--- arch/x86/kvm/lapic.c | 7 ++++--- virt/kvm/ioapic.c | 24 +++++++++++++----------- virt/kvm/irq_comm.c | 22 ++++++++++++---------- 3 files changed, 29 insertions(+), 24 deletions(-)
arch/x86/kvm/lapic.c +4 -3
@@ -483,9 +483,10 @@ static void apic_send_ipi(struct kvm_lapic *apic)struct kvm_vcpu *target;struct kvm_vcpu *vcpu; -unsigned long lpr_map =0 ; +DECLARE_BITMAP (lpr_map,KVM_MAX_VCPUS );int i; +bitmap_zero (lpr_map,KVM_MAX_VCPUS ); apic_debug("icr_high 0x%x, icr_low 0x%x, " "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, " "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x\n",
@@ -500,7 +501,7 @@ static void apic_send_ipi(struct kvm_lapic *apic)if (vcpu->arch.apic &&apic_match_dest (vcpu, apic, short_hand, dest, dest_mode)) {if (delivery_mode ==APIC_DM_LOWEST ) -set_bit (vcpu->vcpu_id, &lpr_map); +set_bit (vcpu->vcpu_id, lpr_map);else __apic_accept_irq (vcpu->arch.apic, delivery_mode, vector, level, trig_mode);
@@ -508,7 +509,7 @@ static void apic_send_ipi(struct kvm_lapic *apic) }if (delivery_mode ==APIC_DM_LOWEST ) { - target =kvm_get_lowest_prio_vcpu (vcpu->kvm, vector, &lpr_map); + target =kvm_get_lowest_prio_vcpu (vcpu->kvm, vector, lpr_map);if (target !=NULL )__apic_accept_irq (target->arch.apic, delivery_mode, vector, level, trig_mode);
virt/kvm/ioapic.c +13 -11
@@ -200,7 +200,7 @@ void kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,static int ioapic_deliver (struct kvm_ioapic *ioapic,int irq) {union kvm_ioapic_redirect_entry entry = ioapic->redirtbl[irq]; -unsigned long deliver_bitmask; +DECLARE_BITMAP (deliver_bitmask,KVM_MAX_VCPUS );struct kvm_vcpu *vcpu;int vcpu_id, r =0 ;
@@ -210,22 +210,24 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) entry.fields.delivery_mode, entry.fields.vector, entry.fields.trig_mode); -kvm_get_intr_delivery_bitmask (ioapic, &entry, &deliver_bitmask); -if (!deliver_bitmask) { -ioapic_debug ("no target on destination\n" ); -return 0 ; - } +bitmap_zero (deliver_bitmask,KVM_MAX_VCPUS );/* Always delivery PIT interrupt to vcpu 0 */ #ifdef CONFIG_X86 if (irq ==0 ) - deliver_bitmask =1 <<0 ; +set_bit (0 , deliver_bitmask); + else#endif +kvm_get_intr_delivery_bitmask (ioapic, &entry, deliver_bitmask); + +if (find_first_bit (deliver_bitmask,KVM_MAX_VCPUS ) >=KVM_MAX_VCPUS ) { +ioapic_debug ("no target on destination\n" ); +return 0 ; + } -for (vcpu_id =0 ; deliver_bitmask !=0 ; vcpu_id++) { -if (!(deliver_bitmask & (1 << vcpu_id))) -continue ; - deliver_bitmask &= ~(1 << vcpu_id); +while ((vcpu_id =find_first_bit (deliver_bitmask,KVM_MAX_VCPUS )) + <KVM_MAX_VCPUS ) { +clear_bit (vcpu_id, deliver_bitmask); vcpu = ioapic->kvm->vcpus[vcpu_id];if (vcpu) { if (entry.fields.delivery_mode ==
virt/kvm/irq_comm.c +12 -10
@@ -56,7 +56,7 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,case IOAPIC_LOWEST_PRIORITY : vcpu =kvm_get_lowest_prio_vcpu (ioapic->kvm, entry->fields.vector, deliver_bitmask); - *deliver_bitmask =1 << vcpu->vcpu_id; +set_bit (vcpu->vcpu_id, deliver_bitmask);break ;case IOAPIC_FIXED :case IOAPIC_NMI :
@@ -76,10 +76,12 @@ static void kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,struct kvm_vcpu *vcpu;struct kvm_ioapic *ioapic =ioapic_irqchip (kvm);union kvm_ioapic_redirect_entry entry; -unsigned long deliver_bitmask; +DECLARE_BITMAP (deliver_bitmask,KVM_MAX_VCPUS );BUG_ON (!ioapic); +bitmap_zero (deliver_bitmask,KVM_MAX_VCPUS ); + entry.bits =0 ; entry.fields.dest_id = (e->msi.address_lo &MSI_ADDR_DEST_ID_MASK ) >>MSI_ADDR_DEST_ID_SHIFT ;
@@ -94,17 +96,17 @@ static void kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, (unsigned long *)&e->msi.data);/* TODO Deal with RH bit of MSI message address */ +kvm_get_intr_delivery_bitmask (ioapic, &entry, deliver_bitmask); -kvm_get_intr_delivery_bitmask (ioapic, &entry, &deliver_bitmask); - -if (!deliver_bitmask) { -printk (KERN_WARNING "kvm: no destination for MSI delivery!" ); +if (find_first_bit (deliver_bitmask,KVM_MAX_VCPUS ) + >=KVM_MAX_VCPUS ) { +printk (KERN_WARNING +"kvm: no destination for MSI delivery!" );return ; } -for (vcpu_id =0 ; deliver_bitmask !=0 ; vcpu_id++) { -if (!(deliver_bitmask & (1 << vcpu_id))) -continue ; - deliver_bitmask &= ~(1 << vcpu_id); +while ((vcpu_id =find_first_bit (deliver_bitmask, +KVM_MAX_VCPUS )) <KVM_MAX_VCPUS ) { +clear_bit (vcpu_id, deliver_bitmask); vcpu = ioapic->kvm->vcpus[vcpu_id];if (vcpu) kvm_apic_set_irq(vcpu, entry.fields.vector,
Signature · 1 line
1.5.4.5
Quoted 5 lines · Sheng Yang
This patchset based on MSI patch which changed deliver method to irq routing.
Thanks.
Looks good to me, will apply if further review doesn't generate comments.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 8 lines · Avi Kivity
Quoted 5 lines · Sheng Yang
This patchset based on MSI patch which changed deliver method to irq routing.
Thanks.
Looks good to me, will apply if further review doesn't generate comments.
ACK.
Avi Kivity
AppliedQuoted 3 lines · Sheng Yang
This patchset based on MSI patch which changed deliver method to irq routing.
Applied all, thanks. There were many merge conflicts, please look at the final result to see if I missed anything.
Signature · 1 line
error compiling committee.c: too many arguments to function