From: Bruce Edge Subject: [PATCH] pt_msix_init: Error: Can't map physical MSI-X table: Invalid argument Date: Tue, 20 Oct 2009 17:12:46 -0700 Message-ID: <45c43ef50910201712qce79e09lbaa15167f2a4c28f@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1205842429==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1205842429== Content-Type: multipart/alternative; boundary=0016e6461142a77e29047666d6fd --0016e6461142a77e29047666d6fd Content-Type: text/plain; charset=ISO-8859-1 I submitted this patch last week and did'nt see any feedback or indication as to why it would not be accepted. This is a confirmed tested fix that is required for pci passthorugh with msi-x. If there is something wrong with the format or the contents please let me know so that I can fix and resubmit. Thanks in advance. -Bruce Force msi-x init mmap to a page boundary or mmap fails with. pt_msix_init: Error: Can't map physical MSI-X table: Invalid argument Signed-off-by: Bruce Edge > --- ./tools/ioemu-remote/hw/pass-through.h.orig 2009-10-15 10:22:17.000000000 -0700 +++ ./tools/ioemu-remote/hw/pass-through.h 2009-10-15 11:08:58.000000000 -0700 @@ -193,6 +193,7 @@ int mmio_index; void *phys_iomem_base; struct msix_entry_info msix_entry[0]; + uint32_t table_offset_adjust; /* page align mmap */ }; struct pt_pm_info { --- ./tools/ioemu-remote/hw/pt-msi.c.orig 2009-10-13 11:54:11.000000000 -0700 +++ ./tools/ioemu-remote/hw/pt-msi.c 2009-10-15 10:29:50.000000000 -0700 @@ -542,6 +542,7 @@ int i, total_entries, table_off, bar_index; struct pci_dev *pd = dev->pci_dev; int fd; + int err; id = pci_read_byte(pd, pos + PCI_CAP_LIST_ID); @@ -584,9 +585,15 @@ PT_LOG("Error: Can't open /dev/mem: %s\n", strerror(errno)); goto error_out; } - dev->msix->phys_iomem_base = mmap(0, total_entries * 16, + PT_LOG("table_off = %llx, total_entries = %d\n",table_off,total_entries); + dev->msix->table_offset_adjust = table_off & 0x0fff; + dev->msix->phys_iomem_base = mmap(0, total_entries * 16 + dev->msix->table_offset_adjust, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_LOCKED, - fd, dev->msix->table_base + table_off); + fd, dev->msix->table_base + table_off - dev->msix->table_offset_adjust); + dev->msix->phys_iomem_base = (void *)((char *)dev->msix->phys_iomem_base + + dev->msix->table_offset_adjust); + err = errno; + PT_LOG("errno = %d\n",err); if ( dev->msix->phys_iomem_base == MAP_FAILED ) { PT_LOG("Error: Can't map physical MSI-X table: %s\n", strerror(errno)); @@ -612,7 +619,8 @@ { PT_LOG("unmapping physical MSI-X table from %lx\n", (unsigned long)dev->msix->phys_iomem_base); - munmap(dev->msix->phys_iomem_base, dev->msix->total_entries * 16); + munmap(dev->msix->phys_iomem_base, dev->msix->total_entries * 16 + + dev->msix->table_offset_adjust); } free(dev->msix); --0016e6461142a77e29047666d6fd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I submitted this patch last week and did'nt see any feedback or indicat= ion as to why it would not be accepted.
This is a confirmed tested fix t= hat is required for pci passthorugh with msi-x.

If there is somethin= g wrong with the format or the contents please let me know so that I can fi= x and resubmit.

Thanks in advance.

-Bruce

Force msi-x init mmap to a page boundary or mmap fails with.
=A0 =A0pt_msix_init: Error: Can't map physical MSI<= /span>-X table: Invalid argument

Signed-off-by: Bruce Edge <bruce.e= dge@gmail.com>

--- ./tools/ioemu-remote/hw/pass-through.h.orig 2009-10-15
10:22:17.000000000 -0700
+++ ./tools/ioemu-remote/hw/pass-through.h =A0 =A0 =A02009-10-15
11:08:58.000000000 -0700
@@ -193,6 +193,7 @@
=A0 =A0int mmio_index;
=A0 =A0void *phys_iomem_base;
=A0 =A0struct msix_entry_info msix_entry[0];
+ =A0 =A0 =A0 uint32_t table_offset_adjust; =A0 /* page align mmap */
=A0};

=A0struct pt_pm_info {


--- ./tools/ioemu-remote/hw/pt-msi.c.orig =A0 =A0= =A0 2009-10-13
11:54:11.000000000 -0700
+++ ./tools/ioemu-remote/hw/pt-msi.c =A0 =A02009-= 10-15 10:29:50.000000000 -0700
@@ -542,6 +542,7 @@
=A0 =A0int i, total_entries, table_off, bar_index;
=A0 =A0struct pci_dev *pd =3D dev->pci_dev;
=A0 =A0int fd;
+ =A0 =A0int err;

=A0 =A0id =3D pci_read_byte(pd, pos + PCI_CAP_LIST_ID);

@@ -584,9 +585,15 @@
=A0 =A0 =A0 =A0PT_LOG("Error: Can't open /dev/mem: %s\n", st= rerror(errno));
=A0 =A0 =A0 =A0goto error_out;
=A0 =A0}
- =A0 =A0dev->msix->phys_iomem_base =3D mmap(0, total_entries * 16, + =A0 =A0PT_LOG("table_off =3D %llx, total_entries =3D %d\n",tabl= e_off,total_entries);
+ =A0 =A0dev->msix->table_offset_adjust =3D table_off & 0x0fff; + =A0 =A0dev->msix->phys_iomem_base =3D mmap(0, total_entries * 16 +<= br> dev->msix->table_offset_adjust,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0PROT_WRITE | PROT_READ,= MAP_SHARED | MAP_LOCKED,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fd, dev->msix->t= able_base + table_off);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fd, dev->msix->t= able_base + table_off -
dev->msix->table_offset_adjust);
+ =A0 =A0dev->msix->phys_iomem_base =3D (void *)((char *)dev->msix= ->phys_iomem_base +
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->msix->table= _offset_adjust);
+ =A0 =A0err =3D errno;
+ =A0 =A0PT_LOG("errno =3D %d\n",err);
=A0 =A0if ( dev->msix->phys_iomem_base =3D=3D MAP_FAILED )
=A0 =A0{
=A0 =A0 =A0 =A0PT_LOG("Error: Can't map physical MSI-X table: %s\n", strerror(errno));
@@ -612,7 +619,8 @@
=A0 =A0{
=A0 =A0 =A0 =A0PT_LOG("unmapping physical MSI-X table from %lx\n",
=A0 =A0 =A0 =A0 =A0 (unsigned long)dev->msix->phys_iomem_base);
- =A0 =A0 =A0 =A0munmap(dev->msix->phys_iomem_base, dev->msix->= total_entries * 16);
+ =A0 =A0 =A0 =A0munmap(dev->msix->phys_iomem_base, dev->msix->= total_entries * 16 +
+ =A0 =A0 =A0 =A0 =A0 dev->msix->table_offset_adjust);
=A0 =A0}

=A0 =A0free(dev->msix);


--0016e6461142a77e29047666d6fd-- --===============1205842429== 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.xensource.com http://lists.xensource.com/xen-devel --===============1205842429==--