Skip to contentSkip to conversation

VFIO PCI INTx fixes

PATCH New Alex Williamson 1 participant 3 messages Oct 4, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover VFIO PCI INTx fixes

These patches are now available in my next tree to fix a couple issues with PCI INTx. Thanks,

Alex

---

Alex Williamson (2):
vfio: Fix PCI INTx disable consistency
vfio: Move PCI INTx eventfd setting earlier

 drivers/vfio/pci/vfio_pci_intrs.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 vfio: Move PCI INTx eventfd setting earlier

We need to be ready to recieve an interrupt as soon as we call request_irq, so our eventfd context setting needs to be moved earlier. Without this, an interrupt from our device or one sharing the interrupt line can pass a NULL into eventfd_signal and oops.

---

 drivers/vfio/pci/vfio_pci_intrs.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_intrs.c +3 -2
index d8dedc7..c8139a5 100644
@@ -400,19 +400,20 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)
 		return PTR_ERR(trigger);
 	}
 
+	vdev->ctx[0].trigger = trigger;
+
 	if (!vdev->pci_2_3)
 		irqflags = 0;
 
 	ret = request_irq(pdev->irq, vfio_intx_handler,
 			  irqflags, vdev->ctx[0].name, vdev);
 	if (ret) {
+		vdev->ctx[0].trigger = NULL;
 		kfree(vdev->ctx[0].name);
 		eventfd_ctx_put(trigger);
 		return ret;
 	}
 
-	vdev->ctx[0].trigger = trigger;
-
 	/*
 	 * INTx disable will stick across the new irq setup,
 	 * disable_irq won't.
#2 lore raw

PATCH 2/2 vfio: Fix PCI INTx disable consistency

In reply to Alex Williamson

The virq_disabled flag tracks the userspace view of INTx masking across interrupt mode changes, but we're not consistently applying this to the interrupt and masking handler notion of the device. Currently if the user sets DisINTx while in MSI or MSIX mode, then returns to INTx mode (ex. rebooting a qemu guest), the hardware has DisINTx+, but the management of INTx thinks it's enabled, making it impossible to actually clear DisINTx. Fix this by updating the handler state when INTx is re-enabled.

---

 drivers/vfio/pci/vfio_pci_intrs.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_intrs.c +12 -1
index c8139a5..3639371 100644
@@ -366,6 +366,17 @@ static int vfio_intx_enable(struct vfio_pci_device *vdev)
 		return -ENOMEM;
 
 	vdev->num_ctx = 1;
+
+	/*
+	 * If the virtual interrupt is masked, restore it.  Devices
+	 * supporting DisINTx can be masked at the hardware level
+	 * here, non-PCI-2.3 devices will have to wait until the
+	 * interrupt is enabled.
+	 */
+	vdev->ctx[0].masked = vdev->virq_disabled;
+	if (vdev->pci_2_3)
+		pci_intx(vdev->pdev, !vdev->ctx[0].masked);
+
 	vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX;
 
 	return 0;
@@ -419,7 +430,7 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)
 	 * disable_irq won't.
 	 */
 	spin_lock_irqsave(&vdev->irqlock, flags);
-	if (!vdev->pci_2_3 && (vdev->ctx[0].masked || vdev->virq_disabled))
+	if (!vdev->pci_2_3 && vdev->ctx[0].masked)
 		disable_irq_nosync(pdev->irq);
 	spin_unlock_irqrestore(&vdev->irqlock, flags);