From: "Jan Beulich" Subject: [PATCH] PCI: break MSI-X data out of struct pci_dev_info Date: Thu, 22 Aug 2013 12:55:55 +0100 Message-ID: <5216186B02000078000EDA8C@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part88BBC25B.0__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VCTUc-0002Ry-Vv for xen-devel@lists.xenproject.org; Thu, 22 Aug 2013 11:55:59 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part88BBC25B.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Considering that a significant share of PCI devices out there (not the least the myriad of CPU-exposed ones) don't support MSI-X at all, and that the amount of data is well beyond a handful of bytes, break this out of the common structure, at once allowing the actual data to be tracked to become architecture specific. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -199,7 +199,7 @@ static void __iomem *msixtbl_addr_to_vir nr_page =3D (addr >> PAGE_SHIFT) - (entry->gtable >> PAGE_SHIFT); =20 - idx =3D entry->pdev->msix_table_idx[nr_page]; + idx =3D entry->pdev->msix->table_idx[nr_page]; if ( !idx ) return NULL; =20 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -66,7 +66,7 @@ static void msix_fixmap_free(int idx) spin_unlock(&msix_fixmap_lock); } =20 -static int msix_get_fixmap(struct pci_dev *dev, u64 table_paddr, +static int msix_get_fixmap(struct arch_msix *msix, u64 table_paddr, u64 entry_paddr) { long nr_page; @@ -77,48 +77,48 @@ static int msix_get_fixmap(struct pci_de if ( nr_page < 0 || nr_page >=3D MAX_MSIX_TABLE_PAGES ) return -EINVAL; =20 - spin_lock(&dev->msix_table_lock); - if ( dev->msix_table_refcnt[nr_page]++ =3D=3D 0 ) + spin_lock(&msix->table_lock); + if ( msix->table_refcnt[nr_page]++ =3D=3D 0 ) { idx =3D msix_fixmap_alloc(); if ( idx < 0 ) { - dev->msix_table_refcnt[nr_page]--; + msix->table_refcnt[nr_page]--; goto out; } set_fixmap_nocache(idx, entry_paddr); - dev->msix_table_idx[nr_page] =3D idx; + msix->table_idx[nr_page] =3D idx; } else - idx =3D dev->msix_table_idx[nr_page]; + idx =3D msix->table_idx[nr_page]; =20 out: - spin_unlock(&dev->msix_table_lock); + spin_unlock(&msix->table_lock); return idx; } =20 -static void msix_put_fixmap(struct pci_dev *dev, int idx) +static void msix_put_fixmap(struct arch_msix *msix, int idx) { int i; =20 - spin_lock(&dev->msix_table_lock); + spin_lock(&msix->table_lock); for ( i =3D 0; i < MAX_MSIX_TABLE_PAGES; i++ ) { - if ( dev->msix_table_idx[i] =3D=3D idx ) + if ( msix->table_idx[i] =3D=3D idx ) break; } if ( i =3D=3D MAX_MSIX_TABLE_PAGES ) goto out; =20 - if ( --dev->msix_table_refcnt[i] =3D=3D 0 ) + if ( --msix->table_refcnt[i] =3D=3D 0 ) { __set_fixmap(idx, 0, 0); msix_fixmap_free(idx); - dev->msix_table_idx[i] =3D 0; + msix->table_idx[i] =3D 0; } =20 out: - spin_unlock(&dev->msix_table_lock); + spin_unlock(&msix->table_lock); } =20 /* @@ -503,7 +503,7 @@ int msi_free_irq(struct msi_desc *entry) { unsigned long start; start =3D (unsigned long)entry->mask_base & ~(PAGE_SIZE - 1); - msix_put_fixmap(entry->dev, virt_to_fix(start)); + msix_put_fixmap(entry->dev->msix, virt_to_fix(start)); nr =3D 1; } =20 @@ -698,6 +698,7 @@ static int msix_capability_init(struct p struct msi_desc **desc, unsigned int nr_entries) { + struct arch_msix *msix =3D dev->msix; struct msi_desc *entry =3D NULL; int pos, vf; u16 control; @@ -757,17 +758,17 @@ static int msix_capability_init(struct p } table_paddr +=3D table_offset; =20 - if ( !dev->msix_used_entries ) + if ( !msix->used_entries ) { u64 pba_paddr; u32 pba_offset; =20 - dev->msix_nr_entries =3D nr_entries; - dev->msix_table.first =3D PFN_DOWN(table_paddr); - dev->msix_table.last =3D PFN_DOWN(table_paddr + - nr_entries * PCI_MSIX_ENTRY_SIZE = - 1); - WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, dev->msix_table.fi= rst, - dev->msix_table.last)); + msix->nr_entries =3D nr_entries; + msix->table.first =3D PFN_DOWN(table_paddr); + msix->table.last =3D PFN_DOWN(table_paddr + + nr_entries * PCI_MSIX_ENTRY_SIZE - = 1); + WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->table.first,= + msix->table.last)); =20 pba_offset =3D pci_conf_read32(seg, bus, slot, func, msix_pba_offset_reg(pos)); @@ -776,18 +777,18 @@ static int msix_capability_init(struct p WARN_ON(!pba_paddr); pba_paddr +=3D pba_offset & ~PCI_MSIX_BIRMASK; =20 - dev->msix_pba.first =3D PFN_DOWN(pba_paddr); - dev->msix_pba.last =3D PFN_DOWN(pba_paddr + - BITS_TO_LONGS(nr_entries) - 1); - WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, dev->msix_pba.firs= t, - dev->msix_pba.last)); + msix->pba.first =3D PFN_DOWN(pba_paddr); + msix->pba.last =3D PFN_DOWN(pba_paddr + + BITS_TO_LONGS(nr_entries) - 1); + WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->pba.first, + msix->pba.last)); } =20 if ( entry ) { /* Map MSI-X table region */ u64 entry_paddr =3D table_paddr + msi->entry_nr * PCI_MSIX_ENTRY_S= IZE; - int idx =3D msix_get_fixmap(dev, table_paddr, entry_paddr); + int idx =3D msix_get_fixmap(msix, table_paddr, entry_paddr); void __iomem *base; =20 if ( idx < 0 ) @@ -815,13 +816,13 @@ static int msix_capability_init(struct p *desc =3D entry; } =20 - if ( !dev->msix_used_entries ) + if ( !msix->used_entries ) { - if ( rangeset_add_range(mmio_ro_ranges, dev->msix_table.first, - dev->msix_table.last) ) + if ( rangeset_add_range(mmio_ro_ranges, msix->table.first, + msix->table.last) ) WARN(); - if ( rangeset_add_range(mmio_ro_ranges, dev->msix_pba.first, - dev->msix_pba.last) ) + if ( rangeset_add_range(mmio_ro_ranges, msix->pba.first, + msix->pba.last) ) WARN(); =20 if ( dev->domain ) @@ -834,16 +835,16 @@ static int msix_capability_init(struct p if ( !d ) for_each_domain(d) if ( !paging_mode_translate(d) && - (iomem_access_permitted(d, dev->msix_table.first,= - dev->msix_table.last) || - iomem_access_permitted(d, dev->msix_pba.first, - dev->msix_pba.last)) ) + (iomem_access_permitted(d, msix->table.first, + msix->table.last) || + iomem_access_permitted(d, msix->pba.first, + msix->pba.last)) ) break; if ( d ) { - if ( !is_hardware_domain(d) && dev->msix_warned !=3D = d->domain_id ) + if ( !is_hardware_domain(d) && msix->warned !=3D = d->domain_id ) { - dev->msix_warned =3D d->domain_id; + msix->warned =3D d->domain_id; printk(XENLOG_ERR "Potentially insecure use of MSI-X on = %04x:%02x:%02x.%u by Dom%d\n", seg, bus, slot, func, d->domain_id); @@ -852,9 +853,9 @@ static int msix_capability_init(struct p } } } - WARN_ON(dev->msix_nr_entries !=3D nr_entries); - WARN_ON(dev->msix_table.first !=3D (table_paddr >> PAGE_SHIFT)); - ++dev->msix_used_entries; + WARN_ON(msix->nr_entries !=3D nr_entries); + WARN_ON(msix->table.first !=3D (table_paddr >> PAGE_SHIFT)); + ++msix->used_entries; =20 /* Restore MSI-X enabled bits */ pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), = control); @@ -978,15 +979,15 @@ static int __pci_enable_msix(struct msi_ return status; } =20 -static void _pci_cleanup_msix(struct pci_dev *dev) +static void _pci_cleanup_msix(struct arch_msix *msix) { - if ( !--dev->msix_used_entries ) + if ( !--msix->used_entries ) { - if ( rangeset_remove_range(mmio_ro_ranges, dev->msix_table.first, - dev->msix_table.last) ) + if ( rangeset_remove_range(mmio_ro_ranges, msix->table.first, + msix->table.last) ) WARN(); - if ( rangeset_remove_range(mmio_ro_ranges, dev->msix_pba.first, - dev->msix_pba.last) ) + if ( rangeset_remove_range(mmio_ro_ranges, msix->pba.first, + msix->pba.last) ) WARN(); } } @@ -1014,7 +1015,7 @@ static void __pci_disable_msix(struct ms =20 pci_conf_write16(seg, bus, slot, func, msix_control_reg(pos), = control); =20 - _pci_cleanup_msix(dev); + _pci_cleanup_msix(dev->msix); } =20 int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off) @@ -1035,11 +1036,11 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 pdev =3D pci_get_pdev(seg, bus, devfn); if ( !pdev ) rc =3D -ENODEV; - else if ( pdev->msix_used_entries !=3D !!off ) + else if ( pdev->msix->used_entries !=3D !!off ) rc =3D -EBUSY; else if ( off ) { - _pci_cleanup_msix(pdev); + _pci_cleanup_msix(pdev->msix); rc =3D 0; } else --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -179,8 +179,22 @@ static struct pci_dev *alloc_pdev(struct *((u8*) &pdev->devfn) =3D devfn; pdev->domain =3D NULL; INIT_LIST_HEAD(&pdev->msi_list); + + if ( pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(devf= n), + PCI_CAP_ID_MSIX) ) + { + struct arch_msix *msix =3D xzalloc(struct arch_msix); + + if ( !msix ) + { + xfree(pdev); + return NULL; + } + spin_lock_init(&msix->table_lock); + pdev->msix =3D msix; + } + list_add(&pdev->alldevs_list, &pseg->alldevs_list); - spin_lock_init(&pdev->msix_table_lock); =20 /* update bus2bridge */ switch ( pdev->type =3D pdev_type(pseg->nr, bus, devfn) ) @@ -277,6 +291,7 @@ static void free_pdev(struct pci_seg *ps } =20 list_del(&pdev->alldevs_list); + xfree(pdev->msix); xfree(pdev); } =20 --- a/xen/include/asm-x86/msi.h +++ b/xen/include/asm-x86/msi.h @@ -214,6 +214,22 @@ struct msg_address { __u32 hi_address; } __attribute__ ((packed)); =20 +#define MAX_MSIX_TABLE_ENTRIES (PCI_MSIX_FLAGS_QSIZE + 1) +#define MAX_MSIX_TABLE_PAGES PFN_UP(MAX_MSIX_TABLE_ENTRIES * \ + PCI_MSIX_ENTRY_SIZE + \ + (~PCI_MSIX_BIRMASK & (PAGE_SIZE - = 1))) + +struct arch_msix { + unsigned int nr_entries, used_entries; + struct { + unsigned long first, last; + } table, pba; + int table_refcnt[MAX_MSIX_TABLE_PAGES]; + int table_idx[MAX_MSIX_TABLE_PAGES]; + spinlock_t table_lock; + domid_t warned; +}; + void early_msi_init(void); void msi_compose_msg(struct irq_desc *, struct msi_msg *); void __msi_set_enable(u16 seg, u8 bus, u8 slot, u8 func, int pos, int = enable); --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -32,10 +32,6 @@ #define PCI_BDF(b,d,f) ((((b) & 0xff) << 8) | PCI_DEVFN(d,f)) #define PCI_BDF2(b,df) ((((b) & 0xff) << 8) | ((df) & 0xff)) =20 -#define MAX_MSIX_TABLE_ENTRIES (PCI_MSIX_FLAGS_QSIZE + 1) -#define MAX_MSIX_TABLE_PAGES PFN_UP(MAX_MSIX_TABLE_ENTRIES * \ - PCI_MSIX_ENTRY_SIZE + \ - (~PCI_MSIX_BIRMASK & (PAGE_SIZE - = 1))) struct pci_dev_info { bool_t is_extfn; bool_t is_virtfn; @@ -50,14 +46,8 @@ struct pci_dev { struct list_head domain_list; =20 struct list_head msi_list; - unsigned int msix_nr_entries, msix_used_entries; - struct { - unsigned long first, last; - } msix_table, msix_pba; - int msix_table_refcnt[MAX_MSIX_TABLE_PAGES]; - int msix_table_idx[MAX_MSIX_TABLE_PAGES]; - spinlock_t msix_table_lock; - domid_t msix_warned; + + struct arch_msix *msix; =20 struct domain *domain; const u16 seg; --=__Part88BBC25B.0__= Content-Type: text/plain; name="x86-pcidev-split-MSI-X-pieces.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-pcidev-split-MSI-X-pieces.patch" PCI: break MSI-X data out of struct pci_dev_info=0A=0AConsidering that a = significant share of PCI devices out there (not the=0Aleast the myriad of = CPU-exposed ones) don't support MSI-X at all, and=0Athat the amount of = data is well beyond a handful of bytes, break this=0Aout of the common = structure, at once allowing the actual data to be=0Atracked to become = architecture specific.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/hvm/vmsi.c=0A+++ b/xen/arch/x86/hvm/vmsi.c=0A@@ = -199,7 +199,7 @@ static void __iomem *msixtbl_addr_to_vir=0A nr_page = =3D (addr >> PAGE_SHIFT) -=0A (entry->gtable >> PAGE_SHIFT);= =0A =0A- idx =3D entry->pdev->msix_table_idx[nr_page];=0A+ idx =3D = entry->pdev->msix->table_idx[nr_page];=0A if ( !idx )=0A = return NULL;=0A =0A--- a/xen/arch/x86/msi.c=0A+++ b/xen/arch/x86/msi.c=0A@@= -66,7 +66,7 @@ static void msix_fixmap_free(int idx)=0A spin_unlock(&m= six_fixmap_lock);=0A }=0A =0A-static int msix_get_fixmap(struct pci_dev = *dev, u64 table_paddr,=0A+static int msix_get_fixmap(struct arch_msix = *msix, u64 table_paddr,=0A u64 entry_paddr)=0A = {=0A long nr_page;=0A@@ -77,48 +77,48 @@ static int msix_get_fixmap(str= uct pci_de=0A if ( nr_page < 0 || nr_page >=3D MAX_MSIX_TABLE_PAGES = )=0A return -EINVAL;=0A =0A- spin_lock(&dev->msix_table_lock);= =0A- if ( dev->msix_table_refcnt[nr_page]++ =3D=3D 0 )=0A+ spin_lock(= &msix->table_lock);=0A+ if ( msix->table_refcnt[nr_page]++ =3D=3D 0 = )=0A {=0A idx =3D msix_fixmap_alloc();=0A if ( idx < 0 = )=0A {=0A- dev->msix_table_refcnt[nr_page]--;=0A+ = msix->table_refcnt[nr_page]--;=0A goto out;=0A = }=0A set_fixmap_nocache(idx, entry_paddr);=0A- dev->msix_tab= le_idx[nr_page] =3D idx;=0A+ msix->table_idx[nr_page] =3D idx;=0A = }=0A else=0A- idx =3D dev->msix_table_idx[nr_page];=0A+ = idx =3D msix->table_idx[nr_page];=0A =0A out:=0A- spin_unlock(&dev->ms= ix_table_lock);=0A+ spin_unlock(&msix->table_lock);=0A return = idx;=0A }=0A =0A-static void msix_put_fixmap(struct pci_dev *dev, int = idx)=0A+static void msix_put_fixmap(struct arch_msix *msix, int idx)=0A = {=0A int i;=0A =0A- spin_lock(&dev->msix_table_lock);=0A+ = spin_lock(&msix->table_lock);=0A for ( i =3D 0; i < MAX_MSIX_TABLE_PAGE= S; i++ )=0A {=0A- if ( dev->msix_table_idx[i] =3D=3D idx )=0A+ = if ( msix->table_idx[i] =3D=3D idx )=0A break;=0A = }=0A if ( i =3D=3D MAX_MSIX_TABLE_PAGES )=0A goto out;=0A =0A- = if ( --dev->msix_table_refcnt[i] =3D=3D 0 )=0A+ if ( --msix->table_re= fcnt[i] =3D=3D 0 )=0A {=0A __set_fixmap(idx, 0, 0);=0A = msix_fixmap_free(idx);=0A- dev->msix_table_idx[i] =3D 0;=0A+ = msix->table_idx[i] =3D 0;=0A }=0A =0A out:=0A- spin_unlock(&dev->ms= ix_table_lock);=0A+ spin_unlock(&msix->table_lock);=0A }=0A =0A /*=0A@@ = -503,7 +503,7 @@ int msi_free_irq(struct msi_desc *entry)=0A {=0A = unsigned long start;=0A start =3D (unsigned long)entry->mask_bas= e & ~(PAGE_SIZE - 1);=0A- msix_put_fixmap(entry->dev, virt_to_fix(st= art));=0A+ msix_put_fixmap(entry->dev->msix, virt_to_fix(start));=0A= nr =3D 1;=0A }=0A =0A@@ -698,6 +698,7 @@ static int msix_capab= ility_init(struct p=0A struct msi_desc = **desc,=0A unsigned int nr_entries)=0A = {=0A+ struct arch_msix *msix =3D dev->msix;=0A struct msi_desc = *entry =3D NULL;=0A int pos, vf;=0A u16 control;=0A@@ -757,17 = +758,17 @@ static int msix_capability_init(struct p=0A }=0A = table_paddr +=3D table_offset;=0A =0A- if ( !dev->msix_used_entries = )=0A+ if ( !msix->used_entries )=0A {=0A u64 pba_paddr;=0A = u32 pba_offset;=0A =0A- dev->msix_nr_entries =3D nr_entries;= =0A- dev->msix_table.first =3D PFN_DOWN(table_paddr);=0A- = dev->msix_table.last =3D PFN_DOWN(table_paddr +=0A- = nr_entries * PCI_MSIX_ENTRY_SIZE - 1);=0A- = WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, dev->msix_table.first,=0A- = dev->msix_table.last));=0A+ = msix->nr_entries =3D nr_entries;=0A+ msix->table.first =3D = PFN_DOWN(table_paddr);=0A+ msix->table.last =3D PFN_DOWN(table_paddr= +=0A+ nr_entries * PCI_MSIX_ENTRY_SIZE = - 1);=0A+ WARN_ON(rangeset_overlaps_range(mmio_ro_ranges, msix->tabl= e.first,=0A+ msix->table.last));=0A = =0A pba_offset =3D pci_conf_read32(seg, bus, slot, func,=0A = msix_pba_offset_reg(pos));=0A@@ -776,18 = +777,18 @@ static int msix_capability_init(struct p=0A WARN_ON(!pba= _paddr);=0A pba_paddr +=3D pba_offset & ~PCI_MSIX_BIRMASK;=0A =0A- = dev->msix_pba.first =3D PFN_DOWN(pba_paddr);=0A- dev->msix_pb= a.last =3D PFN_DOWN(pba_paddr +=0A- = BITS_TO_LONGS(nr_entries) - 1);=0A- WARN_ON(rangeset_overlaps_range(= mmio_ro_ranges, dev->msix_pba.first,=0A- = dev->msix_pba.last));=0A+ msix->pba.first =3D PFN_DOWN(pba_padd= r);=0A+ msix->pba.last =3D PFN_DOWN(pba_paddr +=0A+ = BITS_TO_LONGS(nr_entries) - 1);=0A+ WARN_ON(rangese= t_overlaps_range(mmio_ro_ranges, msix->pba.first,=0A+ = msix->pba.last));=0A }=0A =0A if ( entry )=0A = {=0A /* Map MSI-X table region */=0A u64 entry_paddr =3D = table_paddr + msi->entry_nr * PCI_MSIX_ENTRY_SIZE;=0A- int idx =3D = msix_get_fixmap(dev, table_paddr, entry_paddr);=0A+ int idx =3D = msix_get_fixmap(msix, table_paddr, entry_paddr);=0A void __iomem = *base;=0A =0A if ( idx < 0 )=0A@@ -815,13 +816,13 @@ static int = msix_capability_init(struct p=0A *desc =3D entry;=0A }=0A =0A- = if ( !dev->msix_used_entries )=0A+ if ( !msix->used_entries )=0A = {=0A- if ( rangeset_add_range(mmio_ro_ranges, dev->msix_table.first,= =0A- dev->msix_table.last) )=0A+ if = ( rangeset_add_range(mmio_ro_ranges, msix->table.first,=0A+ = msix->table.last) )=0A WARN();=0A- if ( = rangeset_add_range(mmio_ro_ranges, dev->msix_pba.first,=0A- = dev->msix_pba.last) )=0A+ if ( rangeset_add_range(mm= io_ro_ranges, msix->pba.first,=0A+ = msix->pba.last) )=0A WARN();=0A =0A if ( dev->domain = )=0A@@ -834,16 +835,16 @@ static int msix_capability_init(struct p=0A = if ( !d )=0A for_each_domain(d)=0A = if ( !paging_mode_translate(d) &&=0A- (iomem_acc= ess_permitted(d, dev->msix_table.first,=0A- = dev->msix_table.last) ||=0A- = iomem_access_permitted(d, dev->msix_pba.first,=0A- = dev->msix_pba.last)) )=0A+ = (iomem_access_permitted(d, msix->table.first,=0A+ = msix->table.last) ||=0A+ = iomem_access_permitted(d, msix->pba.first,=0A+ = msix->pba.last)) )=0A = break;=0A if ( d )=0A {=0A- if ( = !is_hardware_domain(d) && dev->msix_warned !=3D d->domain_id )=0A+ = if ( !is_hardware_domain(d) && msix->warned !=3D d->domain_id )=0A = {=0A- dev->msix_warned =3D d->domain_id;= =0A+ msix->warned =3D d->domain_id;=0A = printk(XENLOG_ERR=0A "Potentially insecure = use of MSI-X on %04x:%02x:%02x.%u by Dom%d\n",=0A = seg, bus, slot, func, d->domain_id);=0A@@ -852,9 +853,9 @@ static int = msix_capability_init(struct p=0A }=0A }=0A }=0A- = WARN_ON(dev->msix_nr_entries !=3D nr_entries);=0A- WARN_ON(dev->msix_ta= ble.first !=3D (table_paddr >> PAGE_SHIFT));=0A- ++dev->msix_used_entrie= s;=0A+ WARN_ON(msix->nr_entries !=3D nr_entries);=0A+ WARN_ON(msix->t= able.first !=3D (table_paddr >> PAGE_SHIFT));=0A+ ++msix->used_entries;= =0A =0A /* Restore MSI-X enabled bits */=0A pci_conf_write16(seg, = bus, slot, func, msix_control_reg(pos), control);=0A@@ -978,15 +979,15 @@ = static int __pci_enable_msix(struct msi_=0A return status;=0A }=0A = =0A-static void _pci_cleanup_msix(struct pci_dev *dev)=0A+static void = _pci_cleanup_msix(struct arch_msix *msix)=0A {=0A- if ( !--dev->msix_use= d_entries )=0A+ if ( !--msix->used_entries )=0A {=0A- if ( = rangeset_remove_range(mmio_ro_ranges, dev->msix_table.first,=0A- = dev->msix_table.last) )=0A+ if ( rangeset_re= move_range(mmio_ro_ranges, msix->table.first,=0A+ = msix->table.last) )=0A WARN();=0A- if ( = rangeset_remove_range(mmio_ro_ranges, dev->msix_pba.first,=0A- = dev->msix_pba.last) )=0A+ if ( rangeset_remove= _range(mmio_ro_ranges, msix->pba.first,=0A+ = msix->pba.last) )=0A WARN();=0A }=0A }=0A@@ -1014,7 = +1015,7 @@ static void __pci_disable_msix(struct ms=0A =0A pci_conf_wri= te16(seg, bus, slot, func, msix_control_reg(pos), control);=0A =0A- = _pci_cleanup_msix(dev);=0A+ _pci_cleanup_msix(dev->msix);=0A }=0A =0A = int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool_t off)=0A@@ -1035,11 = +1036,11 @@ int pci_prepare_msix(u16 seg, u8 bus, u8=0A pdev =3D = pci_get_pdev(seg, bus, devfn);=0A if ( !pdev )=0A rc =3D = -ENODEV;=0A- else if ( pdev->msix_used_entries !=3D !!off )=0A+ else = if ( pdev->msix->used_entries !=3D !!off )=0A rc =3D -EBUSY;=0A = else if ( off )=0A {=0A- _pci_cleanup_msix(pdev);=0A+ = _pci_cleanup_msix(pdev->msix);=0A rc =3D 0;=0A }=0A = else=0A--- a/xen/drivers/passthrough/pci.c=0A+++ b/xen/drivers/passthrough/= pci.c=0A@@ -179,8 +179,22 @@ static struct pci_dev *alloc_pdev(struct=0A = *((u8*) &pdev->devfn) =3D devfn;=0A pdev->domain =3D NULL;=0A = INIT_LIST_HEAD(&pdev->msi_list);=0A+=0A+ if ( pci_find_cap_offset(pseg->= nr, bus, PCI_SLOT(devfn), PCI_FUNC(devfn),=0A+ = PCI_CAP_ID_MSIX) )=0A+ {=0A+ struct arch_msix *msix =3D = xzalloc(struct arch_msix);=0A+=0A+ if ( !msix )=0A+ {=0A+ = xfree(pdev);=0A+ return NULL;=0A+ }=0A+ = spin_lock_init(&msix->table_lock);=0A+ pdev->msix =3D msix;=0A+ = }=0A+=0A list_add(&pdev->alldevs_list, &pseg->alldevs_list);=0A- = spin_lock_init(&pdev->msix_table_lock);=0A =0A /* update bus2bridge = */=0A switch ( pdev->type =3D pdev_type(pseg->nr, bus, devfn) )=0A@@ = -277,6 +291,7 @@ static void free_pdev(struct pci_seg *ps=0A }=0A =0A = list_del(&pdev->alldevs_list);=0A+ xfree(pdev->msix);=0A = xfree(pdev);=0A }=0A =0A--- a/xen/include/asm-x86/msi.h=0A+++ b/xen/include= /asm-x86/msi.h=0A@@ -214,6 +214,22 @@ struct msg_address {=0A __u32 = hi_address;=0A } __attribute__ ((packed));=0A =0A+#define MAX_MSIX_TABLE_EN= TRIES (PCI_MSIX_FLAGS_QSIZE + 1)=0A+#define MAX_MSIX_TABLE_PAGES = PFN_UP(MAX_MSIX_TABLE_ENTRIES * \=0A+ = PCI_MSIX_ENTRY_SIZE + \=0A+ = (~PCI_MSIX_BIRMASK & (PAGE_SIZE - 1)))=0A+=0A+struct arch_msix {=0A+ = unsigned int nr_entries, used_entries;=0A+ struct {=0A+ unsigned = long first, last;=0A+ } table, pba;=0A+ int table_refcnt[MAX_MSIX_TAB= LE_PAGES];=0A+ int table_idx[MAX_MSIX_TABLE_PAGES];=0A+ spinlock_t = table_lock;=0A+ domid_t warned;=0A+};=0A+=0A void early_msi_init(void);= =0A void msi_compose_msg(struct irq_desc *, struct msi_msg *);=0A void = __msi_set_enable(u16 seg, u8 bus, u8 slot, u8 func, int pos, int = enable);=0A--- a/xen/include/xen/pci.h=0A+++ b/xen/include/xen/pci.h=0A@@ = -32,10 +32,6 @@=0A #define PCI_BDF(b,d,f) ((((b) & 0xff) << 8) | = PCI_DEVFN(d,f))=0A #define PCI_BDF2(b,df) ((((b) & 0xff) << 8) | ((df) & = 0xff))=0A =0A-#define MAX_MSIX_TABLE_ENTRIES (PCI_MSIX_FLAGS_QSIZE + = 1)=0A-#define MAX_MSIX_TABLE_PAGES PFN_UP(MAX_MSIX_TABLE_ENTRIES * = \=0A- PCI_MSIX_ENTRY_SIZE + \=0A- = (~PCI_MSIX_BIRMASK & (PAGE_SIZE - = 1)))=0A struct pci_dev_info {=0A bool_t is_extfn;=0A bool_t = is_virtfn;=0A@@ -50,14 +46,8 @@ struct pci_dev {=0A struct list_head = domain_list;=0A =0A struct list_head msi_list;=0A- unsigned int = msix_nr_entries, msix_used_entries;=0A- struct {=0A- unsigned = long first, last;=0A- } msix_table, msix_pba;=0A- int msix_table_refc= nt[MAX_MSIX_TABLE_PAGES];=0A- int msix_table_idx[MAX_MSIX_TABLE_PAGES];= =0A- spinlock_t msix_table_lock;=0A- domid_t msix_warned;=0A+=0A+ = struct arch_msix *msix;=0A =0A struct domain *domain;=0A const u16 = seg;=0A --=__Part88BBC25B.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part88BBC25B.0__=--