Skip to contentSkip to conversation

vfio/pci: Clear MSI-X IRQ index always

PATCH Applied Cédric Le Goater 3 participants 5 messages Jan 25, 2024 – Jan 29, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: Clear MSI-X IRQ index always

When doing device assignment of a physical device, MSI-X can be enabled with no vectors enabled and this sets the IRQ index to VFIO_PCI_MSIX_IRQ_INDEX. However, when MSI-X is disabled, the IRQ index is left untouched if no vectors are in use. Then, when INTx is enabled, the IRQ index value is considered incompatible (set to MSI-X) and VFIO_DEVICE_SET_IRQS fails. QEMU complains with :

qemu-system-x86_64: vfio 0000:08:00.0: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0: VFIO_DEVICE_SET_IRQS failure: Invalid argument

To avoid that, unconditionaly clear the IRQ index when MSI-X is disabled.

Fixes 5ebffa4e87e7 ("vfio/pci: use an invalid fd to enable MSI-X")
Cc Jing Liu <[email protected]>
Cc Alex Williamson <[email protected]>
---
 hw/vfio/pci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/vfio/pci.c +5 -3
index d7fe06715c4b9cde66a68c31aaf405315921b0d6..4fa387f0430d62ca2ba1b5ae5b7037f8f06b33f9 100644
@@ -826,9 +826,11 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
         }
     }
 
-    if (vdev->nr_vectors) {
-        vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
-    }
+    /*
+     * Always clear MSI-X IRQ index. A PF device could have enabled
+     * MSI-X with no vectors. See vfio_msix_enable().
+     */
+    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
 
     vfio_msi_disable_common(vdev);
     vfio_intx_enable(vdev, &err);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · On Thu, 25 Jan 2024 15:42:20 +0100 Cédric Le Goater <[email protected]> wrote:

When doing device assignment of a physical device, MSI-X can be enabled with no vectors enabled and this sets the IRQ index to VFIO_PCI_MSIX_IRQ_INDEX. However, when MSI-X is disabled, the IRQ index is left untouched if no vectors are in use. Then, when INTx is enabled, the IRQ index value is considered incompatible (set to MSI-X) and VFIO_DEVICE_SET_IRQS fails. QEMU complains with :

qemu-system-x86_64: vfio 0000:08:00.0: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0: VFIO_DEVICE_SET_IRQS failure: Invalid argument

To avoid that, unconditionaly clear the IRQ index when MSI-X is disabled.

Fixes 5ebffa4e87e7 ("vfio/pci: use an invalid fd to enable MSI-X")
Cc Jing Liu <[email protected]>
Cc Alex Williamson <[email protected]>
---
 hw/vfio/pci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/vfio/pci.c +0 -1
index d7fe06715c4b9cde66a68c31aaf405315921b0d6..4fa387f0430d62ca2ba1b5ae5b7037f8f06b33f9 100644
@@ -826,9 +826,11 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
         }
     }
 
-    if (vdev->nr_vectors) {

hw/vfio/pci.c static void vfio_msix_disable(VFIOPCIDevice *vdev) · line 836

Quoted 10 lines
hw/vfio/pci.c +5 -2
-        vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
-    }
+    /*
+     * Always clear MSI-X IRQ index. A PF device could have enabled
+     * MSI-X with no vectors. See vfio_msix_enable().
+     */
+    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
 
     vfio_msi_disable_common(vdev);
     vfio_intx_enable(vdev, &err);

LGTM, at worst the SET_IRQS ioctl return an errno if we try to disable an unconfigured interrupt index, so seems safe to call unconditionally here.

author Applied
#2 lore raw
In reply to Cédric Le Goater
Quoted 11 lines · Cédric Le Goater

When doing device assignment of a physical device, MSI-X can be enabled with no vectors enabled and this sets the IRQ index to VFIO_PCI_MSIX_IRQ_INDEX. However, when MSI-X is disabled, the IRQ index is left untouched if no vectors are in use. Then, when INTx is enabled, the IRQ index value is considered incompatible (set to MSI-X) and VFIO_DEVICE_SET_IRQS fails. QEMU complains with :

qemu-system-x86_64: vfio 0000:08:00.0: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0: VFIO_DEVICE_SET_IRQS failure: Invalid argument

To avoid that, unconditionaly clear the IRQ index when MSI-X is disabled.

Applied to vfio-next.

Thanks,

C.

#3 lore raw
In reply to Cédric Le Goater

25.01.2024 17:42, Cédric Le Goater:

Quoted 9 lines

When doing device assignment of a physical device, MSI-X can be enabled with no vectors enabled and this sets the IRQ index to VFIO_PCI_MSIX_IRQ_INDEX. However, when MSI-X is disabled, the IRQ index is left untouched if no vectors are in use. Then, when INTx is enabled, the IRQ index value is considered incompatible (set to MSI-X) and VFIO_DEVICE_SET_IRQS fails. QEMU complains with :

qemu-system-x86_64: vfio 0000:08:00.0: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0: VFIO_DEVICE_SET_IRQS failure: Invalid argument

Quoted 8 lines

To avoid that, unconditionaly clear the IRQ index when MSI-X is disabled.

Fixes 5ebffa4e87e7 ("vfio/pci: use an invalid fd to enable MSI-X")
Cc Jing Liu <[email protected]>
Cc Alex Williamson <[email protected]>

This seems to be a stable material too, for stable-8.2 series. Please let me know if it is not.
Please Cc: qemu-stable@ for other stable-worthy changes.

Thanks,

/mjt

Quoted 23 lines
---
  hw/vfio/pci.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
hw/vfio/pci.c +5 -3
index d7fe06715c4b9cde66a68c31aaf405315921b0d6..4fa387f0430d62ca2ba1b5ae5b7037f8f06b33f9 100644
@@ -826,9 +826,11 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
          }
      }
 
-    if (vdev->nr_vectors) {
-        vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
-    }
+    /*
+     * Always clear MSI-X IRQ index. A PF device could have enabled
+     * MSI-X with no vectors. See vfio_msix_enable().
+     */
+    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
 
      vfio_msi_disable_common(vdev);
      vfio_intx_enable(vdev, &err);
#4 lore raw

29.01.2024 23:10, Michael Tokarev пишет:

Quoted 3 lines

This seems to be a stable material too, for stable-8.2 series. Please let me know if it is not.
Please Cc: qemu-stable@ for other stable-worthy changes.

Ahh, this is already Cc'ed to qemu-stable@, - please excuse me for the noise!

/mjt