Skip to contentSkip to conversation

mdev based hardware virtio offloading support

PATCH In review Jason Wang 6 participants 47 messages Sep 23, 2019 – Sep 25, 2019

Subsystems (16)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

cover mdev based hardware virtio offloading support

Hi all:

There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.

Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.

A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.

Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with id_talbe claimed by the driver. On top, this seris also decouple device specific parents ops out of the common ones.

Pktgen test was done with virito-net + mvnet loop back device.

Please review.

[1] https://lkml.org/lkml/2019/9/16/869

Changes from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseve MDEV_ID_VHOST for future vhost-mdev work
- introduce "virtio" type for mvnet and make "vhost" type for future work
- add entries in MAINTAINER
- tweak and typos fixes in commit log

Changes from RFC-V1:

- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- split device_ops into seperate headers
- drop the mdev_set_dma_ops()
- use device_ops to implement the transport API, then it's not a part of UAPI any more
- use GFP_ATOMIC in mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet device

Jason Wang (6):
mdev: class id support
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
vringh: fix copy direction of vringh_iov_push_kern()
docs: sample driver to demonstrate how to implement virtio-mdev
framework

 .../driver-api/vfio-mediated-device.rst       |  11 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  14 +-
 drivers/vfio/mdev/Kconfig                     |   7 +
 drivers/vfio/mdev/Makefile                    |   1 +
 drivers/vfio/mdev/mdev_core.c                 |  21 +-
 drivers/vfio/mdev/mdev_driver.c               |  14 +
 drivers/vfio/mdev/mdev_private.h              |   1 +
 drivers/vfio/mdev/vfio_mdev.c                 |  37 +-
 drivers/vfio/mdev/virtio_mdev.c               | 416 +++++++++++
 drivers/vhost/vringh.c                        |   8 +-
 include/linux/mdev.h                          |  47 +-
 include/linux/mod_devicetable.h               |   8 +
 include/linux/vfio_mdev.h                     |  53 ++
 include/linux/virtio_mdev.h                   | 144 ++++
 samples/Kconfig                               |   7 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet.c                     | 688 ++++++++++++++++++
 23 files changed, 1481 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
 create mode 100644 include/linux/vfio_mdev.h
 create mode 100644 include/linux/virtio_mdev.h
 create mode 100644 samples/vfio-mdev/mvnet.c
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/6 mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +12 -2
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 
 	if (!mdev_bus_compat_class) {
 		mdev_bus_compat_class = class_compat_register("mdev_bus");
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO);
+}
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b70bbebc9dd3 100644
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv)
+{
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h +6 -1
index 0ce30ca78db0..3ebae310f599 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/
 struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);
 struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
+#define MDEV_ID_VFIO 1 /* VFIO device */
+
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -1
index ac5c8c17b1ff..71a4469be85d 100644
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c +1 -1
index cc86bf6566e4..d3029dd27d91 100644
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c +1 -1
index 92e770a06ea2..744c88a6b22c 100644
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
Signature · 6 lines
2.19.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH 1/6] mdev: class id support

Quoted 125 lines · On Mon, 23 Sep 2019 21:03:26 +0800 Jason Wang <[email protected]> wrote:

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +4 -1
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;

drivers/vfio/mdev/mdev_core.c int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) · line 182

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 

I don't think we want to tie the class_id to the parent. mdev parent devices can create various types of devices, some might be virtio, some might be vfio. I think the cover letter even suggests that's a direction these virtio devices might be headed. It seems the class should be on the resulting device itself. That also suggests that at the parent we cannot have a single device_ops, the ops used will depend on the type of device created. Perhaps that means we need vfio_ops alongside virtio_ops, rather than a common device_ops. Thanks,

Alex

Quoted 170 lines
drivers/vfio/mdev/mdev_core.c +7 -1
 	if (!mdev_bus_compat_class) {
 		mdev_bus_compat_class = class_compat_register("mdev_bus");
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO);
+}
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b70bbebc9dd3 100644
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv)
+{
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h +6 -1
index 0ce30ca78db0..3ebae310f599 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/
 struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);
 struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
+#define MDEV_ID_VFIO 1 /* VFIO device */
+
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -1
index ac5c8c17b1ff..71a4469be85d 100644
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c +1 -1
index cc86bf6566e4..d3029dd27d91 100644
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c +1 -1
index 92e770a06ea2..744c88a6b22c 100644
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
author
#3 lore raw

Re: [PATCH 1/6] mdev: class id support

Quoted 142 lines · Alex Williamson
Quoted 125 lines · On Mon, 23 Sep 2019 21:03:26 +0800 Jason Wang <[email protected]> wrote:

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +4 -1
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;

drivers/vfio/mdev/mdev_core.c int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) · line 182

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 

I don't think we want to tie the class_id to the parent. mdev parent devices can create various types of devices, some might be virtio, some might be vfio. I think the cover letter even suggests that's a direction these virtio devices might be headed. It seems the class should be on the resulting device itself. That also suggests that at the parent we cannot have a single device_ops, the ops used will depend on the type of device created. Perhaps that means we need vfio_ops alongside virtio_ops, rather than a common device_ops. Thanks,

Quoted 2 lines

Alex

Yes, will do it in V2.

Thanks

author
#4 lore raw

Re: [PATCH 1/6] mdev: class id support

In reply to Alex Williamson
Quoted 142 lines · Alex Williamson
Quoted 125 lines · On Mon, 23 Sep 2019 21:03:26 +0800 Jason Wang <[email protected]> wrote:

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +4 -1
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;

drivers/vfio/mdev/mdev_core.c int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) · line 182

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 

I don't think we want to tie the class_id to the parent. mdev parent devices can create various types of devices, some might be virtio, some might be vfio. I think the cover letter even suggests that's a direction these virtio devices might be headed. It seems the class should be on the resulting device itself. That also suggests that at the parent we cannot have a single device_ops, the ops used will depend on the type of device created. Perhaps that means we need vfio_ops alongside virtio_ops, rather than a common device_ops. Thanks,

Quoted 2 lines

Alex

Yes, will do it in V2.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#5 lore raw

Re: [PATCH 1/6] mdev: class id support

In reply to Jason Wang
Quoted 125 lines · On Mon, 23 Sep 2019 21:03:26 +0800 Jason Wang <[email protected]> wrote:

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +4 -1
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;

drivers/vfio/mdev/mdev_core.c int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops) · line 182

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 

I don't think we want to tie the class_id to the parent. mdev parent devices can create various types of devices, some might be virtio, some might be vfio. I think the cover letter even suggests that's a direction these virtio devices might be headed. It seems the class should be on the resulting device itself. That also suggests that at the parent we cannot have a single device_ops, the ops used will depend on the type of device created. Perhaps that means we need vfio_ops alongside virtio_ops, rather than a common device_ops. Thanks,

Alex

Quoted 170 lines
drivers/vfio/mdev/mdev_core.c +7 -1
 	if (!mdev_bus_compat_class) {
 		mdev_bus_compat_class = class_compat_register("mdev_bus");
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO);
+}
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b70bbebc9dd3 100644
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv)
+{
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h +6 -1
index 0ce30ca78db0..3ebae310f599 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/
 struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);
 struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
+#define MDEV_ID_VFIO 1 /* VFIO device */
+
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -1
index ac5c8c17b1ff..71a4469be85d 100644
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c +1 -1
index cc86bf6566e4..d3029dd27d91 100644
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c +1 -1
index 92e770a06ea2..744c88a6b22c 100644
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
#6 lore raw

RE: [PATCH 1/6] mdev: class id support

In reply to Jason Wang

Hi Jason,

Quoted 54 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 25eb7d5b834b..0e052072e1d8 100644

Documentation/driver-api/vfio-mediated-device.rst structure to represent a mediated device's driver:: · line 105

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.

No full stop at the end.

Quoted 11 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls

Documentation/driver-api/vfio-mediated-device.rst to register and unregister itself with the core driver: · line 122

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 

Unrelated change in this patch.

Documentation/driver-api/vfio-mediated-device.rst A driver should use the mdev_parent_ops structure in the function call to · line 169

Quoted 10 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in

the function call to register itself with the mdev core driver::

Documentation/driver-api/vfio-mediated-device.rst +2 -1
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);

Cover letter from Change-V2 says that it class_id changed from " use u16 instead u8 for class id" But it is still u8 here?

Quoted 50 lines

However, the mdev_parent_ops structure is not required in the function call
that a driver should use to unregister itself with the mdev core driver::

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void
 *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 

static void kvmgt_host_exit(struct device *dev) diff --git
a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..246ff0f80944 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -1
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch) diff --git

a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 5c0f53c6dde7..7487fc39d2c5 100644

drivers/s390/crypto/vfio_ap_ops.c +2 -1
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)  {
 	atomic_set(&matrix_dev->available_instances,
 MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device,
 &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 

void vfio_ap_mdev_unregister(void)

drivers/vfio/mdev/mdev_core.c +0 -0
index b558d4cfd082..a02c256a3514 100644

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 140

Quoted 6 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device
 *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *

It device id here, but in below its class_id. Please make them uniform.

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device *dev, void *data) · line 146

Quoted 9 lines
drivers/vfio/mdev/mdev_core.c +3 -1
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {

u16 class_id?

Quoted 119 lines
drivers/vfio/mdev/mdev_core.c +1 -0
 	int ret;
 	struct mdev_parent *parent;
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 
 	if (!mdev_bus_compat_class) {

mdev_bus_compat_class =
class_compat_register("mdev_bus");

drivers/vfio/mdev/mdev_core.c +5 -1
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops) {
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO); }
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device diff --git

a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b70bbebc9dd3 100644

drivers/vfio/mdev/mdev_driver.c +13 -0
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv) {
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h index renamed from include/linux/mdev.h +0 -0

0ce30ca78db0..3ebae310f599 100644

include/linux/mdev.h +1 -0
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name
 =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/

struct mdev_driver {

include/linux/mdev.h +3 -1
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 

int mdev_register_driver(struct mdev_driver *drv, struct module *owner);

include/linux/mdev.h struct device *mdev_parent_dev(struct mdev_device · line 152

Quoted 5 lines
include/linux/mdev.h +2 -0
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device
 *mdev);  struct device *mdev_dev(struct mdev_device *mdev);  struct
 mdev_device *mdev_from_dev(struct device *dev);
 
+#define MDEV_ID_VFIO 1 /* VFIO device */
+

Instead of define, please put them as enum

enum mdev_class/device_id {
	MDEV_ID_VFIO = 1,
	/* New entries must be added here */
};
Quoted 6 lines
include/linux/mdev.h +0 -0
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +0 -0
index 5714fd35a83c..f32c6e44fb1a 100644

include/linux/mod_devicetable.h struct wmi_device_id { · line 830

Quoted 10 lines
include/linux/mod_devicetable.h +7 -0
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};

This is u16 as I guess you wanted as opposed to u8 in other places in patch.

Quoted 43 lines
include/linux/mod_devicetable.h +1 -0
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

ac5c8c17b1ff..71a4469be85d 100644

samples/vfio-mdev/mbochs.c +1 -1
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..d3029dd27d91 100644

samples/vfio-mdev/mdpy.c +1 -1
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

92e770a06ea2..744c88a6b22c 100644

samples/vfio-mdev/mtty.c +1 -2
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
--

2.19.1

author
#7 lore raw

Re: [PATCH 1/6] mdev: class id support

Quoted 50 lines · Parav Pandit

Hi Jason,

Quoted 48 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Quoted 11 lines

Documentation/driver-api/vfio-mediated-device.rst structure to represent a mediated device's driver:: · line 105

Quoted 10 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.

No full stop at the end.

Will fix this.

Quoted 14 lines
Quoted 14 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
Quoted 5 lines

Documentation/driver-api/vfio-mediated-device.rst to register and unregister itself with the core driver: · line 122

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 

Unrelated change in this patch.

Yes, will fix.

Quoted 6 lines
Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in

the function call to register itself with the mdev core driver::

Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst A driver should use the mdev_parent_ops structure in the function call to · line 169

Quoted 5 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);

Cover letter from Change-V2 says that it class_id changed from " use u16 instead u8 for class id" But it is still u8 here?

Right, let me fix it in v2.

Quoted 45 lines
Quoted 45 lines

However, the mdev_parent_ops structure is not required in the function call
that a driver should use to unregister itself with the mdev core driver::

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void
 *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 

static void kvmgt_host_exit(struct device *dev) diff --git
a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..246ff0f80944 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -1
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch) diff --git

a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 5c0f53c6dde7..7487fc39d2c5 100644

drivers/s390/crypto/vfio_ap_ops.c +2 -1
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)  {
 	atomic_set(&matrix_dev->available_instances,
 MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device,
 &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
Quoted 13 lines

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 140

Quoted 12 lines

void vfio_ap_mdev_unregister(void)

drivers/vfio/mdev/mdev_core.c +1 -0
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device
 *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *

It device id here, but in below its class_id. Please make them uniform.

Yes, will fix.

Quoted 10 lines

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device *dev, void *data) · line 146

Quoted 9 lines
drivers/vfio/mdev/mdev_core.c +3 -1
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {

u16 class_id?

Yes it is.

Quoted 123 lines
Quoted 123 lines
drivers/vfio/mdev/mdev_core.c +1 -0
 	int ret;
 	struct mdev_parent *parent;
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 
 	if (!mdev_bus_compat_class) {

mdev_bus_compat_class =
class_compat_register("mdev_bus");

drivers/vfio/mdev/mdev_core.c +5 -1
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops) {
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO); }
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device diff --git

a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b70bbebc9dd3 100644

drivers/vfio/mdev/mdev_driver.c +13 -0
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv) {
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h index renamed from include/linux/mdev.h +0 -0

0ce30ca78db0..3ebae310f599 100644

include/linux/mdev.h +1 -0
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name
 =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/

struct mdev_driver {

include/linux/mdev.h +3 -1
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 

int mdev_register_driver(struct mdev_driver *drv, struct module *owner);

include/linux/mdev.h +0 -0
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device
 *mdev);  struct device *mdev_dev(struct mdev_device *mdev);  struct
 mdev_device *mdev_from_dev(struct device *dev);
 
Quoted 8 lines

include/linux/mdev.h struct device *mdev_parent_dev(struct mdev_device *mdev); · line 152

Quoted 2 lines
include/linux/mdev.h +2 -0
+#define MDEV_ID_VFIO 1 /* VFIO device */
+

Instead of define, please put them as enum

enum mdev_class/device_id {
	MDEV_ID_VFIO = 1,
	/* New entries must be added here */
};

Ok.

Quoted 10 lines
Quoted 10 lines
include/linux/mdev.h +0 -0
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +0 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
Quoted 8 lines

include/linux/mod_devicetable.h struct wmi_device_id { · line 830

Quoted 7 lines
include/linux/mod_devicetable.h +7 -0
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};

This is u16 as I guess you wanted as opposed to u8 in other places in patch.

Right.

Thanks

Quoted 43 lines
Quoted 43 lines
include/linux/mod_devicetable.h +1 -0
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

ac5c8c17b1ff..71a4469be85d 100644

samples/vfio-mdev/mbochs.c +1 -1
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..d3029dd27d91 100644

samples/vfio-mdev/mdpy.c +1 -1
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

92e770a06ea2..744c88a6b22c 100644

samples/vfio-mdev/mtty.c +1 -2
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
--

2.19.1

author
#8 lore raw

Re: [PATCH 1/6] mdev: class id support

In reply to Parav Pandit
Quoted 50 lines · Parav Pandit

Hi Jason,

Quoted 48 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Quoted 11 lines

Documentation/driver-api/vfio-mediated-device.rst structure to represent a mediated device's driver:: · line 105

Quoted 10 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.

No full stop at the end.

Will fix this.

Quoted 14 lines
Quoted 14 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
Quoted 5 lines

Documentation/driver-api/vfio-mediated-device.rst to register and unregister itself with the core driver: · line 122

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 

Unrelated change in this patch.

Yes, will fix.

Quoted 6 lines
Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in

the function call to register itself with the mdev core driver::

Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst A driver should use the mdev_parent_ops structure in the function call to · line 169

Quoted 5 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);

Cover letter from Change-V2 says that it class_id changed from " use u16 instead u8 for class id" But it is still u8 here?

Right, let me fix it in v2.

Quoted 45 lines
Quoted 45 lines

However, the mdev_parent_ops structure is not required in the function call
that a driver should use to unregister itself with the mdev core driver::

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void
 *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 

static void kvmgt_host_exit(struct device *dev) diff --git
a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..246ff0f80944 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -1
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch) diff --git

a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 5c0f53c6dde7..7487fc39d2c5 100644

drivers/s390/crypto/vfio_ap_ops.c +2 -1
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)  {
 	atomic_set(&matrix_dev->available_instances,
 MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device,
 &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
Quoted 13 lines

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 140

Quoted 12 lines

void vfio_ap_mdev_unregister(void)

drivers/vfio/mdev/mdev_core.c +1 -0
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device
 *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *

It device id here, but in below its class_id. Please make them uniform.

Yes, will fix.

Quoted 10 lines

drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device *dev, void *data) · line 146

Quoted 9 lines
drivers/vfio/mdev/mdev_core.c +3 -1
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {

u16 class_id?

Yes it is.

Quoted 123 lines
Quoted 123 lines
drivers/vfio/mdev/mdev_core.c +1 -0
 	int ret;
 	struct mdev_parent *parent;
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 
 	if (!mdev_bus_compat_class) {

mdev_bus_compat_class =
class_compat_register("mdev_bus");

drivers/vfio/mdev/mdev_core.c +5 -1
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const
 struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops) {
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO); }
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device diff --git

a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b70bbebc9dd3 100644

drivers/vfio/mdev/mdev_driver.c +13 -0
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv) {
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h index renamed from include/linux/mdev.h +0 -0

0ce30ca78db0..3ebae310f599 100644

include/linux/mdev.h +1 -0
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name
 =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/

struct mdev_driver {

include/linux/mdev.h +3 -1
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops
 *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 

int mdev_register_driver(struct mdev_driver *drv, struct module *owner);

include/linux/mdev.h +0 -0
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device
 *mdev);  struct device *mdev_dev(struct mdev_device *mdev);  struct
 mdev_device *mdev_from_dev(struct device *dev);
 
Quoted 8 lines

include/linux/mdev.h struct device *mdev_parent_dev(struct mdev_device *mdev); · line 152

Quoted 2 lines
include/linux/mdev.h +2 -0
+#define MDEV_ID_VFIO 1 /* VFIO device */
+

Instead of define, please put them as enum

enum mdev_class/device_id {
	MDEV_ID_VFIO = 1,
	/* New entries must be added here */
};

Ok.

Quoted 10 lines
Quoted 10 lines
include/linux/mdev.h +0 -0
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +0 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
Quoted 8 lines

include/linux/mod_devicetable.h struct wmi_device_id { · line 830

Quoted 7 lines
include/linux/mod_devicetable.h +7 -0
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};

This is u16 as I guess you wanted as opposed to u8 in other places in patch.

Right.

Thanks

Quoted 36 lines
Quoted 36 lines
include/linux/mod_devicetable.h +1 -0
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

ac5c8c17b1ff..71a4469be85d 100644

samples/vfio-mdev/mbochs.c +1 -1
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..d3029dd27d91 100644

samples/vfio-mdev/mdpy.c +1 -1
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

92e770a06ea2..744c88a6b22c 100644

samples/vfio-mdev/mtty.c +0 -0
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
Quoted 7 lines
Quoted 7 lines
samples/vfio-mdev/mtty.c +1 -2
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
--

2.19.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#9 lore raw

RE: [PATCH 1/6] mdev: class id support

In reply to Jason Wang

Hi Jason,

Quoted 32 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

Quoted 16 lines
---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)

You additionally need modpost support for id table integration to modifo, modprobe and other tools. A small patch similar to this one [1] is needed.
Please include in the series.

[1] https://lore.kernel.org/patchwork/patch/1046991/

author
#10 lore raw

Re: [PATCH 1/6] mdev: class id support

Quoted 51 lines · Parav Pandit

Hi Jason,

Quoted 32 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

Quoted 16 lines
---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Quoted 5 lines

You additionally need modpost support for id table integration to modifo, modprobe and other tools. A small patch similar to this one [1] is needed.
Please include in the series.

[1] https://lore.kernel.org/patchwork/patch/1046991/

My understanding is this could be done on top and may require uevent support for the bus. I can try to implement this in V2.

Thanks

Quoted 2 lines
author
#11 lore raw

Re: [PATCH 1/6] mdev: class id support

In reply to Parav Pandit
Quoted 51 lines · Parav Pandit

Hi Jason,

Quoted 32 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 1/6] mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

Quoted 16 lines
---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Quoted 5 lines

You additionally need modpost support for id table integration to modifo, modprobe and other tools. A small patch similar to this one [1] is needed.
Please include in the series.

[1] https://lore.kernel.org/patchwork/patch/1046991/

My understanding is this could be done on top and may require uevent support for the bus. I can try to implement this in V2.

Thanks

Quoted 2 lines

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#12 lore raw

PATCH 1/6 mdev: class id support

In reply to Jason Wang

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, one example is virtio-mdev[1] driver. This means we need to add device class id support in bus match method to pair the mdev device and mdev driver correctly.

So this patch adds id_table to mdev_driver and class_id for mdev parent with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 +++++--
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  2 +-
 drivers/s390/cio/vfio_ccw_ops.c                   |  2 +-
 drivers/s390/crypto/vfio_ap_ops.c                 |  3 ++-
 drivers/vfio/mdev/mdev_core.c                     | 14 ++++++++++++--
 drivers/vfio/mdev/mdev_driver.c                   | 14 ++++++++++++++
 drivers/vfio/mdev/mdev_private.h                  |  1 +
 drivers/vfio/mdev/vfio_mdev.c                     |  6 ++++++
 include/linux/mdev.h                              |  7 ++++++-
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  2 +-
 samples/vfio-mdev/mdpy.c                          |  2 +-
 samples/vfio-mdev/mtty.c                          |  2 +-
 13 files changed, 59 insertions(+), 11 deletions(-)
Documentation/driver-api/vfio-mediated-device.rst +5 -2
index 25eb7d5b834b..0e052072e1d8 100644
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
       * @probe: called when new device created
       * @remove: called when device removed
       * @driver: device driver structure
+      * @id_table: the ids serviced by this driver.
       */
      struct mdev_driver {
 	     const char *name;
 	     int  (*probe)  (struct device *dev);
 	     void (*remove) (struct device *dev);
 	     struct device_driver    driver;
+	     const struct mdev_class_id *id_table;
      };
 
 A mediated bus driver for mdev should use this structure in the function calls
@@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
 * Register::
 
     extern int  mdev_register_driver(struct mdev_driver *drv,
-				   struct module *owner);
+                                     struct module *owner);
 
 * Unregister::
 
@@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
 	extern int  mdev_register_device(struct device *dev,
-	                                 const struct mdev_parent_ops *ops);
+	                                 const struct mdev_parent_ops *ops,
+	                                 u8 class_id);
 
 However, the mdev_parent_ops structure is not required in the function call
 that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -1
index 23aa3e50cbf8..19d51a35f019 100644
@@ -1625,7 +1625,7 @@ static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 		return -EFAULT;
 	intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
 
-	return mdev_register_device(dev, &intel_vgpu_ops);
+	return mdev_register_vfio_device(dev, &intel_vgpu_ops);
 }
 
 static void kvmgt_host_exit(struct device *dev)
drivers/s390/cio/vfio_ccw_ops.c +1 -1
index f0d71ab77c50..246ff0f80944 100644
@@ -588,7 +588,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
-	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
+	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
 }
 
 void vfio_ccw_mdev_unreg(struct subchannel *sch)
drivers/s390/crypto/vfio_ap_ops.c +2 -1
index 5c0f53c6dde7..7487fc39d2c5 100644
@@ -1295,7 +1295,8 @@ int vfio_ap_mdev_register(void)
 {
 	atomic_set(&matrix_dev->available_instances, MAX_ZDEV_ENTRIES_EXT);
 
-	return mdev_register_device(&matrix_dev->device, &vfio_ap_matrix_ops);
+	return mdev_register_vfio_device(&matrix_dev->device,
+					 &vfio_ap_matrix_ops);
 }
 
 void vfio_ap_mdev_unregister(void)
drivers/vfio/mdev/mdev_core.c +12 -2
index b558d4cfd082..a02c256a3514 100644
@@ -135,11 +135,14 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
  * @ops: Parent device operation structure to be registered.
+ * @id: device id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
  */
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
+int mdev_register_device(struct device *dev,
+			 const struct mdev_parent_ops *ops,
+			 u8 class_id)
 {
 	int ret;
 	struct mdev_parent *parent;
@@ -175,6 +178,7 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 
 	parent->dev = dev;
 	parent->ops = ops;
+	parent->class_id = class_id;
 
 	if (!mdev_bus_compat_class) {
 		mdev_bus_compat_class = class_compat_register("mdev_bus");
@@ -208,7 +212,13 @@ int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
 		put_device(dev);
 	return ret;
 }
-EXPORT_SYMBOL(mdev_register_device);
+
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VFIO);
+}
+EXPORT_SYMBOL(mdev_register_vfio_device);
 
 /*
  * mdev_unregister_device : Unregister a parent device
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b70bbebc9dd3 100644
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)
 	return 0;
 }
 
+static int mdev_match(struct device *dev, struct device_driver *drv)
+{
+	unsigned int i;
+	struct mdev_device *mdev = to_mdev_device(dev);
+	struct mdev_driver *mdrv = to_mdev_driver(drv);
+	const struct mdev_class_id *ids = mdrv->id_table;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->parent->class_id)
+			return 1;
+	return 0;
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
+	.match		= mdev_match,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
drivers/vfio/mdev/mdev_private.h +1 -0
index 7d922950caaf..e58b07c866b1 100644
@@ -22,6 +22,7 @@ struct mdev_parent {
 	struct list_head type_list;
 	/* Synchronize device creation/removal with parent unregistration */
 	struct rw_semaphore unreg_sem;
+	u8 class_id;
 };
 
 struct mdev_device {
drivers/vfio/mdev/vfio_mdev.c +6 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h +6 -1
index 0ce30ca78db0..3ebae310f599 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver.
  *
  **/
 struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -135,7 +137,8 @@ const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
-int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
+int mdev_register_vfio_device(struct device *dev,
+			      const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -145,4 +148,6 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);
 struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
+#define MDEV_ID_VFIO 1 /* VFIO device */
+
 #endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
index 5714fd35a83c..f32c6e44fb1a 100644
@@ -821,4 +821,12 @@ struct wmi_device_id {
 	const void *context;
 };
 
+/**
+ * struct mdev_class_id - MDEV device class identifier
+ * @id: Used to identify a specific class of device, e.g vfio-mdev device.
+ */
+struct mdev_class_id {
+	__u16 id;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -1
index ac5c8c17b1ff..71a4469be85d 100644
@@ -1468,7 +1468,7 @@ static int __init mbochs_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mbochs_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mbochs_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mdpy.c +1 -1
index cc86bf6566e4..d3029dd27d91 100644
@@ -775,7 +775,7 @@ static int __init mdpy_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mdpy_dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mdpy_dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
samples/vfio-mdev/mtty.c +1 -1
index 92e770a06ea2..744c88a6b22c 100644
@@ -1468,7 +1468,7 @@ static int __init mtty_dev_init(void)
 	if (ret)
 		goto failed2;
 
-	ret = mdev_register_device(&mtty_dev.dev, &mdev_fops);
+	ret = mdev_register_vfio_device(&mtty_dev.dev, &mdev_fops);
 	if (ret)
 		goto failed3;
 
Signature · 1 line
2.19.1
author
#13 lore raw

PATCH 2/6 mdev: introduce device specific ops

In reply to Jason Wang

Currently, except for the create and remove. The rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. Follow the class id support by previous patch, this patch introduces device specific ops pointer inside parent ops which points to device specific ops (e.g vfio ops). This allows the future drivers like virtio-mdev to implement its own device specific ops.

---
 .../driver-api/vfio-mediated-device.rst       |  4 +-
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 15 +++---
 drivers/s390/cio/vfio_ccw_ops.c               | 15 ++++--
 drivers/s390/crypto/vfio_ap_ops.c             | 11 ++--
 drivers/vfio/mdev/vfio_mdev.c                 | 31 ++++++-----
 include/linux/mdev.h                          | 36 ++-----------
 include/linux/vfio_mdev.h                     | 53 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 17 +++---
 samples/vfio-mdev/mdpy.c                      | 17 +++---
 samples/vfio-mdev/mtty.c                      | 15 ++++--
 11 files changed, 138 insertions(+), 77 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +3 -1
index 0e052072e1d8..3ab00e48212f 100644
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization.
 Vendor drivers are expected to be fully asynchronous in this respect or
 provide their own internal resource protection.)
 
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
 
 * open: open callback of mediated device
 * close: close callback of mediated device
MAINTAINERS +1 -0
index b2326dece28e..89832b316500 100644
@@ -17075,6 +17075,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/vfio_mdev.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +9 -6
index 19d51a35f019..8ea86b1e69f1 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/debugfs.h>
 
 #include <linux/nospec.h>
@@ -1600,20 +1601,22 @@ static const struct attribute_group *intel_vgpu_groups[] = {
 	NULL,
 };
 
-static struct mdev_parent_ops intel_vgpu_ops = {
-	.mdev_attr_groups       = intel_vgpu_groups,
-	.create			= intel_vgpu_create,
-	.remove			= intel_vgpu_remove,
-
+static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {
 	.open			= intel_vgpu_open,
 	.release		= intel_vgpu_release,
-
 	.read			= intel_vgpu_read,
 	.write			= intel_vgpu_write,
 	.mmap			= intel_vgpu_mmap,
 	.ioctl			= intel_vgpu_ioctl,
 };
 
+static struct mdev_parent_ops intel_vgpu_ops = {
+	.mdev_attr_groups       = intel_vgpu_groups,
+	.create			= intel_vgpu_create,
+	.remove			= intel_vgpu_remove,
+	.device_ops	        = &intel_vfio_vgpu_ops,
+};
+
 static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 {
 	struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +10 -5
index 246ff0f80944..02122bbc213e 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -574,11 +575,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
 	}
 }
 
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
-	.owner			= THIS_MODULE,
-	.supported_type_groups  = mdev_type_groups,
-	.create			= vfio_ccw_mdev_create,
-	.remove			= vfio_ccw_mdev_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
 	.read			= vfio_ccw_mdev_read,
@@ -586,6 +583,14 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 	.ioctl			= vfio_ccw_mdev_ioctl,
 };
 
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+	.owner			= THIS_MODULE,
+	.supported_type_groups  = mdev_type_groups,
+	.create			= vfio_ccw_mdev_create,
+	.remove			= vfio_ccw_mdev_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
 	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +8 -3
index 7487fc39d2c5..4251becc7a6d 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/vfio_mdev.h>
 #include <asm/kvm.h>
 #include <asm/zcrypt.h>
 
@@ -1280,15 +1281,19 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open			= vfio_ap_mdev_open,
+	.release		= vfio_ap_mdev_release,
+	.ioctl			= vfio_ap_mdev_ioctl,
+};
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= vfio_ap_mdev_type_groups,
 	.mdev_attr_groups	= vfio_ap_mdev_attr_groups,
 	.create			= vfio_ap_mdev_create,
 	.remove			= vfio_ap_mdev_remove,
-	.open			= vfio_ap_mdev_open,
-	.release		= vfio_ap_mdev_release,
-	.ioctl			= vfio_ap_mdev_ioctl,
+	.device_ops		= &vfio_mdev_ops,
 };
 
 int vfio_ap_mdev_register(void)
drivers/vfio/mdev/vfio_mdev.c +19 -12
index fd2a4d9a3f26..d23c9f58c84f 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 
 #include "mdev_private.h"
 
@@ -25,15 +26,16 @@ static int vfio_mdev_open(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 	int ret;
 
-	if (unlikely(!parent->ops->open))
+	if (unlikely(!ops->open))
 		return -EINVAL;
 
 	if (!try_module_get(THIS_MODULE))
 		return -ENODEV;
 
-	ret = parent->ops->open(mdev);
+	ret = ops->open(mdev);
 	if (ret)
 		module_put(THIS_MODULE);
 
@@ -44,9 +46,10 @@ static void vfio_mdev_release(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -56,11 +59,12 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->ioctl))
+	if (unlikely(!ops->ioctl))
 		return -EINVAL;
 
-	return parent->ops->ioctl(mdev, cmd, arg);
+	return ops->ioctl(mdev, cmd, arg);
 }
 
 static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
@@ -68,11 +72,12 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->read))
+	if (unlikely(!ops->read))
 		return -EINVAL;
 
-	return parent->ops->read(mdev, buf, count, ppos);
+	return ops->read(mdev, buf, count, ppos);
 }
 
 static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
@@ -80,22 +85,24 @@ static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->write))
+	if (unlikely(!ops->write))
 		return -EINVAL;
 
-	return parent->ops->write(mdev, buf, count, ppos);
+	return ops->write(mdev, buf, count, ppos);
 }
 
 static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->mmap))
+	if (unlikely(!ops->mmap))
 		return -EINVAL;
 
-	return parent->ops->mmap(mdev, vma);
+	return ops->mmap(mdev, vma);
 }
 
 static const struct vfio_device_ops vfio_mdev_dev_ops = {
include/linux/mdev.h +3 -33
index 3ebae310f599..fa167bcb81e1 100644
@@ -48,30 +48,8 @@ struct device *mdev_get_iommu_device(struct device *dev);
  *			@mdev: mdev_device device structure which is being
  *			       destroyed
  *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ * @device_ops:         Device specific emulation callback.
+ *
  * Parent device that support mediated device should be registered with mdev
  * module with mdev_parent_ops structure.
  **/
@@ -83,15 +61,7 @@ struct mdev_parent_ops {
 
 	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
 	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
+	const void *device_ops;
 };
 
 /* interface for exporting mdev supported type attributes */
include/linux/vfio_mdev.h new file +53 -0

53 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +11 -6
index 71a4469be85d..107cc30d0f45 100644
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -1418,12 +1419,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mbochs_create,
-	.remove			= mbochs_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
 	.read			= mbochs_read,
@@ -1432,6 +1428,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mbochs_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mbochs_create,
+	.remove			= mbochs_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c +11 -6
index d3029dd27d91..2cd2018a53f9 100644
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <drm/drm_fourcc.h>
 #include "mdpy-defs.h"
@@ -725,12 +726,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mdpy_create,
-	.remove			= mdpy_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -739,6 +735,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mdpy_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mdpy_create,
+	.remove			= mdpy_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c +10 -5
index 744c88a6b22c..e427425b5daf 100644
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/serial.h>
 #include <uapi/linux/serial_reg.h>
@@ -1410,6 +1411,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open                   = mtty_open,
+	.release                = mtty_close,
+	.read                   = mtty_read,
+	.write                  = mtty_write,
+	.ioctl		        = mtty_ioctl,
+};
+
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
 	.dev_attr_groups        = mtty_dev_groups,
@@ -1417,11 +1426,7 @@ static const struct mdev_parent_ops mdev_fops = {
 	.supported_type_groups  = mdev_type_groups,
 	.create                 = mtty_create,
 	.remove			= mtty_remove,
-	.open                   = mtty_open,
-	.release                = mtty_close,
-	.read                   = mtty_read,
-	.write                  = mtty_write,
-	.ioctl		        = mtty_ioctl,
+	.device_ops             = &vfio_mdev_ops,
 };
 
 static void mtty_device_release(struct device *dev)
Signature · 1 line
2.19.1
#14 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

I love your patch! Yet something to improve:

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
>> include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration
    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
>> include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
>> include/linux/mdev.h:69:19: error: field 'attr' has incomplete type
     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~
   include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*store)(struct kobject *kobj, struct device *dev,
                             ^~~~~~~
>> include/linux/mdev.h:98:23: error: field 'driver' has incomplete type
     struct device_driver driver;
                          ^~~~~~
>> include/linux/mdev.h:106:7: error: unknown type name 'guid_t'
    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~
   In file included from <command-line>:0:0:
>> include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration
     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#15 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

Quoted 19 lines · kbuild test robot

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

Quoted 4 lines

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

Looks like a bunch of includes missing. I guess they happen to be pulled in on some platforms but not others - ideally headers should be self contained though, pulling in all their dependencies.

Quoted 134 lines

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration

    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration

     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:69:19: error: field 'attr' has incomplete type

     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~

include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
ssize_t (*store)(struct kobject *kobj, struct device *dev,
^~~~~~~

Quoted 1 line
Quoted 1 line

include/linux/mdev.h:98:23: error: field 'driver' has incomplete type

     struct device_driver driver;
                          ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:106:7: error: unknown type name 'guid_t'

    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~

In file included from <command-line>:0:0:

Quoted 1 line
Quoted 1 line

include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration

     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author
#16 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · kbuild test robot

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

Quoted 8 lines
Quoted 4 lines

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

Looks like a bunch of includes missing. I guess they happen to be pulled in on some platforms but not others - ideally headers should be self contained though, pulling in all their dependencies.

Right, will fix in V2.

Thanks

Quoted 130 lines
Quoted 130 lines

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration

    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration

     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:69:19: error: field 'attr' has incomplete type

     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~

include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
ssize_t (*store)(struct kobject *kobj, struct device *dev,
^~~~~~~

Quoted 1 line
Quoted 1 line

include/linux/mdev.h:98:23: error: field 'driver' has incomplete type

     struct device_driver driver;
                          ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:106:7: error: unknown type name 'guid_t'

    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~

In file included from <command-line>:0:0:

Quoted 1 line
Quoted 1 line

include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration

     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

Quoted 7 lines
Quoted 6 lines

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#17 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

In reply to Michael S. Tsirkin
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · kbuild test robot

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

Quoted 8 lines
Quoted 4 lines

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

Looks like a bunch of includes missing. I guess they happen to be pulled in on some platforms but not others - ideally headers should be self contained though, pulling in all their dependencies.

Right, will fix in V2.

Thanks

Quoted 130 lines
Quoted 130 lines

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration

    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration

     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:69:19: error: field 'attr' has incomplete type

     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~

include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
ssize_t (*store)(struct kobject *kobj, struct device *dev,
^~~~~~~

Quoted 1 line
Quoted 1 line

include/linux/mdev.h:98:23: error: field 'driver' has incomplete type

     struct device_driver driver;
                          ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:106:7: error: unknown type name 'guid_t'

    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~

In file included from <command-line>:0:0:

Quoted 1 line
Quoted 1 line

include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration

     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

Quoted 7 lines
Quoted 6 lines

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#18 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

In reply to kbuild test robot
Quoted 19 lines · kbuild test robot

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

Quoted 4 lines

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

Looks like a bunch of includes missing. I guess they happen to be pulled in on some platforms but not others - ideally headers should be self contained though, pulling in all their dependencies.

Quoted 134 lines

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration

    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration

     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:69:19: error: field 'attr' has incomplete type

     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~

include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
ssize_t (*store)(struct kobject *kobj, struct device *dev,
^~~~~~~

Quoted 1 line
Quoted 1 line

include/linux/mdev.h:98:23: error: field 'driver' has incomplete type

     struct device_driver driver;
                          ^~~~~~
Quoted 1 line
Quoted 1 line

include/linux/mdev.h:106:7: error: unknown type name 'guid_t'

    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~

In file included from <command-line>:0:0:

Quoted 1 line
Quoted 1 line

include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration

     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#19 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

In reply to Jason Wang
I love your patch! Yet something to improve:

Hi Jason,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Jason-Wang/mdev-based-hardware-virtio-offloading-support/20190923-210738
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from include/linux/vfio_mdev.h:10:0,

                    from <command-line>:0:
>> include/linux/mdev.h:25:34: warning: 'struct device' declared inside parameter list will not be visible outside of this definition or declaration
    int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
                                     ^~~~~~
>> include/linux/mdev.h:62:27: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
                              ^~~~~~~
>> include/linux/mdev.h:69:19: error: field 'attr' has incomplete type
     struct attribute attr;
                      ^~~~
   include/linux/mdev.h:70:25: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
                            ^~~~~~~
   include/linux/mdev.h:71:26: warning: 'struct kobject' declared inside parameter list will not be visible outside of this definition or declaration
     ssize_t (*store)(struct kobject *kobj, struct device *dev,
                             ^~~~~~~
>> include/linux/mdev.h:98:23: error: field 'driver' has incomplete type
     struct device_driver driver;
                          ^~~~~~
>> include/linux/mdev.h:106:7: error: unknown type name 'guid_t'
    const guid_t *mdev_uuid(struct mdev_device *mdev);
          ^~~~~~
   In file included from <command-line>:0:0:
>> include/linux/vfio_mdev.h:50:47: warning: 'struct vm_area_struct' declared inside parameter list will not be visible outside of this definition or declaration
     int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
                                                  ^~~~~~~~~~~~~~

vim +/attr +69 include/linux/mdev.h

7b96953bc640b6 Kirti Wankhede  2016-11-17   14  
8ac13175cbe985 Lu Baolu        2019-04-12   15  /*
8ac13175cbe985 Lu Baolu        2019-04-12   16   * Called by the parent device driver to set the device which represents
8ac13175cbe985 Lu Baolu        2019-04-12   17   * this mdev in iommu protection scope. By default, the iommu device is
8ac13175cbe985 Lu Baolu        2019-04-12   18   * NULL, that indicates using vendor defined isolation.
8ac13175cbe985 Lu Baolu        2019-04-12   19   *
8ac13175cbe985 Lu Baolu        2019-04-12   20   * @dev: the mediated device that iommu will isolate.
8ac13175cbe985 Lu Baolu        2019-04-12   21   * @iommu_device: a pci device which represents the iommu for @dev.
8ac13175cbe985 Lu Baolu        2019-04-12   22   *
8ac13175cbe985 Lu Baolu        2019-04-12   23   * Return 0 for success, otherwise negative error value.
8ac13175cbe985 Lu Baolu        2019-04-12   24   */
8ac13175cbe985 Lu Baolu        2019-04-12  @25  int mdev_set_iommu_device(struct device *dev, struct device *iommu_device);
8ac13175cbe985 Lu Baolu        2019-04-12   26  
8ac13175cbe985 Lu Baolu        2019-04-12   27  struct device *mdev_get_iommu_device(struct device *dev);
8ac13175cbe985 Lu Baolu        2019-04-12   28  
7b96953bc640b6 Kirti Wankhede  2016-11-17   29  /**
42930553a7c11f Alex Williamson 2016-12-30   30   * struct mdev_parent_ops - Structure to be registered for each parent device to
7b96953bc640b6 Kirti Wankhede  2016-11-17   31   * register the device to mdev module.
7b96953bc640b6 Kirti Wankhede  2016-11-17   32   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   33   * @owner:		The module owner.
7b96953bc640b6 Kirti Wankhede  2016-11-17   34   * @dev_attr_groups:	Attributes of the parent device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   35   * @mdev_attr_groups:	Attributes of the mediated device.
7b96953bc640b6 Kirti Wankhede  2016-11-17   36   * @supported_type_groups: Attributes to define supported types. It is mandatory
7b96953bc640b6 Kirti Wankhede  2016-11-17   37   *			to provide supported types.
7b96953bc640b6 Kirti Wankhede  2016-11-17   38   * @create:		Called to allocate basic resources in parent device's
7b96953bc640b6 Kirti Wankhede  2016-11-17   39   *			driver for a particular mediated device. It is
7b96953bc640b6 Kirti Wankhede  2016-11-17   40   *			mandatory to provide create ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   41   *			@kobj: kobject of type for which 'create' is called.
7b96953bc640b6 Kirti Wankhede  2016-11-17   42   *			@mdev: mdev_device structure on of mediated device
7b96953bc640b6 Kirti Wankhede  2016-11-17   43   *			      that is being created
7b96953bc640b6 Kirti Wankhede  2016-11-17   44   *			Returns integer: success (0) or error (< 0)
7b96953bc640b6 Kirti Wankhede  2016-11-17   45   * @remove:		Called to free resources in parent device's driver for a
7b96953bc640b6 Kirti Wankhede  2016-11-17   46   *			a mediated device. It is mandatory to provide 'remove'
7b96953bc640b6 Kirti Wankhede  2016-11-17   47   *			ops.
7b96953bc640b6 Kirti Wankhede  2016-11-17   48   *			@mdev: mdev_device device structure which is being
7b96953bc640b6 Kirti Wankhede  2016-11-17   49   *			       destroyed
7b96953bc640b6 Kirti Wankhede  2016-11-17   50   *			Returns integer: success (0) or error (< 0)
0baad8a6f6fefa Jason Wang      2019-09-23   51   * @device_ops:         Device specific emulation callback.
0baad8a6f6fefa Jason Wang      2019-09-23   52   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   53   * Parent device that support mediated device should be registered with mdev
42930553a7c11f Alex Williamson 2016-12-30   54   * module with mdev_parent_ops structure.
7b96953bc640b6 Kirti Wankhede  2016-11-17   55   **/
42930553a7c11f Alex Williamson 2016-12-30   56  struct mdev_parent_ops {
7b96953bc640b6 Kirti Wankhede  2016-11-17   57  	struct module   *owner;
7b96953bc640b6 Kirti Wankhede  2016-11-17   58  	const struct attribute_group **dev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   59  	const struct attribute_group **mdev_attr_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   60  	struct attribute_group **supported_type_groups;
7b96953bc640b6 Kirti Wankhede  2016-11-17   61  
7b96953bc640b6 Kirti Wankhede  2016-11-17  @62  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   63  	int     (*remove)(struct mdev_device *mdev);
0baad8a6f6fefa Jason Wang      2019-09-23   64  	const void *device_ops;
7b96953bc640b6 Kirti Wankhede  2016-11-17   65  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   66  
7b96953bc640b6 Kirti Wankhede  2016-11-17   67  /* interface for exporting mdev supported type attributes */
7b96953bc640b6 Kirti Wankhede  2016-11-17   68  struct mdev_type_attribute {
7b96953bc640b6 Kirti Wankhede  2016-11-17  @69  	struct attribute attr;
7b96953bc640b6 Kirti Wankhede  2016-11-17  @70  	ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf);
7b96953bc640b6 Kirti Wankhede  2016-11-17   71  	ssize_t (*store)(struct kobject *kobj, struct device *dev,
7b96953bc640b6 Kirti Wankhede  2016-11-17   72  			 const char *buf, size_t count);
7b96953bc640b6 Kirti Wankhede  2016-11-17   73  };
7b96953bc640b6 Kirti Wankhede  2016-11-17   74  
7b96953bc640b6 Kirti Wankhede  2016-11-17   75  #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   76  struct mdev_type_attribute mdev_type_attr_##_name =		\
7b96953bc640b6 Kirti Wankhede  2016-11-17   77  	__ATTR(_name, _mode, _show, _store)
7b96953bc640b6 Kirti Wankhede  2016-11-17   78  #define MDEV_TYPE_ATTR_RW(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   79  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   80  #define MDEV_TYPE_ATTR_RO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   81  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   82  #define MDEV_TYPE_ATTR_WO(_name) \
7b96953bc640b6 Kirti Wankhede  2016-11-17   83  	struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
7b96953bc640b6 Kirti Wankhede  2016-11-17   84  
7b96953bc640b6 Kirti Wankhede  2016-11-17   85  /**
7b96953bc640b6 Kirti Wankhede  2016-11-17   86   * struct mdev_driver - Mediated device driver
7b96953bc640b6 Kirti Wankhede  2016-11-17   87   * @name: driver name
7b96953bc640b6 Kirti Wankhede  2016-11-17   88   * @probe: called when new device created
7b96953bc640b6 Kirti Wankhede  2016-11-17   89   * @remove: called when device removed
7b96953bc640b6 Kirti Wankhede  2016-11-17   90   * @driver: device driver structure
6294ee8e0b5153 Jason Wang      2019-09-23   91   * @id_table: the ids serviced by this driver.
7b96953bc640b6 Kirti Wankhede  2016-11-17   92   *
7b96953bc640b6 Kirti Wankhede  2016-11-17   93   **/
7b96953bc640b6 Kirti Wankhede  2016-11-17   94  struct mdev_driver {
7b96953bc640b6 Kirti Wankhede  2016-11-17   95  	const char *name;
7b96953bc640b6 Kirti Wankhede  2016-11-17   96  	int  (*probe)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17   97  	void (*remove)(struct device *dev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  @98  	struct device_driver driver;
6294ee8e0b5153 Jason Wang      2019-09-23   99  	const struct mdev_class_id *id_table;
7b96953bc640b6 Kirti Wankhede  2016-11-17  100  };
7b96953bc640b6 Kirti Wankhede  2016-11-17  101  
7b96953bc640b6 Kirti Wankhede  2016-11-17  102  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
7b96953bc640b6 Kirti Wankhede  2016-11-17  103  
50732af3b65691 Parav Pandit    2019-04-30  104  void *mdev_get_drvdata(struct mdev_device *mdev);
50732af3b65691 Parav Pandit    2019-04-30  105  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
50732af3b65691 Parav Pandit    2019-04-30 @106  const guid_t *mdev_uuid(struct mdev_device *mdev);
7b96953bc640b6 Kirti Wankhede  2016-11-17  107  

:::::: The code at line 69 was first introduced by commit
:::::: 7b96953bc640b6b25665fe17ffca4b668b371f14 vfio: Mediated device Core driver

:::::: TO: Kirti Wankhede <[email protected]> :::::: CC: Alex Williamson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#20 lore raw

RE: [PATCH 2/6] mdev: introduce device specific ops

In reply to Jason Wang
Quoted 90 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 2/6] mdev: introduce device specific ops

Currently, except for the create and remove. The rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. Follow the class id support by previous patch, this patch introduces device specific ops pointer inside parent ops which points to device specific ops (e.g vfio ops). This allows the future drivers like virtio-mdev to implement its own device specific ops.

---
 .../driver-api/vfio-mediated-device.rst       |  4 +-
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 15 +++---
 drivers/s390/cio/vfio_ccw_ops.c               | 15 ++++--
 drivers/s390/crypto/vfio_ap_ops.c             | 11 ++--
 drivers/vfio/mdev/vfio_mdev.c                 | 31 ++++++-----
 include/linux/mdev.h                          | 36 ++-----------
 include/linux/vfio_mdev.h                     | 53 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 17 +++---
 samples/vfio-mdev/mdpy.c                      | 17 +++---
 samples/vfio-mdev/mtty.c                      | 15 ++++--
 11 files changed, 138 insertions(+), 77 deletions(-)  create mode 100644

include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 0e052072e1d8..3ab00e48212f 100644
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or

any other categorization.
Vendor drivers are expected to be fully asynchronous in this respect or
provide their own internal resource protection.)

Documentation/driver-api/vfio-mediated-device.rst +3 -1
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
 
 * open: open callback of mediated device
 * close: close callback of mediated device diff --git a/MAINTAINERS

b/MAINTAINERS index b2326dece28e..89832b316500 100644

MAINTAINERS +1 -0
@@ -17075,6 +17075,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/vfio_mdev.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 19d51a35f019..8ea86b1e69f1 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/debugfs.h>
 
 #include <linux/nospec.h>

drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group · line 1605

Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -5
@@ -1600,20 +1601,22 @@ static const struct attribute_group
 *intel_vgpu_groups[] = {
 	NULL,
 };
 
-static struct mdev_parent_ops intel_vgpu_ops = {
-	.mdev_attr_groups       = intel_vgpu_groups,
-	.create			= intel_vgpu_create,
-	.remove			= intel_vgpu_remove,
-
+static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {

Naming it with _dev prefix as intel_vfio_vgpu_dev_ops is better to differentiate with parent_ops.

Quoted 109 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +7 -1
 	.open			= intel_vgpu_open,
 	.release		= intel_vgpu_release,
-
 	.read			= intel_vgpu_read,
 	.write			= intel_vgpu_write,
 	.mmap			= intel_vgpu_mmap,
 	.ioctl			= intel_vgpu_ioctl,
 };
 
+static struct mdev_parent_ops intel_vgpu_ops = {
+	.mdev_attr_groups       = intel_vgpu_groups,
+	.create			= intel_vgpu_create,
+	.remove			= intel_vgpu_remove,
+	.device_ops	        = &intel_vfio_vgpu_ops,
+};
+
 static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)  {
 	struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +2 -5
index 246ff0f80944..02122bbc213e 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -574,11 +575,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
 mdev_device *mdev,
 	}
 }
 
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
-	.owner			= THIS_MODULE,
-	.supported_type_groups  = mdev_type_groups,
-	.create			= vfio_ccw_mdev_create,
-	.remove			= vfio_ccw_mdev_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
drivers/s390/cio/vfio_ccw_ops.c +8 -0
 	.read			= vfio_ccw_mdev_read,
@@ -586,6 +583,14 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 	.ioctl			= vfio_ccw_mdev_ioctl,
 };
 
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+	.owner			= THIS_MODULE,
+	.supported_type_groups  = mdev_type_groups,
+	.create			= vfio_ccw_mdev_create,
+	.remove			= vfio_ccw_mdev_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
 	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +8 -3
index 7487fc39d2c5..4251becc7a6d 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/vfio_mdev.h>
 #include <asm/kvm.h>
 #include <asm/zcrypt.h>
 
@@ -1280,15 +1281,19 @@ static ssize_t vfio_ap_mdev_ioctl(struct
 mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open			= vfio_ap_mdev_open,
+	.release		= vfio_ap_mdev_release,
+	.ioctl			= vfio_ap_mdev_ioctl,
+};
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= vfio_ap_mdev_type_groups,
 	.mdev_attr_groups	= vfio_ap_mdev_attr_groups,
 	.create			= vfio_ap_mdev_create,
 	.remove			= vfio_ap_mdev_remove,
-	.open			= vfio_ap_mdev_open,
-	.release		= vfio_ap_mdev_release,
-	.ioctl			= vfio_ap_mdev_ioctl,
+	.device_ops		= &vfio_mdev_ops,
 };
 

int vfio_ap_mdev_register(void)

drivers/vfio/mdev/vfio_mdev.c +1 -0
index fd2a4d9a3f26..d23c9f58c84f 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 
 #include "mdev_private.h"
 

drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) { · line 33

Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2 -1
@@ -25,15 +26,16 @@ static int vfio_mdev_open(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 	int ret;
 
-	if (unlikely(!parent->ops->open))
+	if (unlikely(!ops->open))
 		return -EINVAL;
 

device_ops is optional and can be NULL for mdev devices which are not required to be mapped via vfio. So please change to,

If (!ops || !ops->open)

	return -EINVAL;

and rest of the below places.

Quoted 321 lines
drivers/vfio/mdev/vfio_mdev.c +8 -5
 	if (!try_module_get(THIS_MODULE))
 		return -ENODEV;
 
-	ret = parent->ops->open(mdev);
+	ret = ops->open(mdev);
 	if (ret)
 		module_put(THIS_MODULE);
 
@@ -44,9 +46,10 @@ static void vfio_mdev_release(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -56,11 +59,12 @@ static long vfio_mdev_unlocked_ioctl(void
 *device_data,  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->ioctl))
+	if (unlikely(!ops->ioctl))
 		return -EINVAL;
 
-	return parent->ops->ioctl(mdev, cmd, arg);
+	return ops->ioctl(mdev, cmd, arg);
 }
 
 static ssize_t vfio_mdev_read(void *device_data, char __user *buf, @@ -68,11
+72,12 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,

{

drivers/vfio/mdev/vfio_mdev.c +3 -3
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->read))
+	if (unlikely(!ops->read))
 		return -EINVAL;
 
-	return parent->ops->read(mdev, buf, count, ppos);
+	return ops->read(mdev, buf, count, ppos);
 }
 
 static ssize_t vfio_mdev_write(void *device_data, const char __user *buf, @@
-80,22 +85,24 @@ static ssize_t vfio_mdev_write(void *device_data, const char

__user *buf, {

drivers/vfio/mdev/vfio_mdev.c +6 -4
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->write))
+	if (unlikely(!ops->write))
 		return -EINVAL;
 
-	return parent->ops->write(mdev, buf, count, ppos);
+	return ops->write(mdev, buf, count, ppos);
 }
 
 static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->mmap))
+	if (unlikely(!ops->mmap))
 		return -EINVAL;
 
-	return parent->ops->mmap(mdev, vma);
+	return ops->mmap(mdev, vma);
 }
 
 static const struct vfio_device_ops vfio_mdev_dev_ops = { diff --git

a/include/linux/mdev.h b/include/linux/mdev.h index 3ebae310f599..fa167bcb81e1 100644

include/linux/mdev.h +2 -24
@@ -48,30 +48,8 @@ struct device *mdev_get_iommu_device(struct device
 *dev);
  *			@mdev: mdev_device device structure which is being
  *			       destroyed
  *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ * @device_ops:         Device specific emulation callback.
+ *
  * Parent device that support mediated device should be registered with mdev
  * module with mdev_parent_ops structure.

**/

include/linux/mdev.h +1 -9
@@ -83,15 +61,7 @@ struct mdev_parent_ops {
 
 	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
 	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct
 *vma);
+	const void *device_ops;
 };
 

/* interface for exporting mdev supported type attributes */ diff --git
a/include/linux/vfio_mdev.h b/include/linux/vfio_mdev.h new file mode 100644 index 000000000000..0c1b34f98f5d

include/linux/vfio_mdev.h new file +50 -0
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO Mediated device definition
+ */
+
+#ifndef VFIO_MDEV_H
+#define VFIO_MDEV_H
+
+#include <linux/types.h>
+#include <linux/mdev.h>
+
+/**
+ * struct vfio_mdev_parent_ops - Structure to be registered for each
+ * parent device to register the device to vfio-mdev module.
+ *
+ * @open:		Open mediated device.
+ *			@mdev: mediated device.
+ *			Returns integer: success (0) or error (< 0)
+ * @release:		release mediated device
+ *			@mdev: mediated device.
+ * @read:		Read emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: read buffer
+ *			@count: number of bytes to read
+ *			@ppos: address.
+ *			Retuns number on bytes read on success or error.
+ * @write:		Write emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: write buffer
+ *			@count: number of bytes to be written
+ *			@ppos: address.
+ *			Retuns number on bytes written on success or error.
+ * @ioctl:		IOCTL callback
+ *			@mdev: mediated device structure
+ *			@cmd: ioctl command
+ *			@arg: arguments to ioctl
+ * @mmap:		mmap callback
+ *			@mdev: mediated device structure
+ *			@vma: vma structure
+ */
+struct vfio_mdev_parent_ops {
+	int     (*open)(struct mdev_device *mdev);
+	void    (*release)(struct mdev_device *mdev);
+	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
+			size_t count, loff_t *ppos);
+	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
+			 size_t count, loff_t *ppos);
+	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
+			 unsigned long arg);
+	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct

*vma);

include/linux/vfio_mdev.h new file +3 -0
+};
+
+#endif
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

71a4469be85d..107cc30d0f45 100644

samples/vfio-mdev/mbochs.c +2 -6
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -1418,12 +1419,7 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mbochs_create,
-	.remove			= mbochs_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
samples/vfio-mdev/mbochs.c +9 -0
 	.read			= mbochs_read,
@@ -1432,6 +1428,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mbochs_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mbochs_create,
+	.remove			= mbochs_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

d3029dd27d91..2cd2018a53f9 100644

samples/vfio-mdev/mdpy.c +11 -6
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <drm/drm_fourcc.h>
 #include "mdpy-defs.h"
@@ -725,12 +726,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mdpy_create,
-	.remove			= mdpy_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -739,6 +735,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mdpy_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mdpy_create,
+	.remove			= mdpy_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

744c88a6b22c..e427425b5daf 100644

samples/vfio-mdev/mtty.c +9 -0
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/serial.h>
 #include <uapi/linux/serial_reg.h>
@@ -1410,6 +1411,14 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open                   = mtty_open,
+	.release                = mtty_close,
+	.read                   = mtty_read,
+	.write                  = mtty_write,
+	.ioctl		        = mtty_ioctl,
+};
+
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
samples/vfio-mdev/mtty.c +1 -6
 	.dev_attr_groups        = mtty_dev_groups,
