public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] VFIO PCI INTx fixes
@ 2012-10-04 17:00 Alex Williamson
  2012-10-04 17:00 ` [PATCH 1/2] vfio: Move PCI INTx eventfd setting earlier Alex Williamson
  2012-10-04 17:01 ` [PATCH 2/2] vfio: Fix PCI INTx disable consistency Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Williamson @ 2012-10-04 17:00 UTC (permalink / raw)
  To: alex.williamson; +Cc: kvm, linux-kernel

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(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] vfio: Move PCI INTx eventfd setting earlier
  2012-10-04 17:00 [PATCH 0/2] VFIO PCI INTx fixes Alex Williamson
@ 2012-10-04 17:00 ` Alex Williamson
  2012-10-04 17:01 ` [PATCH 2/2] vfio: Fix PCI INTx disable consistency Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2012-10-04 17:00 UTC (permalink / raw)
  To: alex.williamson; +Cc: kvm, linux-kernel

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.

Cc: stable@vger.kernel.org
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 drivers/vfio/pci/vfio_pci_intrs.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index d8dedc7..c8139a5 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -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.


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] vfio: Fix PCI INTx disable consistency
  2012-10-04 17:00 [PATCH 0/2] VFIO PCI INTx fixes Alex Williamson
  2012-10-04 17:00 ` [PATCH 1/2] vfio: Move PCI INTx eventfd setting earlier Alex Williamson
@ 2012-10-04 17:01 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2012-10-04 17:01 UTC (permalink / raw)
  To: alex.williamson; +Cc: kvm, linux-kernel

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.

Cc: stable@vger.kernel.org
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 drivers/vfio/pci/vfio_pci_intrs.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index c8139a5..3639371 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -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);
 


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-04 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-04 17:00 [PATCH 0/2] VFIO PCI INTx fixes Alex Williamson
2012-10-04 17:00 ` [PATCH 1/2] vfio: Move PCI INTx eventfd setting earlier Alex Williamson
2012-10-04 17:01 ` [PATCH 2/2] vfio: Fix PCI INTx disable consistency Alex Williamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox