diff mbox series

[v6,19/20] vfio: mdev: Add device request interface

Message ID 162164286322.261970.2647654897518928545.stgit@djiang5-desk3.ch.intel.com (mailing list archive)
State New, archived
Headers show
Series Add VFIO mediated device support and DEV-MSI support for the idxd driver | expand

Commit Message

Dave Jiang May 22, 2021, 12:21 a.m. UTC
Similar to commit 6140a8f56238 ("vfio-pci: Add device request interface").
Add request interface for mdev to allow userspace to opt in to receive
a device request notification, indicating that the device should be
released.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 drivers/vfio/mdev/mdev_irqs.c |   23 +++++++++++++++++++++++
 include/linux/mdev.h          |   15 +++++++++++++++
 2 files changed, 38 insertions(+)

Comments

Jason Gunthorpe May 23, 2021, 10:38 p.m. UTC | #1
On Fri, May 21, 2021 at 05:21:03PM -0700, Dave Jiang wrote:
> Similar to commit 6140a8f56238 ("vfio-pci: Add device request interface").
> Add request interface for mdev to allow userspace to opt in to receive
> a device request notification, indicating that the device should be
> released.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  drivers/vfio/mdev/mdev_irqs.c |   23 +++++++++++++++++++++++
>  include/linux/mdev.h          |   15 +++++++++++++++
>  2 files changed, 38 insertions(+)

Please don't add new things to mdev, put the req_trigger in the vdcm_idxd
struct vfio_device class.

 
> diff --git a/drivers/vfio/mdev/mdev_irqs.c b/drivers/vfio/mdev/mdev_irqs.c
> index ed2d11a7c729..11b1f8df020c 100644
> --- a/drivers/vfio/mdev/mdev_irqs.c
> +++ b/drivers/vfio/mdev/mdev_irqs.c

and similarly this shouldn't be called mdev_irqs and the code in here
should have nothign to do with mdevs. Providing the special IRQ
emulation stuff is just generic vfio_device functionality with no
linkage to mdev.

> @@ -316,3 +316,26 @@ void mdev_irqs_free(struct mdev_device *mdev)
>  	memset(&mdev->mdev_irq, 0, sizeof(mdev->mdev_irq));
>  }
>  EXPORT_SYMBOL_GPL(mdev_irqs_free);
> +
> +void vfio_mdev_request(struct vfio_device *vdev, unsigned int count)
> +{
> +	struct device *dev = vdev->dev;
> +	struct mdev_device *mdev = to_mdev_device(dev);

Yuk, don't do stuff like that, if it needs a mdev then pass in a mdev.

Jason
diff mbox series

Patch

diff --git a/drivers/vfio/mdev/mdev_irqs.c b/drivers/vfio/mdev/mdev_irqs.c
index ed2d11a7c729..11b1f8df020c 100644
--- a/drivers/vfio/mdev/mdev_irqs.c
+++ b/drivers/vfio/mdev/mdev_irqs.c
@@ -316,3 +316,26 @@  void mdev_irqs_free(struct mdev_device *mdev)
 	memset(&mdev->mdev_irq, 0, sizeof(mdev->mdev_irq));
 }
 EXPORT_SYMBOL_GPL(mdev_irqs_free);
+
+void vfio_mdev_request(struct vfio_device *vdev, unsigned int count)
+{
+	struct device *dev = vdev->dev;
+	struct mdev_device *mdev = to_mdev_device(dev);
+
+	if (mdev->req_trigger) {
+		dev_dbg(dev, "Requesting device from user\n");
+		eventfd_signal(mdev->req_trigger, 1);
+	}
+}
+EXPORT_SYMBOL_GPL(vfio_mdev_request);
+
+int vfio_mdev_set_req_trigger(struct mdev_device *mdev, unsigned int index,
+			      unsigned int start, unsigned int count, u32 flags,
+			      void *data)
+{
+	if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count != 1)
+		return -EINVAL;
+
+	return vfio_set_ctx_trigger_single(&mdev->req_trigger, count, flags, data);
+}
+EXPORT_SYMBOL_GPL(vfio_mdev_set_req_trigger);
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 035c021e8068..db73d58f5e81 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -11,6 +11,8 @@ 
 #define MDEV_H
 
 #include <linux/irqbypass.h>
+#include <linux/eventfd.h>
+#include <linux/vfio.h>
 
 struct mdev_type;
 
@@ -38,6 +40,7 @@  struct mdev_device {
 	struct device *iommu_device;
 	struct mutex creation_lock;
 	struct mdev_irq mdev_irq;
+	struct eventfd_ctx *req_trigger;
 };
 
 static inline struct mdev_device *irq_to_mdev(struct mdev_irq *mdev_irq)
@@ -131,6 +134,10 @@  void mdev_msix_send_signal(struct mdev_device *mdev, int vector);
 int mdev_irqs_init(struct mdev_device *mdev, int num, bool *ims_map);
 void mdev_irqs_free(struct mdev_device *mdev);
 void mdev_irqs_set_pasid(struct mdev_device *mdev, u32 pasid);
+void vfio_mdev_request(struct vfio_device *vdev, unsigned int count);
+int vfio_mdev_set_req_trigger(struct mdev_device *mdev, unsigned int index,
+			      unsigned int start, unsigned int count, u32 flags,
+			      void *data);
 #else
 static inline int mdev_set_msix_trigger(struct mdev_device *mdev, unsigned int index,
 					unsigned int start, unsigned int count, u32 flags,
@@ -148,6 +155,14 @@  static inline int mdev_irqs_init(struct mdev_device *mdev, int num, bool *ims_ma
 
 void mdev_irqs_free(struct mdev_device *mdev) {}
 void mdev_irqs_set_pasid(struct mdev_device *mdev, u32 pasid) {}
+void vfio_mdev_request(struct vfio_device *vdev, unsigned int count) {}
+
+int vfio_mdev_set_req_trigger(struct mdev_device *mdev, unsigned int index,
+			      unsigned int start, unsigned int count, u32 flags,
+			      void *data)
+{
+	return -EOPNOTSUPP;
+}
 #endif /* CONFIG_VFIO_MDEV_IMS */
 
 #endif /* MDEV_H */