@@ -1417,11 +1426,7 @@ static const struct mdev_parent_ops mdev_fops = {
 	.supported_type_groups  = mdev_type_groups,
 	.create                 = mtty_create,
 	.remove			= mtty_remove,
-	.open                   = mtty_open,
-	.release                = mtty_close,
-	.read                   = mtty_read,
-	.write                  = mtty_write,
-	.ioctl		        = mtty_ioctl,
+	.device_ops             = &vfio_mdev_ops,
 };
 
 static void mtty_device_release(struct device *dev)
--

2.19.1

author
#21 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

Quoted 93 lines · Parav Pandit
Quoted 93 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 2/6] mdev: introduce device specific ops

Currently, except for the create and remove. The rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. Follow the class id support by previous patch, this patch introduces device specific ops pointer inside parent ops which points to device specific ops (e.g vfio ops). This allows the future drivers like virtio-mdev to implement its own device specific ops.

---
 .../driver-api/vfio-mediated-device.rst       |  4 +-
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 15 +++---
 drivers/s390/cio/vfio_ccw_ops.c               | 15 ++++--
 drivers/s390/crypto/vfio_ap_ops.c             | 11 ++--
 drivers/vfio/mdev/vfio_mdev.c                 | 31 ++++++-----
 include/linux/mdev.h                          | 36 ++-----------
 include/linux/vfio_mdev.h                     | 53 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 17 +++---
 samples/vfio-mdev/mdpy.c                      | 17 +++---
 samples/vfio-mdev/mtty.c                      | 15 ++++--
 11 files changed, 138 insertions(+), 77 deletions(-)  create mode 100644

include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 0e052072e1d8..3ab00e48212f 100644
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or

any other categorization.
Vendor drivers are expected to be fully asynchronous in this respect or
provide their own internal resource protection.)

Documentation/driver-api/vfio-mediated-device.rst +3 -1
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
 
 * open: open callback of mediated device
 * close: close callback of mediated device diff --git a/MAINTAINERS

b/MAINTAINERS index b2326dece28e..89832b316500 100644

MAINTAINERS +1 -0
@@ -17075,6 +17075,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/vfio_mdev.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 19d51a35f019..8ea86b1e69f1 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/debugfs.h>
 
 #include <linux/nospec.h>
@@ -1600,20 +1601,22 @@ static const struct attribute_group
 *intel_vgpu_groups[] = {
 	NULL,
 };
 
Quoted 7 lines

drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1604

Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -5
-static struct mdev_parent_ops intel_vgpu_ops = {
-	.mdev_attr_groups       = intel_vgpu_groups,
-	.create			= intel_vgpu_create,
-	.remove			= intel_vgpu_remove,
-
+static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {

Naming it with _dev prefix as intel_vfio_vgpu_dev_ops is better to differentiate with parent_ops.

Ok.

Quoted 121 lines
Quoted 109 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +7 -1
 	.open			= intel_vgpu_open,
 	.release		= intel_vgpu_release,
-
 	.read			= intel_vgpu_read,
 	.write			= intel_vgpu_write,
 	.mmap			= intel_vgpu_mmap,
 	.ioctl			= intel_vgpu_ioctl,
 };
 
+static struct mdev_parent_ops intel_vgpu_ops = {
+	.mdev_attr_groups       = intel_vgpu_groups,
+	.create			= intel_vgpu_create,
+	.remove			= intel_vgpu_remove,
+	.device_ops	        = &intel_vfio_vgpu_ops,
+};
+
 static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)  {
 	struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +2 -5
index 246ff0f80944..02122bbc213e 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -574,11 +575,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
 mdev_device *mdev,
 	}
 }
 
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
-	.owner			= THIS_MODULE,
-	.supported_type_groups  = mdev_type_groups,
-	.create			= vfio_ccw_mdev_create,
-	.remove			= vfio_ccw_mdev_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
drivers/s390/cio/vfio_ccw_ops.c +8 -0
 	.read			= vfio_ccw_mdev_read,
@@ -586,6 +583,14 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 	.ioctl			= vfio_ccw_mdev_ioctl,
 };
 
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+	.owner			= THIS_MODULE,
+	.supported_type_groups  = mdev_type_groups,
+	.create			= vfio_ccw_mdev_create,
+	.remove			= vfio_ccw_mdev_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
 	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +8 -3
index 7487fc39d2c5..4251becc7a6d 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/vfio_mdev.h>
 #include <asm/kvm.h>
 #include <asm/zcrypt.h>
 
@@ -1280,15 +1281,19 @@ static ssize_t vfio_ap_mdev_ioctl(struct
 mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open			= vfio_ap_mdev_open,
+	.release		= vfio_ap_mdev_release,
+	.ioctl			= vfio_ap_mdev_ioctl,
+};
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= vfio_ap_mdev_type_groups,
 	.mdev_attr_groups	= vfio_ap_mdev_attr_groups,
 	.create			= vfio_ap_mdev_create,
 	.remove			= vfio_ap_mdev_remove,
-	.open			= vfio_ap_mdev_open,
-	.release		= vfio_ap_mdev_release,
-	.ioctl			= vfio_ap_mdev_ioctl,
+	.device_ops		= &vfio_mdev_ops,
 };
 

int vfio_ap_mdev_register(void)

drivers/vfio/mdev/vfio_mdev.c +1 -0
index fd2a4d9a3f26..d23c9f58c84f 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 
 #include "mdev_private.h"
 

drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) { · line 33

Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2 -1
@@ -25,15 +26,16 @@ static int vfio_mdev_open(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 	int ret;
 
-	if (unlikely(!parent->ops->open))
+	if (unlikely(!ops->open))
 		return -EINVAL;
 

device_ops is optional and can be NULL for mdev devices which are not required to be mapped via vfio. So please change to,

Quoted 4 lines

If (!ops || !ops->open)

	return -EINVAL;

and rest of the below places.

My understanding is vfio_mdev can not talk to non vfio mdev device with the help of class id.

Thanks

Quoted 322 lines
Quoted 322 lines
drivers/vfio/mdev/vfio_mdev.c +8 -5
 	if (!try_module_get(THIS_MODULE))
 		return -ENODEV;
 
-	ret = parent->ops->open(mdev);
+	ret = ops->open(mdev);
 	if (ret)
 		module_put(THIS_MODULE);
 
@@ -44,9 +46,10 @@ static void vfio_mdev_release(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -56,11 +59,12 @@ static long vfio_mdev_unlocked_ioctl(void
 *device_data,  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->ioctl))
+	if (unlikely(!ops->ioctl))
 		return -EINVAL;
 
-	return parent->ops->ioctl(mdev, cmd, arg);
+	return ops->ioctl(mdev, cmd, arg);
 }
 
 static ssize_t vfio_mdev_read(void *device_data, char __user *buf, @@ -68,11
+72,12 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,

{

drivers/vfio/mdev/vfio_mdev.c +3 -3
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->read))
+	if (unlikely(!ops->read))
 		return -EINVAL;
 
-	return parent->ops->read(mdev, buf, count, ppos);
+	return ops->read(mdev, buf, count, ppos);
 }
 
 static ssize_t vfio_mdev_write(void *device_data, const char __user *buf, @@
-80,22 +85,24 @@ static ssize_t vfio_mdev_write(void *device_data, const char

__user *buf, {

drivers/vfio/mdev/vfio_mdev.c +6 -4
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->write))
+	if (unlikely(!ops->write))
 		return -EINVAL;
 
-	return parent->ops->write(mdev, buf, count, ppos);
+	return ops->write(mdev, buf, count, ppos);
 }
 
 static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->mmap))
+	if (unlikely(!ops->mmap))
 		return -EINVAL;
 
-	return parent->ops->mmap(mdev, vma);
+	return ops->mmap(mdev, vma);
 }
 
 static const struct vfio_device_ops vfio_mdev_dev_ops = { diff --git

a/include/linux/mdev.h b/include/linux/mdev.h index 3ebae310f599..fa167bcb81e1 100644

include/linux/mdev.h +2 -24
@@ -48,30 +48,8 @@ struct device *mdev_get_iommu_device(struct device
 *dev);
  *			@mdev: mdev_device device structure which is being
  *			       destroyed
  *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ * @device_ops:         Device specific emulation callback.
+ *
  * Parent device that support mediated device should be registered with mdev
  * module with mdev_parent_ops structure.

**/

include/linux/mdev.h +1 -9
@@ -83,15 +61,7 @@ struct mdev_parent_ops {
 
 	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
 	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct
 *vma);
+	const void *device_ops;
 };
 

/* interface for exporting mdev supported type attributes */ diff --git
a/include/linux/vfio_mdev.h b/include/linux/vfio_mdev.h new file mode 100644 index 000000000000..0c1b34f98f5d

include/linux/vfio_mdev.h new file +50 -0
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO Mediated device definition
+ */
+
+#ifndef VFIO_MDEV_H
+#define VFIO_MDEV_H
+
+#include <linux/types.h>
+#include <linux/mdev.h>
+
+/**
+ * struct vfio_mdev_parent_ops - Structure to be registered for each
+ * parent device to register the device to vfio-mdev module.
+ *
+ * @open:		Open mediated device.
+ *			@mdev: mediated device.
+ *			Returns integer: success (0) or error (< 0)
+ * @release:		release mediated device
+ *			@mdev: mediated device.
+ * @read:		Read emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: read buffer
+ *			@count: number of bytes to read
+ *			@ppos: address.
+ *			Retuns number on bytes read on success or error.
+ * @write:		Write emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: write buffer
+ *			@count: number of bytes to be written
+ *			@ppos: address.
+ *			Retuns number on bytes written on success or error.
+ * @ioctl:		IOCTL callback
+ *			@mdev: mediated device structure
+ *			@cmd: ioctl command
+ *			@arg: arguments to ioctl
+ * @mmap:		mmap callback
+ *			@mdev: mediated device structure
+ *			@vma: vma structure
+ */
+struct vfio_mdev_parent_ops {
+	int     (*open)(struct mdev_device *mdev);
+	void    (*release)(struct mdev_device *mdev);
+	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
+			size_t count, loff_t *ppos);
+	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
+			 size_t count, loff_t *ppos);
+	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
+			 unsigned long arg);
+	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct

*vma);

include/linux/vfio_mdev.h new file +3 -0
+};
+
+#endif
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

71a4469be85d..107cc30d0f45 100644

samples/vfio-mdev/mbochs.c +2 -6
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -1418,12 +1419,7 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mbochs_create,
-	.remove			= mbochs_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
samples/vfio-mdev/mbochs.c +9 -0
 	.read			= mbochs_read,
@@ -1432,6 +1428,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mbochs_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mbochs_create,
+	.remove			= mbochs_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

d3029dd27d91..2cd2018a53f9 100644

samples/vfio-mdev/mdpy.c +11 -6
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <drm/drm_fourcc.h>
 #include "mdpy-defs.h"
@@ -725,12 +726,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mdpy_create,
-	.remove			= mdpy_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -739,6 +735,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mdpy_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mdpy_create,
+	.remove			= mdpy_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

744c88a6b22c..e427425b5daf 100644

samples/vfio-mdev/mtty.c +9 -0
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/serial.h>
 #include <uapi/linux/serial_reg.h>
@@ -1410,6 +1411,14 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open                   = mtty_open,
+	.release                = mtty_close,
+	.read                   = mtty_read,
+	.write                  = mtty_write,
+	.ioctl		        = mtty_ioctl,
+};
+
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
samples/vfio-mdev/mtty.c +1 -6
 	.dev_attr_groups        = mtty_dev_groups,
@@ -1417,11 +1426,7 @@ static const struct mdev_parent_ops mdev_fops = {
 	.supported_type_groups  = mdev_type_groups,
 	.create                 = mtty_create,
 	.remove			= mtty_remove,
-	.open                   = mtty_open,
-	.release                = mtty_close,
-	.read                   = mtty_read,
-	.write                  = mtty_write,
-	.ioctl		        = mtty_ioctl,
+	.device_ops             = &vfio_mdev_ops,
 };
 
 static void mtty_device_release(struct device *dev)
--

2.19.1

author
#22 lore raw

Re: [PATCH 2/6] mdev: introduce device specific ops

In reply to Parav Pandit
Quoted 93 lines · Parav Pandit
Quoted 93 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 2/6] mdev: introduce device specific ops

Currently, except for the create and remove. The rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. Follow the class id support by previous patch, this patch introduces device specific ops pointer inside parent ops which points to device specific ops (e.g vfio ops). This allows the future drivers like virtio-mdev to implement its own device specific ops.

---
 .../driver-api/vfio-mediated-device.rst       |  4 +-
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 15 +++---
 drivers/s390/cio/vfio_ccw_ops.c               | 15 ++++--
 drivers/s390/crypto/vfio_ap_ops.c             | 11 ++--
 drivers/vfio/mdev/vfio_mdev.c                 | 31 ++++++-----
 include/linux/mdev.h                          | 36 ++-----------
 include/linux/vfio_mdev.h                     | 53 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 17 +++---
 samples/vfio-mdev/mdpy.c                      | 17 +++---
 samples/vfio-mdev/mtty.c                      | 15 ++++--
 11 files changed, 138 insertions(+), 77 deletions(-)  create mode 100644

include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 0e052072e1d8..3ab00e48212f 100644
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or

any other categorization.
Vendor drivers are expected to be fully asynchronous in this respect or
provide their own internal resource protection.)

Documentation/driver-api/vfio-mediated-device.rst +3 -1
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
 
 * open: open callback of mediated device
 * close: close callback of mediated device diff --git a/MAINTAINERS

b/MAINTAINERS index b2326dece28e..89832b316500 100644

MAINTAINERS +1 -0
@@ -17075,6 +17075,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/vfio_mdev.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 19d51a35f019..8ea86b1e69f1 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/debugfs.h>
 
 #include <linux/nospec.h>
@@ -1600,20 +1601,22 @@ static const struct attribute_group
 *intel_vgpu_groups[] = {
 	NULL,
 };
 
Quoted 7 lines

drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1604

Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -5
-static struct mdev_parent_ops intel_vgpu_ops = {
-	.mdev_attr_groups       = intel_vgpu_groups,
-	.create			= intel_vgpu_create,
-	.remove			= intel_vgpu_remove,
-
+static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {

Naming it with _dev prefix as intel_vfio_vgpu_dev_ops is better to differentiate with parent_ops.

Ok.

Quoted 121 lines
Quoted 109 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +7 -1
 	.open			= intel_vgpu_open,
 	.release		= intel_vgpu_release,
-
 	.read			= intel_vgpu_read,
 	.write			= intel_vgpu_write,
 	.mmap			= intel_vgpu_mmap,
 	.ioctl			= intel_vgpu_ioctl,
 };
 
+static struct mdev_parent_ops intel_vgpu_ops = {
+	.mdev_attr_groups       = intel_vgpu_groups,
+	.create			= intel_vgpu_create,
+	.remove			= intel_vgpu_remove,
+	.device_ops	        = &intel_vfio_vgpu_ops,
+};
+
 static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)  {
 	struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +2 -5
index 246ff0f80944..02122bbc213e 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -574,11 +575,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
 mdev_device *mdev,
 	}
 }
 
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
-	.owner			= THIS_MODULE,
-	.supported_type_groups  = mdev_type_groups,
-	.create			= vfio_ccw_mdev_create,
-	.remove			= vfio_ccw_mdev_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
drivers/s390/cio/vfio_ccw_ops.c +8 -0
 	.read			= vfio_ccw_mdev_read,
@@ -586,6 +583,14 @@ static const struct mdev_parent_ops
 vfio_ccw_mdev_ops = {
 	.ioctl			= vfio_ccw_mdev_ioctl,
 };
 
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+	.owner			= THIS_MODULE,
+	.supported_type_groups  = mdev_type_groups,
+	.create			= vfio_ccw_mdev_create,
+	.remove			= vfio_ccw_mdev_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)  {
 	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +8 -3
index 7487fc39d2c5..4251becc7a6d 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/vfio_mdev.h>
 #include <asm/kvm.h>
 #include <asm/zcrypt.h>
 
@@ -1280,15 +1281,19 @@ static ssize_t vfio_ap_mdev_ioctl(struct
 mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open			= vfio_ap_mdev_open,
+	.release		= vfio_ap_mdev_release,
+	.ioctl			= vfio_ap_mdev_ioctl,
+};
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= vfio_ap_mdev_type_groups,
 	.mdev_attr_groups	= vfio_ap_mdev_attr_groups,
 	.create			= vfio_ap_mdev_create,
 	.remove			= vfio_ap_mdev_remove,
-	.open			= vfio_ap_mdev_open,
-	.release		= vfio_ap_mdev_release,
-	.ioctl			= vfio_ap_mdev_ioctl,
+	.device_ops		= &vfio_mdev_ops,
 };
 

int vfio_ap_mdev_register(void)

drivers/vfio/mdev/vfio_mdev.c +1 -0
index fd2a4d9a3f26..d23c9f58c84f 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 
 #include "mdev_private.h"
 

drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) { · line 33

Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2 -1
@@ -25,15 +26,16 @@ static int vfio_mdev_open(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 	int ret;
 
-	if (unlikely(!parent->ops->open))
+	if (unlikely(!ops->open))
 		return -EINVAL;
 

device_ops is optional and can be NULL for mdev devices which are not required to be mapped via vfio. So please change to,

Quoted 4 lines

If (!ops || !ops->open)

	return -EINVAL;

and rest of the below places.

My understanding is vfio_mdev can not talk to non vfio mdev device with the help of class id.

Thanks

Quoted 319 lines
Quoted 319 lines
drivers/vfio/mdev/vfio_mdev.c +8 -5
 	if (!try_module_get(THIS_MODULE))
 		return -ENODEV;
 
-	ret = parent->ops->open(mdev);
+	ret = ops->open(mdev);
 	if (ret)
 		module_put(THIS_MODULE);
 
@@ -44,9 +46,10 @@ static void vfio_mdev_release(void *device_data)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -56,11 +59,12 @@ static long vfio_mdev_unlocked_ioctl(void
 *device_data,  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->ioctl))
+	if (unlikely(!ops->ioctl))
 		return -EINVAL;
 
-	return parent->ops->ioctl(mdev, cmd, arg);
+	return ops->ioctl(mdev, cmd, arg);
 }
 
 static ssize_t vfio_mdev_read(void *device_data, char __user *buf, @@ -68,11
+72,12 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,

{

drivers/vfio/mdev/vfio_mdev.c +3 -3
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->read))
+	if (unlikely(!ops->read))
 		return -EINVAL;
 
-	return parent->ops->read(mdev, buf, count, ppos);
+	return ops->read(mdev, buf, count, ppos);
 }
 
 static ssize_t vfio_mdev_write(void *device_data, const char __user *buf, @@
-80,22 +85,24 @@ static ssize_t vfio_mdev_write(void *device_data, const char

__user *buf, {

drivers/vfio/mdev/vfio_mdev.c +6 -4
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->write))
+	if (unlikely(!ops->write))
 		return -EINVAL;
 
-	return parent->ops->write(mdev, buf, count, ppos);
+	return ops->write(mdev, buf, count, ppos);
 }
 
 static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)  {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->mmap))
+	if (unlikely(!ops->mmap))
 		return -EINVAL;
 
-	return parent->ops->mmap(mdev, vma);
+	return ops->mmap(mdev, vma);
 }
 
 static const struct vfio_device_ops vfio_mdev_dev_ops = { diff --git

a/include/linux/mdev.h b/include/linux/mdev.h index 3ebae310f599..fa167bcb81e1 100644

include/linux/mdev.h +2 -24
@@ -48,30 +48,8 @@ struct device *mdev_get_iommu_device(struct device
 *dev);
  *			@mdev: mdev_device device structure which is being
  *			       destroyed
  *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ * @device_ops:         Device specific emulation callback.
+ *
  * Parent device that support mediated device should be registered with mdev
  * module with mdev_parent_ops structure.

**/

include/linux/mdev.h +1 -9
@@ -83,15 +61,7 @@ struct mdev_parent_ops {
 
 	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
 	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct
 *vma);
+	const void *device_ops;
 };
 

/* interface for exporting mdev supported type attributes */ diff --git
a/include/linux/vfio_mdev.h b/include/linux/vfio_mdev.h new file mode 100644 index 000000000000..0c1b34f98f5d

include/linux/vfio_mdev.h new file +50 -0
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO Mediated device definition
+ */
+
+#ifndef VFIO_MDEV_H
+#define VFIO_MDEV_H
+
+#include <linux/types.h>
+#include <linux/mdev.h>
+
+/**
+ * struct vfio_mdev_parent_ops - Structure to be registered for each
+ * parent device to register the device to vfio-mdev module.
+ *
+ * @open:		Open mediated device.
+ *			@mdev: mediated device.
+ *			Returns integer: success (0) or error (< 0)
+ * @release:		release mediated device
+ *			@mdev: mediated device.
+ * @read:		Read emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: read buffer
+ *			@count: number of bytes to read
+ *			@ppos: address.
+ *			Retuns number on bytes read on success or error.
+ * @write:		Write emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: write buffer
+ *			@count: number of bytes to be written
+ *			@ppos: address.
+ *			Retuns number on bytes written on success or error.
+ * @ioctl:		IOCTL callback
+ *			@mdev: mediated device structure
+ *			@cmd: ioctl command
+ *			@arg: arguments to ioctl
+ * @mmap:		mmap callback
+ *			@mdev: mediated device structure
+ *			@vma: vma structure
+ */
+struct vfio_mdev_parent_ops {
+	int     (*open)(struct mdev_device *mdev);
+	void    (*release)(struct mdev_device *mdev);
+	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
+			size_t count, loff_t *ppos);
+	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
+			 size_t count, loff_t *ppos);
+	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
+			 unsigned long arg);
+	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct

*vma);

include/linux/vfio_mdev.h new file +3 -0
+};
+
+#endif
samples/vfio-mdev/mbochs.c index renamed from samples/vfio-mdev/mbochs.c +0 -0

71a4469be85d..107cc30d0f45 100644

samples/vfio-mdev/mbochs.c +2 -6
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -1418,12 +1419,7 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mbochs_create,
-	.remove			= mbochs_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
samples/vfio-mdev/mbochs.c +9 -0
 	.read			= mbochs_read,
@@ -1432,6 +1428,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mbochs_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mbochs_create,
+	.remove			= mbochs_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

d3029dd27d91..2cd2018a53f9 100644

samples/vfio-mdev/mdpy.c +11 -6
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <drm/drm_fourcc.h>
 #include "mdpy-defs.h"
@@ -725,12 +726,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mdpy_create,
-	.remove			= mdpy_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -739,6 +735,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mdpy_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mdpy_create,
+	.remove			= mdpy_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

744c88a6b22c..e427425b5daf 100644

samples/vfio-mdev/mtty.c +9 -0
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/serial.h>
 #include <uapi/linux/serial_reg.h>
@@ -1410,6 +1411,14 @@ static struct attribute_group *mdev_type_groups[]
 = {
 	NULL,
 };
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open                   = mtty_open,
+	.release                = mtty_close,
+	.read                   = mtty_read,
+	.write                  = mtty_write,
+	.ioctl		        = mtty_ioctl,
+};
+
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
samples/vfio-mdev/mtty.c +1 -5
 	.dev_attr_groups        = mtty_dev_groups,
@@ -1417,11 +1426,7 @@ static const struct mdev_parent_ops mdev_fops = {
 	.supported_type_groups  = mdev_type_groups,
 	.create                 = mtty_create,
 	.remove			= mtty_remove,
-	.open                   = mtty_open,
-	.release                = mtty_close,
-	.read                   = mtty_read,
-	.write                  = mtty_write,
-	.ioctl		        = mtty_ioctl,
+	.device_ops             = &vfio_mdev_ops,
 };
 
Quoted 3 lines
Quoted 3 lines
samples/vfio-mdev/mtty.c +0 -1
 static void mtty_device_release(struct device *dev)
--

2.19.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#23 lore raw

PATCH 2/6 mdev: introduce device specific ops

In reply to Jason Wang

Currently, except for the create and remove. The rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. Follow the class id support by previous patch, this patch introduces device specific ops pointer inside parent ops which points to device specific ops (e.g vfio ops). This allows the future drivers like virtio-mdev to implement its own device specific ops.

---
 .../driver-api/vfio-mediated-device.rst       |  4 +-
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 15 +++---
 drivers/s390/cio/vfio_ccw_ops.c               | 15 ++++--
 drivers/s390/crypto/vfio_ap_ops.c             | 11 ++--
 drivers/vfio/mdev/vfio_mdev.c                 | 31 ++++++-----
 include/linux/mdev.h                          | 36 ++-----------
 include/linux/vfio_mdev.h                     | 53 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 17 +++---
 samples/vfio-mdev/mdpy.c                      | 17 +++---
 samples/vfio-mdev/mtty.c                      | 15 ++++--
 11 files changed, 138 insertions(+), 77 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +3 -1
index 0e052072e1d8..3ab00e48212f 100644
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization.
 Vendor drivers are expected to be fully asynchronous in this respect or
 provide their own internal resource protection.)
 
-The callbacks in the mdev_parent_ops structure are as follows:
+The device specific callbacks are referred through device_ops pointer
+in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops
+are as follows:
 
 * open: open callback of mediated device
 * close: close callback of mediated device
MAINTAINERS +1 -0
index b2326dece28e..89832b316500 100644
@@ -17075,6 +17075,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/vfio_mdev.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +9 -6
index 19d51a35f019..8ea86b1e69f1 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/debugfs.h>
 
 #include <linux/nospec.h>
@@ -1600,20 +1601,22 @@ static const struct attribute_group *intel_vgpu_groups[] = {
 	NULL,
 };
 
-static struct mdev_parent_ops intel_vgpu_ops = {
-	.mdev_attr_groups       = intel_vgpu_groups,
-	.create			= intel_vgpu_create,
-	.remove			= intel_vgpu_remove,
-
+static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {
 	.open			= intel_vgpu_open,
 	.release		= intel_vgpu_release,
-
 	.read			= intel_vgpu_read,
 	.write			= intel_vgpu_write,
 	.mmap			= intel_vgpu_mmap,
 	.ioctl			= intel_vgpu_ioctl,
 };
 
+static struct mdev_parent_ops intel_vgpu_ops = {
+	.mdev_attr_groups       = intel_vgpu_groups,
+	.create			= intel_vgpu_create,
+	.remove			= intel_vgpu_remove,
+	.device_ops	        = &intel_vfio_vgpu_ops,
+};
+
 static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
 {
 	struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +10 -5
index 246ff0f80944..02122bbc213e 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -574,11 +575,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,
 	}
 }
 
-static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
-	.owner			= THIS_MODULE,
-	.supported_type_groups  = mdev_type_groups,
-	.create			= vfio_ccw_mdev_create,
-	.remove			= vfio_ccw_mdev_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
 	.read			= vfio_ccw_mdev_read,
@@ -586,6 +583,14 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
 	.ioctl			= vfio_ccw_mdev_ioctl,
 };
 
+static const struct mdev_parent_ops vfio_ccw_mdev_ops = {
+	.owner			= THIS_MODULE,
+	.supported_type_groups  = mdev_type_groups,
+	.create			= vfio_ccw_mdev_create,
+	.remove			= vfio_ccw_mdev_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
 	return mdev_register_vfio_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +8 -3
index 7487fc39d2c5..4251becc7a6d 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/vfio_mdev.h>
 #include <asm/kvm.h>
 #include <asm/zcrypt.h>
 
@@ -1280,15 +1281,19 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open			= vfio_ap_mdev_open,
+	.release		= vfio_ap_mdev_release,
+	.ioctl			= vfio_ap_mdev_ioctl,
+};
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
 	.owner			= THIS_MODULE,
 	.supported_type_groups	= vfio_ap_mdev_type_groups,
 	.mdev_attr_groups	= vfio_ap_mdev_attr_groups,
 	.create			= vfio_ap_mdev_create,
 	.remove			= vfio_ap_mdev_remove,
-	.open			= vfio_ap_mdev_open,
-	.release		= vfio_ap_mdev_release,
-	.ioctl			= vfio_ap_mdev_ioctl,
+	.device_ops		= &vfio_mdev_ops,
 };
 
 int vfio_ap_mdev_register(void)
drivers/vfio/mdev/vfio_mdev.c +19 -12
index fd2a4d9a3f26..d23c9f58c84f 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 
 #include "mdev_private.h"
 
@@ -25,15 +26,16 @@ static int vfio_mdev_open(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 	int ret;
 
-	if (unlikely(!parent->ops->open))
+	if (unlikely(!ops->open))
 		return -EINVAL;
 
 	if (!try_module_get(THIS_MODULE))
 		return -ENODEV;
 
-	ret = parent->ops->open(mdev);
+	ret = ops->open(mdev);
 	if (ret)
 		module_put(THIS_MODULE);
 
@@ -44,9 +46,10 @@ static void vfio_mdev_release(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -56,11 +59,12 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->ioctl))
+	if (unlikely(!ops->ioctl))
 		return -EINVAL;
 
-	return parent->ops->ioctl(mdev, cmd, arg);
+	return ops->ioctl(mdev, cmd, arg);
 }
 
 static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
@@ -68,11 +72,12 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->read))
+	if (unlikely(!ops->read))
 		return -EINVAL;
 
-	return parent->ops->read(mdev, buf, count, ppos);
+	return ops->read(mdev, buf, count, ppos);
 }
 
 static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
@@ -80,22 +85,24 @@ static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->write))
+	if (unlikely(!ops->write))
 		return -EINVAL;
 
-	return parent->ops->write(mdev, buf, count, ppos);
+	return ops->write(mdev, buf, count, ppos);
 }
 
 static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)
 {
 	struct mdev_device *mdev = device_data;
 	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_parent_ops *ops = parent->ops->device_ops;
 
-	if (unlikely(!parent->ops->mmap))
+	if (unlikely(!ops->mmap))
 		return -EINVAL;
 
-	return parent->ops->mmap(mdev, vma);
+	return ops->mmap(mdev, vma);
 }
 
 static const struct vfio_device_ops vfio_mdev_dev_ops = {
include/linux/mdev.h +3 -33
index 3ebae310f599..fa167bcb81e1 100644
@@ -48,30 +48,8 @@ struct device *mdev_get_iommu_device(struct device *dev);
  *			@mdev: mdev_device device structure which is being
  *			       destroyed
  *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ * @device_ops:         Device specific emulation callback.
+ *
  * Parent device that support mediated device should be registered with mdev
  * module with mdev_parent_ops structure.
  **/
@@ -83,15 +61,7 @@ struct mdev_parent_ops {
 
 	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
 	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
+	const void *device_ops;
 };
 
 /* interface for exporting mdev supported type attributes */
include/linux/vfio_mdev.h new file +53 -0

53 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +11 -6
index 71a4469be85d..107cc30d0f45 100644
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/dma-buf.h>
 #include <linux/highmem.h>
@@ -1418,12 +1419,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mbochs_create,
-	.remove			= mbochs_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
 	.read			= mbochs_read,
@@ -1432,6 +1428,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mbochs_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mbochs_create,
+	.remove			= mbochs_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c +11 -6
index d3029dd27d91..2cd2018a53f9 100644
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <drm/drm_fourcc.h>
 #include "mdpy-defs.h"
@@ -725,12 +726,7 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
-static const struct mdev_parent_ops mdev_fops = {
-	.owner			= THIS_MODULE,
-	.mdev_attr_groups	= mdev_dev_groups,
-	.supported_type_groups	= mdev_type_groups,
-	.create			= mdpy_create,
-	.remove			= mdpy_remove,
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -739,6 +735,15 @@ static const struct mdev_parent_ops mdev_fops = {
 	.mmap			= mdpy_mmap,
 };
 
+static const struct mdev_parent_ops mdev_fops = {
+	.owner			= THIS_MODULE,
+	.mdev_attr_groups	= mdev_dev_groups,
+	.supported_type_groups	= mdev_type_groups,
+	.create			= mdpy_create,
+	.remove			= mdpy_remove,
+	.device_ops		= &vfio_mdev_ops,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c +10 -5
index 744c88a6b22c..e427425b5daf 100644
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/vfio_mdev.h>
 #include <linux/pci.h>
 #include <linux/serial.h>
 #include <uapi/linux/serial_reg.h>
@@ -1410,6 +1411,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_parent_ops vfio_mdev_ops = {
+	.open                   = mtty_open,
+	.release                = mtty_close,
+	.read                   = mtty_read,
+	.write                  = mtty_write,
+	.ioctl		        = mtty_ioctl,
+};
+
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
 	.dev_attr_groups        = mtty_dev_groups,
@@ -1417,11 +1426,7 @@ static const struct mdev_parent_ops mdev_fops = {
 	.supported_type_groups  = mdev_type_groups,
 	.create                 = mtty_create,
 	.remove			= mtty_remove,
-	.open                   = mtty_open,
-	.release                = mtty_close,
-	.read                   = mtty_read,
-	.write                  = mtty_write,
-	.ioctl		        = mtty_ioctl,
+	.device_ops             = &vfio_mdev_ops,
 };
 
 static void mtty_device_release(struct device *dev)
Signature · 1 line
2.19.1
author
#24 lore raw

PATCH 3/6 mdev: introduce virtio device and its device ops

In reply to Jason Wang

This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.

---
 drivers/vfio/mdev/mdev_core.c |   7 ++
 include/linux/mdev.h          |   4 +
 include/linux/virtio_mdev.h   | 144 ++++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 include/linux/virtio_mdev.h
drivers/vfio/mdev/mdev_core.c +7 -0
index a02c256a3514..6d39caf96222 100644
@@ -220,6 +220,13 @@ int mdev_register_vfio_device(struct device *dev,
 }
 EXPORT_SYMBOL(mdev_register_vfio_device);
 
+int mdev_register_virtio_device(struct device *dev,
+				const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VIRTIO);
+}
+EXPORT_SYMBOL(mdev_register_virtio_device);
+
 /*
  * mdev_unregister_device : Unregister a parent device
  * @dev: device structure representing parent device.
include/linux/mdev.h +4 -0
index fa167bcb81e1..1d061739021e 100644
@@ -109,6 +109,8 @@ extern struct bus_type mdev_bus_type;
 
 int mdev_register_vfio_device(struct device *dev,
 			      const struct mdev_parent_ops *ops);
+int mdev_register_virtio_device(struct device *dev,
+				const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -119,5 +121,7 @@ struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
 #define MDEV_ID_VFIO 1 /* VFIO device */
+#define MDEV_ID_VIRTIO 2 /* Virtio Device */
+#define MDEV_ID_VHOST 3 /* Vhost Device */
 
 #endif /* MDEV_H */
include/linux/virtio_mdev.h new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#25 lore raw

PATCH 3/6 mdev: introduce virtio device and its device ops

In reply to Jason Wang

This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.

---
 drivers/vfio/mdev/mdev_core.c |   7 ++
 include/linux/mdev.h          |   4 +
 include/linux/virtio_mdev.h   | 144 ++++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 include/linux/virtio_mdev.h
drivers/vfio/mdev/mdev_core.c +7 -0
index a02c256a3514..6d39caf96222 100644
@@ -220,6 +220,13 @@ int mdev_register_vfio_device(struct device *dev,
 }
 EXPORT_SYMBOL(mdev_register_vfio_device);
 
+int mdev_register_virtio_device(struct device *dev,
+				const struct mdev_parent_ops *ops)
+{
+	return mdev_register_device(dev, ops, MDEV_ID_VIRTIO);
+}
+EXPORT_SYMBOL(mdev_register_virtio_device);
+
 /*
  * mdev_unregister_device : Unregister a parent device
  * @dev: device structure representing parent device.
include/linux/mdev.h +4 -0
index fa167bcb81e1..1d061739021e 100644
@@ -109,6 +109,8 @@ extern struct bus_type mdev_bus_type;
 
 int mdev_register_vfio_device(struct device *dev,
 			      const struct mdev_parent_ops *ops);
+int mdev_register_virtio_device(struct device *dev,
+				const struct mdev_parent_ops *ops);
 void mdev_unregister_device(struct device *dev);
 
 int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
@@ -119,5 +121,7 @@ struct device *mdev_dev(struct mdev_device *mdev);
 struct mdev_device *mdev_from_dev(struct device *dev);
 
 #define MDEV_ID_VFIO 1 /* VFIO device */
+#define MDEV_ID_VIRTIO 2 /* Virtio Device */
+#define MDEV_ID_VHOST 3 /* Vhost Device */
 
 #endif /* MDEV_H */
include/linux/virtio_mdev.h new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#26 lore raw

PATCH 4/6 virtio: introduce a mdev based transport

In reply to Jason Wang

This patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a new virtio-mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.

---
 MAINTAINERS                     |   1 +
 drivers/vfio/mdev/Kconfig       |   7 +
 drivers/vfio/mdev/Makefile      |   1 +
 drivers/vfio/mdev/virtio_mdev.c | 416 ++++++++++++++++++++++++++++++++
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
MAINTAINERS +1 -0
index 89832b316500..820ec250cc52 100644
@@ -17202,6 +17202,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	drivers/vfio/mdev/virtio_mdev.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/Kconfig +7 -0
index 5da27f2100f9..c488c31fc137 100644
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile +1 -0
index 101516fdf375..99d31e29c23e 100644
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/vfio/mdev/virtio_mdev.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
2.19.1
#27 lore raw

RE: [PATCH 4/6] virtio: introduce a mdev based transport

Quoted 110 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 4/6] virtio: introduce a mdev based transport

This patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a new virtio- mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.

---
 MAINTAINERS                     |   1 +
 drivers/vfio/mdev/Kconfig       |   7 +
 drivers/vfio/mdev/Makefile      |   1 +
 drivers/vfio/mdev/virtio_mdev.c | 416 ++++++++++++++++++++++++++++++++
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
MAINTAINERS +1 -0
index 89832b316500..820ec250cc52 100644
@@ -17202,6 +17202,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	drivers/vfio/mdev/virtio_mdev.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/Kconfig index renamed from drivers/vfio/mdev/Kconfig +0 -0

5da27f2100f9..c488c31fc137 100644

drivers/vfio/mdev/Kconfig +7 -0
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile index renamed from drivers/vfio/mdev/Makefile +0 -0

101516fdf375..99d31e29c23e 100644

drivers/vfio/mdev/Makefile +1 -0
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/vfio/mdev/virtio_mdev.c new file +25 -0
new file mode 100644 index 000000000000..919a082adc9c
@@ -0,0 +1,416 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VIRTIO based driver for Mediated device
+ *
+ * Copyright (c) 2019, Red Hat. All rights reserved.
+ *     Author: Jason Wang <[email protected]>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/uuid.h>
+#include <linux/mdev.h>
+#include <linux/virtio_mdev.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.h>
+#include "mdev_private.h"
+
+#define DRIVER_VERSION  "0.1"
+#define DRIVER_AUTHOR   "Red Hat Corporation"
+#define DRIVER_DESC     "VIRTIO based driver for Mediated device"

drivers/vfio/mdev/virtio_mdev.c line 35

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+
+#define to_virtio_mdev_device(dev) \
+	container_of(dev, struct virtio_mdev_device, vdev)
+
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;

Every lock must need a comment to describe what it locks.
I don't see this lock is used in this patch. Please introduce in the patch that uses it.

Quoted 114 lines
drivers/vfio/mdev/virtio_mdev.c new file +30 -0
+	spinlock_t lock;
+};
+
+struct virtio_mdev_vq_info {
+	/* the actual virtqueue */
+	struct virtqueue *vq;
+
+	/* the list node for the virtqueues list */
+	struct list_head node;
+};
+
+static struct mdev_device *vm_get_mdev(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return mdev;
+}
+
+static const struct virtio_mdev_parent_ops *mdev_get_parent_ops(struct
+mdev_device *mdev) {
+	struct mdev_parent *parent = mdev->parent;
+
+	return parent->ops->device_ops;
+}
+
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
+			    void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	ops->get_config(mdev, offset, buf, len); }
+
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
+			    const void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+
+	ops->set_config(mdev, offset, buf, len); }
+
+static u32 virtio_mdev_generation(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_generation(mdev);
+}
+
+static u8 virtio_mdev_get_status(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	return ops->get_status(mdev);
+}
+
+static void virtio_mdev_set_status(struct virtio_device *vdev, u8
+status) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, status);
+}
+
+static void virtio_mdev_reset(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, 0);
+}
+
+static bool virtio_mdev_notify(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +27 -0
+
+	ops->kick_vq(mdev, vq->index);
+
+	return true;
+}
+
+static irqreturn_t virtio_mdev_config_cb(void *private) {
+	struct virtio_mdev_device *vm_dev = private;
+
+	virtio_config_changed(&vm_dev->vdev);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t virtio_mdev_virtqueue_cb(void *private) {
+	struct virtio_mdev_vq_info *info = private;
+
+	return vring_interrupt(0, info->vq);
+}
+
+static struct virtqueue *
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,
+		     void (*callback)(struct virtqueue *vq),
+		     const char *name, bool ctx)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+	struct virtio_mdev_vq_info *info;
+	struct virtio_mdev_callback cb;
+	struct virtqueue *vq;
+	u32 align, num;
+	u64 desc_addr, driver_addr, device_addr;
+	int err;

drivers/vfio/mdev/virtio_mdev.c line 161

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+
+	if (!name)
+		return NULL;
+
+	/* Queue shouldn't already be set up. */
+	if (ops->get_vq_ready(mdev, index)) {
+		err = -ENOENT;
+		goto error_available;
+	}
+

No need for a goto, to single return done later.
Just do

	if (ops->get_vq_ready(mdev, index))
		return -ENOENT;

drivers/vfio/mdev/virtio_mdev.c line 168

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+	/* Allocate and fill out our active queue description */
+	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	if (!info) {
+		err = -ENOMEM;
+		goto error_kmalloc;
+	}
+

Similar to above one.

Quoted 194 lines
drivers/vfio/mdev/virtio_mdev.c new file +55 -0
+	num = ops->get_queue_max(mdev);
+	if (num == 0) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}
+
+	/* Create the vring */
+	align = ops->get_vq_align(mdev);
+	vq = vring_create_virtqueue(index, num, align, vdev,
+				    true, true, ctx,
+				    virtio_mdev_notify, callback, name);
+	if (!vq) {
+		err = -ENOMEM;
+		goto error_new_virtqueue;
+	}
+
+	/* Setup virtqueue callback */
+	cb.callback = virtio_mdev_virtqueue_cb;
+	cb.private = info;
+	ops->set_vq_cb(mdev, index, &cb);
+	ops->set_vq_num(mdev, index, virtqueue_get_vring_size(vq));
+
+	desc_addr = virtqueue_get_desc_addr(vq);
+	driver_addr = virtqueue_get_avail_addr(vq);
+	device_addr = virtqueue_get_used_addr(vq);
+
+	if (ops->set_vq_address(mdev, index,
+				desc_addr, driver_addr,
+				device_addr)) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
+	ops->set_vq_ready(mdev, index, 1);
+
+	vq->priv = info;
+	info->vq = vq;
+
+	return vq;
+
+err_vq:
+	vring_del_virtqueue(vq);
+error_new_virtqueue:
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+	kfree(info);
+error_kmalloc:
+error_available:
+	return ERR_PTR(err);
+
+}
+
+static void virtio_mdev_del_vq(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +29 -0
+	struct virtio_mdev_vq_info *info = vq->priv;
+	unsigned int index = vq->index;
+
+	/* Select and deactivate the queue */
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+
+	vring_del_virtqueue(vq);
+
+	kfree(info);
+}
+
+static void virtio_mdev_del_vqs(struct virtio_device *vdev) {
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_mdev_del_vq(vq);
+}
+
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+				struct virtqueue *vqs[],
+				vq_callback_t *callbacks[],
+				const char * const names[],
+				const bool *ctx,
+				struct irq_affinity *desc)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +38 -0
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);
+	if (!vm_dev->vqs)
+		return -ENOMEM;
+
+	for (i = 0; i < nvqs; ++i) {
+		if (!names[i]) {
+			vqs[i] = NULL;
+			continue;
+		}
+
+		vqs[i] = virtio_mdev_setup_vq(vdev, queue_idx++,
+					      callbacks[i], names[i], ctx ?
+					      ctx[i] : false);
+		if (IS_ERR(vqs[i])) {
+			err = PTR_ERR(vqs[i]);
+			goto err_setup_vq;
+		}
+	}
+
+	cb.callback = virtio_mdev_config_cb;
+	cb.private = vm_dev;
+	ops->set_config_cb(mdev, &cb);
+
+	return 0;
+
+err_setup_vq:
+	kfree(vm_dev->vqs);
+	virtio_mdev_del_vqs(vdev);
+	return err;
+}
+
+static u64 virtio_mdev_get_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_features(mdev);
+}
+
+static int virtio_mdev_finalize_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +39 -0
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	return ops->set_features(mdev, vdev->features); }
+
+static const char *virtio_mdev_bus_name(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return dev_name(&mdev->dev);
+}
+
+static const struct virtio_config_ops virtio_mdev_config_ops = {
+	.get		= virtio_mdev_get,
+	.set		= virtio_mdev_set,
+	.generation	= virtio_mdev_generation,
+	.get_status	= virtio_mdev_get_status,
+	.set_status	= virtio_mdev_set_status,
+	.reset		= virtio_mdev_reset,
+	.find_vqs	= virtio_mdev_find_vqs,
+	.del_vqs	= virtio_mdev_del_vqs,
+	.get_features	= virtio_mdev_get_features,
+	.finalize_features = virtio_mdev_finalize_features,
+	.bus_name	= virtio_mdev_bus_name,
+};
+
+static void virtio_mdev_release_dev(struct device *_d) {
+	struct virtio_device *vdev =
+	       container_of(_d, struct virtio_device, dev);
+	struct virtio_mdev_device *vm_dev =
+	       container_of(vdev, struct virtio_mdev_device, vdev);
+
+	devm_kfree(_d, vm_dev);
+}
+
+static int virtio_mdev_probe(struct device *dev) {
+	struct mdev_device *mdev = to_mdev_device(dev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +21 -0
+	struct virtio_mdev_device *vm_dev;
+	int rc;
+
+	vm_dev = devm_kzalloc(dev, sizeof(*vm_dev), GFP_KERNEL);
+	if (!vm_dev)
+		return -ENOMEM;
+
+	vm_dev->vdev.dev.parent = dev;
+	vm_dev->vdev.dev.release = virtio_mdev_release_dev;
+	vm_dev->vdev.config = &virtio_mdev_config_ops;
+	vm_dev->mdev = mdev;
+	vm_dev->vqs = NULL;
+	spin_lock_init(&vm_dev->lock);
+
+	vm_dev->version = ops->get_version(mdev);
+	if (vm_dev->version != 1) {
+		dev_err(dev, "Version %ld not supported!\n",
+			vm_dev->version);
+		return -ENXIO;
+	}
+

drivers/vfio/mdev/virtio_mdev.c line 375

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+	vm_dev->vdev.id.device = ops->get_device_id(mdev);
+	if (vm_dev->vdev.id.device == 0)
+		return -ENODEV;
+
+	vm_dev->vdev.id.vendor = ops->get_vendor_id(mdev);
+	rc = register_virtio_device(&vm_dev->vdev);
+	if (rc)
+		put_device(dev);
+
+	dev_set_drvdata(dev, vm_dev);

No need to set drvdata when there is error returned from register_virtio_device().

drivers/vfio/mdev/virtio_mdev.c line 378

Quoted 3 lines
drivers/vfio/mdev/virtio_mdev.c new file +3 -0
+
+	return rc;
+

Extra line not needed.

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+}
+
+static void virtio_mdev_remove(struct device *dev) {
+	struct virtio_mdev_device *vm_dev = dev_get_drvdata(dev);
+
+	unregister_virtio_device(&vm_dev->vdev);
+}

drivers/vfio/mdev/virtio_mdev.c line 396

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VIRTIO },
+	{ 0 },
+};
+
+static struct mdev_driver virtio_mdev_driver = {
+	.name	= "virtio_mdev",
+	.probe	= virtio_mdev_probe,
+	.remove	= virtio_mdev_remove,

No need for tab, just do single white space.

Quoted 19 lines
drivers/vfio/mdev/virtio_mdev.c new file +17 -1
+	.id_table = id_table,
+};
+
+static int __init virtio_mdev_init(void) {
+	return mdev_register_driver(&virtio_mdev_driver, THIS_MODULE); }
+
+static void __exit virtio_mdev_exit(void) {
+	mdev_unregister_driver(&virtio_mdev_driver);
+}
+
+module_init(virtio_mdev_init)
+module_exit(virtio_mdev_exit)
+
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
--

2.19.1

author
#28 lore raw

Re: [PATCH 4/6] virtio: introduce a mdev based transport

Quoted 113 lines · Parav Pandit
Quoted 113 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 4/6] virtio: introduce a mdev based transport

This patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a new virtio- mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.

---
 MAINTAINERS                     |   1 +
 drivers/vfio/mdev/Kconfig       |   7 +
 drivers/vfio/mdev/Makefile      |   1 +
 drivers/vfio/mdev/virtio_mdev.c | 416 ++++++++++++++++++++++++++++++++
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
MAINTAINERS +1 -0
index 89832b316500..820ec250cc52 100644
@@ -17202,6 +17202,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	drivers/vfio/mdev/virtio_mdev.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/Kconfig index renamed from drivers/vfio/mdev/Kconfig +0 -0

5da27f2100f9..c488c31fc137 100644

drivers/vfio/mdev/Kconfig +7 -0
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile index renamed from drivers/vfio/mdev/Makefile +0 -0

101516fdf375..99d31e29c23e 100644

drivers/vfio/mdev/Makefile +1 -0
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/vfio/mdev/virtio_mdev.c new file +29 -0
new file mode 100644 index 000000000000..919a082adc9c
@@ -0,0 +1,416 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VIRTIO based driver for Mediated device
+ *
+ * Copyright (c) 2019, Red Hat. All rights reserved.
+ *     Author: Jason Wang <[email protected]>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/uuid.h>
+#include <linux/mdev.h>
+#include <linux/virtio_mdev.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.h>
+#include "mdev_private.h"
+
+#define DRIVER_VERSION  "0.1"
+#define DRIVER_AUTHOR   "Red Hat Corporation"
+#define DRIVER_DESC     "VIRTIO based driver for Mediated device"
+
+#define to_virtio_mdev_device(dev) \
+	container_of(dev, struct virtio_mdev_device, vdev)
+
Quoted 8 lines

drivers/vfio/mdev/virtio_mdev.c line 35

Quoted 6 lines
drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;

Every lock must need a comment to describe what it locks.
I don't see this lock is used in this patch. Please introduce in the patch that uses it.

Actually, it is used to sync the virtqueue list add and remove, but the logic is missed in this patch.

Will fix it in next version.

Quoted 126 lines
Quoted 114 lines
drivers/vfio/mdev/virtio_mdev.c new file +30 -0
+	spinlock_t lock;
+};
+
+struct virtio_mdev_vq_info {
+	/* the actual virtqueue */
+	struct virtqueue *vq;
+
+	/* the list node for the virtqueues list */
+	struct list_head node;
+};
+
+static struct mdev_device *vm_get_mdev(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return mdev;
+}
+
+static const struct virtio_mdev_parent_ops *mdev_get_parent_ops(struct
+mdev_device *mdev) {
+	struct mdev_parent *parent = mdev->parent;
+
+	return parent->ops->device_ops;
+}
+
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
+			    void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	ops->get_config(mdev, offset, buf, len); }
+
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
+			    const void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+
+	ops->set_config(mdev, offset, buf, len); }
+
+static u32 virtio_mdev_generation(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_generation(mdev);
+}
+
+static u8 virtio_mdev_get_status(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	return ops->get_status(mdev);
+}
+
+static void virtio_mdev_set_status(struct virtio_device *vdev, u8
+status) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, status);
+}
+
+static void virtio_mdev_reset(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, 0);
+}
+
+static bool virtio_mdev_notify(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +27 -0
+
+	ops->kick_vq(mdev, vq->index);
+
+	return true;
+}
+
+static irqreturn_t virtio_mdev_config_cb(void *private) {
+	struct virtio_mdev_device *vm_dev = private;
+
+	virtio_config_changed(&vm_dev->vdev);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t virtio_mdev_virtqueue_cb(void *private) {
+	struct virtio_mdev_vq_info *info = private;
+
+	return vring_interrupt(0, info->vq);
+}
+
+static struct virtqueue *
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,
+		     void (*callback)(struct virtqueue *vq),
+		     const char *name, bool ctx)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+	struct virtio_mdev_vq_info *info;
+	struct virtio_mdev_callback cb;
+	struct virtqueue *vq;
+	u32 align, num;
+	u64 desc_addr, driver_addr, device_addr;
+	int err;

drivers/vfio/mdev/virtio_mdev.c line 161

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+
+	if (!name)
+		return NULL;
+
+	/* Queue shouldn't already be set up. */
+	if (ops->get_vq_ready(mdev, index)) {
+		err = -ENOENT;
+		goto error_available;
+	}
+

No need for a goto, to single return done later.
Just do

Quoted 2 lines
	if (ops->get_vq_ready(mdev, index))
		return -ENOENT;

Ok, will fix.

Quoted 9 lines

drivers/vfio/mdev/virtio_mdev.c line 168

Quoted 8 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+	/* Allocate and fill out our active queue description */
+	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	if (!info) {
+		err = -ENOMEM;
+		goto error_kmalloc;
+	}
+

Similar to above one.

Ok.

Quoted 198 lines
Quoted 198 lines
drivers/vfio/mdev/virtio_mdev.c new file +55 -0
+	num = ops->get_queue_max(mdev);
+	if (num == 0) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}
+
+	/* Create the vring */
+	align = ops->get_vq_align(mdev);
+	vq = vring_create_virtqueue(index, num, align, vdev,
+				    true, true, ctx,
+				    virtio_mdev_notify, callback, name);
+	if (!vq) {
+		err = -ENOMEM;
+		goto error_new_virtqueue;
+	}
+
+	/* Setup virtqueue callback */
+	cb.callback = virtio_mdev_virtqueue_cb;
+	cb.private = info;
+	ops->set_vq_cb(mdev, index, &cb);
+	ops->set_vq_num(mdev, index, virtqueue_get_vring_size(vq));
+
+	desc_addr = virtqueue_get_desc_addr(vq);
+	driver_addr = virtqueue_get_avail_addr(vq);
+	device_addr = virtqueue_get_used_addr(vq);
+
+	if (ops->set_vq_address(mdev, index,
+				desc_addr, driver_addr,
+				device_addr)) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
+	ops->set_vq_ready(mdev, index, 1);
+
+	vq->priv = info;
+	info->vq = vq;
+
+	return vq;
+
+err_vq:
+	vring_del_virtqueue(vq);
+error_new_virtqueue:
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+	kfree(info);
+error_kmalloc:
+error_available:
+	return ERR_PTR(err);
+
+}
+
+static void virtio_mdev_del_vq(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +29 -0
+	struct virtio_mdev_vq_info *info = vq->priv;
+	unsigned int index = vq->index;
+
+	/* Select and deactivate the queue */
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+
+	vring_del_virtqueue(vq);
+
+	kfree(info);
+}
+
+static void virtio_mdev_del_vqs(struct virtio_device *vdev) {
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_mdev_del_vq(vq);
+}
+
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+				struct virtqueue *vqs[],
+				vq_callback_t *callbacks[],
+				const char * const names[],
+				const bool *ctx,
+				struct irq_affinity *desc)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +38 -0
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);
+	if (!vm_dev->vqs)
+		return -ENOMEM;
+
+	for (i = 0; i < nvqs; ++i) {
+		if (!names[i]) {
+			vqs[i] = NULL;
+			continue;
+		}
+
+		vqs[i] = virtio_mdev_setup_vq(vdev, queue_idx++,
+					      callbacks[i], names[i], ctx ?
+					      ctx[i] : false);
+		if (IS_ERR(vqs[i])) {
+			err = PTR_ERR(vqs[i]);
+			goto err_setup_vq;
+		}
+	}
+
+	cb.callback = virtio_mdev_config_cb;
+	cb.private = vm_dev;
+	ops->set_config_cb(mdev, &cb);
+
+	return 0;
+
+err_setup_vq:
+	kfree(vm_dev->vqs);
+	virtio_mdev_del_vqs(vdev);
+	return err;
+}
+
+static u64 virtio_mdev_get_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_features(mdev);
+}
+
+static int virtio_mdev_finalize_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +39 -0
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	return ops->set_features(mdev, vdev->features); }
+
+static const char *virtio_mdev_bus_name(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return dev_name(&mdev->dev);
+}
+
+static const struct virtio_config_ops virtio_mdev_config_ops = {
+	.get		= virtio_mdev_get,
+	.set		= virtio_mdev_set,
+	.generation	= virtio_mdev_generation,
+	.get_status	= virtio_mdev_get_status,
+	.set_status	= virtio_mdev_set_status,
+	.reset		= virtio_mdev_reset,
+	.find_vqs	= virtio_mdev_find_vqs,
+	.del_vqs	= virtio_mdev_del_vqs,
+	.get_features	= virtio_mdev_get_features,
+	.finalize_features = virtio_mdev_finalize_features,
+	.bus_name	= virtio_mdev_bus_name,
+};
+
+static void virtio_mdev_release_dev(struct device *_d) {
+	struct virtio_device *vdev =
+	       container_of(_d, struct virtio_device, dev);
+	struct virtio_mdev_device *vm_dev =
+	       container_of(vdev, struct virtio_mdev_device, vdev);
+
+	devm_kfree(_d, vm_dev);
+}
+
+static int virtio_mdev_probe(struct device *dev) {
+	struct mdev_device *mdev = to_mdev_device(dev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +24 -0
+	struct virtio_mdev_device *vm_dev;
+	int rc;
+
+	vm_dev = devm_kzalloc(dev, sizeof(*vm_dev), GFP_KERNEL);
+	if (!vm_dev)
+		return -ENOMEM;
+
+	vm_dev->vdev.dev.parent = dev;
+	vm_dev->vdev.dev.release = virtio_mdev_release_dev;
+	vm_dev->vdev.config = &virtio_mdev_config_ops;
+	vm_dev->mdev = mdev;
+	vm_dev->vqs = NULL;
+	spin_lock_init(&vm_dev->lock);
+
+	vm_dev->version = ops->get_version(mdev);
+	if (vm_dev->version != 1) {
+		dev_err(dev, "Version %ld not supported!\n",
+			vm_dev->version);
+		return -ENXIO;
+	}
+
+	vm_dev->vdev.id.device = ops->get_device_id(mdev);
+	if (vm_dev->vdev.id.device == 0)
+		return -ENODEV;
Quoted 9 lines

drivers/vfio/mdev/virtio_mdev.c line 375

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	vm_dev->vdev.id.vendor = ops->get_vendor_id(mdev);
+	rc = register_virtio_device(&vm_dev->vdev);
+	if (rc)
+		put_device(dev);
+
+	dev_set_drvdata(dev, vm_dev);

No need to set drvdata when there is error returned from register_virtio_device().

Fixed in V2.

Quoted 5 lines

drivers/vfio/mdev/virtio_mdev.c line 378

Quoted 3 lines
drivers/vfio/mdev/virtio_mdev.c new file +3 -0
+
+	return rc;
+

Extra line not needed.

Quoted 1 line

+}

Fixed.

Quoted 9 lines
Quoted 9 lines
drivers/vfio/mdev/virtio_mdev.c new file +9 -0
+
+static void virtio_mdev_remove(struct device *dev) {
+	struct virtio_mdev_device *vm_dev = dev_get_drvdata(dev);
+
+	unregister_virtio_device(&vm_dev->vdev);
+}
+
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VIRTIO },
Quoted 8 lines

drivers/vfio/mdev/virtio_mdev.c line 396

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+	{ 0 },
+};
+
+static struct mdev_driver virtio_mdev_driver = {
+	.name	= "virtio_mdev",
+	.probe	= virtio_mdev_probe,
+	.remove	= virtio_mdev_remove,

No need for tab, just do single white space.

Yes, fixed.

Thanks

Quoted 19 lines
Quoted 19 lines
drivers/vfio/mdev/virtio_mdev.c new file +17 -1
+	.id_table = id_table,
+};
+
+static int __init virtio_mdev_init(void) {
+	return mdev_register_driver(&virtio_mdev_driver, THIS_MODULE); }
+
+static void __exit virtio_mdev_exit(void) {
+	mdev_unregister_driver(&virtio_mdev_driver);
+}
+
+module_init(virtio_mdev_init)
+module_exit(virtio_mdev_exit)
+
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
--

2.19.1

author
#29 lore raw

Re: [PATCH 4/6] virtio: introduce a mdev based transport

In reply to Parav Pandit
Quoted 113 lines · Parav Pandit
Quoted 113 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Monday, September 23, 2019 8:03 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; Jason Wang <[email protected]>
Subject: [PATCH 4/6] virtio: introduce a mdev based transport

This patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a new virtio- mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.

---
 MAINTAINERS                     |   1 +
 drivers/vfio/mdev/Kconfig       |   7 +
 drivers/vfio/mdev/Makefile      |   1 +
 drivers/vfio/mdev/virtio_mdev.c | 416 ++++++++++++++++++++++++++++++++
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
MAINTAINERS +1 -0
index 89832b316500..820ec250cc52 100644
@@ -17202,6 +17202,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	drivers/vfio/mdev/virtio_mdev.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/Kconfig index renamed from drivers/vfio/mdev/Kconfig +0 -0

5da27f2100f9..c488c31fc137 100644

drivers/vfio/mdev/Kconfig +7 -0
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile index renamed from drivers/vfio/mdev/Makefile +0 -0

101516fdf375..99d31e29c23e 100644

drivers/vfio/mdev/Makefile +1 -0
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/vfio/mdev/virtio_mdev.c new file +29 -0
new file mode 100644 index 000000000000..919a082adc9c
@@ -0,0 +1,416 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VIRTIO based driver for Mediated device
+ *
+ * Copyright (c) 2019, Red Hat. All rights reserved.
+ *     Author: Jason Wang <[email protected]>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/uuid.h>
+#include <linux/mdev.h>
+#include <linux/virtio_mdev.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_ring.h>
+#include "mdev_private.h"
+
+#define DRIVER_VERSION  "0.1"
+#define DRIVER_AUTHOR   "Red Hat Corporation"
+#define DRIVER_DESC     "VIRTIO based driver for Mediated device"
+
+#define to_virtio_mdev_device(dev) \
+	container_of(dev, struct virtio_mdev_device, vdev)
+
Quoted 8 lines

drivers/vfio/mdev/virtio_mdev.c line 35

Quoted 6 lines
drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;

Every lock must need a comment to describe what it locks.
I don't see this lock is used in this patch. Please introduce in the patch that uses it.

Actually, it is used to sync the virtqueue list add and remove, but the logic is missed in this patch.

Will fix it in next version.

Quoted 126 lines
Quoted 114 lines
drivers/vfio/mdev/virtio_mdev.c new file +30 -0
+	spinlock_t lock;
+};
+
+struct virtio_mdev_vq_info {
+	/* the actual virtqueue */
+	struct virtqueue *vq;
+
+	/* the list node for the virtqueues list */
+	struct list_head node;
+};
+
+static struct mdev_device *vm_get_mdev(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return mdev;
+}
+
+static const struct virtio_mdev_parent_ops *mdev_get_parent_ops(struct
+mdev_device *mdev) {
+	struct mdev_parent *parent = mdev->parent;
+
+	return parent->ops->device_ops;
+}
+
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
+			    void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	ops->get_config(mdev, offset, buf, len); }
+
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
+			    const void *buf, unsigned len)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+
+	ops->set_config(mdev, offset, buf, len); }
+
+static u32 virtio_mdev_generation(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_generation(mdev);
+}
+
+static u8 virtio_mdev_get_status(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +8 -0
+
+	return ops->get_status(mdev);
+}
+
+static void virtio_mdev_set_status(struct virtio_device *vdev, u8
+status) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, status);
+}
+
+static void virtio_mdev_reset(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->set_status(mdev, 0);
+}
+
+static bool virtio_mdev_notify(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +27 -0
+
+	ops->kick_vq(mdev, vq->index);
+
+	return true;
+}
+
+static irqreturn_t virtio_mdev_config_cb(void *private) {
+	struct virtio_mdev_device *vm_dev = private;
+
+	virtio_config_changed(&vm_dev->vdev);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t virtio_mdev_virtqueue_cb(void *private) {
+	struct virtio_mdev_vq_info *info = private;
+
+	return vring_interrupt(0, info->vq);
+}
+
+static struct virtqueue *
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,
+		     void (*callback)(struct virtqueue *vq),
+		     const char *name, bool ctx)
+{
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +6 -0
+	struct virtio_mdev_vq_info *info;
+	struct virtio_mdev_callback cb;
+	struct virtqueue *vq;
+	u32 align, num;
+	u64 desc_addr, driver_addr, device_addr;
+	int err;

drivers/vfio/mdev/virtio_mdev.c line 161

Quoted 10 lines
drivers/vfio/mdev/virtio_mdev.c new file +10 -0
+
+	if (!name)
+		return NULL;
+
+	/* Queue shouldn't already be set up. */
+	if (ops->get_vq_ready(mdev, index)) {
+		err = -ENOENT;
+		goto error_available;
+	}
+

No need for a goto, to single return done later.
Just do

Quoted 2 lines
	if (ops->get_vq_ready(mdev, index))
		return -ENOENT;

Ok, will fix.

Quoted 9 lines

drivers/vfio/mdev/virtio_mdev.c line 168

Quoted 8 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+	/* Allocate and fill out our active queue description */
+	info = kmalloc(sizeof(*info), GFP_KERNEL);
+	if (!info) {
+		err = -ENOMEM;
+		goto error_kmalloc;
+	}
+

Similar to above one.

Ok.

Quoted 198 lines
Quoted 198 lines
drivers/vfio/mdev/virtio_mdev.c new file +55 -0
+	num = ops->get_queue_max(mdev);
+	if (num == 0) {
+		err = -ENOENT;
+		goto error_new_virtqueue;
+	}
+
+	/* Create the vring */
+	align = ops->get_vq_align(mdev);
+	vq = vring_create_virtqueue(index, num, align, vdev,
+				    true, true, ctx,
+				    virtio_mdev_notify, callback, name);
+	if (!vq) {
+		err = -ENOMEM;
+		goto error_new_virtqueue;
+	}
+
+	/* Setup virtqueue callback */
+	cb.callback = virtio_mdev_virtqueue_cb;
+	cb.private = info;
+	ops->set_vq_cb(mdev, index, &cb);
+	ops->set_vq_num(mdev, index, virtqueue_get_vring_size(vq));
+
+	desc_addr = virtqueue_get_desc_addr(vq);
+	driver_addr = virtqueue_get_avail_addr(vq);
+	device_addr = virtqueue_get_used_addr(vq);
+
+	if (ops->set_vq_address(mdev, index,
+				desc_addr, driver_addr,
+				device_addr)) {
+		err = -EINVAL;
+		goto err_vq;
+	}
+
+	ops->set_vq_ready(mdev, index, 1);
+
+	vq->priv = info;
+	info->vq = vq;
+
+	return vq;
+
+err_vq:
+	vring_del_virtqueue(vq);
+error_new_virtqueue:
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+	kfree(info);
+error_kmalloc:
+error_available:
+	return ERR_PTR(err);
+
+}
+
+static void virtio_mdev_del_vq(struct virtqueue *vq) {
+	struct mdev_device *mdev = vm_get_mdev(vq->vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +29 -0
+	struct virtio_mdev_vq_info *info = vq->priv;
+	unsigned int index = vq->index;
+
+	/* Select and deactivate the queue */
+	ops->set_vq_ready(mdev, index, 0);
+	WARN_ON(ops->get_vq_ready(mdev, index));
+
+	vring_del_virtqueue(vq);
+
+	kfree(info);
+}
+
+static void virtio_mdev_del_vqs(struct virtio_device *vdev) {
+	struct virtqueue *vq, *n;
+
+	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
+		virtio_mdev_del_vq(vq);
+}
+
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,
+				struct virtqueue *vqs[],
+				vq_callback_t *callbacks[],
+				const char * const names[],
+				const bool *ctx,
+				struct irq_affinity *desc)
+{
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +38 -0
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);
+	if (!vm_dev->vqs)
+		return -ENOMEM;
+
+	for (i = 0; i < nvqs; ++i) {
+		if (!names[i]) {
+			vqs[i] = NULL;
+			continue;
+		}
+
+		vqs[i] = virtio_mdev_setup_vq(vdev, queue_idx++,
+					      callbacks[i], names[i], ctx ?
+					      ctx[i] : false);
+		if (IS_ERR(vqs[i])) {
+			err = PTR_ERR(vqs[i]);
+			goto err_setup_vq;
+		}
+	}
+
+	cb.callback = virtio_mdev_config_cb;
+	cb.private = vm_dev;
+	ops->set_config_cb(mdev, &cb);
+
+	return 0;
+
+err_setup_vq:
+	kfree(vm_dev->vqs);
+	virtio_mdev_del_vqs(vdev);
+	return err;
+}
+
+static u64 virtio_mdev_get_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	return ops->get_features(mdev);
+}
+
+static int virtio_mdev_finalize_features(struct virtio_device *vdev) {
+	struct mdev_device *mdev = vm_get_mdev(vdev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +39 -0
+
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	return ops->set_features(mdev, vdev->features); }
+
+static const char *virtio_mdev_bus_name(struct virtio_device *vdev) {
+	struct virtio_mdev_device *vm_dev = to_virtio_mdev_device(vdev);
+	struct mdev_device *mdev = vm_dev->mdev;
+
+	return dev_name(&mdev->dev);
+}
+
+static const struct virtio_config_ops virtio_mdev_config_ops = {
+	.get		= virtio_mdev_get,
+	.set		= virtio_mdev_set,
+	.generation	= virtio_mdev_generation,
+	.get_status	= virtio_mdev_get_status,
+	.set_status	= virtio_mdev_set_status,
+	.reset		= virtio_mdev_reset,
+	.find_vqs	= virtio_mdev_find_vqs,
+	.del_vqs	= virtio_mdev_del_vqs,
+	.get_features	= virtio_mdev_get_features,
+	.finalize_features = virtio_mdev_finalize_features,
+	.bus_name	= virtio_mdev_bus_name,
+};
+
+static void virtio_mdev_release_dev(struct device *_d) {
+	struct virtio_device *vdev =
+	       container_of(_d, struct virtio_device, dev);
+	struct virtio_mdev_device *vm_dev =
+	       container_of(vdev, struct virtio_mdev_device, vdev);
+
+	devm_kfree(_d, vm_dev);
+}
+
+static int virtio_mdev_probe(struct device *dev) {
+	struct mdev_device *mdev = to_mdev_device(dev);
+	const struct virtio_mdev_parent_ops *ops =

mdev_get_parent_ops(mdev);

drivers/vfio/mdev/virtio_mdev.c new file +24 -0
+	struct virtio_mdev_device *vm_dev;
+	int rc;
+
+	vm_dev = devm_kzalloc(dev, sizeof(*vm_dev), GFP_KERNEL);
+	if (!vm_dev)
+		return -ENOMEM;
+
+	vm_dev->vdev.dev.parent = dev;
+	vm_dev->vdev.dev.release = virtio_mdev_release_dev;
+	vm_dev->vdev.config = &virtio_mdev_config_ops;
+	vm_dev->mdev = mdev;
+	vm_dev->vqs = NULL;
+	spin_lock_init(&vm_dev->lock);
+
+	vm_dev->version = ops->get_version(mdev);
+	if (vm_dev->version != 1) {
+		dev_err(dev, "Version %ld not supported!\n",
+			vm_dev->version);
+		return -ENXIO;
+	}
+
+	vm_dev->vdev.id.device = ops->get_device_id(mdev);
+	if (vm_dev->vdev.id.device == 0)
+		return -ENODEV;
Quoted 9 lines

drivers/vfio/mdev/virtio_mdev.c line 375

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+
+	vm_dev->vdev.id.vendor = ops->get_vendor_id(mdev);
+	rc = register_virtio_device(&vm_dev->vdev);
+	if (rc)
+		put_device(dev);
+
+	dev_set_drvdata(dev, vm_dev);

No need to set drvdata when there is error returned from register_virtio_device().

Fixed in V2.

Quoted 5 lines

drivers/vfio/mdev/virtio_mdev.c line 378

Quoted 3 lines
drivers/vfio/mdev/virtio_mdev.c new file +3 -0
+
+	return rc;
+

Extra line not needed.

Quoted 1 line

+}

Fixed.

Quoted 9 lines
Quoted 9 lines
drivers/vfio/mdev/virtio_mdev.c new file +9 -0
+
+static void virtio_mdev_remove(struct device *dev) {
+	struct virtio_mdev_device *vm_dev = dev_get_drvdata(dev);
+
+	unregister_virtio_device(&vm_dev->vdev);
+}
+
+static struct mdev_class_id id_table[] = {
+	{ MDEV_ID_VIRTIO },
Quoted 8 lines

drivers/vfio/mdev/virtio_mdev.c line 396

Quoted 7 lines
drivers/vfio/mdev/virtio_mdev.c new file +7 -0
+	{ 0 },
+};
+
+static struct mdev_driver virtio_mdev_driver = {
+	.name	= "virtio_mdev",
+	.probe	= virtio_mdev_probe,
+	.remove	= virtio_mdev_remove,

No need for tab, just do single white space.

Yes, fixed.

Thanks

Quoted 11 lines
Quoted 11 lines
drivers/vfio/mdev/virtio_mdev.c new file +11 -0
+	.id_table = id_table,
+};
+
+static int __init virtio_mdev_init(void) {
+	return mdev_register_driver(&virtio_mdev_driver, THIS_MODULE); }
+
+static void __exit virtio_mdev_exit(void) {
+	mdev_unregister_driver(&virtio_mdev_driver);
+}
+
+module_init(virtio_mdev_init)
Quoted 8 lines
Quoted 8 lines
drivers/vfio/mdev/virtio_mdev.c new file +6 -1
+module_exit(virtio_mdev_exit)
+
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
--

2.19.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#30 lore raw

PATCH 4/6 virtio: introduce a mdev based transport

In reply to Jason Wang

This patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.

A new virtio-mdev driver will be registered to the mdev bus, when a new virtio-mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.

---
 MAINTAINERS                     |   1 +
 drivers/vfio/mdev/Kconfig       |   7 +
 drivers/vfio/mdev/Makefile      |   1 +
 drivers/vfio/mdev/virtio_mdev.c | 416 ++++++++++++++++++++++++++++++++
 4 files changed, 425 insertions(+)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
MAINTAINERS +1 -0
index 89832b316500..820ec250cc52 100644
@@ -17202,6 +17202,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	drivers/vfio/mdev/virtio_mdev.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/Kconfig +7 -0
index 5da27f2100f9..c488c31fc137 100644
@@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
 	default n
 	help
 	  VFIO based driver for Mediated devices.
+
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
drivers/vfio/mdev/Makefile +1 -0
index 101516fdf375..99d31e29c23e 100644
@@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
 
 obj-$(CONFIG_VFIO_MDEV) += mdev.o
 obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/vfio/mdev/virtio_mdev.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#31 lore raw

PATCH 5/6 vringh: fix copy direction of vringh_iov_push_kern()

In reply to Jason Wang

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
Signature · 1 line
2.19.1
#32 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
#33 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

Quoted 11 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 4 lines

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

Quoted 26 lines
Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
#34 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

Quoted 12 lines · On Mon, 23 Sep 2019 12:00:41 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 11 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)  
Quoted 7 lines
Quoted 4 lines

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

It's a fix, please submit it separately through virtio/vhost channels, then it will already be in the base kernel we use for the rest of the series. The remainder of the series certainly suggests a workflow through the vfio tree rather than virtio/vhost. Thanks,

Alex

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
author
#35 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

Quoted 17 lines · Alex Williamson
Quoted 14 lines · On Mon, 23 Sep 2019 12:00:41 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)  

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

Quoted 8 lines
Quoted 2 lines

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

It's a fix, please submit it separately through virtio/vhost channels, then it will already be in the base kernel we use for the rest of the series. The remainder of the series certainly suggests a workflow through the vfio tree rather than virtio/vhost. Thanks,

Alex

Ok.

Thanks

author
#36 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

In reply to Alex Williamson
Quoted 17 lines · Alex Williamson
Quoted 14 lines · On Mon, 23 Sep 2019 12:00:41 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 13 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)  

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

Quoted 8 lines
Quoted 2 lines

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

It's a fix, please submit it separately through virtio/vhost channels, then it will already be in the base kernel we use for the rest of the series. The remainder of the series certainly suggests a workflow through the vfio tree rather than virtio/vhost. Thanks,

Alex

Ok.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#37 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

In reply to Michael S. Tsirkin
Quoted 12 lines · On Mon, 23 Sep 2019 12:00:41 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 11 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)  
Quoted 7 lines
Quoted 4 lines

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

It's a fix, please submit it separately through virtio/vhost channels, then it will already be in the base kernel we use for the rest of the series. The remainder of the series certainly suggests a workflow through the vfio tree rather than virtio/vhost. Thanks,

Alex

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
#38 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

In reply to Alex Williamson
Quoted 11 lines · Alex Williamson
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 4 lines

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

It's better to have it as patch 1/6, but it's a dependency of the example driver in the series. I can reorder when I apply.

Quoted 26 lines
Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
#39 lore raw

Re: [PATCH 5/6] vringh: fix copy direction of vringh_iov_push_kern()

In reply to Jason Wang
Quoted 6 lines · On Mon, 23 Sep 2019 21:03:30 +0800 Jason Wang <[email protected]> wrote:

We want to copy from iov to buf, so the direction was wrong.

---
 drivers/vhost/vringh.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Why is this included in the series? Seems like an unrelated fix being held up within a proposal for a new feature. Thanks,

Alex

Quoted 26 lines
drivers/vhost/vringh.c +7 -1
index 08ad0d1f0476..a0a2d74967ef 100644
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)
 	return 0;
 }
 
+static inline int kern_xfer(void *dst, void *src, size_t len)
+{
+	memcpy(dst, src, len);
+	return 0;
+}
+
 /**
  * vringh_init_kern - initialize a vringh for a kernelspace vring.
  * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);
 ssize_t vringh_iov_push_kern(struct vringh_kiov *wiov,
 			     const void *src, size_t len)
 {
-	return vringh_iov_xfer(wiov, (void *)src, len, xfer_kern);
+	return vringh_iov_xfer(wiov, (void *)src, len, kern_xfer);
 }
 EXPORT_SYMBOL(vringh_iov_push_kern);
 
author
#40 lore raw

PATCH 6/6 docs: sample driver to demonstrate how to implement virtio-mdev framework

In reply to Jason Wang

This sample driver creates mdev device that simulate virtio net device over virtio mdev transport. The device is implemented through vringh and workqueue. A device specific dma ops is to make sure HVA is used directly as the IOVA. This should be sufficient for kernel virtio driver to work.

Only 'virtio' type is supported right now. I plan to add 'vhost' type on top which requires some virtual IOMMU in this sample driver.

---
 MAINTAINERS                |   1 +
 samples/Kconfig            |   7 +
 samples/vfio-mdev/Makefile |   1 +
 samples/vfio-mdev/mvnet.c  | 688 +++++++++++++++++++++++++++++++++++++
 4 files changed, 697 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
index 820ec250cc52..6cee388eec6a 100644
@@ -17203,6 +17203,7 @@ F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
 F:	drivers/vfio/mdev/virtio_mdev.c
+F:	samples/vfio-mdev/mvnet.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
samples/Kconfig +7 -0
index c8dacb4dda80..a1a1ca2c00b7 100644
@@ -131,6 +131,13 @@ config SAMPLE_VFIO_MDEV_MDPY
 	  mediated device.  It is a simple framebuffer and supports
 	  the region display interface (VFIO_GFX_PLANE_TYPE_REGION).
 
+config SAMPLE_VIRTIO_MDEV_NET
+        tristate "Build virtio mdev net example mediated device sample code -- loadable modules only"
+	depends on VIRTIO_MDEV_DEVICE && VHOST_RING && m
+	help
+	  Build a networking sample device for use as a virtio
+	  mediated device.
+
 config SAMPLE_VFIO_MDEV_MDPY_FB
 	tristate "Build VFIO mdpy example guest fbdev driver -- loadable module only"
 	depends on FB && m
samples/vfio-mdev/Makefile +1 -0
index 10d179c4fdeb..f34af90ed0a0 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_VFIO_MDEV_MTTY) += mtty.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY) += mdpy.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY_FB) += mdpy-fb.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MBOCHS) += mbochs.o
+obj-$(CONFIG_SAMPLE_VIRTIO_MDEV_NET) += mvnet.o
samples/vfio-mdev/mvnet.c new file +688 -0

688 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#41 lore raw

PATCH 6/6 docs: sample driver to demonstrate how to implement virtio-mdev framework

In reply to Jason Wang

This sample driver creates mdev device that simulate virtio net device over virtio mdev transport. The device is implemented through vringh and workqueue. A device specific dma ops is to make sure HVA is used directly as the IOVA. This should be sufficient for kernel virtio driver to work.

Only 'virtio' type is supported right now. I plan to add 'vhost' type on top which requires some virtual IOMMU in this sample driver.

---
 MAINTAINERS                |   1 +
 samples/Kconfig            |   7 +
 samples/vfio-mdev/Makefile |   1 +
 samples/vfio-mdev/mvnet.c  | 688 +++++++++++++++++++++++++++++++++++++
 4 files changed, 697 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
index 820ec250cc52..6cee388eec6a 100644
@@ -17203,6 +17203,7 @@ F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
 F:	drivers/vfio/mdev/virtio_mdev.c
+F:	samples/vfio-mdev/mvnet.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
samples/Kconfig +7 -0
index c8dacb4dda80..a1a1ca2c00b7 100644
@@ -131,6 +131,13 @@ config SAMPLE_VFIO_MDEV_MDPY
 	  mediated device.  It is a simple framebuffer and supports
 	  the region display interface (VFIO_GFX_PLANE_TYPE_REGION).
 
+config SAMPLE_VIRTIO_MDEV_NET
+        tristate "Build virtio mdev net example mediated device sample code -- loadable modules only"
+	depends on VIRTIO_MDEV_DEVICE && VHOST_RING && m
+	help
+	  Build a networking sample device for use as a virtio
+	  mediated device.
+
 config SAMPLE_VFIO_MDEV_MDPY_FB
 	tristate "Build VFIO mdpy example guest fbdev driver -- loadable module only"
 	depends on FB && m
samples/vfio-mdev/Makefile +1 -0
index 10d179c4fdeb..f34af90ed0a0 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_VFIO_MDEV_MTTY) += mtty.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY) += mdpy.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY_FB) += mdpy-fb.o
 obj-$(CONFIG_SAMPLE_VFIO_MDEV_MBOCHS) += mbochs.o
+obj-$(CONFIG_SAMPLE_VIRTIO_MDEV_NET) += mvnet.o
samples/vfio-mdev/mvnet.c new file +688 -0

688 lines not on this page · raw message

Signature · 1 line
2.19.1
maintainer Acked-by on the v1 series
#42 lore raw
In reply to Jason Wang
Quoted 51 lines · Jason Wang

Hi all:

There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.

Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.

A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.

Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with id_talbe claimed by the driver. On top, this seris also decouple device specific parents ops out of the common ones.

Pktgen test was done with virito-net + mvnet loop back device.

Please review.

[1] https://lkml.org/lkml/2019/9/16/869

Changes from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseve MDEV_ID_VHOST for future vhost-mdev work
- introduce "virtio" type for mvnet and make "vhost" type for future work
- add entries in MAINTAINER
- tweak and typos fixes in commit log

Changes from RFC-V1:

- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- split device_ops into seperate headers
- drop the mdev_set_dma_ops()
- use device_ops to implement the transport API, then it's not a part of UAPI any more
- use GFP_ATOMIC in mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet device

Quoted 8 lines

Jason Wang (6):
mdev: class id support
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
vringh: fix copy direction of vringh_iov_push_kern()
docs: sample driver to demonstrate how to implement virtio-mdev
framework

That's pretty clean, so how about we start by just merging this? Alex are you going to handle this through your next tree? If yes, pls include:

Quoted 20 lines
 .../driver-api/vfio-mediated-device.rst       |  11 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  14 +-
 drivers/vfio/mdev/Kconfig                     |   7 +
 drivers/vfio/mdev/Makefile                    |   1 +
 drivers/vfio/mdev/mdev_core.c                 |  21 +-
 drivers/vfio/mdev/mdev_driver.c               |  14 +
 drivers/vfio/mdev/mdev_private.h              |   1 +
 drivers/vfio/mdev/vfio_mdev.c                 |  37 +-
 drivers/vfio/mdev/virtio_mdev.c               | 416 +++++++++++
 drivers/vhost/vringh.c                        |   8 +-
 include/linux/mdev.h                          |  47 +-
 include/linux/mod_devicetable.h               |   8 +
 include/linux/vfio_mdev.h                     |  53 ++
 include/linux/virtio_mdev.h                   | 144 ++++
 samples/Kconfig                               |   7 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
Quoted 11 lines
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet.c                     | 688 ++++++++++++++++++
 23 files changed, 1481 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
 create mode 100644 include/linux/vfio_mdev.h
 create mode 100644 include/linux/virtio_mdev.h
 create mode 100644 samples/vfio-mdev/mvnet.c
Signature · 1 line
2.19.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

maintainer Acked-by on the v1 series
#43 lore raw
In reply to Jason Wang
Quoted 51 lines · Jason Wang

Hi all:

There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.

Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.

A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.

Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with id_talbe claimed by the driver. On top, this seris also decouple device specific parents ops out of the common ones.

Pktgen test was done with virito-net + mvnet loop back device.

Please review.

[1] https://lkml.org/lkml/2019/9/16/869

Changes from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseve MDEV_ID_VHOST for future vhost-mdev work
- introduce "virtio" type for mvnet and make "vhost" type for future work
- add entries in MAINTAINER
- tweak and typos fixes in commit log

Changes from RFC-V1:

- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- split device_ops into seperate headers
- drop the mdev_set_dma_ops()
- use device_ops to implement the transport API, then it's not a part of UAPI any more
- use GFP_ATOMIC in mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet device

Quoted 8 lines

Jason Wang (6):
mdev: class id support
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
vringh: fix copy direction of vringh_iov_push_kern()
docs: sample driver to demonstrate how to implement virtio-mdev
framework

That's pretty clean, so how about we start by just merging this? Alex are you going to handle this through your next tree? If yes, pls include:

Quoted 31 lines
 .../driver-api/vfio-mediated-device.rst       |  11 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  14 +-
 drivers/vfio/mdev/Kconfig                     |   7 +
 drivers/vfio/mdev/Makefile                    |   1 +
 drivers/vfio/mdev/mdev_core.c                 |  21 +-
 drivers/vfio/mdev/mdev_driver.c               |  14 +
 drivers/vfio/mdev/mdev_private.h              |   1 +
 drivers/vfio/mdev/vfio_mdev.c                 |  37 +-
 drivers/vfio/mdev/virtio_mdev.c               | 416 +++++++++++
 drivers/vhost/vringh.c                        |   8 +-
 include/linux/mdev.h                          |  47 +-
 include/linux/mod_devicetable.h               |   8 +
 include/linux/vfio_mdev.h                     |  53 ++
 include/linux/virtio_mdev.h                   | 144 ++++
 samples/Kconfig                               |   7 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet.c                     | 688 ++++++++++++++++++
 23 files changed, 1481 insertions(+), 89 deletions(-)
 create mode 100644 drivers/vfio/mdev/virtio_mdev.c
 create mode 100644 include/linux/vfio_mdev.h
 create mode 100644 include/linux/virtio_mdev.h
 create mode 100644 samples/vfio-mdev/mvnet.c
Signature · 1 line
2.19.1
#44 lore raw

✗ Fi.CI.CHECKPATCH: warning for mdev based hardware virtio offloading support (rev2)

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support (rev2)
URL : https://patchwork.freedesktop.org/series/66989/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
d79d4220ecb7 mdev: class id support
39e2e5c7ea18 mdev: introduce device specific ops
-:317: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating?
#317: 
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 411 lines checked
48d2885862d8 mdev: introduce virtio device and its device ops
-:51: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #51:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 172 lines checked
ada668d2b867 virtio: introduce a mdev based transport
-:55: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #55:
new file mode 100644

-:95: CHECK:UNCOMMENTED_DEFINITION: spinlock_t definition without comment #95: FILE: drivers/vfio/mdev/virtio_mdev.c:36:
+ spinlock_t lock;

-:122: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #122: FILE: drivers/vfio/mdev/virtio_mdev.c:63:
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,

-:123: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #123: FILE: drivers/vfio/mdev/virtio_mdev.c:64:
+ void *buf, unsigned len)

-:131: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #131: FILE: drivers/vfio/mdev/virtio_mdev.c:72:
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,

-:132: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #132: FILE: drivers/vfio/mdev/virtio_mdev.c:73:
+ const void *buf, unsigned len)

-:199: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #199: FILE: drivers/vfio/mdev/virtio_mdev.c:140:
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,

-:278: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #278: FILE: drivers/vfio/mdev/virtio_mdev.c:219:
+
+}

-:304: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #304: FILE: drivers/vfio/mdev/virtio_mdev.c:245:
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,

-:438: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #438: FILE: drivers/vfio/mdev/virtio_mdev.c:379:
+
+}

total: 0 errors, 7 warnings, 3 checks, 437 lines checked
5aa1512e1678 vringh: fix copy direction of vringh_iov_push_kern()
6d4e2cf95a29 docs: sample driver to demonstrate how to implement virtio-mdev framework -:38: WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully #38: FILE: samples/Kconfig:134:
+config SAMPLE_VIRTIO_MDEV_NET

-:58: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #58:
new file mode 100644

-:146: CHECK:UNCOMMENTED_DEFINITION: spinlock_t definition without comment #146: FILE: samples/vfio-mdev/mvnet.c:84:
+ spinlock_t lock;

-:179: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #179: FILE: samples/vfio-mdev/mvnet.c:117:
+ vringh_init_kern(&vq->vring, mvnet_features, MVNET_QUEUE_MAX,
+ false, 0, 0, 0);

-:284: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!addr" #284: FILE: samples/vfio-mdev/mvnet.c:222:
+ if (addr == NULL)

-:287: CHECK:SPACING: No space is necessary after a cast #287: FILE: samples/vfio-mdev/mvnet.c:225:
+ *dma_addr = (dma_addr_t) addr;

-:315: CHECK:ALLOC_SIZEOF_STRUCT: Prefer kzalloc(sizeof(*mvnet)...) over kzalloc(sizeof(struct mvnet_state)...) #315: FILE: samples/vfio-mdev/mvnet.c:253:
+ mvnet = kzalloc(sizeof(struct mvnet_state), GFP_KERNEL);

-:316: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!mvnet" #316: FILE: samples/vfio-mdev/mvnet.c:254:
+ if (mvnet == NULL)

-:370: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #370: FILE: samples/vfio-mdev/mvnet.c:308:
+sample_mvnet_dev_show(struct device *dev, struct device_attribute *attr,
+ char *buf)

total: 0 errors, 2 warnings, 7 checks, 712 lines checked

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#45 lore raw

✓ Fi.CI.BAT: success for mdev based hardware virtio offloading support (rev2)

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support (rev2)
URL : https://patchwork.freedesktop.org/series/66989/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6944 -> Patchwork_14501
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/

Known issues
------------

Here are the changes found in Patchwork_14501 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_mmap@basic-small-bo:
- fi-icl-u3: [PASS][1] -> [DMESG-WARN][2] ([fdo#107724]) +2 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-icl-u3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-icl-u3/igt@[email protected]

* igt@i915_selftest@live_hangcheck:
- fi-icl-u2: [PASS][3] -> [INCOMPLETE][4] ([fdo#107713] / [fdo#108569])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-icl-u2/igt@i915_selftest@live_hangcheck.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-icl-u2/igt@i915_selftest@live_hangcheck.html

#### Possible fixes ####

* igt@gem_cpu_reloc@basic:
- {fi-tgl-u}: [INCOMPLETE][5] -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-tgl-u/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-tgl-u/igt@[email protected]

* igt@gem_exec_suspend@basic-s3:
- fi-blb-e6850: [INCOMPLETE][7] ([fdo#107718]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-blb-e6850/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-blb-e6850/igt@[email protected]

* igt@gem_mmap_gtt@basic-write:
- fi-icl-u3: [DMESG-WARN][9] ([fdo#107724]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-icl-u3/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-icl-u3/igt@[email protected]

* igt@i915_module_load@reload:
- fi-icl-u3: [DMESG-WARN][11] ([fdo#107724] / [fdo#111214]) -> [PASS][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/fi-icl-u3/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/fi-icl-u3/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
[fdo#108569]: https://bugs.freedesktop.org/show_bug.cgi?id=108569
[fdo#111045]: https://bugs.freedesktop.org/show_bug.cgi?id=111045
[fdo#111096]: https://bugs.freedesktop.org/show_bug.cgi?id=111096
[fdo#111214]: https://bugs.freedesktop.org/show_bug.cgi?id=111214
[fdo#111600]: https://bugs.freedesktop.org/show_bug.cgi?id=111600

Participating hosts (54 -> 47)
------------------------------

Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-icl-y fi-byt-clapper fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_6944 -> Patchwork_14501

CI-20190529: 20190529
CI_DRM_6944: 2c9a75480b3c8a78ed86404c8c0afea389622df6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5197: aa534ff47fd2f455c8be9e59eae807695b87fcdd @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14501: 6d4e2cf95a29e6dc701f4d61c784961791d442c6 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

6d4e2cf95a29 docs: sample driver to demonstrate how to implement virtio-mdev framework 5aa1512e1678 vringh: fix copy direction of vringh_iov_push_kern() ada668d2b867 virtio: introduce a mdev based transport
48d2885862d8 mdev: introduce virtio device and its device ops 39e2e5c7ea18 mdev: introduce device specific ops
d79d4220ecb7 mdev: class id support

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#46 lore raw

✓ Fi.CI.IGT: success for mdev based hardware virtio offloading support (rev2)

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support (rev2)
URL : https://patchwork.freedesktop.org/series/66989/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6944_full -> Patchwork_14501_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_14501_full:

### IGT changes ###

#### Suppressed ####

The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.

* {igt@gem_eio@kms}:
- shard-snb: [INCOMPLETE][1] ([fdo#105411]) -> [DMESG-WARN][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-snb1/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-snb6/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_14501_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_schedule@independent-bsd2:
- shard-iclb: [PASS][3] -> [SKIP][4] ([fdo#109276]) +23 similar issues
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb4/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb5/igt@[email protected]

* igt@gem_exec_schedule@reorder-wide-bsd:
- shard-iclb: [PASS][5] -> [SKIP][6] ([fdo#111325]) +2 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb2/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-128x42-random:
- shard-apl: [PASS][7] -> [INCOMPLETE][8] ([fdo#103927])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-apl3/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-apl1/igt@[email protected]

* igt@kms_cursor_crc@pipe-b-cursor-128x42-random:
- shard-iclb: [PASS][9] -> [INCOMPLETE][10] ([fdo#107713])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb1/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb7/igt@[email protected]

* igt@kms_cursor_legacy@pipe-c-single-move:
- shard-kbl: [PASS][11] -> [INCOMPLETE][12] ([fdo#103665])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-kbl2/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-kbl4/igt@[email protected]

* igt@kms_flip@2x-flip-vs-expired-vblank-interruptible:
- shard-glk: [PASS][13] -> [FAIL][14] ([fdo#105363])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-glk4/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-glk5/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank:
- shard-skl: [PASS][15] -> [FAIL][16] ([fdo#105363])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl5/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl4/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-apl: [PASS][17] -> [DMESG-WARN][18] ([fdo#108566]) +5 similar issues
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-apl8/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-apl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-mmap-gtt:
- shard-iclb: [PASS][19] -> [INCOMPLETE][20] ([fdo#106978] / [fdo#107713])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb2/igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-mmap-gtt.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb7/igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-mmap-gtt.html

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-indfb-msflip-blt:
- shard-iclb: [PASS][21] -> [FAIL][22] ([fdo#103167]) +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb7/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-indfb-msflip-blt.html
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb3/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-indfb-msflip-blt.html

* igt@kms_plane_alpha_blend@pipe-b-coverage-7efc:
- shard-skl: [PASS][23] -> [FAIL][24] ([fdo#108145] / [fdo#110403])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl7/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl6/igt@[email protected]

* igt@kms_psr@psr2_sprite_blt:
- shard-iclb: [PASS][25] -> [SKIP][26] ([fdo#109441]) +1 similar issue
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb2/igt@kms_psr@psr2_sprite_blt.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb7/igt@kms_psr@psr2_sprite_blt.html

* igt@perf@polling:
- shard-skl: [PASS][27] -> [FAIL][28] ([fdo#110728])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl2/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl6/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_schedule@preempt-bsd:
- shard-iclb: [SKIP][29] ([fdo#111325]) -> [PASS][30] +3 similar issues
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb1/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb5/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-256x256-random:
- shard-snb: [SKIP][31] ([fdo#109271]) -> [PASS][32] +5 similar issues
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-snb6/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-snb7/igt@[email protected]

* igt@kms_flip@dpms-vs-vblank-race:
- shard-apl: [FAIL][33] ([fdo#111609]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-apl2/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-apl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite:
- shard-iclb: [FAIL][35] ([fdo#103167]) -> [PASS][36] +5 similar issues
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb3/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite.html
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb6/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite.html

* igt@kms_frontbuffer_tracking@psr-suspend:
- shard-skl: [INCOMPLETE][37] ([fdo#104108] / [fdo#106978]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl7/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl8/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min:
- shard-skl: [FAIL][39] ([fdo#108145]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl2/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl3/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-coverage-7efc:
- shard-skl: [FAIL][41] ([fdo#108145] / [fdo#110403]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-skl9/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-skl9/igt@[email protected]

* igt@kms_psr@psr2_primary_mmap_gtt:
- shard-iclb: [SKIP][43] ([fdo#109441]) -> [PASS][44] +1 similar issue
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb7/igt@kms_psr@psr2_primary_mmap_gtt.html
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb2/igt@kms_psr@psr2_primary_mmap_gtt.html

* igt@kms_rotation_crc@primary-rotation-180:
- shard-iclb: [INCOMPLETE][45] ([fdo#107713] / [fdo#110026]) -> [PASS][46]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb7/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb1/igt@[email protected]

* igt@kms_vblank@pipe-a-ts-continuation-suspend:
- shard-apl: [DMESG-WARN][47] ([fdo#108566]) -> [PASS][48] +5 similar issues
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-apl1/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-apl1/igt@[email protected]

* igt@prime_vgem@fence-wait-bsd2:
- shard-iclb: [SKIP][49] ([fdo#109276]) -> [PASS][50] +12 similar issues
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb6/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb4/igt@[email protected]

#### Warnings ####

* igt@gem_mocs_settings@mocs-isolation-bsd2:
- shard-iclb: [FAIL][51] ([fdo#111330]) -> [SKIP][52] ([fdo#109276])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-iclb2/igt@[email protected]
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-iclb6/igt@[email protected]

* igt@kms_vblank@pipe-c-query-busy:
- shard-snb: [SKIP][53] ([fdo#109271]) -> [SKIP][54] ([fdo#109271] / [fdo#109278])
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6944/shard-snb6/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/shard-snb7/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
[fdo#105411]: https://bugs.freedesktop.org/show_bug.cgi?id=105411
[fdo#106978]: https://bugs.freedesktop.org/show_bug.cgi?id=106978
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#110026]: https://bugs.freedesktop.org/show_bug.cgi?id=110026
[fdo#110403]: https://bugs.freedesktop.org/show_bug.cgi?id=110403
[fdo#110728]: https://bugs.freedesktop.org/show_bug.cgi?id=110728
[fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
[fdo#111330]: https://bugs.freedesktop.org/show_bug.cgi?id=111330
[fdo#111609]: https://bugs.freedesktop.org/show_bug.cgi?id=111609

Participating hosts (8 -> 9)
------------------------------

Additional (1): pig-hsw-4770r

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_6944 -> Patchwork_14501

CI-20190529: 20190529
CI_DRM_6944: 2c9a75480b3c8a78ed86404c8c0afea389622df6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5197: aa534ff47fd2f455c8be9e59eae807695b87fcdd @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14501: 6d4e2cf95a29e6dc701f4d61c784961791d442c6 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14501/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx