pci-assign: Fix MSI-X support
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
Thanks,
Alex
---
Alex Williamson (2):
pci-assign: Fix MSI-X registration
pci-assign: Re-order initfn for memory API
hw/device-assignment.c | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-)
PATCH 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 | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
hw/device-assignment.c +8 -8
@@ -1603,6 +1603,14 @@ 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 +1626,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 +1636,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);
PATCH 2/2 pci-assign: Fix MSI-X registration
In reply to Alex WilliamsonCommit 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. Since we can't specifically check for MSIX support and KVM_CAP_ASSIGN_DEV_IRQ indicates more than just MSI, let's just revert c4525754 and replace it with a sanity check that we need KVM_CAP_ASSIGN_DEV_IRQ if the device supports any kind of interrupt (which is still mostly paranoia).
---
hw/device-assignment.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
hw/device-assignment.c +9 -4
@@ -1189,8 +1189,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)/* Expose MSI capability * MSI capability is the 1st capability in capability config */ - pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSI ,0 ); -if (pos !=0 &&kvm_check_extension (kvm_state,KVM_CAP_ASSIGN_DEV_IRQ )) { +if ((pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSI ,0 ))) { dev->cap.available |=ASSIGNED_DEVICE_CAP_MSI ;/* Only 32-bit/no-mask currently supported */ if ((ret =pci_add_capability (pci_dev,PCI_CAP_ID_MSI , pos,10 )) <0 ) {
@@ -1211,8 +1210,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)pci_set_word (pci_dev->wmask + pos +PCI_MSI_DATA_32 ,0xffff ); }/* 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 )) { +if ((pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSIX ,0 ))) {int bar_nr;uint32_t msix_table_entry;
@@ -1606,6 +1604,13 @@ static int assigned_initfn(struct PCIDevice *pci_dev)if (assigned_device_pci_cap_init (pci_dev) <0 ) goto out; +if (!kvm_check_extension (kvm_state,KVM_CAP_ASSIGN_DEV_IRQ ) && + (dev->cap.available &ASSIGNED_DEVICE_CAP_MSIX || + dev->cap.available &ASSIGNED_DEVICE_CAP_MSI || +assigned_dev_pci_read_byte (pci_dev,PCI_INTERRUPT_PIN ) !=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))
Re: [PATCH 1/2] pci-assign: Re-order initfn for memory API
In reply to Alex WilliamsonQuoted 16 lines · Alex Williamson
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.
Signed-off-by Alex Williamson <[email protected]>---
hw/device-assignment.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)hw/device-assignment.c +0
-0@@ -1603,6 +1603,14 @@ static int assigned_initfn(struct PCIDevice *pci_dev) goto out;
hw/device-assignment.c static int assigned_initfn(struct PCIDevice *pci_dev) · line 1613
Quoted 10 lines
hw/device-assignment.c +8
-0} +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; +
Please adjust the coding style at this chance.
Looks correct otherwise.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [PATCH 2/2] pci-assign: Fix MSI-X registration
In reply to Alex WilliamsonQuoted 3 lines · Alex Williamson
Commit
c4525754added a capability check forKVM_CAP_DEVICE_MSIX, which is unfortunately not exposed, resulting in MSIX never being listed as a capability.
Oops. Should we fix this nevertheless in the kernel?
Quoted 38 lines
This breaks anything depending on
MSIX, such as igbvf. Since we can't specifically check for MSIX support andKVM_CAP_ASSIGN_DEV_IRQindicates more than just MSI, let's just revertc4525754and replace it with a sanity check that we needKVM_CAP_ASSIGN_DEV_IRQif the device supports any kind of interrupt (which is still mostly paranoia).Signed-off-by Alex Williamson <[email protected]>---
hw/device-assignment.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)hw/device-assignment.c +2
-4@@ -1189,8 +1189,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)/* Expose MSI capability * MSI capability is the 1st capability in capability config */ - pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSI ,0 ); -if (pos !=0 &&kvm_check_extension (kvm_state,KVM_CAP_ASSIGN_DEV_IRQ )) { +if ((pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSI ,0 ))) { dev->cap.available |=ASSIGNED_DEVICE_CAP_MSI ;/* Only 32-bit/no-mask currently supported */ if ((ret =pci_add_capability (pci_dev,PCI_CAP_ID_MSI , pos,10 )) <0 ) {@@ -1211,8 +1210,7 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)pci_set_word (pci_dev->wmask + pos +PCI_MSI_DATA_32 ,0xffff ); }/* 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 )) { +if ((pos =pci_find_cap_offset (pci_dev,PCI_CAP_ID_MSIX ,0 ))) {int bar_nr;uint32_t msix_table_entry;
hw/device-assignment.c static int assigned_initfn(struct PCIDevice *pci_dev) · line 1613
Quoted 10 lines
hw/device-assignment.c +7
-0@@ -1606,6 +1604,13 @@ static int assigned_initfn(struct PCIDevice *pci_dev)if (assigned_device_pci_cap_init (pci_dev) <0 ) goto out; +if (!kvm_check_extension (kvm_state,KVM_CAP_ASSIGN_DEV_IRQ ) && + (dev->cap.available &ASSIGNED_DEVICE_CAP_MSIX || + dev->cap.available &ASSIGNED_DEVICE_CAP_MSI || +assigned_dev_pci_read_byte (pci_dev,PCI_INTERRUPT_PIN ) !=0 )) { + goto out; + } +
That's not equivalent as it needlessly prevents IRQ support in the absence of KVM_CAP_ASSIGN_DEV_IRQ.
Let's just fix the core issue and replace the test for KVM_CAP_DEVICE_MSIX with a test call of KVM_ASSIGN_SET_MSIX_NR, passing in a NULL struct. If it returns -EFAULT, the IOCTL is known and MSIX is supported.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Re: [PATCH 2/2] pci-assign: Fix MSI-X registration
Quoted 10 lines · Jan Kiszka
Quoted 9 lines
goto out;+ if (!kvm_check_extension(kvm_state, KVM_CAP_ASSIGN_DEV_IRQ)&&
+ (dev->cap.available& ASSIGNED_DEVICE_CAP_MSIX || + dev->cap.available& ASSIGNED_DEVICE_CAP_MSI ||+
assigned_dev_pci_read_byte(pci_dev, PCI_INTERRUPT_PIN)!= 0)) {
+ goto out;
+ }
+
Quoted 8 lines
That's not equivalent as it needlessly prevents IRQ support in the absence of
KVM_CAP_ASSIGN_DEV_IRQ.Let's just fix the core issue and replace the test for
KVM_CAP_DEVICE_MSIXwith a test call ofKVM_ASSIGN_SET_MSIX_NR, passing in a NULL struct. If it returns-EFAULT, the IOCTL is known and MSIX is supported.
Or just add KVM_CAP_DEVICE_MSIX to the kernel and backport it where needed?
Signature · 1 line
error compiling committee.c: too many arguments to function