Skip to contentSkip to conversation

pci-assign: Fix MSI-X support

PATCH Applied Alex Williamson 3 participants 5 messages Sep 22, 2011 – Oct 3, 2011 KVM

lore
Share & tools
lore
#0 lore raw

v2 cover pci-assign: Fix MSI-X support

Assigned device MSI-X support hasn't been working, this fixes it. I believe this should also fix:

https://bugs.launchpad.net/qemu/+bug/830558

v2:
Incorporate comments from Jan

WRT exposing KVM_CAP_DEVICE_MSIX, I'll send a patch with a big comment noting that we can't rely on it for older kernels. Maybe some day we'll draw a line in the sand and be able to use it. Thanks,

Alex

---

Alex Williamson (2):
pci-assign: Fix MSI-X capability test
pci-assign: Re-order initfn for memory API

 hw/device-assignment.c |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)
#1 lore raw

PATCH v2 1/2 pci-assign: Re-order initfn for memory API

We now need to scan PCI capabilities and setup an MSI-X page before we walk the device resources since the overlay is now setup during init instead of at the first mapping by the guest.

---

 hw/device-assignment.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
hw/device-assignment.c +11 -8
index 288f80c..137c409 100644
@@ -1603,6 +1603,17 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
         goto out;
     }
 
+    if (assigned_device_pci_cap_init(pci_dev) < 0) {
+        goto out;
+    }
+
+    /* intercept MSI-X entry page in the MMIO */
+    if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {
+        if (assigned_dev_register_msix_mmio(dev)) {
+            goto out;
+        }
+    }
+
     /* handle real device's MMIO/PIO BARs */
     if (assigned_dev_register_regions(dev->real_device.regions,
                                       dev->real_device.region_number,
@@ -1618,9 +1629,6 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
     dev->h_busnr = dev->host.bus;
     dev->h_devfn = PCI_DEVFN(dev->host.dev, dev->host.func);
 
-    if (assigned_device_pci_cap_init(pci_dev) < 0)
-        goto out;
-
     /* assign device to guest */
     r = assign_device(dev);
     if (r < 0)
@@ -1631,11 +1639,6 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
     if (r < 0)
         goto assigned_out;
 
-    /* intercept MSI-X entry page in the MMIO */
-    if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX)
-        if (assigned_dev_register_msix_mmio(dev))
-            goto assigned_out;
-
     assigned_dev_load_option_rom(dev);
     QLIST_INSERT_HEAD(&devs, dev, next);
 
#2 lore raw

PATCH v2 2/2 pci-assign: Fix MSI-X capability test

In reply to Alex Williamson

Commit c4525754 added a capability check for KVM_CAP_DEVICE_MSIX, which is unfortunately not exposed, resulting in MSIX never being listed as a capability. This breaks anything depending on MSIX, such as igbvf. Instead let's use a dummy call to KVM_ASSIGN_SET_MSIX_NR which will return -EFAULT if the call exists.

---

 hw/device-assignment.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
hw/device-assignment.c +4 -1
index 137c409..f0a6ca9 100644
@@ -1212,7 +1212,10 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
     }
     /* Expose MSI-X capability */
     pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0);
-    if (pos != 0 && kvm_check_extension(kvm_state, KVM_CAP_DEVICE_MSIX)) {
+    /* Would really like to test kvm_check_extension(, KVM_CAP_DEVICE_MSIX),
+     * but the kernel doesn't expose it.  Instead do a dummy call to
+     * KVM_ASSIGN_SET_MSIX_NR to see if it exists. */
+    if (pos != 0 && kvm_assign_set_msix_nr(kvm_state, NULL) == -EFAULT) {
         int bar_nr;
         uint32_t msix_table_entry;
 
#4 lore raw
In reply to Alex Williamson
Quoted 8 lines · Alex Williamson

Assigned device MSI-X support hasn't been working, this fixes it. I believe this should also fix:

https://bugs.launchpad.net/qemu/+bug/830558

v2:
Incorporate comments from Jan

Quoted 6 lines

WRT exposing KVM_CAP_DEVICE_MSIX, I'll send a patch with a big comment noting that we can't rely on it for older kernels. Maybe some day we'll draw a line in the sand and be able to use it. Thanks,

Alex

Applied, thanks.