[PATCH 14/17] vfio/pci: Add utility to trigger INTx eventfd knowing interrupt context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



vfio_send_intx_eventfd() is available to signal the eventfd associated
with the INTx interrupt. It does so by first obtaining the vector's
interrupt context and then signaling the eventfd. The interrupt context
may already be available before vfio_send_intx_eventfd() is called,
making the additional query unnecessary.

Introduce vfio_send_intx_eventfd_ctx() that can be used to signal the
eventfd associated with the INTx interrupt when the interrupt context
is already known and use it instead of vfio_send_intx_eventfd() in the
one instance where the interrupt context is already known.

Replace usage of vfio_send_intx_eventfd() within
vfio_pci_set_intx_trigger() with a new snippet that results in the
same functionality while mirroring the flow vfio_pci_set_msi_trigger()
as a preparatory step to merge vfio_pci_set_msi_trigger() and
vfio_pci_set_intx_trigger(). The new snippet is marked as
"temporary" until the flows are merged.

Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
---
 drivers/vfio/pci/vfio_pci_intrs.c | 32 ++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index d7c2cd739d74..37065623d286 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -103,6 +103,13 @@ vfio_irq_ctx_alloc(struct vfio_pci_core_device *vdev, unsigned long index)
 /*
  * INTx
  */
+static void vfio_send_intx_eventfd_ctx(struct vfio_pci_core_device *vdev,
+				       struct vfio_pci_irq_ctx *ctx)
+{
+	if (likely(is_intx(vdev) && !vdev->virq_disabled))
+		eventfd_signal(ctx->trigger);
+}
+
 static void vfio_send_intx_eventfd(void *opaque, void *unused)
 {
 	struct vfio_pci_core_device *vdev = opaque;
@@ -245,7 +252,7 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
 	spin_unlock_irqrestore(&vdev->irqlock, flags);
 
 	if (ret == IRQ_HANDLED)
-		vfio_send_intx_eventfd(vdev, NULL);
+		vfio_send_intx_eventfd_ctx(vdev, ctx);
 
 	return ret;
 }
@@ -690,6 +697,9 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev,
 				     unsigned int count, uint32_t flags,
 				     void *data)
 {
+	struct vfio_pci_irq_ctx *ctx;
+	unsigned int i;
+
 	if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
 		vfio_intx_disable(vdev);
 		return 0;
@@ -719,13 +729,21 @@ static int vfio_pci_set_intx_trigger(struct vfio_pci_core_device *vdev,
 	if (!is_intx(vdev))
 		return -EINVAL;
 
-	if (flags & VFIO_IRQ_SET_DATA_NONE) {
-		vfio_send_intx_eventfd(vdev, NULL);
-	} else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
-		uint8_t trigger = *(uint8_t *)data;
-		if (trigger)
-			vfio_send_intx_eventfd(vdev, NULL);
+	/* temporary */
+	for (i = start; i < start + count; i++) {
+		ctx = vfio_irq_ctx_get(vdev, i);
+		if (!ctx || !ctx->trigger)
+			continue;
+		if (flags & VFIO_IRQ_SET_DATA_NONE) {
+			vfio_send_intx_eventfd_ctx(vdev, ctx);
+		} else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
+			uint8_t *bools = data;
+
+			if (bools[i - start])
+				vfio_send_intx_eventfd_ctx(vdev, ctx);
+		}
 	}
+
 	return 0;
 }
 
-- 
2.34.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux