Skip to contentSkip to conversation

mdev based hardware virtio offloading support

PATCH Superseded Jason Wang 6 participants 71 messages Oct 11, 2019 – Oct 17, 2019

Subsystems (16)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

v3 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/26/15

Changes from V2:

- fail when class_id is not specified
- drop the vringh patch
- match the doc to the code
- tweak the commit log
- move device_ops from parent to mdev device
- remove the unused MDEV_ID_VHOST

Changes from V1:

- move virtio_mdev.c to drivers/virtio
- store class_id in mdev_device instead of mdev_parent
- store device_ops in mdev_device instead of mdev_parent
- reorder the patch, vringh fix comes first
- really silent compiling warnings
- really switch to use u16 for class_id
- uevent and modpost support for mdev class_id
- vraious tweaks per comments from Parav

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 (7):
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework

 .../driver-api/vfio-mediated-device.rst       |  25 +-
 MAINTAINERS                                   |   2 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  13 +-
 drivers/vfio/mdev/mdev_core.c                 |  18 +
 drivers/vfio/mdev/mdev_driver.c               |  22 +
 drivers/vfio/mdev/mdev_private.h              |   2 +
 drivers/vfio/mdev/vfio_mdev.c                 |  45 +-
 drivers/virtio/Kconfig                        |   7 +
 drivers/virtio/Makefile                       |   1 +
 drivers/virtio/virtio_mdev.c                  | 416 +++++++++++
 include/linux/mdev.h                          |  49 +-
 include/linux/mod_devicetable.h               |   8 +
 include/linux/vfio_mdev.h                     |  52 ++
 include/linux/virtio_mdev.h                   | 148 ++++
 samples/Kconfig                               |   7 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  20 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet.c                     | 691 ++++++++++++++++++
 scripts/mod/devicetable-offsets.c             |   3 +
 scripts/mod/file2alias.c                      |  10 +
 24 files changed, 1523 insertions(+), 87 deletions(-)
 create mode 100644 drivers/virtio/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 v3 1/7 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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
 drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
 drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
 drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
 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                              |  8 ++++++++
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  1 +
 samples/vfio-mdev/mdpy.c                          |  1 +
 samples/vfio-mdev/mtty.c                          |  1 +
 13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +6 -1
index 25eb7d5b834b..2035e48da7b2 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
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 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::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-
 Mediated Device Management Interface Through sysfs
 ==================================================
 
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..17e9d4634c84 100644
@@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 		     dev_name(mdev_dev(mdev)));
 	ret = 0;
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 out:
 	return ret;
 }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
index f0d71ab77c50..b5d223882c6c 100644
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 			   private->sch->schid.ssid,
 			   private->sch->schid.sch_no);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..47df1c593c35 100644
@@ -343,6 +343,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
 	mutex_unlock(&matrix_dev->lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
drivers/vfio/mdev/mdev_core.c +11 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id)
+		goto class_id_fail;
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
 sysfs_fail:
 	device_del(&mdev->dev);
+class_id_fail:
 add_fail:
 	parent->ops->remove(mdev);
 ops_create_fail:
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b7c40ce86ee3 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->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..c65f436c1869 100644
@@ -33,6 +33,7 @@ struct mdev_device {
 	struct kobject *type_kobj;
 	struct device *iommu_device;
 	bool active;
+	u16 class_id;
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
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 +8 -0
index 0ce30ca78db0..a7570cf13ba4 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,12 +126,14 @@ 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)
 
 void *mdev_get_drvdata(struct mdev_device *mdev);
 void mdev_set_drvdata(struct mdev_device *mdev, void *data);
+void mdev_set_class(struct mdev_device *mdev, u16 id);
 const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ 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);
 
+enum {
+	MDEV_ID_VFIO = 1,
+	/* New entries must be added here */
+};
+
 #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 -0
index ac5c8c17b1ff..fd8491e58fe2 100644
@@ -561,6 +561,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 	mbochs_reset(mdev);
 
 	mbochs_used_mbytes += type->mbytes;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 
 err_mem:
samples/vfio-mdev/mdpy.c +1 -0
index cc86bf6566e4..889472b06708 100644
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
samples/vfio-mdev/mtty.c +1 -0
index ce84a300a4da..618810ca4331 100644
@@ -755,6 +755,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&mdev_state->next, &mdev_devices_list);
 	mutex_unlock(&mdev_list_lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
Signature · 1 line
2.19.1
#2 lore raw

Re: [PATCH V3 1/7] mdev: class id support

Quoted 46 lines · On Fri, 11 Oct 2019 16:15:51 +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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
 drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
 drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
 drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
 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                              |  8 ++++++++
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  1 +
 samples/vfio-mdev/mdpy.c                          |  1 +
 samples/vfio-mdev/mtty.c                          |  1 +
 13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Should the document state explicitly that this should be done in the ->create() callback? Also, I think that the class_id might be different for different mdevs (even if the parent is the same) -- should that be mentioned explicitly?

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 181

Quoted 10 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
+
 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::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-
 Mediated Device Management Interface Through sysfs
 ==================================================
 

(...)

Looks reasonable to me.

author
#3 lore raw

Re: [PATCH V3 1/7] mdev: class id support

Quoted 52 lines · Cornelia Huck
Quoted 49 lines · On Fri, 11 Oct 2019 16:15:51 +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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
  Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
  drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
  drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
  drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
  drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
  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                              |  8 ++++++++
  include/linux/mod_devicetable.h                   |  8 ++++++++
  samples/vfio-mdev/mbochs.c                        |  1 +
  samples/vfio-mdev/mdpy.c                          |  1 +
  samples/vfio-mdev/mtty.c                          |  1 +
  13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
Quoted 5 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Should the document state explicitly that this should be done in the ->create() callback?

Yes, it's better.

Quoted 3 lines

Also, I think that the class_id might be different
for different mdevs (even if the parent is the same) -- should that be mentioned explicitly?

Yes, depends on the mdev_supported_type.

Thanks

Quoted 14 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 181

Quoted 11 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
+
  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::
 
  	extern void mdev_unregister_device(struct device *dev);
 
-
  Mediated Device Management Interface Through sysfs
  ==================================================
 

(...)

Looks reasonable to me.

author
#4 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Cornelia Huck
Quoted 52 lines · Cornelia Huck
Quoted 49 lines · On Fri, 11 Oct 2019 16:15:51 +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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
  Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
  drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
  drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
  drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
  drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
  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                              |  8 ++++++++
  include/linux/mod_devicetable.h                   |  8 ++++++++
  samples/vfio-mdev/mbochs.c                        |  1 +
  samples/vfio-mdev/mdpy.c                          |  1 +
  samples/vfio-mdev/mtty.c                          |  1 +
  13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
Quoted 5 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Should the document state explicitly that this should be done in the ->create() callback?

Yes, it's better.

Quoted 3 lines

Also, I think that the class_id might be different
for different mdevs (even if the parent is the same) -- should that be mentioned explicitly?

Yes, depends on the mdev_supported_type.

Thanks

Quoted 7 lines
Quoted 7 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -0
+
  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::
 
  	extern void mdev_unregister_device(struct device *dev);
 
Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 181

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -1
-
  Mediated Device Management Interface Through sysfs
  ==================================================
 

(...)

Looks reasonable to me.

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

#5 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Jason Wang
Quoted 46 lines · On Fri, 11 Oct 2019 16:15:51 +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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
 drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
 drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
 drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
 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                              |  8 ++++++++
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  1 +
 samples/vfio-mdev/mdpy.c                          |  1 +
 samples/vfio-mdev/mtty.c                          |  1 +
 13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Should the document state explicitly that this should be done in the ->create() callback? Also, I think that the class_id might be different for different mdevs (even if the parent is the same) -- should that be mentioned explicitly?

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 181

Quoted 10 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
+
 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::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-
 Mediated Device Management Interface Through sysfs
 ==================================================
 

(...)

Looks reasonable to me.

#6 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Jason Wang
Quoted 26 lines · On Fri, 11 Oct 2019 16:15:51 +0800 Jason Wang <[email protected]> wrote:
drivers/vfio/mdev/mdev_core.c +7 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 334

Quoted 4 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id)

This is a sanity test failure of the parent driver on a privileged path, I think it's fair to print a warning when this occurs rather than only return an errno to the user. In fact, ret is not set to an error value here, so it looks like this fails to create the device but returns success. Thanks,

Alex

Quoted 13 lines
drivers/vfio/mdev/mdev_core.c +3 -0
+		goto class_id_fail;
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
 sysfs_fail:
 	device_del(&mdev->dev);
+class_id_fail:
 add_fail:
 	parent->ops->remove(mdev);
 ops_create_fail:
author
#7 lore raw

Re: [PATCH V3 1/7] mdev: class id support

Quoted 32 lines · Alex Williamson
Quoted 29 lines · On Fri, 11 Oct 2019 16:15:51 +0800 Jason Wang <[email protected]> wrote:
drivers/vfio/mdev/mdev_core.c +7 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
  }
  EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
  struct device *mdev_dev(struct mdev_device *mdev)
  {
  	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
   *
   * Add device to list of registered parent devices.
   * Returns a negative value on error, otherwise 0.
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
  	if (ret)
  		goto ops_create_fail;
 
Quoted 8 lines

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 334

Quoted 1 line
drivers/vfio/mdev/mdev_core.c +1 -0
+	if (!mdev->class_id)

This is a sanity test failure of the parent driver on a privileged path, I think it's fair to print a warning when this occurs rather than only return an errno to the user. In fact, ret is not set to an error value here, so it looks like this fails to create the device but returns success. Thanks,

Alex

Will fix.

Thanks

Quoted 14 lines
Quoted 14 lines
drivers/vfio/mdev/mdev_core.c +3 -0
+		goto class_id_fail;
+
  	ret = device_add(&mdev->dev);
  	if (ret)
  		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
  sysfs_fail:
  	device_del(&mdev->dev);
+class_id_fail:
  add_fail:
  	parent->ops->remove(mdev);
  ops_create_fail:
author
#8 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Alex Williamson
Quoted 32 lines · Alex Williamson
Quoted 29 lines · On Fri, 11 Oct 2019 16:15:51 +0800 Jason Wang <[email protected]> wrote:
drivers/vfio/mdev/mdev_core.c +7 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
  }
  EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
  struct device *mdev_dev(struct mdev_device *mdev)
  {
  	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
   *
   * Add device to list of registered parent devices.
   * Returns a negative value on error, otherwise 0.
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
  	if (ret)
  		goto ops_create_fail;
 
Quoted 8 lines

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 334

Quoted 1 line
drivers/vfio/mdev/mdev_core.c +1 -0
+	if (!mdev->class_id)

This is a sanity test failure of the parent driver on a privileged path, I think it's fair to print a warning when this occurs rather than only return an errno to the user. In fact, ret is not set to an error value here, so it looks like this fails to create the device but returns success. Thanks,

Alex

Will fix.

Thanks

Quoted 8 lines
Quoted 8 lines
drivers/vfio/mdev/mdev_core.c +2 -0
+		goto class_id_fail;
+
  	ret = device_add(&mdev->dev);
  	if (ret)
  		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
Quoted 6 lines

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 356

Quoted 6 lines
drivers/vfio/mdev/mdev_core.c +1 -0
  sysfs_fail:
  	device_del(&mdev->dev);
+class_id_fail:
  add_fail:
  	parent->ops->remove(mdev);
  ops_create_fail:

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

#9 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Jason Wang
Quoted 26 lines · On Fri, 11 Oct 2019 16:15:51 +0800 Jason Wang <[email protected]> wrote:
drivers/vfio/mdev/mdev_core.c +7 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 334

Quoted 4 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id)

This is a sanity test failure of the parent driver on a privileged path, I think it's fair to print a warning when this occurs rather than only return an errno to the user. In fact, ret is not set to an error value here, so it looks like this fails to create the device but returns success. Thanks,

Alex

Quoted 13 lines
drivers/vfio/mdev/mdev_core.c +3 -0
+		goto class_id_fail;
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
 sysfs_fail:
 	device_del(&mdev->dev);
+class_id_fail:
 add_fail:
 	parent->ops->remove(mdev);
 ops_create_fail:
#10 lore raw

RE: [PATCH V3 1/7] mdev: class id support

In reply to Jason Wang
Quoted 73 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Friday, October 11, 2019 3:16 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]>; [email protected]; [email protected]; Jason Wang <[email protected]>
Subject: [PATCH V3 1/7] 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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
 drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
 drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
 drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
 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                              |  8 ++++++++
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  1 +
 samples/vfio-mdev/mdpy.c                          |  1 +
 samples/vfio-mdev/mtty.c                          |  1 +
 13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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 @@ -165,12 +167,15 @@ register itself with the mdev core driver::

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Drop extern.
In actual API you have correct signature, i.e. struct mdev_device. s/struct device/struct mdev_device.

Quoted 57 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::

Documentation/driver-api/vfio-mediated-device.rst +0 -1
 	extern void mdev_unregister_device(struct device *dev);
 
-
 Mediated Device Management Interface Through sysfs

==================================================

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..17e9d4634c84 100644
@@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj,
 struct mdev_device *mdev)
 		     dev_name(mdev_dev(mdev)));
 	ret = 0;
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 out:
 	return ret;

}

(quoted diff) +0 -0

b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..b5d223882c6c 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -0
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
 			   private->sch->schid.ssid,
 			   private->sch->schid.sch_no);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..47df1c593c35 100644
@@ -343,6 +343,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
 	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
 	mutex_unlock(&matrix_dev->lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
drivers/vfio/mdev/mdev_core.c +0 -0
index b558d4cfd082..724e9b9841d8 100644

drivers/vfio/mdev/mdev_core.c void mdev_set_drvdata(struct mdev_device *mdev, · line 51

Quoted 7 lines
drivers/vfio/mdev/mdev_core.c +5 -0
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev,
 void *data)  }  EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id) {
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+

Usually with every exported symbol we have signature comment block that describes when to use an API etc. Please add it that describes that this API must be called during create() callback.

Quoted 22 lines
drivers/vfio/mdev/mdev_core.c +1 -0
 struct device *mdev_dev(struct mdev_device *mdev)  {
 	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
  *
  * Add device to list of registered parent devices.

* Returns a negative value on error, otherwise 0.

drivers/vfio/mdev/mdev_core.c +3 -0
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id)
+		goto class_id_fail;
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 353

Quoted 4 lines
drivers/vfio/mdev/mdev_core.c +1 -0
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
 sysfs_fail:
 	device_del(&mdev->dev);
+class_id_fail:

No need for new label. Just use add_fail label.

Quoted 48 lines
drivers/vfio/mdev/mdev_core.c +0 -0
 add_fail:
 	parent->ops->remove(mdev);
 ops_create_fail:
(quoted diff) +0 -0

b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b7c40ce86ee3 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->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..c65f436c1869 100644
@@ -33,6 +33,7 @@ struct mdev_device {
 	struct kobject *type_kobj;
 	struct device *iommu_device;
 	bool active;
+	u16 class_id;
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +0 -0
index 30964a4e0a28..fd2a4d9a3f26 100644

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 123

Quoted 4 lines
drivers/vfio/mdev/vfio_mdev.c +1 -0
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static struct mdev_class_id id_table[] = {

static const

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 124

Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +1 -0
+	{ MDEV_ID_VFIO },

I guess you don't need extra braces for each entry.
Since this enum represents MDEV class id, it better to name it as MDEV_CLASS_ID_VFIO. (Similar to PCI_VENDOR_ID, PCI_DEVICE_ID)..

Quoted 26 lines
drivers/vfio/mdev/vfio_mdev.c +4 -0
+	{ 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..a7570cf13ba4 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 +0 -0
@@ -125,12 +126,14 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);

include/linux/mdev.h struct mdev_driver { · line 136

Quoted 10 lines
include/linux/mdev.h +2 -0
 	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)
 
 void *mdev_get_drvdata(struct mdev_device *mdev);  void
 mdev_set_drvdata(struct mdev_device *mdev, void *data);
+void mdev_set_class(struct mdev_device *mdev, u16 id);

Better to insert new API after mdev_uuid().

Quoted 72 lines
include/linux/mdev.h +5 -0
 const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ 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);
 
+enum {
+	MDEV_ID_VFIO = 1,
+	/* New entries must be added here */
+};
+
 #endif /* MDEV_H */
(quoted diff) +0 -0

b/include/linux/mod_devicetable.h index 5714fd35a83c..f32c6e44fb1a 100644

include/linux/mod_devicetable.h +8 -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;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -0
index ac5c8c17b1ff..fd8491e58fe2 100644
@@ -561,6 +561,7 @@ static int mbochs_create(struct kobject *kobj, struct
 mdev_device *mdev)
 	mbochs_reset(mdev);
 
 	mbochs_used_mbytes += type->mbytes;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 

err_mem:

samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..889472b06708 100644

samples/vfio-mdev/mdpy.c +1 -0
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct
 mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

ce84a300a4da..618810ca4331 100644

samples/vfio-mdev/mtty.c +1 -1
@@ -755,6 +755,7 @@ static int mtty_create(struct kobject *kobj, struct
 mdev_device *mdev)
 	list_add(&mdev_state->next, &mdev_devices_list);
 	mutex_unlock(&mdev_list_lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
--

2.19.1

author
#11 lore raw

Re: [PATCH V3 1/7] mdev: class id support

Quoted 75 lines · Parav Pandit
Quoted 75 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Friday, October 11, 2019 3:16 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]>; [email protected]; [email protected]; Jason Wang <[email protected]>
Subject: [PATCH V3 1/7] 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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
  Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
  drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
  drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
  drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
  drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
  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                              |  8 ++++++++
  include/linux/mod_devicetable.h                   |  8 ++++++++
  samples/vfio-mdev/mbochs.c                        |  1 +
  samples/vfio-mdev/mdpy.c                          |  1 +
  samples/vfio-mdev/mtty.c                          |  1 +
  13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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 @@ -165,12 +167,15 @@ register itself with the mdev core driver::
extern int mdev_register_device(struct device *dev,
const struct mdev_parent_ops *ops);

Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Drop extern.
In actual API you have correct signature, i.e. struct mdev_device. s/struct device/struct mdev_device.

Yes, will fix.

Quoted 60 lines
Quoted 60 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::

  	extern void mdev_unregister_device(struct device *dev);

-
Mediated Device Management Interface Through sysfs
==================================================

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..17e9d4634c84 100644
@@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj,
 struct mdev_device *mdev)
  		     dev_name(mdev_dev(mdev)));
  	ret = 0;
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  out:
  	return ret;

}

(quoted diff) +0 -0

b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..b5d223882c6c 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -0
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
  			   private->sch->schid.ssid,
  			   private->sch->schid.sch_no);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..47df1c593c35 100644
@@ -343,6 +343,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
  	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
  	mutex_unlock(&matrix_dev->lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
drivers/vfio/mdev/mdev_core.c +0 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev,
 void *data)  }  EXPORT_SYMBOL(mdev_set_drvdata);
 
Quoted 7 lines

drivers/vfio/mdev/mdev_core.c void mdev_set_drvdata(struct mdev_device *mdev, void *data) · line 53

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +5 -0
+void mdev_set_class(struct mdev_device *mdev, u16 id) {
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+

Usually with every exported symbol we have signature comment block that describes when to use an API etc. Please add it that describes that this API must be called during create() callback.

Ok.

Quoted 24 lines
Quoted 24 lines
drivers/vfio/mdev/mdev_core.c +1 -0
  struct device *mdev_dev(struct mdev_device *mdev)  {
  	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
   *
   * Add device to list of registered parent devices.

* Returns a negative value on error, otherwise 0.

drivers/vfio/mdev/mdev_core.c +3 -0
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
  	if (ret)
  		goto ops_create_fail;
 
+	if (!mdev->class_id)
+		goto class_id_fail;
+
  	ret = device_add(&mdev->dev);
  	if (ret)
  		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
Quoted 4 lines

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 353

Quoted 3 lines
drivers/vfio/mdev/mdev_core.c +1 -0
  sysfs_fail:
  	device_del(&mdev->dev);
+class_id_fail:

No need for new label. Just use add_fail label.

Ok.

Quoted 52 lines
Quoted 52 lines
drivers/vfio/mdev/mdev_core.c +0 -0
  add_fail:
  	parent->ops->remove(mdev);
  ops_create_fail:
(quoted diff) +0 -0

b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b7c40ce86ee3 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->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..c65f436c1869 100644
@@ -33,6 +33,7 @@ struct mdev_device {
  	struct kobject *type_kobj;
  	struct device *iommu_device;
  	bool active;
+	u16 class_id;
  };
 
  #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +0 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
  	vfio_del_group_dev(dev);
  }
 
Quoted 2 lines

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 123

Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +1 -0
+static struct mdev_class_id id_table[] = {

static const

Fixed.

Quoted 5 lines

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 124

Quoted 2 lines
drivers/vfio/mdev/vfio_mdev.c +1 -0
+	{ MDEV_ID_VFIO },

I guess you don't need extra braces for each entry.
Since this enum represents MDEV class id, it better to name it as MDEV_CLASS_ID_VFIO. (Similar to PCI_VENDOR_ID, PCI_DEVICE_ID)..

Will do.

Quoted 31 lines
Quoted 31 lines
drivers/vfio/mdev/vfio_mdev.c +4 -0
+	{ 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..a7570cf13ba4 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 +1 -0
@@ -125,12 +126,14 @@ struct mdev_driver {
  	int  (*probe)(struct device *dev);
  	void (*remove)(struct device *dev);
  	struct device_driver driver;
+	const struct mdev_class_id *id_table;
  };
 
Quoted 6 lines

include/linux/mdev.h struct mdev_driver { · line 136

Quoted 5 lines
include/linux/mdev.h +1 -0
  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
 
  void *mdev_get_drvdata(struct mdev_device *mdev);  void
 mdev_set_drvdata(struct mdev_device *mdev, void *data);
+void mdev_set_class(struct mdev_device *mdev, u16 id);

Better to insert new API after mdev_uuid().

Ok.

Thanks

Quoted 73 lines
Quoted 73 lines
include/linux/mdev.h +5 -0
  const guid_t *mdev_uuid(struct mdev_device *mdev);
 
  extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ 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);
 
+enum {
+	MDEV_ID_VFIO = 1,
+	/* New entries must be added here */
+};
+
  #endif /* MDEV_H */
(quoted diff) +0 -0

b/include/linux/mod_devicetable.h index 5714fd35a83c..f32c6e44fb1a 100644

include/linux/mod_devicetable.h +8 -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;
+};
+
  #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -0
index ac5c8c17b1ff..fd8491e58fe2 100644
@@ -561,6 +561,7 @@ static int mbochs_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	mbochs_reset(mdev);
 
  	mbochs_used_mbytes += type->mbytes;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
 

err_mem:

samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..889472b06708 100644

samples/vfio-mdev/mdpy.c +1 -0
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	mdpy_reset(mdev);
 
  	mdpy_count++;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

ce84a300a4da..618810ca4331 100644

samples/vfio-mdev/mtty.c +1 -1
@@ -755,6 +755,7 @@ static int mtty_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	list_add(&mdev_state->next, &mdev_devices_list);
  	mutex_unlock(&mdev_list_lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
 
--

2.19.1

author
#12 lore raw

Re: [PATCH V3 1/7] mdev: class id support

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

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Friday, October 11, 2019 3:16 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]>; [email protected]; [email protected]; Jason Wang <[email protected]>
Subject: [PATCH V3 1/7] 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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
  Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
  drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
  drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
  drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
  drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
  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                              |  8 ++++++++
  include/linux/mod_devicetable.h                   |  8 ++++++++
  samples/vfio-mdev/mbochs.c                        |  1 +
  samples/vfio-mdev/mdpy.c                          |  1 +
  samples/vfio-mdev/mtty.c                          |  1 +
  13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +2 -0
index 25eb7d5b834b..2035e48da7b2 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 @@ -165,12 +167,15 @@ register itself with the mdev core driver::
extern int mdev_register_device(struct device *dev,
const struct mdev_parent_ops *ops);

Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -0
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 id);

Drop extern.
In actual API you have correct signature, i.e. struct mdev_device. s/struct device/struct mdev_device.

Yes, will fix.

Quoted 60 lines
Quoted 60 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::

  	extern void mdev_unregister_device(struct device *dev);

-
Mediated Device Management Interface Through sysfs
==================================================

drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..17e9d4634c84 100644
@@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj,
 struct mdev_device *mdev)
  		     dev_name(mdev_dev(mdev)));
  	ret = 0;
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  out:
  	return ret;

}

(quoted diff) +0 -0

b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..b5d223882c6c 100644

drivers/s390/cio/vfio_ccw_ops.c +1 -0
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
  			   private->sch->schid.ssid,
  			   private->sch->schid.sch_no);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..47df1c593c35 100644
@@ -343,6 +343,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj,
 struct mdev_device *mdev)
  	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
  	mutex_unlock(&matrix_dev->lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
drivers/vfio/mdev/mdev_core.c +0 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev,
 void *data)  }  EXPORT_SYMBOL(mdev_set_drvdata);
 
Quoted 7 lines

drivers/vfio/mdev/mdev_core.c void mdev_set_drvdata(struct mdev_device *mdev, void *data) · line 53

Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +5 -0
+void mdev_set_class(struct mdev_device *mdev, u16 id) {
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+

Usually with every exported symbol we have signature comment block that describes when to use an API etc. Please add it that describes that this API must be called during create() callback.

Ok.

Quoted 24 lines
Quoted 24 lines
drivers/vfio/mdev/mdev_core.c +1 -0
  struct device *mdev_dev(struct mdev_device *mdev)  {
  	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
   *
   * Add device to list of registered parent devices.

* Returns a negative value on error, otherwise 0.

drivers/vfio/mdev/mdev_core.c +3 -0
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
  	if (ret)
  		goto ops_create_fail;
 
+	if (!mdev->class_id)
+		goto class_id_fail;
+
  	ret = device_add(&mdev->dev);
  	if (ret)
  		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
Quoted 4 lines

drivers/vfio/mdev/mdev_core.c int mdev_device_create(struct kobject *kobj, · line 353

Quoted 3 lines
drivers/vfio/mdev/mdev_core.c +1 -0
  sysfs_fail:
  	device_del(&mdev->dev);
+class_id_fail:

No need for new label. Just use add_fail label.

Ok.

Quoted 52 lines
Quoted 52 lines
drivers/vfio/mdev/mdev_core.c +0 -0
  add_fail:
  	parent->ops->remove(mdev);
  ops_create_fail:
(quoted diff) +0 -0

b/drivers/vfio/mdev/mdev_driver.c index 0d3223aee20b..b7c40ce86ee3 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->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..c65f436c1869 100644
@@ -33,6 +33,7 @@ struct mdev_device {
  	struct kobject *type_kobj;
  	struct device *iommu_device;
  	bool active;
+	u16 class_id;
  };
 
  #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +0 -0
index 30964a4e0a28..fd2a4d9a3f26 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
  	vfio_del_group_dev(dev);
  }
 
Quoted 2 lines

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 123

Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +1 -0
+static struct mdev_class_id id_table[] = {

static const

Fixed.

Quoted 5 lines

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 124

Quoted 2 lines
drivers/vfio/mdev/vfio_mdev.c +1 -0
+	{ MDEV_ID_VFIO },

I guess you don't need extra braces for each entry.
Since this enum represents MDEV class id, it better to name it as MDEV_CLASS_ID_VFIO. (Similar to PCI_VENDOR_ID, PCI_DEVICE_ID)..

Will do.

Quoted 31 lines
Quoted 31 lines
drivers/vfio/mdev/vfio_mdev.c +4 -0
+	{ 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..a7570cf13ba4 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 +1 -0
@@ -125,12 +126,14 @@ struct mdev_driver {
  	int  (*probe)(struct device *dev);
  	void (*remove)(struct device *dev);
  	struct device_driver driver;
+	const struct mdev_class_id *id_table;
  };
 
Quoted 6 lines

include/linux/mdev.h struct mdev_driver { · line 136

Quoted 5 lines
include/linux/mdev.h +1 -0
  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
 
  void *mdev_get_drvdata(struct mdev_device *mdev);  void
 mdev_set_drvdata(struct mdev_device *mdev, void *data);
+void mdev_set_class(struct mdev_device *mdev, u16 id);

Better to insert new API after mdev_uuid().

Ok.

Thanks

Quoted 67 lines
Quoted 67 lines
include/linux/mdev.h +5 -0
  const guid_t *mdev_uuid(struct mdev_device *mdev);
 
  extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ 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);
 
+enum {
+	MDEV_ID_VFIO = 1,
+	/* New entries must be added here */
+};
+
  #endif /* MDEV_H */
(quoted diff) +0 -0

b/include/linux/mod_devicetable.h index 5714fd35a83c..f32c6e44fb1a 100644

include/linux/mod_devicetable.h +8 -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;
+};
+
  #endif /* LINUX_MOD_DEVICETABLE_H */
samples/vfio-mdev/mbochs.c +1 -0
index ac5c8c17b1ff..fd8491e58fe2 100644
@@ -561,6 +561,7 @@ static int mbochs_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	mbochs_reset(mdev);
 
  	mbochs_used_mbytes += type->mbytes;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
 

err_mem:

samples/vfio-mdev/mdpy.c index renamed from samples/vfio-mdev/mdpy.c +0 -0

cc86bf6566e4..889472b06708 100644

samples/vfio-mdev/mdpy.c +1 -0
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	mdpy_reset(mdev);
 
  	mdpy_count++;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
samples/vfio-mdev/mtty.c index renamed from samples/vfio-mdev/mtty.c +0 -0

ce84a300a4da..618810ca4331 100644

samples/vfio-mdev/mtty.c +0 -0
@@ -755,6 +755,7 @@ static int mtty_create(struct kobject *kobj, struct
 mdev_device *mdev)
  	list_add(&mdev_state->next, &mdev_devices_list);
  	mutex_unlock(&mdev_list_lock);
 
Quoted 6 lines
Quoted 6 lines
samples/vfio-mdev/mtty.c +1 -1
+	mdev_set_class(mdev, MDEV_ID_VFIO);
  	return 0;
  }
 
--

2.19.1

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

author
#13 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Parav Pandit
Quoted 8 lines · Parav Pandit
Quoted 1 line

+static struct mdev_class_id id_table[] = {

static const

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 124

Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +1 -0
+	{ MDEV_ID_VFIO },

I guess you don't need extra braces for each entry.
Since this enum represents MDEV class id, it better to name it as MDEV_CLASS_ID_VFIO. (Similar to PCI_VENDOR_ID, PCI_DEVICE_ID)..

Gcc start to complain like:

warning: missing braces around initializer [-Wmissing-braces] static const struct mdev_class_id id_table[] = {
                                                ^ MDEV_ID_VFIO, 0,
  {           } {
 };
 }

So I will keep this part untouched.

Thanks

Quoted 2 lines
Quoted 2 lines
drivers/vfio/mdev/vfio_mdev.c +2 -0
+	{ 0 },
+};
author
#14 lore raw

Re: [PATCH V3 1/7] mdev: class id support

In reply to Parav Pandit
Quoted 8 lines · Parav Pandit
Quoted 1 line

+static struct mdev_class_id id_table[] = {

static const

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 124

Quoted 1 line
drivers/vfio/mdev/vfio_mdev.c +1 -0
+	{ MDEV_ID_VFIO },

I guess you don't need extra braces for each entry.
Since this enum represents MDEV class id, it better to name it as MDEV_CLASS_ID_VFIO. (Similar to PCI_VENDOR_ID, PCI_DEVICE_ID)..

Gcc start to complain like:

warning: missing braces around initializer [-Wmissing-braces] static const struct mdev_class_id id_table[] = {
                                                ^ MDEV_ID_VFIO, 0,
  {           } {
 };
 }

So I will keep this part untouched.

Thanks

Quoted 2 lines

drivers/vfio/mdev/vfio_mdev.c static void vfio_mdev_remove(struct device *dev) · line 126

Quoted 2 lines
drivers/vfio/mdev/vfio_mdev.c +2 -0
+	{ 0 },
+};

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

author
#15 lore raw

PATCH v3 1/7 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, the first driver could be virtio-mdev. 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 device with the match method for mdev bus.

---
 Documentation/driver-api/vfio-mediated-device.rst |  7 ++++++-
 drivers/gpu/drm/i915/gvt/kvmgt.c                  |  1 +
 drivers/s390/cio/vfio_ccw_ops.c                   |  1 +
 drivers/s390/crypto/vfio_ap_ops.c                 |  1 +
 drivers/vfio/mdev/mdev_core.c                     | 11 +++++++++++
 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                              |  8 ++++++++
 include/linux/mod_devicetable.h                   |  8 ++++++++
 samples/vfio-mdev/mbochs.c                        |  1 +
 samples/vfio-mdev/mdpy.c                          |  1 +
 samples/vfio-mdev/mtty.c                          |  1 +
 13 files changed, 60 insertions(+), 1 deletion(-)
Documentation/driver-api/vfio-mediated-device.rst +6 -1
index 25eb7d5b834b..2035e48da7b2 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
@@ -165,12 +167,15 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
+It is also required to specify the class_id through::
+
+	extern int mdev_set_class(struct device *dev, u16 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::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-
 Mediated Device Management Interface Through sysfs
 ==================================================
 
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..17e9d4634c84 100644
@@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 		     dev_name(mdev_dev(mdev)));
 	ret = 0;
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 out:
 	return ret;
 }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
index f0d71ab77c50..b5d223882c6c 100644
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 			   private->sch->schid.ssid,
 			   private->sch->schid.sch_no);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..47df1c593c35 100644
@@ -343,6 +343,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
 	mutex_unlock(&matrix_dev->lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
drivers/vfio/mdev/mdev_core.c +11 -0
index b558d4cfd082..724e9b9841d8 100644
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
@@ -135,6 +141,7 @@ 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: class id.
  *
  * Add device to list of registered parent devices.
  * Returns a negative value on error, otherwise 0.
@@ -324,6 +331,9 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id)
+		goto class_id_fail;
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;
@@ -340,6 +350,7 @@ int mdev_device_create(struct kobject *kobj,
 
 sysfs_fail:
 	device_del(&mdev->dev);
+class_id_fail:
 add_fail:
 	parent->ops->remove(mdev);
 ops_create_fail:
drivers/vfio/mdev/mdev_driver.c +14 -0
index 0d3223aee20b..b7c40ce86ee3 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->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..c65f436c1869 100644
@@ -33,6 +33,7 @@ struct mdev_device {
 	struct kobject *type_kobj;
 	struct device *iommu_device;
 	bool active;
+	u16 class_id;
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
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 +8 -0
index 0ce30ca78db0..a7570cf13ba4 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,12 +126,14 @@ 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)
 
 void *mdev_get_drvdata(struct mdev_device *mdev);
 void mdev_set_drvdata(struct mdev_device *mdev, void *data);
+void mdev_set_class(struct mdev_device *mdev, u16 id);
 const guid_t *mdev_uuid(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ 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);
 
+enum {
+	MDEV_ID_VFIO = 1,
+	/* New entries must be added here */
+};
+
 #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 -0
index ac5c8c17b1ff..fd8491e58fe2 100644
@@ -561,6 +561,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 	mbochs_reset(mdev);
 
 	mbochs_used_mbytes += type->mbytes;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 
 err_mem:
samples/vfio-mdev/mdpy.c +1 -0
index cc86bf6566e4..889472b06708 100644
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
samples/vfio-mdev/mtty.c +1 -0
index ce84a300a4da..618810ca4331 100644
@@ -755,6 +755,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&mdev_state->next, &mdev_devices_list);
 	mutex_unlock(&mdev_list_lock);
 
+	mdev_set_class(mdev, MDEV_ID_VFIO);
 	return 0;
 }
 
Signature · 1 line
2.19.1
author
#16 lore raw

PATCH v3 2/7 mdev: bus uevent support

In reply to Jason Wang

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
 drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +8 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
 	return 0;
 }
 
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
 	.match		= mdev_match,
+	.uevent		= mdev_uevent,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
Signature · 1 line
2.19.1
#17 lore raw

Re: [PATCH V3 2/7] mdev: bus uevent support

Quoted 20 lines · On Fri, 11 Oct 2019 16:15:52 +0800 Jason Wang <[email protected]> wrote:

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
 drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +4 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
 	return 0;
 }
 
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+

drivers/vfio/mdev/mdev_driver.c static int mdev_match(struct device *dev, struct device_driver *drv) · line 98

Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
 	.match		= mdev_match,
+	.uevent		= mdev_uevent,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };

I'd merge that into the previous patch.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#18 lore raw

Re: [PATCH V3 2/7] mdev: bus uevent support

Quoted 19 lines · Cornelia Huck
Quoted 16 lines · On Fri, 11 Oct 2019 16:15:52 +0800 Jason Wang <[email protected]> wrote:

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
  drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +0 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
  	return 0;
  }
 
Quoted 15 lines
Quoted 4 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+

drivers/vfio/mdev/mdev_driver.c static int mdev_match(struct device *dev, struct device_driver *drv) · line 98

Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
  struct bus_type mdev_bus_type = {
  	.name		= "mdev",
  	.match		= mdev_match,
+	.uevent		= mdev_uevent,
  	.probe		= mdev_probe,
  	.remove		= mdev_remove,
  };

I'd merge that into the previous patch.

Will do.

Thanks

author
#19 lore raw

Re: [PATCH V3 2/7] mdev: bus uevent support

In reply to Cornelia Huck
Quoted 19 lines · Cornelia Huck
Quoted 16 lines · On Fri, 11 Oct 2019 16:15:52 +0800 Jason Wang <[email protected]> wrote:

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
  drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +0 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
  	return 0;
  }
 
Quoted 15 lines
Quoted 4 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+

drivers/vfio/mdev/mdev_driver.c static int mdev_match(struct device *dev, struct device_driver *drv) · line 98

Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
  struct bus_type mdev_bus_type = {
  	.name		= "mdev",
  	.match		= mdev_match,
+	.uevent		= mdev_uevent,
  	.probe		= mdev_probe,
  	.remove		= mdev_remove,
  };

I'd merge that into the previous patch.

Will do.

Thanks

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

#20 lore raw

Re: [PATCH V3 2/7] mdev: bus uevent support

In reply to Jason Wang
Quoted 20 lines · On Fri, 11 Oct 2019 16:15:52 +0800 Jason Wang <[email protected]> wrote:

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
 drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +4 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
 	return 0;
 }
 
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+

drivers/vfio/mdev/mdev_driver.c static int mdev_match(struct device *dev, struct device_driver *drv) · line 98

Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +4 -0
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
 	.match		= mdev_match,
+	.uevent		= mdev_uevent,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };

I'd merge that into the previous patch.

Reviewed-by on v3 2/7
#21 lore raw

RE: [PATCH V3 2/7] mdev: bus uevent support

In reply to Jason Wang
Quoted 59 lines

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Friday, October 11, 2019 3:16 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]>; [email protected]; [email protected]; Jason Wang <[email protected]>
Subject: [PATCH V3 2/7] mdev: bus uevent support

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
 drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)
(quoted diff) +0 -0

b/drivers/vfio/mdev/mdev_driver.c index b7c40ce86ee3..319d886ffaf7 100644

drivers/vfio/mdev/mdev_driver.c +7 -1
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct
 device_driver *drv)
 	return 0;
 }
 
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev-
 >class_id); }
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
 	.match		= mdev_match,
+	.uevent		= mdev_uevent,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
--
Quoted 1 line

2.19.1

author
#22 lore raw

PATCH v3 2/7 mdev: bus uevent support

In reply to Jason Wang

This patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.

---
 drivers/vfio/mdev/mdev_driver.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +8 -0
index b7c40ce86ee3..319d886ffaf7 100644
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)
 	return 0;
 }
 
+static int mdev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct mdev_device *mdev = to_mdev_device(dev);
+
+	return add_uevent_var(env, "MODALIAS=mdev:c%02X", mdev->class_id);
+}
+
 struct bus_type mdev_bus_type = {
 	.name		= "mdev",
 	.match		= mdev_match,
+	.uevent		= mdev_uevent,
 	.probe		= mdev_probe,
 	.remove		= mdev_remove,
 };
Signature · 1 line
2.19.1
author
#23 lore raw

PATCH v3 3/7 modpost: add support for mdev class id

In reply to Jason Wang

Add support to parse mdev class id table.

---
 drivers/vfio/mdev/vfio_mdev.c     |  2 ++
 scripts/mod/devicetable-offsets.c |  3 +++
 scripts/mod/file2alias.c          | 10 ++++++++++
 3 files changed, 15 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
index fd2a4d9a3f26..891cf83a2d9a 100644
@@ -125,6 +125,8 @@ static struct mdev_class_id id_table[] = {
 	{ 0 },
 };
 
+MODULE_DEVICE_TABLE(mdev, id_table);
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
scripts/mod/devicetable-offsets.c +3 -0
index 054405b90ba4..6cbb1062488a 100644
@@ -231,5 +231,8 @@ int main(void)
 	DEVID(wmi_device_id);
 	DEVID_FIELD(wmi_device_id, guid_string);
 
+	DEVID(mdev_class_id);
+	DEVID_FIELD(mdev_class_id, id);
+
 	return 0;
 }
scripts/mod/file2alias.c +10 -0
index c91eba751804..d365dfe7c718 100644
@@ -1335,6 +1335,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* looks like: "mdev:cN" */
+static int do_mdev_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD(symval, mdev_class_id, id);
+
+	sprintf(alias, "mdev:c%02X", id);
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1407,6 +1416,7 @@ static const struct devtable devtable[] = {
 	{"typec", SIZE_typec_device_id, do_typec_entry},
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
+	{"mdev", SIZE_mdev_class_id, do_mdev_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 6 lines
2.19.1

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

PATCH v3 3/7 modpost: add support for mdev class id

In reply to Jason Wang

Add support to parse mdev class id table.

---
 drivers/vfio/mdev/vfio_mdev.c     |  2 ++
 scripts/mod/devicetable-offsets.c |  3 +++
 scripts/mod/file2alias.c          | 10 ++++++++++
 3 files changed, 15 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
index fd2a4d9a3f26..891cf83a2d9a 100644
@@ -125,6 +125,8 @@ static struct mdev_class_id id_table[] = {
 	{ 0 },
 };
 
+MODULE_DEVICE_TABLE(mdev, id_table);
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
scripts/mod/devicetable-offsets.c +3 -0
index 054405b90ba4..6cbb1062488a 100644
@@ -231,5 +231,8 @@ int main(void)
 	DEVID(wmi_device_id);
 	DEVID_FIELD(wmi_device_id, guid_string);
 
+	DEVID(mdev_class_id);
+	DEVID_FIELD(mdev_class_id, id);
+
 	return 0;
 }
scripts/mod/file2alias.c +10 -0
index c91eba751804..d365dfe7c718 100644
@@ -1335,6 +1335,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)
 	return 1;
 }
 
+/* looks like: "mdev:cN" */
+static int do_mdev_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD(symval, mdev_class_id, id);
+
+	sprintf(alias, "mdev:c%02X", id);
+	return 1;
+}
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
@@ -1407,6 +1416,7 @@ static const struct devtable devtable[] = {
 	{"typec", SIZE_typec_device_id, do_typec_entry},
 	{"tee", SIZE_tee_client_device_id, do_tee_entry},
 	{"wmi", SIZE_wmi_device_id, do_wmi_entry},
+	{"mdev", SIZE_mdev_class_id, do_mdev_entry},
 };
 
 /* Create MODULE_ALIAS() statements.
Signature · 1 line
2.19.1
author
#25 lore raw

PATCH v3 4/7 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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
 .../driver-api/vfio-mediated-device.rst       | 22 +++++---
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
 drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
 drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
 drivers/vfio/mdev/mdev_core.c                 |  9 +++-
 drivers/vfio/mdev/mdev_private.h              |  1 +
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 42 +++------------
 include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 21 +++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 177 insertions(+), 96 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +16 -6
index 2035e48da7b2..553574ebba73 100644
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:
 
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver. The device_ops is device
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver. For vfio-mdev device, its device specific
+ops are as follows:
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
 * read : read emulation callback
 * write: write emulation callback
 * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);
 
 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::
MAINTAINERS +1 -0
index 8824f61cd2c0..3d196a023b5e 100644
@@ -17127,6 +17127,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 +11 -7
index 17e9d4634c84..7e2b720074fd 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>
@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)
 	vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device);
 }
 
+static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops;
+
 static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct intel_vgpu *vgpu = NULL;
@@ -678,7 +681,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 		     dev_name(mdev_dev(mdev)));
 	ret = 0;
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);
 out:
 	return ret;
 }
@@ -1599,20 +1602,21 @@ 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 const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_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,
+};
+
 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 +12 -6
index b5d223882c6c..322991f0feb0 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>
 
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct vfio_ccw_private *private =
@@ -129,7 +132,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 			   private->sch->schid.ssid,
 			   private->sch->schid.sch_no);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -575,11 +578,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_device_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
 	.read			= vfio_ccw_mdev_read,
@@ -587,6 +586,13 @@ 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,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
 	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +10 -4
index 47df1c593c35..e9bd5f3b1cc2 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>
 
@@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
 	matrix->adm_max = info->apxa ? info->Nd : 15;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct ap_matrix_mdev *matrix_mdev;
@@ -343,7 +346,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
 	mutex_unlock(&matrix_dev->lock);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -1281,15 +1284,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_device_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,
 };
 
 int vfio_ap_mdev_register(void)
drivers/vfio/mdev/mdev_core.c +8 -1
index 724e9b9841d8..c79d0e16522b 100644
@@ -45,12 +45,19 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
-void mdev_set_class(struct mdev_device *mdev, u16 id)
+void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops)
 {
 	mdev->class_id = id;
+	mdev->device_ops = ops;
 }
 EXPORT_SYMBOL(mdev_set_class);
 
+const void *mdev_get_dev_ops(struct mdev_device *mdev)
+{
+	return mdev->device_ops;
+}
+EXPORT_SYMBOL(mdev_get_dev_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +1 -0
index c65f436c1869..b666805f0b1f 100644
@@ -34,6 +34,7 @@ struct mdev_device {
 	struct device *iommu_device;
 	bool active;
 	u16 class_id;
+	const void *device_ops;
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
index 891cf83a2d9a..95efa054442f 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"
 
@@ -24,16 +25,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_device_ops *ops = mdev_get_dev_ops(mdev);
 	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);
 
@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)
 static void vfio_mdev_release(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
 				     unsigned int cmd, unsigned long arg)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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,
 			      size_t count, loff_t *ppos)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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,
 			       size_t count, loff_t *ppos)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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 +8 -34

66 lines not on this page · raw message

include/linux/vfio_mdev.h new file +52 -0

52 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +13 -7
index fd8491e58fe2..9db771ed5e4b 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>
@@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)
 	return 0;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mbochs_type *type = mbochs_find_type(kobj);
@@ -561,7 +564,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 	mbochs_reset(mdev);
 
 	mbochs_used_mbytes += type->mbytes;
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 
 err_mem:
@@ -1419,12 +1422,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_device_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
 	.read			= mbochs_read,
@@ -1433,6 +1431,14 @@ 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,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c +14 -7
index 889472b06708..f0fdbc6ec706 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"
@@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)
 	return 0;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -269,7 +272,8 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -726,12 +730,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_device_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -740,6 +739,14 @@ 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,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c +12 -6
index 618810ca4331..18d0f83a228a 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>
@@ -708,6 +709,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,
 	return ret;
 }
 
+static const struct vfio_mdev_device_ops vfio_dev_ops;
+
 static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct mdev_state *mdev_state;
@@ -755,7 +758,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&mdev_state->next, &mdev_devices_list);
 	mutex_unlock(&mdev_list_lock);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_dev_ops);
 	return 0;
 }
 
@@ -1388,6 +1391,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_device_ops vfio_dev_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,
@@ -1395,11 +1406,6 @@ 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,
 };
 
 static void mtty_device_release(struct device *dev)
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#26 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
 .../driver-api/vfio-mediated-device.rst       | 22 +++++---
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
 drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
 drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
 drivers/vfio/mdev/mdev_core.c                 |  9 +++-
 drivers/vfio/mdev/mdev_private.h              |  1 +
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 42 +++------------
 include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 21 +++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 177 insertions(+), 96 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver. 

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -0
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
 * read : read emulation callback
 * write: write emulation callback
 * mmap: mmap emulation callback

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 9 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -2
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops? If the former, would it make sense to first register the ops for an id (once), and then have the ->create callback only set the class id (with the core doing the lookup of the ops)?

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
 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::
author
#27 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 63 lines · Cornelia Huck
Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
  .../driver-api/vfio-mediated-device.rst       | 22 +++++---
  MAINTAINERS                                   |  1 +
  drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
  drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
  drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
  drivers/vfio/mdev/mdev_core.c                 |  9 +++-
  drivers/vfio/mdev/mdev_private.h              |  1 +
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 42 +++------------
  include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 21 +++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 177 insertions(+), 96 deletions(-)

create mode 100644 include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver.

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

Quoted 8 lines

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

All you propose is better than what I wrote, will change the docs.

Quoted 15 lines
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +5 -1
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
  * read : read emulation callback
  * write: write emulation callback
  * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

Thanks

Quoted 7 lines

If the former, would it make sense to first
register the ops for an id (once), and then have the ->create callback only set the class id (with the core doing the lookup of the ops)?

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
  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::
#28 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 100 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 63 lines · Cornelia Huck
Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
  .../driver-api/vfio-mediated-device.rst       | 22 +++++---
  MAINTAINERS                                   |  1 +
  drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
  drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
  drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
  drivers/vfio/mdev/mdev_core.c                 |  9 +++-
  drivers/vfio/mdev/mdev_private.h              |  1 +
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 42 +++------------
  include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 21 +++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 177 insertions(+), 96 deletions(-)

create mode 100644 include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:  

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.  

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver.  

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

Quoted 8 lines

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

All you propose is better than what I wrote, will change the docs.

Quoted 15 lines
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +5 -1
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
  * read : read emulation callback
  * write: write emulation callback
  * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);  

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

Quoted 2 lines

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

#29 lore raw

RE: [PATCH V3 4/7] mdev: introduce device specific ops

Hi Alex,

Quoted 163 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 29 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 28 lines · Cornelia Huck
Quoted 25 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
  .../driver-api/vfio-mediated-device.rst       | 22 +++++---
  MAINTAINERS                                   |  1 +
  drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
  drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
  drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
  drivers/vfio/mdev/mdev_core.c                 |  9 +++-
  drivers/vfio/mdev/mdev_private.h              |  1 +
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 42 +++------------
  include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 21 +++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 177 insertions(+), 96 deletions(-)

create mode 100644 include/linux/vfio_mdev.h

Quoted 6 lines
Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644
@@ -152,11 +152,20 @@ callbacks per mdev parent device, per mdev

type, or any other categorization.

Quoted 58 lines
Quoted 32 lines

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
  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:
+In order to support multiple types of device/driver, device needs
+to provide both class_id and device_ops through:

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 9 lines
Documentation/driver-api/vfio-mediated-device.rst +5 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const
+ void *ops);
+
+The class_id is used to be paired with ids in id_table in
+mdev_driver structure for probing the correct driver.

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver.

"The device specific callbacks (specified in *ops) are obtainable via
mdev_get_dev_ops() (for use by the mdev bus driver.)"

Quoted 8 lines

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

All you propose is better than what I wrote, will change the docs.

Quoted 13 lines
Quoted 13 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -0
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
  * read : read emulation callback
  * write: write emulation callback
  * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops
 *ops);
 
Quoted 2 lines
Quoted 2 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 180

Quoted 2 lines
Documentation/driver-api/vfio-mediated-device.rst +1 -1
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops

through::

Quoted 11 lines
Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint"
driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 4 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better to keep const multiple ops in their parent device. Something like below,

struct mdev_parent {
[..]
struct mdev_parent_ops *parent_ops; /* create, remove */ struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */ struct virtio_mdev_ops *virtio_ops; /* virtio ops */
};

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not expected to grow a lot.
(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#30 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 97 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 78 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 11 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 10 lines · Cornelia Huck

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 180

Quoted 7 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:
Documentation/driver-api/vfio-mediated-device.rst +1 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops
 *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops  

through::

Quoted 11 lines
Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);  

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint"
driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 4 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better to keep const multiple ops in their parent device. Something like below,

Quoted 6 lines

struct mdev_parent {
[..]
struct mdev_parent_ops *parent_ops; /* create, remove */ struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */ struct virtio_mdev_ops *virtio_ops; /* virtio ops */
};

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

Quoted 11 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not expected to grow a lot.
(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct vfio_mdev_ops *vfio_ops)

{
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct virtio_mdev_ops *virtio_ops)

{
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct virtio_mdev_ops *virtio_ops)

{
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}

void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */

{
	mdev->class_id = MDEV_ID_VENDOR;
}

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

#31 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 131 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 94 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 81 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops

through::

Quoted 11 lines
Quoted 7 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 5 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Quoted 6 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 2 lines

Something like below,

Quoted 9 lines
Quoted 5 lines
struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them.
It carries because parent is few, mdevs are several hundreds.
It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

Quoted 32 lines
Quoted 11 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

Quoted 8 lines
virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}

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

#32 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 135 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 135 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 94 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 81 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops  

through::

Quoted 11 lines
Quoted 7 lines

Review register itself with the mdev core driver:: · line 183

Quoted 4 lines
(quoted diff) +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);  

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 5 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Quoted 6 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };  
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it. We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent. For instance, for a vfio-mdev we already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device. The other drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

Quoted 37 lines
Quoted 37 lines
Quoted 11 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
Quoted 3 lines
Quoted 3 lines
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}  

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#33 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 187 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Wednesday, October 16, 2019 11:53 AM
To: Parav Pandit <[email protected]>
Cc: Cornelia Huck <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 86 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 86 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 58 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 56 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops

through::

Quoted 12 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 183

Quoted 4 lines
(quoted diff) +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a
1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do

something like:

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev)

{

Quoted 30 lines
Quoted 30 lines
Quoted 14 lines
Quoted 9 lines
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev 2. mdev binding to virtio 3. mdev binding to mlx5_core without dev_ops

Quoted 7 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it.
We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

Quoted 4 lines

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent.

We should have driver who intent to use different device ops for each device with single parent that supports this claim.

For instance, for a vfio-mdev we

Quoted 4 lines

already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device.

I am not sure if this is really worth it.
Which driver should I look which has if-else conditions sprinkled in these callbacks for different iommu types? If majority code is same, adding few branches looks ok vs creating new ops all together.
So I need to educate myself first with the driver which desires this. Any pointers?

Quoted 5 lines

The other
drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Yeah, we don't support and there is no requirement for binary compatibility.

Quoted 4 lines

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

I am fine with Cornelia's approach.
It comes with small cost of additional symbols and it is probably ok. I just find it over engineered given handful of dev ops types.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 11 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

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

#34 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 92 lines · On Wed, 16 Oct 2019 20:48:06 +0000 Parav Pandit <[email protected]> wrote:
Quoted 92 lines

From: Alex Williamson <[email protected]>

Quoted 16 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 16 lines

From: Cornelia Huck <[email protected]>

Quoted 14 lines · Parav Pandit
Quoted 14 lines

From: Alex Williamson <[email protected]>

Quoted 9 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 4 lines · Cornelia Huck

Apologies if that has already been discussed, but do we want a
1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do

something like:

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev)

{

Quoted 30 lines
Quoted 30 lines
Quoted 14 lines
Quoted 9 lines
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev 2. mdev binding to virtio 3. mdev binding to mlx5_core without dev_ops

Quoted 7 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };  
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it.
We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

Quoted 6 lines
Quoted 4 lines

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent.

We should have driver who intent to use different device ops for each device with single parent that supports this claim.

Why? Are we not allowed to identify restrictions implied by a given proposal if we don't yet have a user? I can't subscribe to that.

Quoted 6 lines

For instance, for a vfio-mdev we

Quoted 5 lines

already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device.

Quoted 6 lines

I am not sure if this is really worth it.
Which driver should I look which has if-else conditions sprinkled in these callbacks for different iommu types? If majority code is same, adding few branches looks ok vs creating new ops all together. So I need to educate myself first with the driver which desires this. Any pointers?

While the iommu backed vfio-mdevs is real, the example that a parent driver might choose to register different device ops based on that is theoretical. Parent drivers don't have that option today, but as we're making the device ops more modular and have stumbled onto this benefit of per device ops, perhaps it might be useful. The "is it worth it" question can also be asked of the claimed benefits of a set of shared devices ops per parent.

Quoted 8 lines
Quoted 5 lines

The other
drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Yeah, we don't support and there is no requirement for binary compatibility.

Quoted 7 lines
Quoted 4 lines

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

I am fine with Cornelia's approach.
It comes with small cost of additional symbols and it is probably ok. I just find it over engineered given handful of dev ops types.

If the device ops types are limited, then so are the additional symbols. Those symbols also add a degree of explicitness to the interface (ie. register this device as vfio-mdev with this set of vfio-mdev-ops, versus register this device as vfio-mdev... which uses the vfio-mdev-ops over in the parent ops structure). I don't really see what's over-engineered about former. I like to think of Rusty's old interface guidelines, particularly the one about making it difficult to use incorrectly for these sorts of interfaces. Thanks,

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

#35 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 128 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Wednesday, October 16, 2019 5:38 PM
To: Parav Pandit <[email protected]>
Cc: Cornelia Huck <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 9 lines · On Wed, 16 Oct 2019 20:48:06 +0000 Parav Pandit <[email protected]> wrote:
Quoted 9 lines

From: Alex Williamson <[email protected]> On Wed, 16 Oct

Quoted 7 lines · 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 7 lines

From: Cornelia Huck <[email protected]> Parav Pandit

Quoted 5 lines · <[email protected]> wrote:
Quoted 5 lines

From: Alex Williamson <[email protected]> On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]>

Quoted 1 line · wrote:

On 2019/10/15 下午6:41, Cornelia Huck wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Apologies if that has already been discussed, but do we want a
1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device

ops.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined

together.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

They are effectively interlocked, the id defines which mdev

"endpoint"

Quoted 21 lines
Quoted 21 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do

something like:

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev)

{

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops; }

The match callback would of course just use the mdev->class.id

value.

Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 19 lines
Quoted 9 lines
Quoted 4 lines

Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev 2. mdev binding to virtio 3. mdev binding to mlx5_core without dev_ops

Quoted 7 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 2 lines

Something like below,

Quoted 9 lines
Quoted 5 lines
struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

Quoted 6 lines
Quoted 6 lines

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how

we get to it.

Quoted 7 lines
Quoted 7 lines

We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of

Quoted 8 lines

mdev devices for a given parent all

Quoted 3 lines
Quoted 1 line

make the same callbacks into the parent.

We should have driver who intent to use different device ops for each device with single parent that supports this claim.

Why? Are we not allowed to identify restrictions implied by a given proposal if we don't yet have a user? I can't subscribe to that.

Of course we can identify the restrictions.
But if there is no current user, who is it restricting?
A future use case? Why can't that change be done when an actual user needs it?

Quoted 33 lines
Quoted 6 lines

For instance, for a vfio-mdev we

Quoted 5 lines

already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device.

Quoted 6 lines

I am not sure if this is really worth it.
Which driver should I look which has if-else conditions sprinkled in these callbacks for different iommu types? If majority code is same, adding few branches looks ok vs creating new ops all together. So I need to educate myself first with the driver which desires this. Any pointers?

While the iommu backed vfio-mdevs is real, the example that a parent driver might choose to register different device ops based on that is theoretical. Parent drivers don't have that option today, but as we're making the device ops more modular and have stumbled onto this benefit of per device ops, perhaps it might be useful. The "is it worth it"
question can also be asked of the claimed benefits of a set of shared devices ops per parent.

Quoted 12 lines
Quoted 5 lines

The other
drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Yeah, we don't support and there is no requirement for binary compatibility.

Quoted 4 lines

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

Quoted 6 lines
Quoted 3 lines

I am fine with Cornelia's approach.
It comes with small cost of additional symbols and it is probably ok. I just find it over engineered given handful of dev ops types.

If the device ops types are limited, then so are the additional symbols. Those symbols also add a degree of explicitness to the interface

Explicitness is good to avoid error.
Such explicitness exist in both the methods if ops are per parent or per device.

(ie. register this

Quoted 3 lines

device as vfio-mdev with this set of vfio-mdev-ops, versus register this device as vfio-mdev... which uses the vfio-mdev-ops over in the parent ops structure). I don't really see what's over-engineered about former.

Vendor driver is expected to setup mdev_device ops field during create() callback for every device vs setting up once during parent setup time. Currently we have only 3 types of ops, but there is no single driver identified who intent to set more than one type per parent for two different device. And for this theoretical use case we are adding 3 exported symbols for setting it.

Anyways, I am ok with this approach too, I just want to see APIs evolving based on actual use case.

Quoted 3 lines

I like to think of Rusty's
old interface guidelines, particularly the one about making it difficult to use incorrectly for these sorts of interfaces. Thanks,

If the call is made only one time per parent, compare to 100 times per mdev, how can it go wrong or how is it difficult to use?

Quoted 2 lines

Alex

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

author
#36 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Alex Williamson
Quoted 163 lines · Alex Williamson
Quoted 130 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 130 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 90 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 78 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
   	extern int  mdev_register_device(struct device *dev,
   	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops

through::

Quoted 9 lines
Quoted 6 lines

Review register itself with the mdev core driver:: · line 183

Quoted 3 lines
(quoted diff) +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 5 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Quoted 6 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it. We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent. For instance, for a vfio-mdev we already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device. The other drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Quoted 4 lines

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

Will go this way.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

Quoted 7 lines

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

I will add a BUG_ON() when class_id has already set.

Thanks

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

#37 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 26 lines · On Thu, 17 Oct 2019 16:30:43 +0800 Jason Wang <[email protected]> wrote:
Quoted 24 lines · Alex Williamson
Quoted 24 lines
Quoted 24 lines

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}  
Quoted 7 lines
Quoted 4 lines

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

I will add a BUG_ON() when class_id has already set.

Probably better a WARN_ON()?
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#38 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 28 lines · Cornelia Huck
Quoted 25 lines · On Thu, 17 Oct 2019 16:30:43 +0800 Jason Wang <[email protected]> wrote:
Quoted 24 lines · Alex Williamson
Quoted 24 lines
Quoted 24 lines

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

I will add a BUG_ON() when class_id has already set.

Probably better a WARN_ON()?

Right.

Thanks

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

author
#39 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Cornelia Huck
Quoted 28 lines · Cornelia Huck
Quoted 25 lines · On Thu, 17 Oct 2019 16:30:43 +0800 Jason Wang <[email protected]> wrote:
Quoted 24 lines · Alex Williamson
Quoted 24 lines
Quoted 24 lines

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

I will add a BUG_ON() when class_id has already set.

Probably better a WARN_ON()?

Right.

Thanks

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

author
#40 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Alex Williamson
Quoted 163 lines · Alex Williamson
Quoted 130 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 130 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 90 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 78 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
   	extern int  mdev_register_device(struct device *dev,
   	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops

through::

Quoted 9 lines
Quoted 6 lines

Review register itself with the mdev core driver:: · line 183

Quoted 3 lines
(quoted diff) +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 5 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Quoted 6 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it. We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent. For instance, for a vfio-mdev we already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device. The other drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Quoted 4 lines

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

Will go this way.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

Quoted 7 lines

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

Alex

I will add a BUG_ON() when class_id has already set.

Thanks

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

#41 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Parav Pandit
Quoted 135 lines · On Wed, 16 Oct 2019 15:31:25 +0000 Parav Pandit <[email protected]> wrote:
Quoted 135 lines

-----Original Message-----
From: Cornelia Huck <[email protected]>
Sent: Wednesday, October 16, 2019 3:53 AM
To: Parav Pandit <[email protected]>
Cc: Alex Williamson <[email protected]>; Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; intel- [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]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 94 lines · On Wed, 16 Oct 2019 05:50:08 +0000 Parav Pandit <[email protected]> wrote:

Hi Alex,

Quoted 81 lines

-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, October 15, 2019 12:27 PM
To: Jason Wang <[email protected]>
Cc: Cornelia Huck <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; [email protected]; intel-gvt- [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]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops

Quoted 4 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 2 lines · Cornelia Huck

On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
<[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines

Review register itself with the mdev core driver:: · line 181

Quoted 8 lines
(quoted diff) +2 -1
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct
 mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device
+specific ops  

through::

Quoted 11 lines
Quoted 7 lines

Review register itself with the mdev core driver:: · line 183

Quoted 4 lines
(quoted diff) +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);  

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}
Quoted 5 lines

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

Alex

We have 3 use cases of mdev.
1. current mdev binding to vfio_mdev
2. mdev binding to virtio
3. mdev binding to mlx5_core without dev_ops

Quoted 6 lines

Also
(a) a given parent may serve multiple types of classes in future.
(b) number of classes may not likely explode, they will be handful of them. (vfio_mdev, virtio)

So, instead of making copies of this dev_ops pointer in each mdev, it is better

to keep const multiple ops in their parent device.

Quoted 7 lines

Something like below,

struct mdev_parent {
	[..]
	struct mdev_parent_ops *parent_ops; /* create, remove */
	struct vfio_mdev_ops *vfio_ops; /* read,write, ioctl etc */
	struct virtio_mdev_ops *virtio_ops; /* virtio ops */ };  
Quoted 7 lines
Quoted 3 lines

That feels a bit odd. Why should the parent carry pointers to every possible version of ops?

How many are we expecting? I envisioned handful of them. It carries because parent is few, mdevs are several hundreds. It makes sense to keep few copies, instead of several hundred copies and it doesn't need to setup on every mdev creation.

It does need setup on every mdev creation, it's just a matter of the scope, 'id and ops' vs 'id only' vs 'ops with implicit id'. The other argument is assuming a space vs time trade-off that I'm having a hard time judging is necessarily the correct approach. We potentially have better data locality in the mdev device structure vs the parent. The caching of the ops structure itself is separate from how we get to it. We might have hundreds of pointers to those ops structure, but the space trade-off might we worth it if they're on the same cacheline as the mdev device itself vs the indirection via the parent.

I see a couple other drawbacks to the parent hosted ops pointers as well. First, it imposes that per parent there can only be one device ops structure per class id, but who's to say that different types of mdev devices for a given parent all make the same callbacks into the parent. For instance, for a vfio-mdev we already support the concept of an iommu backing device which makes the type1 iommu code behave a little differently. Those differences might be sufficient that the parent driver would register a different device ops structure for an iommu backed mdev vs a non-iommu backed device. The other drawback is that it implies a binary difference in all mdev parent drivers to add any new device ids. I know we don't guarantee binary compatibility, but it's rather ugly.

Overall, I guess I tend to prefer Connie's proposal, the class id and structure are tied together and the parent driver is only responsible for one of them, the class id is hidden away in mdev-core and the mdev driver itself.

Quoted 37 lines
Quoted 37 lines
Quoted 11 lines

const struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_parent *parent); const struct virtio_mdev_ops *mdev_get_virtio_ops(struct mdev_parent *parent);

This way,
(a) we have strong type check support
(b) ops pointer is not duplicated across several hundred mdev devices, and don't have to set on every mdev creation
(c) all 3 classes of mdev are supported
(d) one extra symbol table entry used per ops type, but there are not

expected to grow a lot.

Quoted 3 lines

(e) multiple classes per single parent is still supported
(f) still extendible for multiple classes (well defined classes = vfio, virtio, and vendor class)

Yet another suggestion: have the class id derive from the function you use to set up the ops.

void mdev_set_vfio_ops(struct mdev_device *mdev, const struct

vfio_mdev_ops *vfio_ops) {
	mdev->device_ops = vfio_ops;
	mdev->class_id = MDEV_ID_VFIO;
}

void mdev_set_virtio_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VIRTIO;
}

void mdev_set_vhost_ops(struct mdev_device *mdev, const struct

virtio_mdev_ops *virtio_ops) {
	mdev->device_ops = virtio_ops;
	mdev->class_id = MDEV_ID_VHOST;
}
Quoted 3 lines
Quoted 3 lines
void mdev_set_vendor_ops(struct mdev_device *mdev) /* no ops */ {
	mdev->class_id = MDEV_ID_VENDOR;
}  

One further step towards making this hard to use incorrectly might be to return an error if class_id is already set. Thanks,

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

#42 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Jason Wang
Quoted 100 lines · On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang <[email protected]> wrote:
Quoted 63 lines · Cornelia Huck
Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
  .../driver-api/vfio-mediated-device.rst       | 22 +++++---
  MAINTAINERS                                   |  1 +
  drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
  drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
  drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
  drivers/vfio/mdev/mdev_core.c                 |  9 +++-
  drivers/vfio/mdev/mdev_private.h              |  1 +
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 42 +++------------
  include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 21 +++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 177 insertions(+), 96 deletions(-)

create mode 100644 include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:  

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.  

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver.  

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

Quoted 8 lines

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

All you propose is better than what I wrote, will change the docs.

Quoted 15 lines
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +5 -1
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
  * read : read emulation callback
  * write: write emulation callback
  * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);  

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

Quoted 2 lines

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

The contents of the ops structure is essentially defined by the id, which is why I was leaning towards them being defined together. They are effectively interlocked, the id defines which mdev "endpoint" driver is loaded and that driver requires mdev_get_dev_ops() to return the structure required by the driver. I wish there was a way we could incorporate type checking here. We toyed with the idea of having the class in the same structure as the ops, but I think this approach was chosen for simplicity. We could still do something like:

int mdev_set_class_struct(struct device *dev, const struct mdev_class_struct *class);

struct mdev_class_struct {
	u16	id;
	union {
		struct vfio_mdev_ops vfio_ops;
		struct virtio_mdev_ops virtio_ops;
	};
};

Maybe even:

struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device *mdev) {
	BUG_ON(mdev->class.id != MDEV_ID_VFIO);
	return &mdev->class.vfio_ops;
}

The match callback would of course just use the mdev->class.id value. Functionally equivalent, but maybe better type characteristics. Thanks,

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

author
#43 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Cornelia Huck
Quoted 63 lines · Cornelia Huck
Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
  .../driver-api/vfio-mediated-device.rst       | 22 +++++---
  MAINTAINERS                                   |  1 +
  drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
  drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
  drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
  drivers/vfio/mdev/mdev_core.c                 |  9 +++-
  drivers/vfio/mdev/mdev_private.h              |  1 +
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 42 +++------------
  include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 21 +++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 177 insertions(+), 96 deletions(-)

create mode 100644 include/linux/vfio_mdev.h

Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver.

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

Quoted 8 lines

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

All you propose is better than what I wrote, will change the docs.

Quoted 15 lines
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +5 -1
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
  * read : read emulation callback
  * write: write emulation callback
  * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
  	extern int  mdev_register_device(struct device *dev,
  	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
Quoted 6 lines

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops?

I think we have a N:1 mapping between id and ops, e.g we want both virtio-mdev and vhost-mdev use a single set of device ops.

Thanks

Quoted 7 lines

If the former, would it make sense to first
register the ops for an id (once), and then have the ->create callback only set the class id (with the core doing the lookup of the ops)?

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
  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::

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

#44 lore raw

Re: [PATCH V3 4/7] mdev: introduce device specific ops

In reply to Jason Wang
Quoted 30 lines · On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang <[email protected]> wrote:

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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
 .../driver-api/vfio-mediated-device.rst       | 22 +++++---
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
 drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
 drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
 drivers/vfio/mdev/mdev_core.c                 |  9 +++-
 drivers/vfio/mdev/mdev_private.h              |  1 +
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 42 +++------------
 include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 21 +++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 177 insertions(+), 96 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +0 -0
index 2035e48da7b2..553574ebba73 100644

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 156

Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +2 -1
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:

"As multiple types of mediated devices may be supported, the device needs to set up the class id and the device specific callbacks via:"

?

Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization.

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -3
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver.

"The class id (specified in id) is used to match a device with an mdev driver via its id table."

?

Documentation/driver-api/vfio-mediated-device.rst

Quoted 3 lines

The device_ops is device

Documentation/driver-api/vfio-mediated-device.rst +2 -0
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver. 

"The device specific callbacks (specified in *ops) are obtainable via mdev_get_dev_ops() (for use by the mdev bus driver.)"

?

Quoted 2 lines

For vfio-mdev device, its device specific
+ops are as follows:

"A vfio-mdev device (class id MDEV_ID_VFIO) uses the following device-specific ops:"

?

Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst +4 -0
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
 * read : read emulation callback
 * write: write emulation callback
 * mmap: mmap emulation callback

Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 182

Quoted 9 lines
Documentation/driver-api/vfio-mediated-device.rst +3 -2
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);

Apologies if that has already been discussed, but do we want a 1:1 relationship between id and ops, or can different devices with the same id register different ops? If the former, would it make sense to first register the ops for an id (once), and then have the ->create callback only set the class id (with the core doing the lookup of the ops)?

Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0 -0
 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::
author
#45 lore raw

PATCH v3 4/7 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. With the help of class id, this patch introduces device specific callbacks inside mdev_device structure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.

---
 .../driver-api/vfio-mediated-device.rst       | 22 +++++---
 MAINTAINERS                                   |  1 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              | 18 ++++---
 drivers/s390/cio/vfio_ccw_ops.c               | 18 ++++---
 drivers/s390/crypto/vfio_ap_ops.c             | 14 +++--
 drivers/vfio/mdev/mdev_core.c                 |  9 +++-
 drivers/vfio/mdev/mdev_private.h              |  1 +
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 42 +++------------
 include/linux/vfio_mdev.h                     | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 21 +++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 177 insertions(+), 96 deletions(-)
 create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +16 -6
index 2035e48da7b2..553574ebba73 100644
@@ -152,11 +152,20 @@ 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:
+In order to support multiple types of device/driver, device needs to
+provide both class_id and device_ops through:
 
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
+    void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops);
+
+The class_id is used to be paired with ids in id_table in mdev_driver
+structure for probing the correct driver. The device_ops is device
+specific callbacks which can be get through mdev_get_dev_ops()
+function by mdev bus driver. For vfio-mdev device, its device specific
+ops are as follows:
+
+* open: open callback of vfio mediated device
+* close: close callback of vfio mediated device
+* ioctl: ioctl callback of vfio mediated device
 * read : read emulation callback
 * write: write emulation callback
 * mmap: mmap emulation callback
@@ -167,9 +176,10 @@ register itself with the mdev core driver::
 	extern int  mdev_register_device(struct device *dev,
 	                                 const struct mdev_parent_ops *ops);
 
-It is also required to specify the class_id through::
+It is also required to specify the class_id and device specific ops through::
 
-	extern int mdev_set_class(struct device *dev, u16 id);
+	extern int mdev_set_class(struct device *dev, u16 id,
+	                          const void *ops);
 
 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::
MAINTAINERS +1 -0
index 8824f61cd2c0..3d196a023b5e 100644
@@ -17127,6 +17127,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 +11 -7
index 17e9d4634c84..7e2b720074fd 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>
@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)
 	vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device);
 }
 
+static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops;
+
 static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct intel_vgpu *vgpu = NULL;
@@ -678,7 +681,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 		     dev_name(mdev_dev(mdev)));
 	ret = 0;
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);
 out:
 	return ret;
 }
@@ -1599,20 +1602,21 @@ 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 const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_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,
+};
+
 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 +12 -6
index b5d223882c6c..322991f0feb0 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>
 
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct vfio_ccw_private *private =
@@ -129,7 +132,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 			   private->sch->schid.ssid,
 			   private->sch->schid.sch_no);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -575,11 +578,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_device_ops vfio_mdev_ops = {
 	.open			= vfio_ccw_mdev_open,
 	.release		= vfio_ccw_mdev_release,
 	.read			= vfio_ccw_mdev_read,
@@ -587,6 +586,13 @@ 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,
+};
+
 int vfio_ccw_mdev_reg(struct subchannel *sch)
 {
 	return mdev_register_device(&sch->dev, &vfio_ccw_mdev_ops);
drivers/s390/crypto/vfio_ap_ops.c +10 -4
index 47df1c593c35..e9bd5f3b1cc2 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>
 
@@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info,
 	matrix->adm_max = info->apxa ? info->Nd : 15;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct ap_matrix_mdev *matrix_mdev;
@@ -343,7 +346,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&matrix_mdev->node, &matrix_dev->mdev_list);
 	mutex_unlock(&matrix_dev->lock);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -1281,15 +1284,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct vfio_mdev_device_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,
 };
 
 int vfio_ap_mdev_register(void)
drivers/vfio/mdev/mdev_core.c +8 -1
index 724e9b9841d8..c79d0e16522b 100644
@@ -45,12 +45,19 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
-void mdev_set_class(struct mdev_device *mdev, u16 id)
+void mdev_set_class(struct mdev_device *mdev, u16 id, const void *ops)
 {
 	mdev->class_id = id;
+	mdev->device_ops = ops;
 }
 EXPORT_SYMBOL(mdev_set_class);
 
+const void *mdev_get_dev_ops(struct mdev_device *mdev)
+{
+	return mdev->device_ops;
+}
+EXPORT_SYMBOL(mdev_get_dev_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +1 -0
index c65f436c1869..b666805f0b1f 100644
@@ -34,6 +34,7 @@ struct mdev_device {
 	struct device *iommu_device;
 	bool active;
 	u16 class_id;
+	const void *device_ops;
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
index 891cf83a2d9a..95efa054442f 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"
 
@@ -24,16 +25,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_device_ops *ops = mdev_get_dev_ops(mdev);
 	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);
 
@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)
 static void vfio_mdev_release(void *device_data)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	if (likely(parent->ops->release))
-		parent->ops->release(mdev);
+	if (likely(ops->release))
+		ops->release(mdev);
 
 	module_put(THIS_MODULE);
 }
@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
 				     unsigned int cmd, unsigned long arg)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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,
 			      size_t count, loff_t *ppos)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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,
 			       size_t count, loff_t *ppos)
 {
 	struct mdev_device *mdev = device_data;
-	struct mdev_parent *parent = mdev->parent;
+	const struct vfio_mdev_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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_device_ops *ops = mdev_get_dev_ops(mdev);
 
-	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 +8 -34

66 lines not on this page · raw message

include/linux/vfio_mdev.h new file +52 -0

52 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +13 -7
index fd8491e58fe2..9db771ed5e4b 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>
@@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)
 	return 0;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mbochs_type *type = mbochs_find_type(kobj);
@@ -561,7 +564,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev)
 	mbochs_reset(mdev);
 
 	mbochs_used_mbytes += type->mbytes;
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 
 err_mem:
@@ -1419,12 +1422,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_device_ops vfio_mdev_ops = {
 	.open			= mbochs_open,
 	.release		= mbochs_close,
 	.read			= mbochs_read,
@@ -1433,6 +1431,14 @@ 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,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mdpy.c +14 -7
index 889472b06708..f0fdbc6ec706 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"
@@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)
 	return 0;
 }
 
+static const struct vfio_mdev_device_ops vfio_mdev_ops;
+
 static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -269,7 +272,8 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_mdev_ops);
 	return 0;
 }
 
@@ -726,12 +730,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_device_ops vfio_mdev_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -740,6 +739,14 @@ 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,
+};
+
 static const struct file_operations vd_fops = {
 	.owner		= THIS_MODULE,
 };
samples/vfio-mdev/mtty.c +12 -6
index 618810ca4331..18d0f83a228a 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>
@@ -708,6 +709,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,
 	return ret;
 }
 
+static const struct vfio_mdev_device_ops vfio_dev_ops;
+
 static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	struct mdev_state *mdev_state;
@@ -755,7 +758,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 	list_add(&mdev_state->next, &mdev_devices_list);
 	mutex_unlock(&mdev_list_lock);
 
-	mdev_set_class(mdev, MDEV_ID_VFIO);
+	mdev_set_class(mdev, MDEV_ID_VFIO, &vfio_dev_ops);
 	return 0;
 }
 
@@ -1388,6 +1391,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct vfio_mdev_device_ops vfio_dev_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,
@@ -1395,11 +1406,6 @@ 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,
 };
 
 static void mtty_device_release(struct device *dev)
Signature · 1 line
2.19.1
author
#46 lore raw

PATCH v3 5/7 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.

---
 include/linux/mdev.h        |   1 +
 include/linux/virtio_mdev.h | 148 ++++++++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100644 include/linux/virtio_mdev.h
include/linux/mdev.h +1 -0
index f491308674e5..298581e7ad45 100644
@@ -124,6 +124,7 @@ struct mdev_device *mdev_from_dev(struct device *dev);
 
 enum {
 	MDEV_ID_VFIO = 1,
+	MDEV_ID_VIRTIO = 2,
 	/* New entries must be added here */
 };
 
include/linux/virtio_mdev.h new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
2.19.1
#47 lore raw

Re: [PATCH V3 5/7] mdev: introduce virtio device and its device ops

Quoted 1 line · Jason Wang

+ * @set_vq_cb: Set the interrut calback function for

s/interrut/interrupt/

s/calback/callback/

author
#48 lore raw

Re: [PATCH V3 5/7] mdev: introduce virtio device and its device ops

Quoted 5 lines · Stefan Hajnoczi
Quoted 1 line · Jason Wang

+ * @set_vq_cb: Set the interrut calback function for

s/interrut/interrupt/

s/calback/callback/

Fixed.

Thanks

author
#51 lore raw

PATCH v3 5/7 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.

---
 include/linux/mdev.h        |   1 +
 include/linux/virtio_mdev.h | 148 ++++++++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100644 include/linux/virtio_mdev.h
include/linux/mdev.h +1 -0
index f491308674e5..298581e7ad45 100644
@@ -124,6 +124,7 @@ struct mdev_device *mdev_from_dev(struct device *dev);
 
 enum {
 	MDEV_ID_VFIO = 1,
+	MDEV_ID_VIRTIO = 2,
 	/* New entries must be added here */
 };
 
include/linux/virtio_mdev.h new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#52 lore raw

PATCH v3 6/7 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.

---
 drivers/virtio/Kconfig       |   7 +
 drivers/virtio/Makefile      |   1 +
 drivers/virtio/virtio_mdev.c | 416 +++++++++++++++++++++++++++++++++++
 3 files changed, 424 insertions(+)
 create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +7 -0
index 078615cf2afc..8d18722ab572 100644
@@ -43,6 +43,13 @@ config VIRTIO_PCI_LEGACY
 
 	  If unsure, say Y.
 
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
+
 config VIRTIO_PMEM
 	tristate "Support for virtio pmem driver"
 	depends on VIRTIO
drivers/virtio/Makefile +1 -0
index 3a2b5c5dcf46..ebc7fa15ae82 100644
@@ -6,3 +6,4 @@ virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
 virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
2.19.1
#53 lore raw

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

drivers/virtio/virtio_mdev.c line 37

Quoted 9 lines · Jason Wang
drivers/virtio/virtio_mdev.c new file +9 -0
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;
+	/* The lock to protect virtqueue list */
+	spinlock_t lock;
+	struct list_head virtqueues;

Is this a list of struct virtio_mdev_vq_info? Please document the actual type in a comment.

Quoted 5 lines
drivers/virtio/virtio_mdev.c new file +5 -0
+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,

drivers/virtio/virtio_mdev.c line 258

Quoted 10 lines
drivers/virtio/virtio_mdev.c new file +10 -0
+				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_device_ops *ops = mdev_get_dev_ops(mdev);
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);

kmalloc_array(0, ...)? I would have expected nvqs instead of queue_idx (0).

What is this the purpose of vm_dev->vqs and does anything ever access it?

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

author
#54 lore raw

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

Quoted 12 lines · Stefan Hajnoczi

drivers/virtio/virtio_mdev.c line 37

Quoted 9 lines · Jason Wang
drivers/virtio/virtio_mdev.c new file +9 -0
+struct virtio_mdev_device {
+	struct virtio_device vdev;
+	struct mdev_device *mdev;
+	unsigned long version;
+
+	struct virtqueue **vqs;
+	/* The lock to protect virtqueue list */
+	spinlock_t lock;
+	struct list_head virtqueues;

Is this a list of struct virtio_mdev_vq_info? Please document the actual type in a comment.

Ok.

Quoted 18 lines
Quoted 5 lines
drivers/virtio/virtio_mdev.c new file +5 -0
+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,

drivers/virtio/virtio_mdev.c line 258

Quoted 10 lines
drivers/virtio/virtio_mdev.c new file +10 -0
+				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_device_ops *ops = mdev_get_dev_ops(mdev);
+	struct virtio_mdev_callback cb;
+	int i, err, queue_idx = 0;
+
+	vm_dev->vqs = kmalloc_array(queue_idx, sizeof(*vm_dev->vqs),
+				    GFP_KERNEL);

kmalloc_array(0, ...)? I would have expected nvqs instead of queue_idx (0).

Quoted 1 line

What is this the purpose of vm_dev->vqs and does anything ever access it?

It's useless, will remove it.

Thanks

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

author
#55 lore raw

PATCH v3 6/7 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.

---
 drivers/virtio/Kconfig       |   7 +
 drivers/virtio/Makefile      |   1 +
 drivers/virtio/virtio_mdev.c | 416 +++++++++++++++++++++++++++++++++++
 3 files changed, 424 insertions(+)
 create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +7 -0
index 078615cf2afc..8d18722ab572 100644
@@ -43,6 +43,13 @@ config VIRTIO_PCI_LEGACY
 
 	  If unsure, say Y.
 
+config VIRTIO_MDEV_DEVICE
+	tristate "VIRTIO driver for Mediated devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  VIRTIO based driver for Mediated devices.
+
 config VIRTIO_PMEM
 	tristate "Support for virtio pmem driver"
 	depends on VIRTIO
drivers/virtio/Makefile +1 -0
index 3a2b5c5dcf46..ebc7fa15ae82 100644
@@ -6,3 +6,4 @@ virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
 virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
+obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +416 -0

416 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#56 lore raw

PATCH v3 7/7 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 implemented in this sample driver.

---
 MAINTAINERS                |   1 +
 samples/Kconfig            |   7 +
 samples/vfio-mdev/Makefile |   1 +
 samples/vfio-mdev/mvnet.c  | 691 +++++++++++++++++++++++++++++++++++++
 4 files changed, 700 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
index 3d196a023b5e..cb51351cd5c9 100644
@@ -17254,6 +17254,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.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 +691 -0

691 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#57 lore raw

PATCH v3 7/7 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 implemented in this sample driver.

---
 MAINTAINERS                |   1 +
 samples/Kconfig            |   7 +
 samples/vfio-mdev/Makefile |   1 +
 samples/vfio-mdev/mvnet.c  | 691 +++++++++++++++++++++++++++++++++++++
 4 files changed, 700 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
index 3d196a023b5e..cb51351cd5c9 100644
@@ -17254,6 +17254,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.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 +691 -0

691 lines not on this page · raw message

Signature · 1 line
2.19.1
#58 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

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

== Summary ==

$ dim checkpatch origin/drm-tip
1c00a9513524 mdev: class id support
ca514b262666 mdev: bus uevent support
136343b6a2ec modpost: add support for mdev class id
31c623a77f49 mdev: introduce device specific ops
-:454: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating?
#454: 
new file mode 100644

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

-:115: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #115: FILE: include/linux/virtio_mdev.h:87:
+ * @get_status: ^I^IGet the device status$

-:118: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #118: FILE: include/linux/virtio_mdev.h:90:
+ * @set_status: ^I^ISet the device status$

-:121: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #121: FILE: include/linux/virtio_mdev.h:93:
+ * @get_config: ^I^IRead from device specific configuration space$

-:128: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #128: FILE: include/linux/virtio_mdev.h:100:
+ * @set_config: ^I^IWrite to device specific configuration space$

total: 0 errors, 5 warnings, 0 checks, 155 lines checked
09a6fb6a58b7 virtio: introduce a mdev based transport
-:26: WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully #26: FILE: drivers/virtio/Kconfig:46:
+config VIRTIO_MDEV_DEVICE

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

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

-:107: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #107: FILE: drivers/virtio/virtio_mdev.c:57:
+ void *buf, unsigned len)

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

-:116: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #116: FILE: drivers/virtio/virtio_mdev.c:66:
+ const void *buf, unsigned len)

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

-:262: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #262: FILE: drivers/virtio/virtio_mdev.c:212:
+
+}

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

total: 0 errors, 8 warnings, 1 checks, 433 lines checked
6c7d5f4eec30 docs: sample driver to demonstrate how to implement virtio-mdev framework -:39: WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully #39: FILE: samples/Kconfig:134:
+config SAMPLE_VIRTIO_MDEV_NET

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

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

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

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

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

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

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

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

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

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

#59 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

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

== Summary ==

CI Bug Log - changes from CI_DRM_7061 -> Patchwork_14764
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/index.html

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

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

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_suspend@basic-s4-devices:
- fi-icl-u3: [PASS][1] -> [DMESG-WARN][2] ([fdo#107724]) +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-icl-u3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-icl-u3/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
- fi-kbl-7500u: [PASS][3] -> [FAIL][4] ([fdo#103375])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-kbl-7500u/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-kbl-7500u/igt@[email protected]

#### Possible fixes ####

* igt@gem_ctx_switch@rcs0:
- fi-icl-u2: [INCOMPLETE][5] ([fdo#107713]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-icl-u2/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-icl-u2/igt@[email protected]

* igt@i915_pm_rpm@basic-pci-d3-state:
- fi-bsw-kefka: [DMESG-WARN][7] ([fdo#107407]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-bsw-kefka/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-bsw-kefka/igt@[email protected]

* igt@i915_selftest@live_gtt:
- {fi-tgl-u}: [INCOMPLETE][9] ([fdo#111833]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-tgl-u/igt@i915_selftest@live_gtt.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-tgl-u/igt@i915_selftest@live_gtt.html

* igt@vgem_basic@unload:
- fi-icl-u3: [DMESG-WARN][11] ([fdo#107724]) -> [PASS][12] +1 similar issue
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-icl-u3/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-icl-u3/igt@[email protected]

#### Warnings ####

* igt@kms_chamelium@hdmi-hpd-fast:
- fi-kbl-7500u: [FAIL][13] ([fdo#111045] / [fdo#111096]) -> [FAIL][14] ([fdo#111407])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/fi-kbl-7500u/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/fi-kbl-7500u/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#103375]: https://bugs.freedesktop.org/show_bug.cgi?id=103375
[fdo#107407]: https://bugs.freedesktop.org/show_bug.cgi?id=107407
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
[fdo#109644]: https://bugs.freedesktop.org/show_bug.cgi?id=109644
[fdo#110464]: https://bugs.freedesktop.org/show_bug.cgi?id=110464
[fdo#111045]: https://bugs.freedesktop.org/show_bug.cgi?id=111045
[fdo#111096]: https://bugs.freedesktop.org/show_bug.cgi?id=111096
[fdo#111407]: https://bugs.freedesktop.org/show_bug.cgi?id=111407
[fdo#111833]: https://bugs.freedesktop.org/show_bug.cgi?id=111833

Participating hosts (49 -> 43)
------------------------------

Additional (1): fi-tgl-u2
Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-pnv-d510 fi-icl-y fi-bdw-samus

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

* CI: CI-20190529 -> None
* Linux: CI_DRM_7061 -> Patchwork_14764

CI-20190529: 20190529
CI_DRM_7061: 0204e2b48f2a9ae8aff60393755f8164f2fa1038 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5220: 1e38e32d721210a780198c8293a6b8c8e881df68 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14764: 6c7d5f4eec3000a7f0ceedbbdac3641105868761 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

6c7d5f4eec30 docs: sample driver to demonstrate how to implement virtio-mdev framework 09a6fb6a58b7 virtio: introduce a mdev based transport
b894fa7e61e6 mdev: introduce virtio device and its device ops 31c623a77f49 mdev: introduce device specific ops
136343b6a2ec modpost: add support for mdev class id
ca514b262666 mdev: bus uevent support
1c00a9513524 mdev: class id support

== Logs ==

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

#60 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

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

== Summary ==

CI Bug Log - changes from CI_DRM_7061_full -> Patchwork_14764_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

### IGT changes ###

#### Suppressed ####

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

* igt@gem_mmap_gtt@coherency:
- {shard-tglb}: NOTRUN -> [INCOMPLETE][1]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-tglb2/igt@[email protected]

New tests
---------

New tests have been introduced between CI_DRM_7061_full and Patchwork_14764_full:

### New Piglit tests (5) ###

* spec@ext_framebuffer_multisample@draw-buffers-alpha-to-coverage 4:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@ext_framebuffer_multisample@draw-buffers-alpha-to-one 4:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@ext_framebuffer_multisample@sample-alpha-to-coverage 4 color:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@ext_framebuffer_multisample@sample-alpha-to-coverage 4 depth:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

* spec@ext_framebuffer_multisample@sample-alpha-to-one 4:
- Statuses : 1 incomplete(s)
- Exec time: [0.0] s

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

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

### IGT changes ###

#### Issues hit ####

* igt@gem_ctx_isolation@bcs0-s3:
- shard-apl: [PASS][2] -> [DMESG-WARN][3] ([fdo#108566]) +4 similar issues
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-apl8/igt@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-apl8/igt@[email protected]

* igt@gem_eio@in-flight-contexts-immediate:
- shard-snb: [PASS][4] -> [FAIL][5] ([fdo#111925])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-snb4/igt@[email protected]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-snb7/igt@[email protected]

* igt@gem_exec_schedule@independent-bsd2:
- shard-iclb: [PASS][6] -> [SKIP][7] ([fdo#109276]) +6 similar issues
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb2/igt@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb6/igt@[email protected]

* igt@gem_exec_schedule@pi-ringfull-bsd:
- shard-iclb: [PASS][8] -> [SKIP][9] ([fdo#111325]) +1 similar issue
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb3/igt@[email protected]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb2/igt@[email protected]

* igt@gem_mmap_gtt@basic-write-cpu-read-gtt:
- shard-iclb: [PASS][10] -> [INCOMPLETE][11] ([fdo#107713])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb3/igt@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb1/igt@[email protected]

* igt@gem_softpin@noreloc-s3:
- shard-skl: [PASS][12] -> [INCOMPLETE][13] ([fdo#104108])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl10/igt@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl2/igt@[email protected]

* igt@gem_tiled_swapping@non-threaded:
- shard-hsw: [PASS][14] -> [INCOMPLETE][15] ([fdo#103540] / [fdo#108686])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-hsw6/igt@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-hsw4/igt@[email protected]

* igt@gem_userptr_blits@sync-unmap:
- shard-hsw: [PASS][16] -> [DMESG-WARN][17] ([fdo#111870]) +1 similar issue
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-hsw4/igt@[email protected]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-hsw7/igt@[email protected]

* igt@i915_pm_rpm@gem-pread:
- shard-apl: [PASS][18] -> [INCOMPLETE][19] ([fdo#103927])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-apl7/igt@[email protected]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-apl7/igt@[email protected]

* igt@kms_color@pipe-a-ctm-0-75:
- shard-skl: [PASS][20] -> [DMESG-WARN][21] ([fdo#106107])
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl2/igt@[email protected]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl10/igt@[email protected]

* igt@kms_flip@flip-vs-suspend:
- shard-skl: [PASS][22] -> [INCOMPLETE][23] ([fdo#109507])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl8/igt@[email protected]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-render:
- shard-iclb: [PASS][24] -> [FAIL][25] ([fdo#103167]) +2 similar issues
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb3/igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-render.html
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb3/igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-shrfb-draw-render.html

* igt@kms_frontbuffer_tracking@psr-1p-primscrn-pri-shrfb-draw-blt:
- shard-iclb: [PASS][26] -> [INCOMPLETE][27] ([fdo#106978] / [fdo#107713])
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb6/igt@[email protected]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb1/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
- shard-skl: [PASS][28] -> [FAIL][29] ([fdo#108145])
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl1/igt@[email protected]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl4/igt@[email protected]

* igt@kms_setmode@basic:
- shard-apl: [PASS][30] -> [FAIL][31] ([fdo#99912])
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-apl4/igt@[email protected]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-apl8/igt@[email protected]

#### Possible fixes ####

* igt@gem_ctx_isolation@vecs0-s3:
- shard-apl: [DMESG-WARN][32] ([fdo#108566]) -> [PASS][33] +3 similar issues
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-apl1/igt@[email protected]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-apl6/igt@[email protected]

* igt@gem_exec_schedule@reorder-wide-bsd:
- shard-iclb: [SKIP][34] ([fdo#111325]) -> [PASS][35] +4 similar issues
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb1/igt@[email protected]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb8/igt@[email protected]

* igt@gem_userptr_blits@sync-unmap-after-close:
- shard-hsw: [DMESG-WARN][36] ([fdo#111870]) -> [PASS][37] +2 similar issues
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-hsw6/igt@[email protected]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-hsw4/igt@[email protected]

* igt@kms_color@pipe-a-ctm-0-25:
- shard-skl: [DMESG-WARN][38] ([fdo#106107]) -> [PASS][39]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl3/igt@[email protected]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl1/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank:
- shard-skl: [FAIL][40] ([fdo#105363]) -> [PASS][41]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl8/igt@[email protected]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl9/igt@[email protected]

* igt@kms_flip_tiling@flip-changes-tiling-yf:
- shard-skl: [FAIL][42] ([fdo#108303]) -> [PASS][43]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl9/igt@[email protected]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl1/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-offscren-pri-indfb-draw-blt:
- shard-iclb: [FAIL][44] ([fdo#103167]) -> [PASS][45] +3 similar issues
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb2/igt@[email protected]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb6/igt@[email protected]

* igt@kms_psr2_su@frontbuffer:
- shard-iclb: [SKIP][46] ([fdo#109642] / [fdo#111068]) -> [PASS][47]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb3/igt@[email protected]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb2/igt@[email protected]

* igt@kms_psr@psr2_basic:
- shard-iclb: [SKIP][48] ([fdo#109441]) -> [PASS][49] +1 similar issue
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb8/igt@kms_psr@psr2_basic.html
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb2/igt@kms_psr@psr2_basic.html

* igt@kms_setmode@basic:
- shard-hsw: [FAIL][50] ([fdo#99912]) -> [PASS][51]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-hsw5/igt@[email protected]
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-hsw1/igt@[email protected]

* igt@perf@gen8-unprivileged-single-ctx-counters:
- shard-skl: [INCOMPLETE][52] -> [PASS][53]
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-skl2/igt@[email protected]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-skl3/igt@[email protected]

* igt@prime_busy@hang-bsd2:
- shard-iclb: [SKIP][54] ([fdo#109276]) -> [PASS][55] +8 similar issues
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb3/igt@[email protected]
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb2/igt@[email protected]

* igt@prime_mmap_coherency@read:
- shard-apl: [INCOMPLETE][56] ([fdo#103927]) -> [PASS][57]
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-apl3/igt@[email protected]
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-apl3/igt@[email protected]

* igt@sw_sync@sync_expired_merge:
- shard-hsw: [INCOMPLETE][58] ([fdo#103540]) -> [PASS][59]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-hsw7/igt@sw_sync@sync_expired_merge.html
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-hsw6/igt@sw_sync@sync_expired_merge.html

#### Warnings ####

* igt@gem_mocs_settings@mocs-reset-bsd2:
- shard-iclb: [FAIL][60] ([fdo#111330]) -> [SKIP][61] ([fdo#109276]) +1 similar issue
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7061/shard-iclb4/igt@[email protected]
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14764/shard-iclb6/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#103540]: https://bugs.freedesktop.org/show_bug.cgi?id=103540
[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#106107]: https://bugs.freedesktop.org/show_bug.cgi?id=106107
[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#108303]: https://bugs.freedesktop.org/show_bug.cgi?id=108303
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#108686]: https://bugs.freedesktop.org/show_bug.cgi?id=108686
[fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109507]: https://bugs.freedesktop.org/show_bug.cgi?id=109507
[fdo#109642]: https://bugs.freedesktop.org/show_bug.cgi?id=109642
[fdo#111068]: https://bugs.freedesktop.org/show_bug.cgi?id=111068
[fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
[fdo#111329]: https://bugs.freedesktop.org/show_bug.cgi?id=111329
[fdo#111330]: https://bugs.freedesktop.org/show_bug.cgi?id=111330
[fdo#111870]: https://bugs.freedesktop.org/show_bug.cgi?id=111870
[fdo#111925]: https://bugs.freedesktop.org/show_bug.cgi?id=111925
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912

Participating hosts (11 -> 11)
------------------------------

No changes in participating hosts

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

* CI: CI-20190529 -> None
* Linux: CI_DRM_7061 -> Patchwork_14764

CI-20190529: 20190529
CI_DRM_7061: 0204e2b48f2a9ae8aff60393755f8164f2fa1038 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5220: 1e38e32d721210a780198c8293a6b8c8e881df68 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14764: 6c7d5f4eec3000a7f0ceedbbdac3641105868761 @ 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_14764/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#61 lore raw
In reply to Jason Wang
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Stefan

author
#62 lore raw
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 4 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

Thanks

[1] https://lkml.org/lkml/2019/9/26/15

[2] https://patchwork.ozlabs.org/cover/984763/

Quoted 2 lines

Stefan

#63 lore raw
Quoted 41 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 4 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

Does this mean this patch series is useful mostly for presenting virtio devices to containers or the host?

Stefan

author
#64 lore raw
Quoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 3 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 8 lines
Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

This series introduce some infrastructure that would be used by vhost-mdev:

1) allow new type of mdev devices/drivers other than vfio (through class_id and device ops)

2) a set of virtio specific callbacks that will be used by both vhost-mdev and virtio-mdev defined in patch 5

Then vhost-mdev can be implemented on top: a new mdev class id but reuse the callback defined in 2. Through this way the parent can provides a single set of callbacks (device ops) for both kernel virtio driver (through virtio-mdev) or userspace virtio driver (through vhost-mdev).

Quoted 3 lines

Does this mean this patch series is useful mostly for presenting virtio devices to containers or the host?

Patch 6 is mainly for bare metal or container use case, through it could be used in guest as well. Patch 7 is a sample virtio mdev device implementation. Patch 1 - 5 was the infrastructure for implementing types other than vfio, the first user is virito-mdev, then Tiwei's vhost-mdev and Parav's mlx5 mdev.

Thanks

Quoted 2 lines

Stefan

#65 lore raw
Quoted 55 lines · Jason Wang
Quoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 3 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 8 lines
Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

This series introduce some infrastructure that would be used by vhost-mdev:

1) allow new type of mdev devices/drivers other than vfio (through class_id and device ops)

Quoted 7 lines

2) a set of virtio specific callbacks that will be used by both vhost-mdev and virtio-mdev defined in patch 5

Then vhost-mdev can be implemented on top: a new mdev class id but reuse the callback defined in 2. Through this way the parent can provides a single set of callbacks (device ops) for both kernel virtio driver (through virtio-mdev) or userspace virtio driver (through vhost-mdev).

Okay, thanks for explaining!

Stefan

#66 lore raw
In reply to Jason Wang
Quoted 55 lines · Jason Wang
Quoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 3 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 8 lines
Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

This series introduce some infrastructure that would be used by vhost-mdev:

1) allow new type of mdev devices/drivers other than vfio (through class_id and device ops)

Quoted 7 lines

2) a set of virtio specific callbacks that will be used by both vhost-mdev and virtio-mdev defined in patch 5

Then vhost-mdev can be implemented on top: a new mdev class id but reuse the callback defined in 2. Through this way the parent can provides a single set of callbacks (device ops) for both kernel virtio driver (through virtio-mdev) or userspace virtio driver (through vhost-mdev).

Okay, thanks for explaining!

Stefan

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

author
#67 lore raw
In reply to Stefan Hajnoczi
Quoted 38 lines · Stefan Hajnoczi
Quoted 37 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 3 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 8 lines
Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

This series introduce some infrastructure that would be used by vhost-mdev:

1) allow new type of mdev devices/drivers other than vfio (through class_id and device ops)

2) a set of virtio specific callbacks that will be used by both vhost-mdev and virtio-mdev defined in patch 5

Then vhost-mdev can be implemented on top: a new mdev class id but reuse the callback defined in 2. Through this way the parent can provides a single set of callbacks (device ops) for both kernel virtio driver (through virtio-mdev) or userspace virtio driver (through vhost-mdev).

Quoted 3 lines

Does this mean this patch series is useful mostly for presenting virtio devices to containers or the host?

Patch 6 is mainly for bare metal or container use case, through it could be used in guest as well. Patch 7 is a sample virtio mdev device implementation. Patch 1 - 5 was the infrastructure for implementing types other than vfio, the first user is virito-mdev, then Tiwei's vhost-mdev and Parav's mlx5 mdev.

Thanks

Quoted 2 lines

Stefan

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

#68 lore raw
In reply to Jason Wang
Quoted 41 lines · Jason Wang
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 4 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Quoted 5 lines

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

What I'm trying to understand is: if you want to present a virtio-pci device to the guest (e.g. using vhost-mdev or vhost-vfio), then how is that related to this patch series?

Does this mean this patch series is useful mostly for presenting virtio devices to containers or the host?

Stefan

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

author
#69 lore raw
In reply to Stefan Hajnoczi
Quoted 23 lines · Stefan Hajnoczi
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

Quoted 4 lines

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

It could run in either guest or host. But the main focus is to run in the host then we can use virtio drivers in containers.

Quoted 4 lines

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

We will do control path meditation through vhost-mdev[1] and vhost-vfio[2]. Then we will present a full virtio compatible ethernet device for guest.

SR-IOV is not a must, any mdev device that implements the API defined in patch 5 can be used by this framework.

Thanks

[1] https://lkml.org/lkml/2019/9/26/15

[2] https://patchwork.ozlabs.org/cover/984763/

Quoted 2 lines

Stefan

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

#70 lore raw
In reply to Jason Wang
Quoted 17 lines · Jason Wang

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.

Quoted 5 lines

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.

I was curious so I took a quick look and posted comments.

I guess this driver runs inside the guest since it registers virtio devices?

If this is used with physical PCI devices that support datapath offloading then how are physical devices presented to the guest without SR-IOV?

Stefan

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