replace d->nr_pirqs sized arrays with radix tree
PATCH 2/2 replace d->nr_pirqs sized arrays with radix tree
With this it is questionable whether retaining struct domain's nr_pirqs is actually necessary - the value now only serves for bounds checking, and this boundary could easily be nr_irqs.
Another thing to consider is whether it's worth storing the pirq number in struct pirq, to avoid passing the number and a pointer to quite a number of functions.
Note that ia64, the build of which is broken currently anyway, is only partially fixed up.
xen/arch/ia64/vmx/vmx_interrupt.c +2 -2
@@ -155,13 +155,13 @@ void hvm_isa_irq_deassert(struct domain/* dummy */ } -int msixtbl_pt_register (struct domain *d,int pirq,uint64_t gtable) +int msixtbl_pt_register (struct domain *d,struct pirq *pirq,uint64_t gtable) {/* dummy */ return -ENOSYS ; } -void msixtbl_pt_unregister (struct domain *d,int pirq) +void msixtbl_pt_unregister (struct domain *d,struct pirq *pirq) {/* dummy */ }
xen/arch/ia64/xen/hypercall.c +5 -2
@@ -65,8 +65,11 @@ static long __do_pirq_guest_eoi(struct d {if ( pirq <0 || pirq >=NR_IRQS )return -EINVAL ; -if ( d->arch.pirq_eoi_map ) -evtchn_unmask (d->pirq_to_evtchn[pirq]); +if ( d->arch.pirq_eoi_map ) { +spin_lock (&d->event_lock); +evtchn_unmask (pirq_to_evtchn (d, pirq)); +spin_unlock (&d->event_lock); + }return pirq_guest_eoi (d, pirq); }
xen/arch/ia64/xen/irq.c +25 -21
109 lines not on this page · raw message
xen/arch/x86/domain.c +0 -20
@@ -608,25 +608,9 @@ int arch_domain_create(struct domain *d,share_xen_page_with_guest (virt_to_page (d->shared_info), d, XENSHARE_writable); - d->arch.pirq_irq =xmalloc_array (int, d->nr_pirqs); -if ( !d->arch.pirq_irq ) - goto fail; -memset (d->arch.pirq_irq,0 , - d->nr_pirqs *sizeof (*d->arch.pirq_irq)); -if ( (rc =init_domain_irq_mapping (d)) !=0 ) goto fail; -if (is_hvm_domain (d) ) - { - d->arch.pirq_emuirq =xmalloc_array (int, d->nr_pirqs); -if ( !d->arch.pirq_emuirq ) - goto fail; -for (i =0 ; i < d->nr_pirqs; i++) - d->arch.pirq_emuirq[i] =IRQ_UNBOUND ; - } - -if ( (rc =iommu_domain_init (d)) !=0 ) goto fail;
@@ -660,8 +644,6 @@ int arch_domain_create(struct domain *d, fail: d->is_dying = DOMDYING_dead;vmce_destroy_msr (d); -xfree (d->arch.pirq_irq); -xfree (d->arch.pirq_emuirq);cleanup_domain_irq_mapping (d);free_xenheap_page (d->shared_info);if ( paging_initialised )
@@ -714,8 +696,6 @@ void arch_domain_destroy(struct domain *#endif free_xenheap_page (d->shared_info); -xfree (d->arch.pirq_irq); -xfree (d->arch.pirq_emuirq);cleanup_domain_irq_mapping (d); }
xen/arch/x86/hvm/hvm.c +24 -22
64 lines not on this page · raw message
xen/arch/x86/hvm/irq.c +1 -1
@@ -33,7 +33,7 @@ static void assert_irq(struct domain *d,int pirq =domain_emuirq_to_pirq (d, ioapic_gsi);if ( pirq !=IRQ_UNBOUND ) { -send_guest_pirq (d, pirq); +send_guest_pirq (d,pirq_info (d, pirq));return ; }vioapic_irq_positive_edge (d, ioapic_gsi);
xen/arch/x86/hvm/vmsi.c +11 -14
@@ -65,11 +65,10 @@ static void vmsi_inj_irq( } } -int vmsi_deliver (struct domain *d,int pirq) +int vmsi_deliver (struct domain *d,const struct hvm_pirq_dpci *pirq_dpci) { -struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci; -uint32_t flags = hvm_irq_dpci->mirq[pirq].gmsi.gflags; -int vector = hvm_irq_dpci->mirq[pirq].gmsi.gvec; +uint32_t flags = pirq_dpci->gmsi.gflags; +int vector = pirq_dpci->gmsi.gvec;uint8_t dest = (uint8_t )flags;uint8_t dest_mode = !!(flags &VMSI_DM_MASK );uint8_t delivery_mode = (flags &VMSI_DELIV_MASK ) >>GLFAGS_SHIFT_DELIV_MODE ;
@@ -82,11 +81,7 @@ int vmsi_deliver(struct domain *d, int p"vector=%x trig_mode=%x\n" , dest, dest_mode, delivery_mode, vector, trig_mode); -if ( !( hvm_irq_dpci->mirq[pirq].flags &HVM_IRQ_DPCI_GUEST_MSI ) ) - { -gdprintk (XENLOG_WARNING ,"pirq %x not msi \n" , pirq); -return 0 ; - } +ASSERT (pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI );switch ( delivery_mode ) {
@@ -349,7 +344,7 @@ static void del_msixtbl_entry(struct msicall_rcu (&entry->rcu, free_msixtbl_entry); } -int msixtbl_pt_register (struct domain *d,int pirq,uint64_t gtable) +int msixtbl_pt_register (struct domain *d,struct pirq *pirq,uint64_t gtable) {struct irq_desc *irq_desc;struct msi_desc *msi_desc;
@@ -358,6 +353,7 @@ int msixtbl_pt_register(struct domain *dint r = -EINVAL ;ASSERT (spin_is_locked (&pcidevs_lock)); +ASSERT (spin_is_locked (&d->event_lock));/* * xmalloc() with irq_disabled causes the failure of check_lock()
@@ -367,7 +363,7 @@ int msixtbl_pt_register(struct domain *dif ( !new_entry )return -ENOMEM ; - irq_desc =domain_spin_lock_irq_desc (d, pirq,NULL ); + irq_desc =pirq_spin_lock_irq_desc (d, pirq,NULL );if ( !irq_desc ) {xfree (new_entry);
@@ -404,7 +400,7 @@ out:return r; } -void msixtbl_pt_unregister (struct domain *d,int pirq) +void msixtbl_pt_unregister (struct domain *d,struct pirq *pirq) {struct irq_desc *irq_desc;struct msi_desc *msi_desc;
@@ -412,8 +408,9 @@ void msixtbl_pt_unregister(struct domainstruct msixtbl_entry *entry;ASSERT (spin_is_locked (&pcidevs_lock)); +ASSERT (spin_is_locked (&d->event_lock)); - irq_desc =domain_spin_lock_irq_desc (d, pirq,NULL ); + irq_desc =pirq_spin_lock_irq_desc (d, pirq,NULL );if ( !irq_desc )return ;
@@ -447,7 +444,7 @@ found:spin_unlock_irq (&irq_desc->lock); } -void msixtbl_pt_cleanup (struct domain *d,int pirq) +void msixtbl_pt_cleanup (struct domain *d) {struct msixtbl_entry *entry, *temp;unsigned long flags;
xen/arch/x86/irq.c +175 -93
522 lines not on this page · raw message
xen/arch/x86/physdev.c +28 -8
@@ -258,20 +258,28 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H {case PHYSDEVOP_eoi: {struct physdev_eoi eoi; +struct pirq *pirq; + ret = -EFAULT ;if (copy_from_guest (&eoi, arg,1 ) !=0 )break ; ret = -EINVAL ;if ( eoi.irq >= v->domain->nr_pirqs )break ; +spin_lock (&v->domain->event_lock); + pirq =pirq_info (v->domain, eoi.irq); +if ( !pirq ) { +spin_unlock (&v->domain->event_lock); +break ; + }if ( !is_hvm_domain (v->domain) && v->domain->arch.pv_domain.pirq_eoi_map ) -evtchn_unmask (v->domain->pirq_to_evtchn[eoi.irq]); +evtchn_unmask (pirq->evtchn);if ( !is_hvm_domain (v->domain) || -domain_pirq_to_emuirq (v->domain, eoi.irq) ==IRQ_PT ) - ret =pirq_guest_eoi (v->domain, eoi.irq); -else - ret =0 ; + pirq->arch.hvm.emuirq ==IRQ_PT ) +pirq_guest_eoi (v->domain, pirq); +spin_unlock (&v->domain->event_lock); + ret =0 ;break ; }
@@ -564,11 +572,23 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_Hbreak ;spin_lock (&d->event_lock); - out.pirq =get_free_pirq (d, out.type,0 ); - d->arch.pirq_irq[out.pirq] =PIRQ_ALLOCATED ; + ret =get_free_pirq (d, out.type,0 ); +if ( ret >=0 ) + { +struct pirq *info =pirq_get_info (d, ret); + +if ( info ) + info->arch.irq =PIRQ_ALLOCATED ; +else + ret = -ENOMEM ; + }spin_unlock (&d->event_lock); - ret =copy_to_guest (arg, &out,1 ) ? -EFAULT :0 ; +if ( ret >=0 ) + { + out.pirq = ret; + ret =copy_to_guest (arg, &out,1 ) ? -EFAULT :0 ; + }rcu_unlock_domain (d);break ;
xen/common/domain.c +17 -11
@@ -290,13 +290,7 @@ struct domain *domain_create(if ( d->nr_pirqs > nr_irqs ) d->nr_pirqs = nr_irqs; - d->pirq_to_evtchn =xmalloc_array (u16, d->nr_pirqs); - d->pirq_mask =xmalloc_array ( - unsigned long, BITS_TO_LONGS(d->nr_pirqs)); -if ( (d->pirq_to_evtchn ==NULL ) || (d->pirq_mask ==NULL ) ) - goto fail; -memset (d->pirq_to_evtchn,0 , d->nr_pirqs *sizeof (*d->pirq_to_evtchn)); -bitmap_zero (d->pirq_mask, d->nr_pirqs); +INIT_RADIX_TREE (&d->pirq_tree,0 );if (evtchn_init (d) !=0 ) goto fail;
@@ -346,6 +340,7 @@ struct domain *domain_create( {evtchn_destroy (d);evtchn_destroy_final (d); +radix_tree_destroy (&d->pirq_tree, free_pirq_struct,NULL ); }if ( init_status & INIT_rangeset )rangeset_domain_destroy (d);
@@ -353,8 +348,6 @@ struct domain *domain_create(watchdog_domain_destroy (d);if ( init_status & INIT_xsm )xsm_free_security_domain (d); -xfree (d->pirq_mask); -xfree (d->pirq_to_evtchn);free_cpumask_var (d->domain_dirty_cpumask);free_domain_struct (d);return NULL ;
@@ -680,8 +673,7 @@ static void complete_domain_destroy(struevtchn_destroy_final (d); -xfree (d->pirq_mask); -xfree (d->pirq_to_evtchn); +radix_tree_destroy (&d->pirq_tree, free_pirq_struct,NULL );xsm_free_security_domain (d);free_cpumask_var (d->domain_dirty_cpumask);
@@ -963,6 +955,20 @@ long vm_assist(struct domain *p, unsignereturn -ENOSYS ; } +struct pirq *pirq_get_info (struct domain *d,int pirq) +{ +struct pirq *info =pirq_info (d, pirq); + +if ( !info && (info =alloc_pirq_struct (d)) !=NULL && +radix_tree_insert (&d->pirq_tree, pirq, info,NULL ,NULL ) ) + { +free_pirq_struct (info); + info =NULL ; + } + +return info; +} +struct migrate_info {long (*func)(void *data);void *data;
xen/common/event_channel.c +25 -17
108 lines not on this page · raw message
xen/common/radix-tree.c +12 -4
@@ -225,7 +225,8 @@ EXPORT_SYMBOL(radix_tree_lookup);static unsigned int __lookup (struct radix_tree_root *root,void **results,unsigned long index, -unsigned int max_items,unsigned long *next_index) +unsigned int max_items,unsigned long *indexes, +unsigned long *next_index) {unsigned int nr_found =0 ;unsigned int shift, height;
@@ -235,8 +236,11 @@ __lookup(struct radix_tree_root *root, v height = root->height;if (index >radix_tree_maxindex (height))if (height ==0 ) { -if (root->rnode && index ==0 ) +if (root->rnode && index ==0 ) { +if (indexes) + indexes[nr_found] = index; results[nr_found++] = root->rnode; + } goto out; }
@@ -265,6 +269,8 @@ __lookup(struct radix_tree_root *root, vfor (i = index &RADIX_TREE_MAP_MASK ; i <RADIX_TREE_MAP_SIZE ; i++) { index++;if (slot->slots[i]) { +if (indexes) + indexes[nr_found] = index -1 ; results[nr_found++] = slot->slots[i];if (nr_found == max_items) goto out;
@@ -281,6 +287,7 @@ __lookup(struct radix_tree_root *root, v* @results: where the results of the lookup are placed * @first_index: start the lookup from this key * @max_items: place up to this many items at *results +* @indexes: (optional) array to store indexes of items. * * Performs an index-ascending scan of the tree for present items. Places * them at *@results and returns the number of items which were placed at
@@ -290,7 +297,8 @@ __lookup(struct radix_tree_root *root, v*/ unsigned int radix_tree_gang_lookup (struct radix_tree_root *root,void **results, -unsigned long first_index,unsigned int max_items) +unsigned long first_index,unsigned int max_items, +unsigned long *indexes) {const unsigned long max_index =radix_tree_maxindex (root->height);unsigned long cur_index = first_index;
@@ -303,7 +311,7 @@ radix_tree_gang_lookup(struct radix_treeif (cur_index > max_index)break ; nr_found =__lookup (root, results + ret, cur_index, - max_items - ret, &next_index); + max_items - ret, indexes + ret, &next_index); ret += nr_found;if (next_index ==0 )break ;
xen/drivers/passthrough/io.c +206 -180
631 lines not on this page · raw message
xen/drivers/passthrough/pci.c +20 -21
56 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/vtd.c +26 -25
67 lines not on this page · raw message
xen/include/asm-ia64/domain.h +18 -0
@@ -11,6 +11,7 @@#include <xen/list.h> #include <xen/cpumask.h> #include <xen/mm.h> +#include <xen/hvm/irq.h> #include <asm/fpswa.h> #include <xen/rangeset.h>
@@ -316,6 +317,23 @@ struct arch_vcpu {cpumask_t cache_coherent_map; }; +struct arch_pirq { +struct hvm_pirq_dpci dpci; +}; + +#define pirq_dpci (pirq) ((pirq) ? &(pirq)->arch.dpci : NULL) +#define dpci_pirq (dpci) container_of(dpci, struct pirq, arch.dpci) + +#define alloc_pirq_struct (d) ({ \ + struct pirq *pirq = xmalloc(struct pirq); \ + if ( pirq ) \ + { \ + memset(pirq, 0, sizeof(*pirq)); \ + pt_pirq_init(d, &pirq->arch.dpci); \ + } \ + pirq; \ +}) +#include <asm/uaccess.h> /* for KERNEL_DS */ #include <asm/pgtable.h>
xen/include/asm-x86/domain.h +0 -3
@@ -286,9 +286,6 @@ struct arch_domain/* NB. protected by d->event_lock and by irq_desc[irq].lock */ struct radix_tree_root irq_pirq; -int *pirq_irq; -/* pirq to emulated irq */ -int *pirq_emuirq;/* Maximum physical-address bitwidth supported by this guest. */ unsigned int physaddr_bitsize;
xen/include/asm-x86/hvm/irq.h +2 -0
@@ -111,4 +111,6 @@ struct hvm_intack hvm_vcpu_ack_pending_i*/ #define SUPPORT_MSI_REMAPPING 1 +void msixtbl_pt_cleanup (struct domain *d); +#endif /* __ASM_X86_HVM_IRQ_H__ */
xen/include/asm-x86/irq.h +18 -3
@@ -7,6 +7,7 @@#include <asm/atomic.h> #include <xen/cpumask.h> #include <xen/smp.h> +#include <xen/hvm/irq.h> #include <irq_vectors.h> #include <asm/percpu.h>
@@ -105,6 +106,20 @@ extern unsigned int io_apic_irqs; DECLARE_PER_CPU(unsigned int, irq_count); +struct pirq ; +struct arch_pirq { +int irq; +union { +struct hvm_pirq { +int emuirq; +struct hvm_pirq_dpci dpci; + } hvm; + }; +}; + +#define pirq_dpci (pirq) ((pirq) ? &(pirq)->arch.hvm.dpci : NULL) +#define dpci_pirq (pd) container_of(pd, struct pirq, arch.hvm.dpci) +int pirq_shared (struct domain *d ,int irq); int map_domain_pirq(struct domain *d, int pirq, int irq, int type,
@@ -114,7 +129,7 @@ int get_free_pirq(struct domain *d, intvoid free_domain_pirqs (struct domain *d);int map_domain_emuirq_pirq (struct domain *d,int pirq,int irq);int unmap_domain_pirq_emuirq (struct domain *d,int pirq); -int hvm_domain_use_pirq (struct domain *d,int irq); +bool_t hvm_domain_use_pirq (const struct domain *,const struct pirq *);int init_irq_data (void );
@@ -146,11 +161,11 @@ void irq_set_affinity(struct irq_desc *,int init_domain_irq_mapping (struct domain *);void cleanup_domain_irq_mapping (struct domain *); -#define domain_pirq_to_irq (d, pirq) ((d)->arch.pirq_irq[pirq]) +#define domain_pirq_to_irq (d, pirq) pirq_field(d, pirq, arch.irq)#define domain_irq_to_pirq (d, irq) \ ((long)radix_tree_lookup(&(d)->arch.irq_pirq, irq))#define PIRQ_ALLOCATED -1 -#define domain_pirq_to_emuirq (d, pirq) ((d)->arch.pirq_emuirq[pirq]) +#define domain_pirq_to_emuirq (d, pirq) pirq_field(d, pirq, arch.hvm.emuirq)#define domain_emuirq_to_pirq (d, emuirq) \ (((long)radix_tree_lookup(&(d)->arch.hvm_domain.emuirq_pirq, emuirq) ?: \ IRQ_UNBOUND + 1) - 1)
xen/include/xen/domain.h +6 -0
@@ -38,6 +38,12 @@ struct vcpu_guest_context *alloc_vcpu_guvoid free_vcpu_guest_context (struct vcpu_guest_context *);#endif +/* Allocate/free a PIRQ structure. */ +#ifndef alloc_pirq_struct +struct pirq *alloc_pirq_struct (struct domain *); +#endif +#define free_pirq_struct xfree +/* * Initialise/destroy arch-specific details of a VCPU. * - vcpu_initialise() is called after the basic generic fields of the
xen/include/xen/event.h +1 -1
@@ -36,7 +36,7 @@ void send_guest_global_virq(struct domai* @pirq: Physical IRQ number * Returns TRUE if the delivery port was already pending. */ -int send_guest_pirq (struct domain *d,int pirq); +int send_guest_pirq (struct domain *,const struct pirq *);/* Send a notification from a given domain's event-channel port. */ int evtchn_send (struct domain *d,unsigned int lport);
xen/include/xen/hvm/irq.h +25 -14
@@ -25,7 +25,7 @@#include <xen/types.h> #include <xen/spinlock.h> #include <xen/tasklet.h> -#include <asm/irq.h> +#include <xen/timer.h> #include <public/hvm/save.h> struct dev_intx_gsi_link {
@@ -38,11 +38,15 @@ struct dev_intx_gsi_link {#define _HVM_IRQ_DPCI_MACH_PCI_SHIFT 0#define _HVM_IRQ_DPCI_MACH_MSI_SHIFT 1 +#define _HVM_IRQ_DPCI_MAPPED_SHIFT 2 +#define _HVM_IRQ_DPCI_EOI_LATCH_SHIFT 3#define _HVM_IRQ_DPCI_GUEST_PCI_SHIFT 4#define _HVM_IRQ_DPCI_GUEST_MSI_SHIFT 5#define _HVM_IRQ_DPCI_TRANSLATE_SHIFT 15#define HVM_IRQ_DPCI_MACH_PCI (1 << _HVM_IRQ_DPCI_MACH_PCI_SHIFT)#define HVM_IRQ_DPCI_MACH_MSI (1 << _HVM_IRQ_DPCI_MACH_MSI_SHIFT) +#define HVM_IRQ_DPCI_MAPPED (1 << _HVM_IRQ_DPCI_MAPPED_SHIFT) +#define HVM_IRQ_DPCI_EOI_LATCH (1 << _HVM_IRQ_DPCI_EOI_LATCH_SHIFT)#define HVM_IRQ_DPCI_GUEST_PCI (1 << _HVM_IRQ_DPCI_GUEST_PCI_SHIFT)#define HVM_IRQ_DPCI_GUEST_MSI (1 << _HVM_IRQ_DPCI_GUEST_MSI_SHIFT)#define HVM_IRQ_DPCI_TRANSLATE (1 << _HVM_IRQ_DPCI_TRANSLATE_SHIFT)
@@ -63,14 +67,6 @@ struct hvm_gmsi_info {int dest_vcpu_id;/* -1 :multi-dest, non-negative: dest_vcpu_id */ }; -struct hvm_mirq_dpci_mapping { -uint32_t flags; -int pending; -struct list_head digl_list; -struct domain *dom; -struct hvm_gmsi_info gmsi; -}; -struct hvm_girq_dpci_mapping {struct list_head list;uint8_t device;
@@ -88,20 +84,33 @@ struct hvm_girq_dpci_mapping {/* Protected by domain's event_lock */ struct hvm_irq_dpci { -/* Machine IRQ to guest device/intx mapping. */ -unsigned long *mapping; -struct hvm_mirq_dpci_mapping *mirq; -unsigned long *dirq_mask;/* Guest IRQ to guest device/intx mapping. */ struct list_head girq[NR_HVM_IRQS ];/* Record of mapped ISA IRQs */ DECLARE_BITMAP(isairq_map, NR_ISAIRQS);/* Record of mapped Links */ uint8_t link_cnt[NR_LINK ]; -struct timer *hvm_timer;struct tasklet dirq_tasklet; }; +/* Machine IRQ to guest device/intx mapping. */ +struct hvm_pirq_dpci { +uint32_t flags; +bool_t masked; +uint16_t pending; +struct list_head digl_list; +struct domain *dom; +struct hvm_gmsi_info gmsi; +struct timer timer; +}; + +void pt_pirq_init (struct domain *,struct hvm_pirq_dpci *); +bool_t pt_pirq_cleanup_check (struct hvm_pirq_dpci *); +int pt_pirq_iterate (struct domain *d, +int (*cb)(struct domain *,unsigned int pirq, +struct hvm_pirq_dpci *,void *arg), +void *arg); +/* Modify state of a PCI INTx wire. */ void hvm_pci_intx_assert (struct domain *d,unsigned int device,unsigned int intx);
@@ -120,4 +129,6 @@ void hvm_maybe_deassert_evtchn_irq(void)void hvm_assert_evtchn_irq (struct vcpu *v);void hvm_set_callback_via (struct domain *d,uint64_t via); +int vmsi_deliver (struct domain *,const struct hvm_pirq_dpci *); +#endif /* __XEN_HVM_IRQ_H__ */
xen/include/xen/iommu.h +3 -1
@@ -88,7 +88,9 @@ int iommu_unmap_page(struct domain *d, uvoid iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present);void iommu_set_pgd (struct domain *d);void iommu_domain_teardown (struct domain *d); -int hvm_do_IRQ_dpci (struct domain *d,unsigned int irq); + +struct pirq ; +int hvm_do_IRQ_dpci (struct domain *,struct pirq *);int dpci_ioport_intercept (ioreq_t *p);int pt_irq_create_bind_vtd (struct domain *d,xen_domctl_bind_pt_irq_t *pt_irq_bind);
xen/include/xen/irq.h +31 -3
@@ -135,13 +135,41 @@ extern void no_action(int cpl, void *devstruct domain ;struct vcpu ; -extern int pirq_guest_eoi (struct domain *d,int irq); + +struct pirq { +u16 evtchn; +bool_t masked; +struct arch_pirq arch; +}; + +#define pirq_info (d, p) ((struct pirq *)radix_tree_lookup(&(d)->pirq_tree, p)) + +/* Use this instead of pirq_info() if the structure may need allocating. */ +extern struct pirq *pirq_get_info (struct domain *,int pirq); + +#define pirq_field (d, p, f) ({ \ + const struct pirq *__pi = pirq_info(d, p); \ + __pi ? __pi->f : 0; \ +}) +#define pirq_to_evtchn (d, pirq) pirq_field(d, pirq, evtchn) +#define pirq_masked (d, pirq) pirq_field(d, pirq, masked) + +void pirq_cleanup_check (struct pirq *,struct domain *,int ); + +#define pirq_cleanup_check (info, d, pirq) \ + ((info)->evtchn ? pirq_cleanup_check(info, d, pirq) : (void)0) + +extern void pirq_guest_eoi (struct domain *,struct pirq *); +extern void desc_guest_eoi (struct domain *,struct irq_desc *,struct pirq *);extern int pirq_guest_unmask (struct domain *d); -extern int pirq_guest_bind (struct vcpu *v,int irq,int will_share); -extern void pirq_guest_unbind (struct domain *d,int irq); +extern int pirq_guest_bind (struct vcpu *,int pirq,struct pirq *, +int will_share); +extern void pirq_guest_unbind (struct domain *d,int pirq,struct pirq *);extern void pirq_set_affinity (struct domain *d,int irq,const cpumask_t *);extern irq_desc_t *domain_spin_lock_irq_desc (struct domain *d,int irq,unsigned long *pflags); +extern irq_desc_t *pirq_spin_lock_irq_desc ( +struct domain *,const struct pirq *,unsigned long *pflags);static inline void set_native_irq_info (unsigned int irq,const cpumask_t *mask) {
xen/include/xen/pci.h +3 -2
@@ -117,8 +117,9 @@ int pci_find_cap_offset(u8 bus, u8 dev,int pci_find_next_cap (u8 bus,unsigned int devfn,u8 pos,int cap);int pci_find_ext_capability (int seg,int bus,int devfn,int cap); -int msixtbl_pt_register (struct domain *d,int pirq,uint64_t gtable); -void msixtbl_pt_unregister (struct domain *d,int pirq); +struct pirq ; +int msixtbl_pt_register (struct domain *,struct pirq *,uint64_t gtable); +void msixtbl_pt_unregister (struct domain *,struct pirq *);void pci_enable_acs (struct pci_dev *pdev);#endif /* __XEN_PCI_H__ */
xen/include/xen/radix-tree.h +2 -1
@@ -72,6 +72,7 @@ void *radix_tree_delete(struct radix_tre void(*node_free)(struct radix_tree_node *));unsigned int radix_tree_gang_lookup (struct radix_tree_root *root,void **results, -unsigned long first_index,unsigned int max_items); +unsigned long first_index,unsigned int max_items, +unsigned long *indexes);#endif /* _XEN_RADIX_TREE_H */
xen/include/xen/sched.h +4 -5
@@ -21,6 +21,7 @@#include <xen/irq.h> #include <xen/mm.h> #include <xen/tasklet.h> +#include <xen/radix-tree.h> #include <public/mem_event.h> #include <xen/cpumask.h> #include <xen/nodemask.h>
@@ -234,13 +235,11 @@ struct domainstruct grant_table *grant_table;/* -* Interrupt to event-channel mappings. Updates should be protected by the -* domain's event-channel spinlock. Read accesses can also synchronise on -* the lock, but races don't usually matter. +* Interrupt to event-channel mappings and other per-guest-pirq data. +* Protected by the domain's event-channel spinlock. */ unsigned int nr_pirqs; -u16 *pirq_to_evtchn; -unsigned long *pirq_mask; +struct radix_tree_root pirq_tree;/* I/O capabilities (access to IRQs and memory-mapped I/O). */ struct rangeset *iomem_caps;
With this it is questionable whether retaining struct domain's nr_pirqs is actually necessary - the value now only serves for bounds checking, and this boundary could easily be nr_irqs.
Another thing to consider is whether it's worth storing the pirq number in struct pirq, to avoid passing the number and a pointer to quite a number of functions.
Note that ia64, the build of which is broken currently anyway, is only partially fixed up.
xen/arch/ia64/vmx/vmx_interrupt.c +2 -2
@@ -155,13 +155,13 @@ void hvm_isa_irq_deassert(struct domain/* dummy */ } -int msixtbl_pt_register (struct domain *d,int pirq,uint64_t gtable) +int msixtbl_pt_register (struct domain *d,struct pirq *pirq,uint64_t gtable) {/* dummy */ return -ENOSYS ; } -void msixtbl_pt_unregister (struct domain *d,int pirq) +void msixtbl_pt_unregister (struct domain *d,struct pirq *pirq) {/* dummy */ }
xen/arch/ia64/xen/hypercall.c +5 -2
@@ -65,8 +65,11 @@ static long __do_pirq_guest_eoi(struct d {if ( pirq <0 || pirq >=NR_IRQS )return -EINVAL ; -if ( d->arch.pirq_eoi_map ) -evtchn_unmask (d->pirq_to_evtchn[pirq]); +if ( d->arch.pirq_eoi_map ) { +spin_lock (&d->event_lock); +evtchn_unmask (pirq_to_evtchn (d, pirq)); +spin_unlock (&d->event_lock); + }return pirq_guest_eoi (d, pirq); }
xen/arch/ia64/xen/irq.c +25 -21
109 lines not on this page · raw message
xen/arch/x86/domain.c +0 -20
@@ -608,25 +608,9 @@ int arch_domain_create(struct domain *d,share_xen_page_with_guest (virt_to_page (d->shared_info), d, XENSHARE_writable); - d->arch.pirq_irq =xmalloc_array (int, d->nr_pirqs); -if ( !d->arch.pirq_irq ) - goto fail; -memset (d->arch.pirq_irq,0 , - d->nr_pirqs *sizeof (*d->arch.pirq_irq)); -if ( (rc =init_domain_irq_mapping (d)) !=0 ) goto fail; -if (is_hvm_domain (d) ) - { - d->arch.pirq_emuirq =xmalloc_array (int, d->nr_pirqs); -if ( !d->arch.pirq_emuirq ) - goto fail; -for (i =0 ; i < d->nr_pirqs; i++) - d->arch.pirq_emuirq[i] =IRQ_UNBOUND ; - } - -if ( (rc =iommu_domain_init (d)) !=0 ) goto fail;
@@ -660,8 +644,6 @@ int arch_domain_create(struct domain *d, fail: d->is_dying = DOMDYING_dead;vmce_destroy_msr (d); -xfree (d->arch.pirq_irq); -xfree (d->arch.pirq_emuirq);cleanup_domain_irq_mapping (d);free_xenheap_page (d->shared_info);if ( paging_initialised )
@@ -714,8 +696,6 @@ void arch_domain_destroy(struct domain *#endif free_xenheap_page (d->shared_info); -xfree (d->arch.pirq_irq); -xfree (d->arch.pirq_emuirq);cleanup_domain_irq_mapping (d); }
xen/arch/x86/hvm/hvm.c +24 -22
64 lines not on this page · raw message
xen/arch/x86/hvm/irq.c +1 -1
@@ -33,7 +33,7 @@ static void assert_irq(struct domain *d,int pirq =domain_emuirq_to_pirq (d, ioapic_gsi);if ( pirq !=IRQ_UNBOUND ) { -send_guest_pirq (d, pirq); +send_guest_pirq (d,pirq_info (d, pirq));return ; }vioapic_irq_positive_edge (d, ioapic_gsi);
xen/arch/x86/hvm/vmsi.c +11 -14
@@ -65,11 +65,10 @@ static void vmsi_inj_irq( } } -int vmsi_deliver (struct domain *d,int pirq) +int vmsi_deliver (struct domain *d,const struct hvm_pirq_dpci *pirq_dpci) { -struct hvm_irq_dpci *hvm_irq_dpci = d->arch.hvm_domain.irq.dpci; -uint32_t flags = hvm_irq_dpci->mirq[pirq].gmsi.gflags; -int vector = hvm_irq_dpci->mirq[pirq].gmsi.gvec; +uint32_t flags = pirq_dpci->gmsi.gflags; +int vector = pirq_dpci->gmsi.gvec;uint8_t dest = (uint8_t )flags;uint8_t dest_mode = !!(flags &VMSI_DM_MASK );uint8_t delivery_mode = (flags &VMSI_DELIV_MASK ) >>GLFAGS_SHIFT_DELIV_MODE ;
@@ -82,11 +81,7 @@ int vmsi_deliver(struct domain *d, int p"vector=%x trig_mode=%x\n" , dest, dest_mode, delivery_mode, vector, trig_mode); -if ( !( hvm_irq_dpci->mirq[pirq].flags &HVM_IRQ_DPCI_GUEST_MSI ) ) - { -gdprintk (XENLOG_WARNING ,"pirq %x not msi \n" , pirq); -return 0 ; - } +ASSERT (pirq_dpci->flags &HVM_IRQ_DPCI_GUEST_MSI );switch ( delivery_mode ) {
@@ -349,7 +344,7 @@ static void del_msixtbl_entry(struct msicall_rcu (&entry->rcu, free_msixtbl_entry); } -int msixtbl_pt_register (struct domain *d,int pirq,uint64_t gtable) +int msixtbl_pt_register (struct domain *d,struct pirq *pirq,uint64_t gtable) {struct irq_desc *irq_desc;struct msi_desc *msi_desc;
@@ -358,6 +353,7 @@ int msixtbl_pt_register(struct domain *dint r = -EINVAL ;ASSERT (spin_is_locked (&pcidevs_lock)); +ASSERT (spin_is_locked (&d->event_lock));/* * xmalloc() with irq_disabled causes the failure of check_lock()
@@ -367,7 +363,7 @@ int msixtbl_pt_register(struct domain *dif ( !new_entry )return -ENOMEM ; - irq_desc =domain_spin_lock_irq_desc (d, pirq,NULL ); + irq_desc =pirq_spin_lock_irq_desc (d, pirq,NULL );if ( !irq_desc ) {xfree (new_entry);
@@ -404,7 +400,7 @@ out:return r; } -void msixtbl_pt_unregister (struct domain *d,int pirq) +void msixtbl_pt_unregister (struct domain *d,struct pirq *pirq) {struct irq_desc *irq_desc;struct msi_desc *msi_desc;
@@ -412,8 +408,9 @@ void msixtbl_pt_unregister(struct domainstruct msixtbl_entry *entry;ASSERT (spin_is_locked (&pcidevs_lock)); +ASSERT (spin_is_locked (&d->event_lock)); - irq_desc =domain_spin_lock_irq_desc (d, pirq,NULL ); + irq_desc =pirq_spin_lock_irq_desc (d, pirq,NULL );if ( !irq_desc )return ;
@@ -447,7 +444,7 @@ found:spin_unlock_irq (&irq_desc->lock); } -void msixtbl_pt_cleanup (struct domain *d,int pirq) +void msixtbl_pt_cleanup (struct domain *d) {struct msixtbl_entry *entry, *temp;unsigned long flags;
xen/arch/x86/irq.c +175 -93
506 lines not on this page · raw message
xen/arch/x86/physdev.c +28 -8
Lines of this file are not shown. View the raw message.
xen/common/domain.c +17 -11
Lines of this file are not shown. View the raw message.
xen/common/event_channel.c +25 -17
42 lines not on this page · raw message
xen/common/radix-tree.c +12 -4
Lines of this file are not shown. View the raw message.
xen/drivers/passthrough/io.c +206 -180
386 lines not on this page · raw message
xen/drivers/passthrough/pci.c +20 -21
41 lines not on this page · raw message
xen/drivers/passthrough/vtd/x86/vtd.c +26 -25
51 lines not on this page · raw message
xen/include/asm-ia64/domain.h +18 -0
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/domain.h +0 -3
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/hvm/irq.h +2 -0
Lines of this file are not shown. View the raw message.
xen/include/asm-x86/irq.h +18 -3
Lines of this file are not shown. View the raw message.
xen/include/xen/domain.h +6 -0
Lines of this file are not shown. View the raw message.
xen/include/xen/event.h +1 -1
Lines of this file are not shown. View the raw message.
xen/include/xen/hvm/irq.h +25 -14
Lines of this file are not shown. View the raw message.
xen/include/xen/iommu.h +3 -1
Lines of this file are not shown. View the raw message.
xen/include/xen/irq.h +31 -3
Lines of this file are not shown. View the raw message.
xen/include/xen/pci.h +3 -2
Lines of this file are not shown. View the raw message.
xen/include/xen/radix-tree.h +2 -1
Lines of this file are not shown. View the raw message.
xen/include/xen/sched.h +4 -5
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.