Skip to contentSkip to conversation

ioemu-remote: Align MSI-X table mmap/munmap - please apply

PATCH In review Bruce Edge 2 participants 2 messages Oct 23, 2009

lore
Share & tools
lore

Bruce Edge

author
#0 lore raw

PATCH 1/1 ioemu-remote: Align MSI-X table mmap/munmap - please apply

Figured out by cargo-culting that patches to qemu need to be based from tools/ioemu-remote and have same in subject.
Resubmitting this patch re-based accordingly.
If someone else needs to be in the cc for qemu patches, please let me know.

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

hw/pass-through.h +1 -0
diff -Naur a/hw/pass-through.h b/hw/pass-through.h
@@ -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 {
hw/pt-msi.c +4 -1
diff -Naur a/hw/pt-msi.c b/hw/pt-msi.c
@@ -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);
hw/pass-through.h +1 -0
diff -Naur a/hw/pass-through.h b/hw/pass-through.h
@@ -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 {
hw/pt-msi.c +11 -3
diff -Naur a/hw/pt-msi.c b/hw/pt-msi.c
@@ -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);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Bruce Edge writes ("[PATCH] ioemu-remote: Align MSI-X table mmap/munmap - please apply"):

Quoted 3 lines

Figured out by cargo-culting that patches to qemu need to be based from tools/ioemu-remote and have same in subject. Resubmitting this patch re-based accordingly.

In fact your message on Wednesday was fine but it came so quickly after my response that I mistook it for the first one rather than the resend. Sorry for not paying attention properly.

There's no particular need to CC me (or base your patch anywhere in particular) although it does help to remind me if I seem to have missed your patch as I do sometimes make a mistake and overlook something.

I've applied your change now.

Regards,
Ian.