Skip to contentSkip to conversation

mdev based hardware virtio offloading support

PATCH Superseded Jason Wang 5 participants 25 messages Nov 7, 2019 – Nov 9, 2019

Subsystems (16)

v11 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

v11 cover mdev based hardware virtio offloading support

Hi all:

There are hardwares 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.

Also a real IFC VF driver was also posted here[2] which is a good reference for vendors who is interested in their own virtio datapath offloading product.

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 ops out of the common ones for implementing class specific operations over mdev bus.

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

Please review.

[1] https://lkml.org/lkml/2019/11/5/424
[2] https://lkml.org/lkml/2019/11/5/227

Changes from V10:
- rename mvnet to mvnet_loopback
- fix typo in the help text for sample Kconfig

Changes from V9:
- Tweak the help text for virito-mdev kconfig

Changes from V8:
- try silent checkpatch, some are still there becuase they were inherited from virtio_config_ops which needs to be resolved in an independent series
- tweak on the comment and doc
- remove VIRTIO_MDEV_F_VERSION_1 completely
- rename CONFIG_VIRTIO_MDEV_DEVICE to CONFIG_VIRTIO_MDEV

Changes from V7:
- drop {set|get}_mdev_features for virtio
- typo and comment style fixes

Changes from V6:
- rename ops files and compile guard

Changes from V5:
- use dev_warn() instead of WARN(1) when class id is not set
- validate id_table before trying to do matching between device and driver
- add wildcard for modpost script
- use unique name for id_table
- move get_mdev_features() to be the first member of virtio_device_ops and more comments for it
- typo fixes for the comments above virtio_mdev_ops

Changes from V4:
- keep mdev_set_class() for the device that doesn't use device ops
- use union for device ops pointer in mdev_device
- introduce class specific helper for getting is device ops
- use WARN_ON instead of BUG_ON in mdev_set_virtio_ops
- explain details of get_mdev_features() and get_vendor_id()
- distinguish the optional virito device ops from mandatory ones and make get_generation() optional
- rename vfio_mdev.h to vfio_mdev_ops.h, rename virito_mdev.h to virtio_mdev_ops.h
- don't abuse version fileds in virtio_mdev structure, use features instead
- fix warning during device remove
- style & docs tweaks and typo fixes

Changes from V3:
- document that class id (device ops) must be specified in create()
- add WARN() when trying to set class_id when it has already set
- add WARN() when class_id is not specified in create() and correctly return an error in this case
- correct the prototype of mdev_set_class() in the doc
- add documention of mdev_set_class()
- remove the unnecessary "class_id_fail" label when class id is not specified in create()
- convert id_table in vfio_mdev to const
- move mdev_set_class and its friends after mdev_uuid()
- suqash the patch of bus uevent into patch of introducing class id
- tweak the words in the docs per Cornelia suggestion
- tie class_id and device ops through class specific initialization routine like mdev_set_vfio_ops()
- typos fixes in the docs of virtio-mdev callbacks
- document the usage of virtqueues in struct virtio_mdev_device
- remove the useless vqs array in struct virtio_mdev_device
- rename MDEV_ID_XXX to MDEV_CLASS_ID_XXX

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 (6):
mdev: class id 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       |  38 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  13 +-
 drivers/vfio/mdev/mdev_core.c                 |  60 ++
 drivers/vfio/mdev/mdev_driver.c               |  25 +
 drivers/vfio/mdev/mdev_private.h              |   8 +
 drivers/vfio/mdev/vfio_mdev.c                 |  45 +-
 drivers/virtio/Kconfig                        |  13 +
 drivers/virtio/Makefile                       |   1 +
 drivers/virtio/virtio_mdev.c                  | 406 +++++++++++
 include/linux/mdev.h                          |  57 +-
 include/linux/mdev_vfio_ops.h                 |  52 ++
 include/linux/mdev_virtio_ops.h               | 147 ++++
 include/linux/mod_devicetable.h               |   8 +
 samples/Kconfig                               |  10 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet_loopback.c            | 687 ++++++++++++++++++
 scripts/mod/devicetable-offsets.c             |   3 +
 scripts/mod/file2alias.c                      |  11 +
 24 files changed, 1586 insertions(+), 91 deletions(-)
 create mode 100644 drivers/virtio/virtio_mdev.c
 create mode 100644 include/linux/mdev_vfio_ops.h
 create mode 100644 include/linux/mdev_virtio_ops.h
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
Signature · 6 lines
2.19.1

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

PATCH v11 1/6 mdev: class id support

Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, 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.

---
 .../driver-api/vfio-mediated-device.rst       |  5 ++++
 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                 | 17 +++++++++++++
 drivers/vfio/mdev/mdev_driver.c               | 25 +++++++++++++++++++
 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, 76 insertions(+)
Documentation/driver-api/vfio-mediated-device.rst +5 -0
index 25eb7d5b834b..6709413bee29 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
@@ -170,6 +172,9 @@ that a driver should use to unregister itself with the mdev core driver::
 
 	extern void mdev_unregister_device(struct device *dev);
 
+It is also required to specify the class_id in create() callback through::
+
+	int mdev_set_class(struct mdev_device *mdev, u16 id);
 
 Mediated Device Management Interface Through sysfs
 ==================================================
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..6420f0dbd31b 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_CLASS_ID_VFIO);
 out:
 	return ret;
 }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
index f0d71ab77c50..cf2c013ae32f 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_CLASS_ID_VFIO);
 	return 0;
 }
 
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..07c31070afeb 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_CLASS_ID_VFIO);
 	return 0;
 }
 
drivers/vfio/mdev/mdev_core.c +17 -0
index b558d4cfd082..7bfa2e46e829 100644
@@ -45,6 +45,17 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
 }
 EXPORT_SYMBOL(mdev_set_drvdata);
 
+/*
+ * Specify the class for the mdev device, this must be called during
+ * create() callback.
+ */
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	WARN_ON(mdev->class_id);
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
@@ -324,6 +335,12 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto ops_create_fail;
 
+	if (!mdev->class_id) {
+		ret = -EINVAL;
+		dev_warn(dev, "mdev vendor driver failed to specify device class\n");
+		goto add_fail;
+	}
+
 	ret = device_add(&mdev->dev);
 	if (ret)
 		goto add_fail;
drivers/vfio/mdev/mdev_driver.c +25 -0
index 0d3223aee20b..ed06433693e8 100644
@@ -69,8 +69,33 @@ 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;
+
+	if (!ids)
+		return 0;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->class_id)
+			return 1;
+	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,
 };
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..38431e9ef7f5 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
 	vfio_del_group_dev(dev);
 }
 
+static const struct mdev_class_id vfio_id_table[] = {
+	{ MDEV_CLASS_ID_VFIO },
+	{ 0 },
+};
+
 static struct mdev_driver vfio_mdev_driver = {
 	.name	= "vfio_mdev",
 	.probe	= vfio_mdev_probe,
 	.remove	= vfio_mdev_remove,
+	.id_table = vfio_id_table,
 };
 
 static int __init vfio_mdev_init(void)
include/linux/mdev.h +8 -0
index 0ce30ca78db0..78b69d09eb54 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
  * @probe: called when new device created
  * @remove: called when device removed
  * @driver: device driver structure
+ * @id_table: the ids serviced by this driver
  *
  **/
 struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
 	int  (*probe)(struct device *dev);
 	void (*remove)(struct device *dev);
 	struct device_driver driver;
+	const struct mdev_class_id *id_table;
 };
 
 #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -132,6 +134,7 @@ struct mdev_driver {
 void *mdev_get_drvdata(struct mdev_device *mdev);
 void mdev_set_drvdata(struct mdev_device *mdev, void *data);
 const guid_t *mdev_uuid(struct mdev_device *mdev);
+void mdev_set_class(struct mdev_device *mdev, u16 id);
 
 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_CLASS_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..115bc5074656 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_CLASS_ID_VFIO);
 	return 0;
 
 err_mem:
samples/vfio-mdev/mdpy.c +1 -0
index cc86bf6566e4..665614574d50 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_CLASS_ID_VFIO);
 	return 0;
 }
 
samples/vfio-mdev/mtty.c +1 -0
index ce84a300a4da..90da12ff7fd9 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_CLASS_ID_VFIO);
 	return 0;
 }
 
Signature · 1 line
2.19.1
maintainer Reviewed-by on v11 1/6
#2 lore raw

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

Quoted 6 lines · 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.

Quoted 6 lines

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

Thanks,
Kirti

Quoted 272 lines
---
  .../driver-api/vfio-mediated-device.rst       |  5 ++++
  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                 | 17 +++++++++++++
  drivers/vfio/mdev/mdev_driver.c               | 25 +++++++++++++++++++
  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, 76 insertions(+)
Documentation/driver-api/vfio-mediated-device.rst +5 -0
index 25eb7d5b834b..6709413bee29 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
@@ -170,6 +172,9 @@ that a driver should use to unregister itself with the mdev core driver::
 
  	extern void mdev_unregister_device(struct device *dev);
 
+It is also required to specify the class_id in create() callback through::
+
+	int mdev_set_class(struct mdev_device *mdev, u16 id);
 
  Mediated Device Management Interface Through sysfs
  ==================================================
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
index 343d79c1cb7e..6420f0dbd31b 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_CLASS_ID_VFIO);
  out:
  	return ret;
  }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
index f0d71ab77c50..cf2c013ae32f 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_CLASS_ID_VFIO);
  	return 0;
  }
 
drivers/s390/crypto/vfio_ap_ops.c +1 -0
index 5c0f53c6dde7..07c31070afeb 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_CLASS_ID_VFIO);
  	return 0;
  }
 
drivers/vfio/mdev/mdev_core.c +17 -0
index b558d4cfd082..7bfa2e46e829 100644
@@ -45,6 +45,17 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data)
  }
  EXPORT_SYMBOL(mdev_set_drvdata);
 
+/*
+ * Specify the class for the mdev device, this must be called during
+ * create() callback.
+ */
+void mdev_set_class(struct mdev_device *mdev, u16 id)
+{
+	WARN_ON(mdev->class_id);
+	mdev->class_id = id;
+}
+EXPORT_SYMBOL(mdev_set_class);
+
  struct device *mdev_dev(struct mdev_device *mdev)
  {
  	return &mdev->dev;
@@ -324,6 +335,12 @@ int mdev_device_create(struct kobject *kobj,
  	if (ret)
  		goto ops_create_fail;
 
+	if (!mdev->class_id) {
+		ret = -EINVAL;
+		dev_warn(dev, "mdev vendor driver failed to specify device class\n");
+		goto add_fail;
+	}
+
  	ret = device_add(&mdev->dev);
  	if (ret)
  		goto add_fail;
drivers/vfio/mdev/mdev_driver.c +25 -0
index 0d3223aee20b..ed06433693e8 100644
@@ -69,8 +69,33 @@ 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;
+
+	if (!ids)
+		return 0;
+
+	for (i = 0; ids[i].id; i++)
+		if (ids[i].id == mdev->class_id)
+			return 1;
+	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,
  };
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..38431e9ef7f5 100644
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)
  	vfio_del_group_dev(dev);
  }
 
+static const struct mdev_class_id vfio_id_table[] = {
+	{ MDEV_CLASS_ID_VFIO },
+	{ 0 },
+};
+
  static struct mdev_driver vfio_mdev_driver = {
  	.name	= "vfio_mdev",
  	.probe	= vfio_mdev_probe,
  	.remove	= vfio_mdev_remove,
+	.id_table = vfio_id_table,
  };
 
  static int __init vfio_mdev_init(void)
include/linux/mdev.h +8 -0
index 0ce30ca78db0..78b69d09eb54 100644
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name =		\
   * @probe: called when new device created
   * @remove: called when device removed
   * @driver: device driver structure
+ * @id_table: the ids serviced by this driver
   *
   **/
  struct mdev_driver {
@@ -125,6 +126,7 @@ struct mdev_driver {
  	int  (*probe)(struct device *dev);
  	void (*remove)(struct device *dev);
  	struct device_driver driver;
+	const struct mdev_class_id *id_table;
  };
 
  #define to_mdev_driver(drv)	container_of(drv, struct mdev_driver, driver)
@@ -132,6 +134,7 @@ struct mdev_driver {
  void *mdev_get_drvdata(struct mdev_device *mdev);
  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
  const guid_t *mdev_uuid(struct mdev_device *mdev);
+void mdev_set_class(struct mdev_device *mdev, u16 id);
 
  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_CLASS_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..115bc5074656 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_CLASS_ID_VFIO);
  	return 0;
 
  err_mem:
samples/vfio-mdev/mdpy.c +1 -0
index cc86bf6566e4..665614574d50 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_CLASS_ID_VFIO);
  	return 0;
  }
 
samples/vfio-mdev/mtty.c +0 -0
index ce84a300a4da..90da12ff7fd9 100644

samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct mdev_device *mdev) · line 761

Quoted 7 lines
samples/vfio-mdev/mtty.c +1 -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);
 
+	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
  	return 0;
  }
 

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

author
#3 lore raw

PATCH v11 2/6 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          | 11 +++++++++++
 3 files changed, 16 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
index 38431e9ef7f5..a6641cd8b5a3 100644
@@ -125,6 +125,8 @@ static const struct mdev_class_id vfio_id_table[] = {
 	{ 0 },
 };
 
+MODULE_DEVICE_TABLE(mdev, vfio_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 +11 -0
index c91eba751804..45f1c22f49be 100644
@@ -1335,6 +1335,16 @@ 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);
+	add_wildcard(alias);
+	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 +1417,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
maintainer Reviewed-by on v11 2/6
#4 lore raw

Re: [PATCH V11 2/6] modpost: add support for mdev class id

Quoted 5 lines · Jason Wang

Add support to parse mdev class id table.

Thanks,
Kirti

Quoted 62 lines
---
  drivers/vfio/mdev/vfio_mdev.c     |  2 ++
  scripts/mod/devicetable-offsets.c |  3 +++
  scripts/mod/file2alias.c          | 11 +++++++++++
  3 files changed, 16 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
index 38431e9ef7f5..a6641cd8b5a3 100644
@@ -125,6 +125,8 @@ static const struct mdev_class_id vfio_id_table[] = {
  	{ 0 },
  };
 
+MODULE_DEVICE_TABLE(mdev, vfio_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 +11 -0
index c91eba751804..45f1c22f49be 100644
@@ -1335,6 +1335,16 @@ 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);
+	add_wildcard(alias);
+	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 +1417,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.
author
#5 lore raw

PATCH v11 2/6 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          | 11 +++++++++++
 3 files changed, 16 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
index 38431e9ef7f5..a6641cd8b5a3 100644
@@ -125,6 +125,8 @@ static const struct mdev_class_id vfio_id_table[] = {
 	{ 0 },
 };
 
+MODULE_DEVICE_TABLE(mdev, vfio_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 +11 -0
index c91eba751804..45f1c22f49be 100644
@@ -1335,6 +1335,16 @@ 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);
+	add_wildcard(alias);
+	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 +1417,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
#6 lore raw

PATCH v11 3/6 mdev: introduce device specific ops

In reply to Jason Wang

Currently, except for the create and remove, the rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. 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       | 35 +++++++++----
 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                 | 24 ++++++++-
 drivers/vfio/mdev/mdev_private.h              |  5 ++
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 43 ++++-----------
 include/linux/mdev_vfio_ops.h                 | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 20 ++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 206 insertions(+), 99 deletions(-)
 create mode 100644 include/linux/mdev_vfio_ops.h
Documentation/driver-api/vfio-mediated-device.rst +25 -10
index 6709413bee29..04d56884c357 100644
@@ -152,15 +152,6 @@ 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:
-
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
-* read : read emulation callback
-* write: write emulation callback
-* mmap: mmap emulation callback
-
 A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
@@ -172,10 +163,34 @@ that a driver should use to unregister itself with the mdev core driver::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-It is also required to specify the class_id in create() callback through::
+As multiple types of mediated devices may be supported, class id needs
+to be specified in the create() callback. This could be done
+explicitly for the device that interacts with the mdev device directly
+through::
 
 	int mdev_set_class(struct mdev_device *mdev, u16 id);
 
+For the device that uses the mdev bus for its operation, the class
+should provide helper function to set class id and device specific
+ops. E.g for vfio-mdev devices, the function to be called is::
+
+	int mdev_set_vfio_ops(struct mdev_device *mdev,
+                              const struct mdev_vfio_device_ops *vfio_ops);
+
+The class id (set by this function to MDEV_CLASS_ID_VFIO) is used to
+match a device with an mdev driver via its id table. The device
+specific callbacks (specified in *vfio_ops) are obtainable via
+mdev_get_vfio_ops() (for use by the mdev bus driver). A vfio-mdev
+device (class id MDEV_CLASS_ID_VFIO) uses the following
+device-specific ops:
+
+* 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
+
 Mediated Device Management Interface Through sysfs
 ==================================================
 
MAINTAINERS +1 -0
index cba1095547fd..f661d13344d6 100644
@@ -17121,6 +17121,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/mdev_vfio_ops.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +11 -7
index 6420f0dbd31b..662f3a672372 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &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 mdev_vfio_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 cf2c013ae32f..fa473ded71c7 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 07c31070afeb..7bdc62393112 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
 	return 0;
 }
 
@@ -1281,15 +1284,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct mdev_vfio_device_ops mdev_vfio_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 +23 -1
index 7bfa2e46e829..4e70f19ac145 100644
@@ -47,7 +47,8 @@ EXPORT_SYMBOL(mdev_set_drvdata);
 
 /*
  * Specify the class for the mdev device, this must be called during
- * create() callback.
+ * create() callback explicitly or implicitly through the helpers
+ * provided by each class.
  */
 void mdev_set_class(struct mdev_device *mdev, u16 id)
 {
@@ -56,6 +57,27 @@ void mdev_set_class(struct mdev_device *mdev, u16 id)
 }
 EXPORT_SYMBOL(mdev_set_class);
 
+/*
+ * Specify the mdev device to be a VFIO mdev device, and set VFIO
+ * device ops for it. This must be called from the create() callback
+ * for VFIO mdev device.
+ */
+void mdev_set_vfio_ops(struct mdev_device *mdev,
+		       const struct mdev_vfio_device_ops *vfio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev->vfio_ops = vfio_ops;
+}
+EXPORT_SYMBOL(mdev_set_vfio_ops);
+
+/* Get the VFIO device ops for the mdev device. */
+const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VFIO);
+	return mdev->vfio_ops;
+}
+EXPORT_SYMBOL(mdev_get_vfio_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +5 -0
index c65f436c1869..411227373625 100644
@@ -10,6 +10,8 @@
 #ifndef MDEV_PRIVATE_H
 #define MDEV_PRIVATE_H
 
+#include <linux/mdev_vfio_ops.h>
+
 int  mdev_bus_register(void);
 void mdev_bus_unregister(void);
 
@@ -34,6 +36,9 @@ struct mdev_device {
 	struct device *iommu_device;
 	bool active;
 	u16 class_id;
+	union {
+		const struct mdev_vfio_device_ops *vfio_ops;
+	};
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
index a6641cd8b5a3..c01e2194e4b3 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 +10 -33

68 lines not on this page · raw message

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

52 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +13 -7
index 115bc5074656..12963767ba37 100644
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 +13 -7
index 665614574d50..50ee6c98b2af 100644
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_ops;
+
 static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -269,7 +272,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
-	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
 	return 0;
 }
 
@@ -726,12 +729,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 mdev_vfio_device_ops mdev_vfio_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -740,6 +738,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 90da12ff7fd9..be476e7ad1f8 100644
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &vfio_dev_ops);
 	return 0;
 }
 
@@ -1388,6 +1391,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct mdev_vfio_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
Reviewed-by on v11 3/6
#7 lore raw

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

Quoted 9 lines · On Thu, 7 Nov 2019 23:11:06 +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.

Quoted 16 lines
---
 .../driver-api/vfio-mediated-device.rst       | 35 +++++++++----
 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                 | 24 ++++++++-
 drivers/vfio/mdev/mdev_private.h              |  5 ++
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 43 ++++-----------
 include/linux/mdev_vfio_ops.h                 | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 20 ++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 206 insertions(+), 99 deletions(-)
 create mode 100644 include/linux/mdev_vfio_ops.h

You dropped my R-b :(, here it is again:

Reviewed-by on v11 3/6
#8 lore raw

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

In reply to Jason Wang
Quoted 9 lines · On Thu, 7 Nov 2019 23:11:06 +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.

Quoted 16 lines
---
 .../driver-api/vfio-mediated-device.rst       | 35 +++++++++----
 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                 | 24 ++++++++-
 drivers/vfio/mdev/mdev_private.h              |  5 ++
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 43 ++++-----------
 include/linux/mdev_vfio_ops.h                 | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 20 ++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 206 insertions(+), 99 deletions(-)
 create mode 100644 include/linux/mdev_vfio_ops.h

You dropped my R-b :(, here it is again:

maintainer Reviewed-by on v11 3/6
#9 lore raw

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

In reply to Jason Wang
Quoted 9 lines · 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.

Thanks,
Kirti

Quoted 723 lines
---
  .../driver-api/vfio-mediated-device.rst       | 35 +++++++++----
  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                 | 24 ++++++++-
  drivers/vfio/mdev/mdev_private.h              |  5 ++
  drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
  include/linux/mdev.h                          | 43 ++++-----------
  include/linux/mdev_vfio_ops.h                 | 52 +++++++++++++++++++
  samples/vfio-mdev/mbochs.c                    | 20 ++++---
  samples/vfio-mdev/mdpy.c                      | 20 ++++---
  samples/vfio-mdev/mtty.c                      | 18 ++++---
  13 files changed, 206 insertions(+), 99 deletions(-)

create mode 100644 include/linux/mdev_vfio_ops.h

Documentation/driver-api/vfio-mediated-device.rst +25 -10
index 6709413bee29..04d56884c357 100644
@@ -152,15 +152,6 @@ 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:
-
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
-* read : read emulation callback
-* write: write emulation callback
-* mmap: mmap emulation callback
-
  A driver should use the mdev_parent_ops structure in the function call to
  register itself with the mdev core driver::
 
@@ -172,10 +163,34 @@ that a driver should use to unregister itself with the mdev core driver::
 
  	extern void mdev_unregister_device(struct device *dev);
 
-It is also required to specify the class_id in create() callback through::
+As multiple types of mediated devices may be supported, class id needs
+to be specified in the create() callback. This could be done
+explicitly for the device that interacts with the mdev device directly
+through::
 
  	int mdev_set_class(struct mdev_device *mdev, u16 id);
 
+For the device that uses the mdev bus for its operation, the class
+should provide helper function to set class id and device specific
+ops. E.g for vfio-mdev devices, the function to be called is::
+
+	int mdev_set_vfio_ops(struct mdev_device *mdev,
+                              const struct mdev_vfio_device_ops *vfio_ops);
+
+The class id (set by this function to MDEV_CLASS_ID_VFIO) is used to
+match a device with an mdev driver via its id table. The device
+specific callbacks (specified in *vfio_ops) are obtainable via
+mdev_get_vfio_ops() (for use by the mdev bus driver). A vfio-mdev
+device (class id MDEV_CLASS_ID_VFIO) uses the following
+device-specific ops:
+
+* 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
+
  Mediated Device Management Interface Through sysfs
  ==================================================
 
MAINTAINERS +1 -0
index cba1095547fd..f661d13344d6 100644
@@ -17121,6 +17121,7 @@ S:	Maintained
  F:	Documentation/driver-api/vfio-mediated-device.rst
  F:	drivers/vfio/mdev/
  F:	include/linux/mdev.h
+F:	include/linux/mdev_vfio_ops.h
  F:	samples/vfio-mdev/
 
  VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +11 -7
index 6420f0dbd31b..662f3a672372 100644
@@ -42,6 +42,7 @@
  #include <linux/kvm_host.h>
  #include <linux/vfio.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &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 mdev_vfio_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 cf2c013ae32f..fa473ded71c7 100644
@@ -12,6 +12,7 @@
 
  #include <linux/vfio.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.h>
  #include <linux/nospec.h>
  #include <linux/slab.h>
 
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
  	NULL,
  };
 
+static const struct mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 07c31070afeb..7bdc62393112 100644
@@ -16,6 +16,7 @@
  #include <linux/bitops.h>
  #include <linux/kvm_host.h>
  #include <linux/module.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
  	return 0;
  }
 
@@ -1281,15 +1284,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
  	return ret;
  }
 
+static const struct mdev_vfio_device_ops mdev_vfio_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 +23 -1
index 7bfa2e46e829..4e70f19ac145 100644
@@ -47,7 +47,8 @@ EXPORT_SYMBOL(mdev_set_drvdata);
 
  /*
   * Specify the class for the mdev device, this must be called during
- * create() callback.
+ * create() callback explicitly or implicitly through the helpers
+ * provided by each class.
   */
  void mdev_set_class(struct mdev_device *mdev, u16 id)
  {
@@ -56,6 +57,27 @@ void mdev_set_class(struct mdev_device *mdev, u16 id)
  }
  EXPORT_SYMBOL(mdev_set_class);
 
+/*
+ * Specify the mdev device to be a VFIO mdev device, and set VFIO
+ * device ops for it. This must be called from the create() callback
+ * for VFIO mdev device.
+ */
+void mdev_set_vfio_ops(struct mdev_device *mdev,
+		       const struct mdev_vfio_device_ops *vfio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev->vfio_ops = vfio_ops;
+}
+EXPORT_SYMBOL(mdev_set_vfio_ops);
+
+/* Get the VFIO device ops for the mdev device. */
+const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VFIO);
+	return mdev->vfio_ops;
+}
+EXPORT_SYMBOL(mdev_get_vfio_ops);
+
  struct device *mdev_dev(struct mdev_device *mdev)
  {
  	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +5 -0
index c65f436c1869..411227373625 100644
@@ -10,6 +10,8 @@
  #ifndef MDEV_PRIVATE_H
  #define MDEV_PRIVATE_H
 
+#include <linux/mdev_vfio_ops.h>
+
  int  mdev_bus_register(void);
  void mdev_bus_unregister(void);
 
@@ -34,6 +36,9 @@ struct mdev_device {
  	struct device *iommu_device;
  	bool active;
  	u16 class_id;
+	union {
+		const struct mdev_vfio_device_ops *vfio_ops;
+	};
  };
 
  #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
index a6641cd8b5a3..c01e2194e4b3 100644
@@ -14,6 +14,7 @@
  #include <linux/slab.h>
  #include <linux/vfio.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 +10 -33
index 78b69d09eb54..9e37506d1987 100644
@@ -10,7 +10,13 @@
  #ifndef MDEV_H
  #define MDEV_H
 
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/mdev.h>
+#include <uapi/linux/uuid.h>
+
  struct mdev_device;
+struct mdev_vfio_device_ops;
 
  /*
   * Called by the parent device driver to set the device which represents
@@ -48,30 +54,7 @@ struct device *mdev_get_iommu_device(struct device *dev);
   *			@mdev: mdev_device device structure which is being
   *			       destroyed
   *			Returns integer: success (0) or error (< 0)
- * @open:		Open mediated device.
- *			@mdev: mediated device.
- *			Returns integer: success (0) or error (< 0)
- * @release:		release mediated device
- *			@mdev: mediated device.
- * @read:		Read emulation callback
- *			@mdev: mediated device structure
- *			@buf: read buffer
- *			@count: number of bytes to read
- *			@ppos: address.
- *			Retuns number on bytes read on success or error.
- * @write:		Write emulation callback
- *			@mdev: mediated device structure
- *			@buf: write buffer
- *			@count: number of bytes to be written
- *			@ppos: address.
- *			Retuns number on bytes written on success or error.
- * @ioctl:		IOCTL callback
- *			@mdev: mediated device structure
- *			@cmd: ioctl command
- *			@arg: arguments to ioctl
- * @mmap:		mmap callback
- *			@mdev: mediated device structure
- *			@vma: vma structure
+ *
   * Parent device that support mediated device should be registered with mdev
   * module with mdev_parent_ops structure.
   **/
@@ -83,15 +66,6 @@ struct mdev_parent_ops {
 
  	int     (*create)(struct kobject *kobj, struct mdev_device *mdev);
  	int     (*remove)(struct mdev_device *mdev);
-	int     (*open)(struct mdev_device *mdev);
-	void    (*release)(struct mdev_device *mdev);
-	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
-			size_t count, loff_t *ppos);
-	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
-			 size_t count, loff_t *ppos);
-	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
-			 unsigned long arg);
-	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
  };
 
  /* interface for exporting mdev supported type attributes */
@@ -135,6 +109,9 @@ void *mdev_get_drvdata(struct mdev_device *mdev);
  void mdev_set_drvdata(struct mdev_device *mdev, void *data);
  const guid_t *mdev_uuid(struct mdev_device *mdev);
  void mdev_set_class(struct mdev_device *mdev, u16 id);
+void mdev_set_vfio_ops(struct mdev_device *mdev,
+		       const struct mdev_vfio_device_ops *vfio_ops);
+const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev);
 
  extern struct bus_type mdev_bus_type;
 
include/linux/mdev_vfio_ops.h new file +52 -0
new file mode 100644
index 000000000000..317518f30621
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * VFIO Mediated device definition
+ */
+
+#ifndef MDEV_VFIO_OPS_H
+#define MDEV_VFIO_OPS_H
+
+#include <linux/mdev.h>
+
+/**
+ * struct mdev_vfio_device_ops - Structure to be registered for each
+ * mdev device to register the device to vfio-mdev module.
+ *
+ * @open:		Open mediated device.
+ *			@mdev: mediated device.
+ *			Returns integer: success (0) or error (< 0)
+ * @release:		release mediated device
+ *			@mdev: mediated device.
+ * @read:		Read emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: read buffer
+ *			@count: number of bytes to read
+ *			@ppos: address.
+ *			Retuns number on bytes read on success or error.
+ * @write:		Write emulation callback
+ *			@mdev: mediated device structure
+ *			@buf: write buffer
+ *			@count: number of bytes to be written
+ *			@ppos: address.
+ *			Retuns number on bytes written on success or error.
+ * @ioctl:		IOCTL callback
+ *			@mdev: mediated device structure
+ *			@cmd: ioctl command
+ *			@arg: arguments to ioctl
+ * @mmap:		mmap callback
+ *			@mdev: mediated device structure
+ *			@vma: vma structure
+ */
+struct mdev_vfio_device_ops {
+	int     (*open)(struct mdev_device *mdev);
+	void    (*release)(struct mdev_device *mdev);
+	ssize_t (*read)(struct mdev_device *mdev, char __user *buf,
+			size_t count, loff_t *ppos);
+	ssize_t (*write)(struct mdev_device *mdev, const char __user *buf,
+			 size_t count, loff_t *ppos);
+	long	(*ioctl)(struct mdev_device *mdev, unsigned int cmd,
+			 unsigned long arg);
+	int	(*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma);
+};
+
+#endif
samples/vfio-mdev/mbochs.c +13 -7
index 115bc5074656..12963767ba37 100644
@@ -30,6 +30,7 @@
  #include <linux/iommu.h>
  #include <linux/sysfs.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 +13 -7
index 665614574d50..50ee6c98b2af 100644
@@ -26,6 +26,7 @@
  #include <linux/iommu.h>
  #include <linux/sysfs.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_ops;
+
  static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
  {
  	const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -269,7 +272,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
  	mdpy_reset(mdev);
 
  	mdpy_count++;
-	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
  	return 0;
  }
 
@@ -726,12 +729,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 mdev_vfio_device_ops mdev_vfio_ops = {
  	.open			= mdpy_open,
  	.release		= mdpy_close,
  	.read			= mdpy_read,
@@ -740,6 +738,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 -1
index 90da12ff7fd9..be476e7ad1f8 100644
@@ -27,6 +27,7 @@
  #include <linux/ctype.h>
  #include <linux/file.h>
  #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &vfio_dev_ops);
  	return 0;
  }
 
@@ -1388,6 +1391,14 @@ static struct attribute_group *mdev_type_groups[] = {
  	NULL,
  };
 
+static const struct mdev_vfio_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,

samples/vfio-mdev/mtty.c static const struct mdev_parent_ops mdev_fops = { · line 1411

Quoted 10 lines
samples/vfio-mdev/mtty.c +0 -5
  	.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)

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

author
#10 lore raw

PATCH v11 3/6 mdev: introduce device specific ops

In reply to Jason Wang

Currently, except for the create and remove, the rest of mdev_parent_ops is designed for vfio-mdev driver only and may not help for kernel mdev driver. 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       | 35 +++++++++----
 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                 | 24 ++++++++-
 drivers/vfio/mdev/mdev_private.h              |  5 ++
 drivers/vfio/mdev/vfio_mdev.c                 | 37 ++++++-------
 include/linux/mdev.h                          | 43 ++++-----------
 include/linux/mdev_vfio_ops.h                 | 52 +++++++++++++++++++
 samples/vfio-mdev/mbochs.c                    | 20 ++++---
 samples/vfio-mdev/mdpy.c                      | 20 ++++---
 samples/vfio-mdev/mtty.c                      | 18 ++++---
 13 files changed, 206 insertions(+), 99 deletions(-)
 create mode 100644 include/linux/mdev_vfio_ops.h
Documentation/driver-api/vfio-mediated-device.rst +25 -10
index 6709413bee29..04d56884c357 100644
@@ -152,15 +152,6 @@ 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:
-
-* open: open callback of mediated device
-* close: close callback of mediated device
-* ioctl: ioctl callback of mediated device
-* read : read emulation callback
-* write: write emulation callback
-* mmap: mmap emulation callback
-
 A driver should use the mdev_parent_ops structure in the function call to
 register itself with the mdev core driver::
 
@@ -172,10 +163,34 @@ that a driver should use to unregister itself with the mdev core driver::
 
 	extern void mdev_unregister_device(struct device *dev);
 
-It is also required to specify the class_id in create() callback through::
+As multiple types of mediated devices may be supported, class id needs
+to be specified in the create() callback. This could be done
+explicitly for the device that interacts with the mdev device directly
+through::
 
 	int mdev_set_class(struct mdev_device *mdev, u16 id);
 
+For the device that uses the mdev bus for its operation, the class
+should provide helper function to set class id and device specific
+ops. E.g for vfio-mdev devices, the function to be called is::
+
+	int mdev_set_vfio_ops(struct mdev_device *mdev,
+                              const struct mdev_vfio_device_ops *vfio_ops);
+
+The class id (set by this function to MDEV_CLASS_ID_VFIO) is used to
+match a device with an mdev driver via its id table. The device
+specific callbacks (specified in *vfio_ops) are obtainable via
+mdev_get_vfio_ops() (for use by the mdev bus driver). A vfio-mdev
+device (class id MDEV_CLASS_ID_VFIO) uses the following
+device-specific ops:
+
+* 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
+
 Mediated Device Management Interface Through sysfs
 ==================================================
 
MAINTAINERS +1 -0
index cba1095547fd..f661d13344d6 100644
@@ -17121,6 +17121,7 @@ S:	Maintained
 F:	Documentation/driver-api/vfio-mediated-device.rst
 F:	drivers/vfio/mdev/
 F:	include/linux/mdev.h
+F:	include/linux/mdev_vfio_ops.h
 F:	samples/vfio-mdev/
 
 VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +11 -7
index 6420f0dbd31b..662f3a672372 100644
@@ -42,6 +42,7 @@
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &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 mdev_vfio_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 cf2c013ae32f..fa473ded71c7 100644
@@ -12,6 +12,7 @@
 
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.h>
 #include <linux/nospec.h>
 #include <linux/slab.h>
 
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 07c31070afeb..7bdc62393112 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/kvm_host.h>
 #include <linux/module.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
 	return 0;
 }
 
@@ -1281,15 +1284,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
 	return ret;
 }
 
+static const struct mdev_vfio_device_ops mdev_vfio_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 +23 -1
index 7bfa2e46e829..4e70f19ac145 100644
@@ -47,7 +47,8 @@ EXPORT_SYMBOL(mdev_set_drvdata);
 
 /*
  * Specify the class for the mdev device, this must be called during
- * create() callback.
+ * create() callback explicitly or implicitly through the helpers
+ * provided by each class.
  */
 void mdev_set_class(struct mdev_device *mdev, u16 id)
 {
@@ -56,6 +57,27 @@ void mdev_set_class(struct mdev_device *mdev, u16 id)
 }
 EXPORT_SYMBOL(mdev_set_class);
 
+/*
+ * Specify the mdev device to be a VFIO mdev device, and set VFIO
+ * device ops for it. This must be called from the create() callback
+ * for VFIO mdev device.
+ */
+void mdev_set_vfio_ops(struct mdev_device *mdev,
+		       const struct mdev_vfio_device_ops *vfio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev->vfio_ops = vfio_ops;
+}
+EXPORT_SYMBOL(mdev_set_vfio_ops);
+
+/* Get the VFIO device ops for the mdev device. */
+const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VFIO);
+	return mdev->vfio_ops;
+}
+EXPORT_SYMBOL(mdev_get_vfio_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +5 -0
index c65f436c1869..411227373625 100644
@@ -10,6 +10,8 @@
 #ifndef MDEV_PRIVATE_H
 #define MDEV_PRIVATE_H
 
+#include <linux/mdev_vfio_ops.h>
+
 int  mdev_bus_register(void);
 void mdev_bus_unregister(void);
 
@@ -34,6 +36,9 @@ struct mdev_device {
 	struct device *iommu_device;
 	bool active;
 	u16 class_id;
+	union {
+		const struct mdev_vfio_device_ops *vfio_ops;
+	};
 };
 
 #define to_mdev_device(dev)	container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
index a6641cd8b5a3..c01e2194e4b3 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/vfio.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 mdev_vfio_device_ops *ops = mdev_get_vfio_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 +10 -33

68 lines not on this page · raw message

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

52 lines not on this page · raw message

samples/vfio-mdev/mbochs.c +13 -7
index 115bc5074656..12963767ba37 100644
@@ -30,6 +30,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_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 mdev_vfio_device_ops mdev_vfio_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 +13 -7
index 665614574d50..50ee6c98b2af 100644
@@ -26,6 +26,7 @@
 #include <linux/iommu.h>
 #include <linux/sysfs.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_device_ops mdev_vfio_ops;
+
 static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 {
 	const struct mdpy_type *type = mdpy_find_type(kobj);
@@ -269,7 +272,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)
 	mdpy_reset(mdev);
 
 	mdpy_count++;
-	mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &mdev_vfio_ops);
 	return 0;
 }
 
@@ -726,12 +729,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 mdev_vfio_device_ops mdev_vfio_ops = {
 	.open			= mdpy_open,
 	.release		= mdpy_close,
 	.read			= mdpy_read,
@@ -740,6 +738,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 90da12ff7fd9..be476e7ad1f8 100644
@@ -27,6 +27,7 @@
 #include <linux/ctype.h>
 #include <linux/file.h>
 #include <linux/mdev.h>
+#include <linux/mdev_vfio_ops.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 mdev_vfio_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_CLASS_ID_VFIO);
+	mdev_set_vfio_ops(mdev, &vfio_dev_ops);
 	return 0;
 }
 
@@ -1388,6 +1391,14 @@ static struct attribute_group *mdev_type_groups[] = {
 	NULL,
 };
 
+static const struct mdev_vfio_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
#11 lore raw

PATCH v11 4/6 mdev: introduce virtio device and its device ops

In reply to Jason Wang

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

---
 MAINTAINERS                      |   1 +
 drivers/vfio/mdev/mdev_core.c    |  21 +++++
 drivers/vfio/mdev/mdev_private.h |   2 +
 include/linux/mdev.h             |   6 ++
 include/linux/mdev_virtio_ops.h  | 147 +++++++++++++++++++++++++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 include/linux/mdev_virtio_ops.h
MAINTAINERS +1 -0
index f661d13344d6..4997957443df 100644
@@ -17248,6 +17248,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	include/linux/mdev_virtio_ops.h
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/mdev_core.c +21 -0
index 4e70f19ac145..c58253404ed5 100644
@@ -78,6 +78,27 @@ const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
 }
 EXPORT_SYMBOL(mdev_get_vfio_ops);
 
+/*
+ * Specify the virtio device ops for the mdev device, this
+ * must be called during create() callback for virtio mdev device.
+ */
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VIRTIO);
+	mdev->virtio_ops = virtio_ops;
+}
+EXPORT_SYMBOL(mdev_set_virtio_ops);
+
+/* Get the virtio device ops for the mdev device. */
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VIRTIO);
+	return mdev->virtio_ops;
+}
+EXPORT_SYMBOL(mdev_get_virtio_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +2 -0
index 411227373625..2c74dd032409 100644
@@ -11,6 +11,7 @@
 #define MDEV_PRIVATE_H
 
 #include <linux/mdev_vfio_ops.h>
+#include <linux/mdev_virtio_ops.h>
 
 int  mdev_bus_register(void);
 void mdev_bus_unregister(void);
@@ -38,6 +39,7 @@ struct mdev_device {
 	u16 class_id;
 	union {
 		const struct mdev_vfio_device_ops *vfio_ops;
+		const struct mdev_virtio_device_ops *virtio_ops;
 	};
 };
 
include/linux/mdev.h +6 -0
index 9e37506d1987..f3d75a60c2b5 100644
@@ -17,6 +17,7 @@
 
 struct mdev_device;
 struct mdev_vfio_device_ops;
+struct mdev_virtio_device_ops;
 
 /*
  * Called by the parent device driver to set the device which represents
@@ -112,6 +113,10 @@ void mdev_set_class(struct mdev_device *mdev, u16 id);
 void mdev_set_vfio_ops(struct mdev_device *mdev,
 		       const struct mdev_vfio_device_ops *vfio_ops);
 const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev);
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops);
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
@@ -127,6 +132,7 @@ struct mdev_device *mdev_from_dev(struct device *dev);
 
 enum {
 	MDEV_CLASS_ID_VFIO = 1,
+	MDEV_CLASS_ID_VIRTIO = 2,
 	/* New entries must be added here */
 };
 
include/linux/mdev_virtio_ops.h new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.19.1
maintainer Reviewed-by on v11 4/6
#12 lore raw

Re: [PATCH V11 4/6] mdev: introduce virtio device and its device ops

Quoted 5 lines · Jason Wang

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

I'm not expert on virtio part, my ack is from mdev perspective.

Thanks,
Kirti

Quoted 248 lines
---
  MAINTAINERS                      |   1 +
  drivers/vfio/mdev/mdev_core.c    |  21 +++++
  drivers/vfio/mdev/mdev_private.h |   2 +
  include/linux/mdev.h             |   6 ++
  include/linux/mdev_virtio_ops.h  | 147 +++++++++++++++++++++++++++++++
  5 files changed, 177 insertions(+)

create mode 100644 include/linux/mdev_virtio_ops.h

MAINTAINERS +1 -0
index f661d13344d6..4997957443df 100644
@@ -17248,6 +17248,7 @@ F:	include/linux/virtio*.h
  F:	include/uapi/linux/virtio_*.h
  F:	drivers/crypto/virtio/
  F:	mm/balloon_compaction.c
+F:	include/linux/mdev_virtio_ops.h
 
  VIRTIO BLOCK AND SCSI DRIVERS
  M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/mdev_core.c +21 -0
index 4e70f19ac145..c58253404ed5 100644
@@ -78,6 +78,27 @@ const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
  }
  EXPORT_SYMBOL(mdev_get_vfio_ops);
 
+/*
+ * Specify the virtio device ops for the mdev device, this
+ * must be called during create() callback for virtio mdev device.
+ */
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VIRTIO);
+	mdev->virtio_ops = virtio_ops;
+}
+EXPORT_SYMBOL(mdev_set_virtio_ops);
+
+/* Get the virtio device ops for the mdev device. */
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VIRTIO);
+	return mdev->virtio_ops;
+}
+EXPORT_SYMBOL(mdev_get_virtio_ops);
+
  struct device *mdev_dev(struct mdev_device *mdev)
  {
  	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +2 -0
index 411227373625..2c74dd032409 100644
@@ -11,6 +11,7 @@
  #define MDEV_PRIVATE_H
 
  #include <linux/mdev_vfio_ops.h>
+#include <linux/mdev_virtio_ops.h>
 
  int  mdev_bus_register(void);
  void mdev_bus_unregister(void);
@@ -38,6 +39,7 @@ struct mdev_device {
  	u16 class_id;
  	union {
  		const struct mdev_vfio_device_ops *vfio_ops;
+		const struct mdev_virtio_device_ops *virtio_ops;
  	};
  };
 
include/linux/mdev.h +6 -0
index 9e37506d1987..f3d75a60c2b5 100644
@@ -17,6 +17,7 @@
 
  struct mdev_device;
  struct mdev_vfio_device_ops;
+struct mdev_virtio_device_ops;
 
  /*
   * Called by the parent device driver to set the device which represents
@@ -112,6 +113,10 @@ void mdev_set_class(struct mdev_device *mdev, u16 id);
  void mdev_set_vfio_ops(struct mdev_device *mdev,
  		       const struct mdev_vfio_device_ops *vfio_ops);
  const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev);
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops);
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev);
 
  extern struct bus_type mdev_bus_type;
 
@@ -127,6 +132,7 @@ struct mdev_device *mdev_from_dev(struct device *dev);
 
  enum {
  	MDEV_CLASS_ID_VFIO = 1,
+	MDEV_CLASS_ID_VIRTIO = 2,
  	/* New entries must be added here */
  };
 
include/linux/mdev_virtio_ops.h new file +137 -0
new file mode 100644
index 000000000000..8951331c6629
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtio mediated device driver
+ *
+ * Copyright 2019, Red Hat Corp.
+ *     Author: Jason Wang <[email protected]>
+ */
+#ifndef MDEV_VIRTIO_OPS_H
+#define MDEV_VIRTIO_OPS_H
+
+#include <linux/interrupt.h>
+#include <linux/mdev.h>
+#include <uapi/linux/vhost.h>
+
+#define VIRTIO_MDEV_DEVICE_API_STRING		"virtio-mdev"
+
+struct virtio_mdev_callback {
+	irqreturn_t (*callback)(void *data);
+	void *private;
+};
+
+/**
+ * struct mdev_virtio_device_ops - Structure to be registered for each
+ * mdev device to register the device for virtio/vhost drivers.
+ *
+ * The callbacks are mandatory unless explicitly mentioned.
+ *
+ * @set_vq_address:		Set the address of virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				@desc_area: address of desc area
+ *				@driver_area: address of driver area
+ *				@device_area: address of device area
+ *				Returns integer: success (0) or error (< 0)
+ * @set_vq_num:			Set the size of virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				@num: the size of virtqueue
+ * @kick_vq:			Kick the virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ * @set_vq_cb:			Set the interrupt callback function for
+ *				a virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				@cb: virtio-mdev interrupt callback structure
+ * @set_vq_ready:		Set ready status for a virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				@ready: ready (true) not ready(false)
+ * @get_vq_ready:		Get ready status for a virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				Returns boolean: ready (true) or not (false)
+ * @set_vq_state:		Set the state for a virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				@state: virtqueue state (last_avail_idx)
+ *				Returns integer: success (0) or error (< 0)
+ * @get_vq_state:		Get the state for a virtqueue
+ *				@mdev: mediated device
+ *				@idx: virtqueue index
+ *				Returns virtqueue state (last_avail_idx)
+ * @get_vq_align:		Get the virtqueue align requirement
+ *				for the device
+ *				@mdev: mediated device
+ *				Returns virtqueue algin requirement
+ * @get_features:		Get virtio features supported by the device
+ *				@mdev: mediated device
+ *				Returns the virtio features support by the
+ *				device
+ * @set_features:		Set virtio features supported by the driver
+ *				@mdev: mediated device
+ *				@features: feature support by the driver
+ *				Returns integer: success (0) or error (< 0)
+ * @set_config_cb:		Set the config interrupt callback
+ *				@mdev: mediated device
+ *				@cb: virtio-mdev interrupt callback structure
+ * @get_vq_num_max:		Get the max size of virtqueue
+ *				@mdev: mediated device
+ *				Returns u16: max size of virtqueue
+ * @get_device_id:		Get virtio device id
+ *				@mdev: mediated device
+ *				Returns u32: virtio device id
+ * @get_vendor_id:		Get id for the vendor that provides this device
+ *				@mdev: mediated device
+ *				Returns u32: virtio vendor id
+ * @get_status:			Get the device status
+ *				@mdev: mediated device
+ *				Returns u8: virtio device status
+ * @set_status:			Set the device status
+ *				@mdev: mediated device
+ *				@status: virtio device status
+ * @get_config:			Read from device specific configuration space
+ *				@mdev: mediated device
+ *				@offset: offset from the beginning of
+ *				configuration space
+ *				@buf: buffer used to read to
+ *				@len: the length to read from
+ *				configration space
+ * @set_config:			Write to device specific configuration space
+ *				@mdev: mediated device
+ *				@offset: offset from the beginning of
+ *				configuration space
+ *				@buf: buffer used to write from
+ *				@len: the length to write to
+ *				configration space
+ * @get_generation:		Get device config generaton (optional)
+ *				@mdev: mediated device
+ *				Returns u32: device generation
+ */
+struct mdev_virtio_device_ops {
+	/* Virtqueue ops */
+	int (*set_vq_address)(struct mdev_device *mdev,
+			      u16 idx, u64 desc_area, u64 driver_area,
+			      u64 device_area);
+	void (*set_vq_num)(struct mdev_device *mdev, u16 idx, u32 num);
+	void (*kick_vq)(struct mdev_device *mdev, u16 idx);
+	void (*set_vq_cb)(struct mdev_device *mdev, u16 idx,
+			  struct virtio_mdev_callback *cb);
+	void (*set_vq_ready)(struct mdev_device *mdev, u16 idx, bool ready);
+	bool (*get_vq_ready)(struct mdev_device *mdev, u16 idx);
+	int (*set_vq_state)(struct mdev_device *mdev, u16 idx, u64 state);
+	u64 (*get_vq_state)(struct mdev_device *mdev, u16 idx);
+
+	/* Virtio device ops */
+	u16 (*get_vq_align)(struct mdev_device *mdev);
+	u64 (*get_features)(struct mdev_device *mdev);
+	int (*set_features)(struct mdev_device *mdev, u64 features);
+	void (*set_config_cb)(struct mdev_device *mdev,
+			      struct virtio_mdev_callback *cb);
+	u16 (*get_vq_num_max)(struct mdev_device *mdev);
+	u32 (*get_device_id)(struct mdev_device *mdev);
+	u32 (*get_vendor_id)(struct mdev_device *mdev);
+	u8 (*get_status)(struct mdev_device *mdev);
+	void (*set_status)(struct mdev_device *mdev, u8 status);
+	void (*get_config)(struct mdev_device *mdev, unsigned int offset,

include/linux/mdev_virtio_ops.h line 147

Quoted 10 lines
include/linux/mdev_virtio_ops.h new file +10 -0
+			   void *buf, unsigned int len);
+	void (*set_config)(struct mdev_device *mdev, unsigned int offset,
+			   const void *buf, unsigned int len);
+	u32 (*get_generation)(struct mdev_device *mdev);
+};
+
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops);
+
+#endif

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

author
#13 lore raw

PATCH v11 4/6 mdev: introduce virtio device and its device ops

In reply to Jason Wang

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

---
 MAINTAINERS                      |   1 +
 drivers/vfio/mdev/mdev_core.c    |  21 +++++
 drivers/vfio/mdev/mdev_private.h |   2 +
 include/linux/mdev.h             |   6 ++
 include/linux/mdev_virtio_ops.h  | 147 +++++++++++++++++++++++++++++++
 5 files changed, 177 insertions(+)
 create mode 100644 include/linux/mdev_virtio_ops.h
MAINTAINERS +1 -0
index f661d13344d6..4997957443df 100644
@@ -17248,6 +17248,7 @@ F:	include/linux/virtio*.h
 F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
+F:	include/linux/mdev_virtio_ops.h
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
drivers/vfio/mdev/mdev_core.c +21 -0
index 4e70f19ac145..c58253404ed5 100644
@@ -78,6 +78,27 @@ const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev)
 }
 EXPORT_SYMBOL(mdev_get_vfio_ops);
 
+/*
+ * Specify the virtio device ops for the mdev device, this
+ * must be called during create() callback for virtio mdev device.
+ */
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops)
+{
+	mdev_set_class(mdev, MDEV_CLASS_ID_VIRTIO);
+	mdev->virtio_ops = virtio_ops;
+}
+EXPORT_SYMBOL(mdev_set_virtio_ops);
+
+/* Get the virtio device ops for the mdev device. */
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev)
+{
+	WARN_ON(mdev->class_id != MDEV_CLASS_ID_VIRTIO);
+	return mdev->virtio_ops;
+}
+EXPORT_SYMBOL(mdev_get_virtio_ops);
+
 struct device *mdev_dev(struct mdev_device *mdev)
 {
 	return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +2 -0
index 411227373625..2c74dd032409 100644
@@ -11,6 +11,7 @@
 #define MDEV_PRIVATE_H
 
 #include <linux/mdev_vfio_ops.h>
+#include <linux/mdev_virtio_ops.h>
 
 int  mdev_bus_register(void);
 void mdev_bus_unregister(void);
@@ -38,6 +39,7 @@ struct mdev_device {
 	u16 class_id;
 	union {
 		const struct mdev_vfio_device_ops *vfio_ops;
+		const struct mdev_virtio_device_ops *virtio_ops;
 	};
 };
 
include/linux/mdev.h +6 -0
index 9e37506d1987..f3d75a60c2b5 100644
@@ -17,6 +17,7 @@
 
 struct mdev_device;
 struct mdev_vfio_device_ops;
+struct mdev_virtio_device_ops;
 
 /*
  * Called by the parent device driver to set the device which represents
@@ -112,6 +113,10 @@ void mdev_set_class(struct mdev_device *mdev, u16 id);
 void mdev_set_vfio_ops(struct mdev_device *mdev,
 		       const struct mdev_vfio_device_ops *vfio_ops);
 const struct mdev_vfio_device_ops *mdev_get_vfio_ops(struct mdev_device *mdev);
+void mdev_set_virtio_ops(struct mdev_device *mdev,
+			 const struct mdev_virtio_device_ops *virtio_ops);
+const struct mdev_virtio_device_ops *
+mdev_get_virtio_ops(struct mdev_device *mdev);
 
 extern struct bus_type mdev_bus_type;
 
@@ -127,6 +132,7 @@ struct mdev_device *mdev_from_dev(struct device *dev);
 
 enum {
 	MDEV_CLASS_ID_VFIO = 1,
+	MDEV_CLASS_ID_VIRTIO = 2,
 	/* New entries must be added here */
 };
 
include/linux/mdev_virtio_ops.h new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#14 lore raw

PATCH v11 5/6 virtio: introduce a mdev based transport

In reply to Jason Wang

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

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

---
 drivers/virtio/Kconfig       |  13 ++
 drivers/virtio/Makefile      |   1 +
 drivers/virtio/virtio_mdev.c | 406 +++++++++++++++++++++++++++++++++++
 3 files changed, 420 insertions(+)
 create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +13 -0
index 078615cf2afc..bf526ce0facc 100644
@@ -43,6 +43,19 @@ config VIRTIO_PCI_LEGACY
 
 	  If unsure, say Y.
 
+config VIRTIO_MDEV
+	tristate "MDEV driver for virtio devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  This driver provides support for virtio based paravirtual
+	  device driver over MDEV bus. For this to be useful, you need
+	  an appropriate virtio mdev device implementation that
+	  operates on a physical device to allow the datapath of virtio
+	  to be offloaded to hardware.
+
+	  If unsure, say M.
+
 config VIRTIO_PMEM
 	tristate "Support for virtio pmem driver"
 	depends on VIRTIO
drivers/virtio/Makefile +1 -0
index 3a2b5c5dcf46..f2997b6c812f 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) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +406 -0

406 lines not on this page · raw message

Signature · 6 lines
2.19.1

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

PATCH v11 5/6 virtio: introduce a mdev based transport

In reply to Jason Wang

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

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

---
 drivers/virtio/Kconfig       |  13 ++
 drivers/virtio/Makefile      |   1 +
 drivers/virtio/virtio_mdev.c | 406 +++++++++++++++++++++++++++++++++++
 3 files changed, 420 insertions(+)
 create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +13 -0
index 078615cf2afc..bf526ce0facc 100644
@@ -43,6 +43,19 @@ config VIRTIO_PCI_LEGACY
 
 	  If unsure, say Y.
 
+config VIRTIO_MDEV
+	tristate "MDEV driver for virtio devices"
+	depends on VFIO_MDEV && VIRTIO
+	default n
+	help
+	  This driver provides support for virtio based paravirtual
+	  device driver over MDEV bus. For this to be useful, you need
+	  an appropriate virtio mdev device implementation that
+	  operates on a physical device to allow the datapath of virtio
+	  to be offloaded to hardware.
+
+	  If unsure, say M.
+
 config VIRTIO_PMEM
 	tristate "Support for virtio pmem driver"
 	depends on VIRTIO
drivers/virtio/Makefile +1 -0
index 3a2b5c5dcf46..f2997b6c812f 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) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +406 -0

406 lines not on this page · raw message

Signature · 1 line
2.19.1
author
#16 lore raw

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

In reply to Jason Wang

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

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

---
 MAINTAINERS                        |   1 +
 samples/Kconfig                    |  10 +
 samples/vfio-mdev/Makefile         |   1 +
 samples/vfio-mdev/mvnet_loopback.c | 687 +++++++++++++++++++++++++++++
 4 files changed, 699 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
MAINTAINERS +1 -0
index 4997957443df..62c3eafa99b0 100644
@@ -17249,6 +17249,7 @@ F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
 F:	include/linux/mdev_virtio_ops.h
+F:	samples/vfio-mdev/mvnet_loopback.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
samples/Kconfig +10 -0
index c8dacb4dda80..5b347e90fd20 100644
@@ -131,6 +131,16 @@ 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_LOOPBACK
+	tristate "Build loopback VIRTIO net example mediated device sample code -- loadable modules only"
+	depends on VIRTIO_MDEV && VHOST_RING && m
+	help
+	  Build a networking sample device for use as a virtio
+	  mediated device. The device cooperates with virtio-mdev bus
+	  driver to present an virtio ethernet driver for
+	  kernel. It simply loopbacks all packets from its TX
+	  virtqueue to its RX virtqueue.
+
 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..817618569848 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_LOOPBACK) += mvnet_loopback.o
samples/vfio-mdev/mvnet_loopback.c new file +687 -0

687 lines not on this page · raw message

Signature · 1 line
2.19.1
Acked-by on v11 6/6
#17 lore raw

Re: [PATCH V11 6/6] docs: sample driver to demonstrate how to implement virtio-mdev framework

Quoted 10 lines · On Thu, 7 Nov 2019 23:11:09 +0800 Jason Wang <[email protected]> wrote:

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.

Quoted 8 lines
---
 MAINTAINERS                        |   1 +
 samples/Kconfig                    |  10 +
 samples/vfio-mdev/Makefile         |   1 +
 samples/vfio-mdev/mvnet_loopback.c | 687 +++++++++++++++++++++++++++++
 4 files changed, 699 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
Acked-by on v11 6/6
#18 lore raw

Re: [PATCH V11 6/6] docs: sample driver to demonstrate how to implement virtio-mdev framework

In reply to Jason Wang
Quoted 10 lines · On Thu, 7 Nov 2019 23:11:09 +0800 Jason Wang <[email protected]> wrote:

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.

Quoted 8 lines
---
 MAINTAINERS                        |   1 +
 samples/Kconfig                    |  10 +
 samples/vfio-mdev/Makefile         |   1 +
 samples/vfio-mdev/mvnet_loopback.c | 687 +++++++++++++++++++++++++++++
 4 files changed, 699 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
author
#19 lore raw

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

In reply to Jason Wang

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

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

---
 MAINTAINERS                        |   1 +
 samples/Kconfig                    |  10 +
 samples/vfio-mdev/Makefile         |   1 +
 samples/vfio-mdev/mvnet_loopback.c | 687 +++++++++++++++++++++++++++++
 4 files changed, 699 insertions(+)
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
MAINTAINERS +1 -0
index 4997957443df..62c3eafa99b0 100644
@@ -17249,6 +17249,7 @@ F:	include/uapi/linux/virtio_*.h
 F:	drivers/crypto/virtio/
 F:	mm/balloon_compaction.c
 F:	include/linux/mdev_virtio_ops.h
+F:	samples/vfio-mdev/mvnet_loopback.c
 
 VIRTIO BLOCK AND SCSI DRIVERS
 M:	"Michael S. Tsirkin" <[email protected]>
samples/Kconfig +10 -0
index c8dacb4dda80..5b347e90fd20 100644
@@ -131,6 +131,16 @@ 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_LOOPBACK
+	tristate "Build loopback VIRTIO net example mediated device sample code -- loadable modules only"
+	depends on VIRTIO_MDEV && VHOST_RING && m
+	help
+	  Build a networking sample device for use as a virtio
+	  mediated device. The device cooperates with virtio-mdev bus
+	  driver to present an virtio ethernet driver for
+	  kernel. It simply loopbacks all packets from its TX
+	  virtqueue to its RX virtqueue.
+
 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..817618569848 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_LOOPBACK) += mvnet_loopback.o
samples/vfio-mdev/mvnet_loopback.c new file +687 -0

687 lines not on this page · raw message

Signature · 1 line
2.19.1
maintainer Acked-by on the v11 series
#20 lore raw
In reply to Jason Wang
Quoted 32 lines · Jason Wang

Hi all:

There are hardwares 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.

Also a real IFC VF driver was also posted here[2] which is a good reference for vendors who is interested in their own virtio datapath offloading product.

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 ops out of the common ones for implementing class specific operations over mdev bus.

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

Quoted 8 lines

Please review.

[1] https://lkml.org/lkml/2019/11/5/424
[2] https://lkml.org/lkml/2019/11/5/227

Changes from V10:
- rename mvnet to mvnet_loopback
- fix typo in the help text for sample Kconfig

Quoted 140 lines

Changes from V9:
- Tweak the help text for virito-mdev kconfig

Changes from V8:
- try silent checkpatch, some are still there becuase they were inherited from virtio_config_ops which needs to be resolved in an independent series
- tweak on the comment and doc
- remove VIRTIO_MDEV_F_VERSION_1 completely
- rename CONFIG_VIRTIO_MDEV_DEVICE to CONFIG_VIRTIO_MDEV

Changes from V7:
- drop {set|get}_mdev_features for virtio
- typo and comment style fixes

Changes from V6:
- rename ops files and compile guard

Changes from V5:
- use dev_warn() instead of WARN(1) when class id is not set
- validate id_table before trying to do matching between device and driver
- add wildcard for modpost script
- use unique name for id_table
- move get_mdev_features() to be the first member of virtio_device_ops and more comments for it
- typo fixes for the comments above virtio_mdev_ops

Changes from V4:
- keep mdev_set_class() for the device that doesn't use device ops
- use union for device ops pointer in mdev_device
- introduce class specific helper for getting is device ops
- use WARN_ON instead of BUG_ON in mdev_set_virtio_ops
- explain details of get_mdev_features() and get_vendor_id()
- distinguish the optional virito device ops from mandatory ones and make get_generation() optional
- rename vfio_mdev.h to vfio_mdev_ops.h, rename virito_mdev.h to virtio_mdev_ops.h
- don't abuse version fileds in virtio_mdev structure, use features instead
- fix warning during device remove
- style & docs tweaks and typo fixes

Changes from V3:
- document that class id (device ops) must be specified in create()
- add WARN() when trying to set class_id when it has already set
- add WARN() when class_id is not specified in create() and correctly return an error in this case
- correct the prototype of mdev_set_class() in the doc
- add documention of mdev_set_class()
- remove the unnecessary "class_id_fail" label when class id is not specified in create()
- convert id_table in vfio_mdev to const
- move mdev_set_class and its friends after mdev_uuid()
- suqash the patch of bus uevent into patch of introducing class id
- tweak the words in the docs per Cornelia suggestion
- tie class_id and device ops through class specific initialization routine like mdev_set_vfio_ops()
- typos fixes in the docs of virtio-mdev callbacks
- document the usage of virtqueues in struct virtio_mdev_device
- remove the useless vqs array in struct virtio_mdev_device
- rename MDEV_ID_XXX to MDEV_CLASS_ID_XXX

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 (6):
mdev: class id 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       |  38 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  13 +-
 drivers/vfio/mdev/mdev_core.c                 |  60 ++
 drivers/vfio/mdev/mdev_driver.c               |  25 +
 drivers/vfio/mdev/mdev_private.h              |   8 +
 drivers/vfio/mdev/vfio_mdev.c                 |  45 +-
 drivers/virtio/Kconfig                        |  13 +
 drivers/virtio/Makefile                       |   1 +
 drivers/virtio/virtio_mdev.c                  | 406 +++++++++++
 include/linux/mdev.h                          |  57 +-
 include/linux/mdev_vfio_ops.h                 |  52 ++
 include/linux/mdev_virtio_ops.h               | 147 ++++
 include/linux/mod_devicetable.h               |   8 +
 samples/Kconfig                               |  10 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet_loopback.c            | 687 ++++++++++++++++++
 scripts/mod/devicetable-offsets.c             |   3 +
 scripts/mod/file2alias.c                      |  11 +
 24 files changed, 1586 insertions(+), 91 deletions(-)
 create mode 100644 drivers/virtio/virtio_mdev.c
 create mode 100644 include/linux/mdev_vfio_ops.h
 create mode 100644 include/linux/mdev_virtio_ops.h
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
Signature · 1 line
2.19.1
maintainer Acked-by on the v11 series
#21 lore raw
In reply to Jason Wang
Quoted 32 lines · Jason Wang

Hi all:

There are hardwares 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.

Also a real IFC VF driver was also posted here[2] which is a good reference for vendors who is interested in their own virtio datapath offloading product.

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 ops out of the common ones for implementing class specific operations over mdev bus.

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

Quoted 8 lines

Please review.

[1] https://lkml.org/lkml/2019/11/5/424
[2] https://lkml.org/lkml/2019/11/5/227

Changes from V10:
- rename mvnet to mvnet_loopback
- fix typo in the help text for sample Kconfig

Quoted 140 lines

Changes from V9:
- Tweak the help text for virito-mdev kconfig

Changes from V8:
- try silent checkpatch, some are still there becuase they were inherited from virtio_config_ops which needs to be resolved in an independent series
- tweak on the comment and doc
- remove VIRTIO_MDEV_F_VERSION_1 completely
- rename CONFIG_VIRTIO_MDEV_DEVICE to CONFIG_VIRTIO_MDEV

Changes from V7:
- drop {set|get}_mdev_features for virtio
- typo and comment style fixes

Changes from V6:
- rename ops files and compile guard

Changes from V5:
- use dev_warn() instead of WARN(1) when class id is not set
- validate id_table before trying to do matching between device and driver
- add wildcard for modpost script
- use unique name for id_table
- move get_mdev_features() to be the first member of virtio_device_ops and more comments for it
- typo fixes for the comments above virtio_mdev_ops

Changes from V4:
- keep mdev_set_class() for the device that doesn't use device ops
- use union for device ops pointer in mdev_device
- introduce class specific helper for getting is device ops
- use WARN_ON instead of BUG_ON in mdev_set_virtio_ops
- explain details of get_mdev_features() and get_vendor_id()
- distinguish the optional virito device ops from mandatory ones and make get_generation() optional
- rename vfio_mdev.h to vfio_mdev_ops.h, rename virito_mdev.h to virtio_mdev_ops.h
- don't abuse version fileds in virtio_mdev structure, use features instead
- fix warning during device remove
- style & docs tweaks and typo fixes

Changes from V3:
- document that class id (device ops) must be specified in create()
- add WARN() when trying to set class_id when it has already set
- add WARN() when class_id is not specified in create() and correctly return an error in this case
- correct the prototype of mdev_set_class() in the doc
- add documention of mdev_set_class()
- remove the unnecessary "class_id_fail" label when class id is not specified in create()
- convert id_table in vfio_mdev to const
- move mdev_set_class and its friends after mdev_uuid()
- suqash the patch of bus uevent into patch of introducing class id
- tweak the words in the docs per Cornelia suggestion
- tie class_id and device ops through class specific initialization routine like mdev_set_vfio_ops()
- typos fixes in the docs of virtio-mdev callbacks
- document the usage of virtqueues in struct virtio_mdev_device
- remove the useless vqs array in struct virtio_mdev_device
- rename MDEV_ID_XXX to MDEV_CLASS_ID_XXX

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 (6):
mdev: class id 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       |  38 +-
 MAINTAINERS                                   |   3 +
 drivers/gpu/drm/i915/gvt/kvmgt.c              |  17 +-
 drivers/s390/cio/vfio_ccw_ops.c               |  17 +-
 drivers/s390/crypto/vfio_ap_ops.c             |  13 +-
 drivers/vfio/mdev/mdev_core.c                 |  60 ++
 drivers/vfio/mdev/mdev_driver.c               |  25 +
 drivers/vfio/mdev/mdev_private.h              |   8 +
 drivers/vfio/mdev/vfio_mdev.c                 |  45 +-
 drivers/virtio/Kconfig                        |  13 +
 drivers/virtio/Makefile                       |   1 +
 drivers/virtio/virtio_mdev.c                  | 406 +++++++++++
 include/linux/mdev.h                          |  57 +-
 include/linux/mdev_vfio_ops.h                 |  52 ++
 include/linux/mdev_virtio_ops.h               | 147 ++++
 include/linux/mod_devicetable.h               |   8 +
 samples/Kconfig                               |  10 +
 samples/vfio-mdev/Makefile                    |   1 +
 samples/vfio-mdev/mbochs.c                    |  19 +-
 samples/vfio-mdev/mdpy.c                      |  19 +-
 samples/vfio-mdev/mtty.c                      |  17 +-
 samples/vfio-mdev/mvnet_loopback.c            | 687 ++++++++++++++++++
 scripts/mod/devicetable-offsets.c             |   3 +
 scripts/mod/file2alias.c                      |  11 +
 24 files changed, 1586 insertions(+), 91 deletions(-)
 create mode 100644 drivers/virtio/virtio_mdev.c
 create mode 100644 include/linux/mdev_vfio_ops.h
 create mode 100644 include/linux/mdev_virtio_ops.h
 create mode 100644 samples/vfio-mdev/mvnet_loopback.c
Signature · 1 line
2.19.1
#22 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support
URL : https://patchwork.freedesktop.org/series/69135/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
9507b5357d7b mdev: class id support
58af09c8da00 modpost: add support for mdev class id
e94f948040f5 mdev: introduce device specific ops
-:500: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating?
#500: 
new file mode 100644

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

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

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

-:114: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #114: FILE: drivers/virtio/virtio_mdev.c:57:
+ void *buf, unsigned len)

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

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

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

total: 0 errors, 6 warnings, 0 checks, 429 lines checked
202515ad0a81 docs: sample driver to demonstrate how to implement virtio-mdev framework -:63: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #63:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 714 lines checked

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

#23 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support
URL : https://patchwork.freedesktop.org/series/69135/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_7288 -> Patchwork_15176
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/index.html

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

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

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live_gem_contexts:
- fi-bsw-nick: [PASS][1] -> [INCOMPLETE][2] ([fdo# 111542])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/fi-bsw-nick/igt@i915_selftest@live_gem_contexts.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/fi-bsw-nick/igt@i915_selftest@live_gem_contexts.html

* igt@kms_frontbuffer_tracking@basic:
- fi-icl-u2: [PASS][3] -> [FAIL][4] ([fdo#103167])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/fi-icl-u2/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/fi-icl-u2/igt@[email protected]

#### Possible fixes ####

* igt@gem_exec_create@basic:
- {fi-tgl-u}: [INCOMPLETE][5] ([fdo#111736]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/fi-tgl-u/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/fi-tgl-u/igt@[email protected]

* igt@kms_chamelium@hdmi-hpd-fast:
- fi-kbl-7500u: [FAIL][7] ([fdo#111407]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/fi-kbl-7500u/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/fi-kbl-7500u/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
- fi-skl-6700k2: [INCOMPLETE][9] ([fdo#104108]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/fi-skl-6700k2/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/fi-skl-6700k2/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# 111542]: https://bugs.freedesktop.org/show_bug.cgi?id= 111542 [fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#111407]: https://bugs.freedesktop.org/show_bug.cgi?id=111407
[fdo#111736]: https://bugs.freedesktop.org/show_bug.cgi?id=111736

Participating hosts (51 -> 45)
------------------------------

Missing (6): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper

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

* CI: CI-20190529 -> None
* Linux: CI_DRM_7288 -> Patchwork_15176

CI-20190529: 20190529
CI_DRM_7288: 41eb27f39e60d822edc75e6aaeb416b72bc1dcf2 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5266: 60a67653613c87a69ebecf12cf00aa362ac87597 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_15176: 202515ad0a81fdea73f83fb083c14d4ef44c4684 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

202515ad0a81 docs: sample driver to demonstrate how to implement virtio-mdev framework 9f42a0ac8dab virtio: introduce a mdev based transport
1643d29b8cd6 mdev: introduce virtio device and its device ops e94f948040f5 mdev: introduce device specific ops
58af09c8da00 modpost: add support for mdev class id
9507b5357d7b mdev: class id support

== Logs ==

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

#24 lore raw

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

In reply to Jason Wang
== Series Details ==

== Series Details ==

Series: mdev based hardware virtio offloading support
URL : https://patchwork.freedesktop.org/series/69135/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_7288_full -> Patchwork_15176_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

### IGT changes ###

#### Issues hit ####

* igt@gem_ctx_persistence@vcs1-queued:
- shard-iclb: [PASS][1] -> [SKIP][2] ([fdo#109276] / [fdo#112080]) +5 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb4/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb8/igt@[email protected]

* igt@gem_eio@in-flight-contexts-1us:
- shard-snb: [PASS][3] -> [FAIL][4] ([fdo#111946])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-snb7/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-snb7/igt@[email protected]

* igt@gem_exec_create@madvise:
- shard-tglb: [PASS][5] -> [INCOMPLETE][6] ([fdo#111747])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb5/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb6/igt@[email protected]

* igt@gem_exec_parallel@vcs1-fds:
- shard-iclb: [PASS][7] -> [SKIP][8] ([fdo#112080]) +11 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb4/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb8/igt@[email protected]

* igt@gem_exec_schedule@preempt-queue-chain-render:
- shard-tglb: [PASS][9] -> [INCOMPLETE][10] ([fdo#111606] / [fdo#111677])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb7/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb6/igt@[email protected]

* igt@gem_exec_schedule@preempt-self-bsd:
- shard-iclb: [PASS][11] -> [SKIP][12] ([fdo#112146]) +4 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb8/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb1/igt@[email protected]

* igt@gem_softpin@noreloc-s3:
- shard-apl: [PASS][13] -> [INCOMPLETE][14] ([fdo#103927])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-apl3/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-apl6/igt@[email protected]

* igt@gem_sync@basic-store-each:
- shard-tglb: [PASS][15] -> [INCOMPLETE][16] ([fdo#111647] / [fdo#111747])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb3/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb6/igt@[email protected]

* igt@gem_userptr_blits@map-fixed-invalidate-busy-gup:
- shard-snb: [PASS][17] -> [DMESG-WARN][18] ([fdo#111870]) +1 similar issue
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-snb1/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-snb2/igt@[email protected]

* igt@gem_userptr_blits@sync-unmap:
- shard-hsw: [PASS][19] -> [DMESG-WARN][20] ([fdo#111870])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-hsw6/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-hsw4/igt@[email protected]

* igt@gem_userptr_blits@sync-unmap-after-close:
- shard-snb: [PASS][21] -> [DMESG-WARN][22] ([fdo#110789] / [fdo#111870])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-snb1/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-snb4/igt@[email protected]

* igt@i915_selftest@live_hangcheck:
- shard-hsw: [PASS][23] -> [DMESG-FAIL][24] ([fdo#111991])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-hsw2/igt@i915_selftest@live_hangcheck.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-hsw8/igt@i915_selftest@live_hangcheck.html
- shard-iclb: [PASS][25] -> [INCOMPLETE][26] ([fdo#107713] / [fdo#108569])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb4/igt@i915_selftest@live_hangcheck.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb3/igt@i915_selftest@live_hangcheck.html

* igt@i915_suspend@fence-restore-untiled:
- shard-kbl: [PASS][27] -> [DMESG-WARN][28] ([fdo#108566]) +1 similar issue
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-kbl6/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-kbl7/igt@[email protected]

* igt@i915_suspend@sysfs-reader:
- shard-tglb: [PASS][29] -> [INCOMPLETE][30] ([fdo#111832] / [fdo#111850]) +4 similar issues
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb2/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb1/igt@[email protected]

* igt@kms_cursor_legacy@2x-flip-vs-cursor-atomic:
- shard-glk: [PASS][31] -> [FAIL][32] ([fdo#104873])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-glk8/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-glk9/igt@[email protected]

* igt@kms_cursor_legacy@flip-vs-cursor-toggle:
- shard-skl: [PASS][33] -> [FAIL][34] ([fdo#102670] / [fdo#106081])
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl6/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl3/igt@[email protected]

* igt@kms_fbcon_fbt@fbc-suspend:
- shard-tglb: [PASS][35] -> [INCOMPLETE][36] ([fdo#111747] / [fdo#111832] / [fdo#111850])
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb9/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb1/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank-interruptible:
- shard-tglb: [PASS][37] -> [FAIL][38] ([fdo#105363])
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb5/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb6/igt@[email protected]
- shard-glk: [PASS][39] -> [FAIL][40] ([fdo#105363])
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-glk4/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-glk3/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render:
- shard-iclb: [PASS][41] -> [FAIL][42] ([fdo#103167]) +5 similar issues
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-move:
- shard-tglb: [PASS][43] -> [FAIL][44] ([fdo#103167]) +3 similar issues
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb1/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb8/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-c:
- shard-skl: [PASS][45] -> [INCOMPLETE][46] ([fdo#104108])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl5/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl6/igt@[email protected]

* igt@kms_plane@plane-panning-bottom-right-suspend-pipe-b-planes:
- shard-apl: [PASS][47] -> [DMESG-WARN][48] ([fdo#108566])
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-apl2/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-apl4/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-constant-alpha-min:
- shard-skl: [PASS][49] -> [FAIL][50] ([fdo#108145])
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl9/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl10/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-coverage-7efc:
- shard-skl: [PASS][51] -> [FAIL][52] ([fdo#108145] / [fdo#110403])
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl8/igt@[email protected]
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl7/igt@[email protected]

* igt@kms_plane_lowres@pipe-a-tiling-y:
- shard-iclb: [PASS][53] -> [FAIL][54] ([fdo#103166])
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb7/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb4/igt@[email protected]

* igt@prime_busy@hang-bsd2:
- shard-iclb: [PASS][55] -> [SKIP][56] ([fdo#109276]) +14 similar issues
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb4/igt@[email protected]
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb8/igt@[email protected]

#### Possible fixes ####

* igt@gem_ctx_persistence@bcs0-mixed-process:
- shard-skl: [FAIL][57] ([fdo#112194]) -> [PASS][58]
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl8/igt@[email protected]
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl7/igt@[email protected]

* igt@gem_ctx_persistence@vcs1-mixed-process:
- shard-iclb: [SKIP][59] ([fdo#109276] / [fdo#112080]) -> [PASS][60] +2 similar issues
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb6/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb4/igt@[email protected]

* igt@gem_exec_balancer@smoke:
- shard-iclb: [SKIP][61] ([fdo#110854]) -> [PASS][62]
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb3/igt@[email protected]
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb2/igt@[email protected]

* igt@gem_exec_create@basic:
- shard-tglb: [INCOMPLETE][63] ([fdo#111736]) -> [PASS][64]
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb6/igt@[email protected]
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb5/igt@[email protected]

* igt@gem_exec_schedule@out-order-bsd2:
- shard-iclb: [SKIP][65] ([fdo#109276]) -> [PASS][66] +15 similar issues
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb7/igt@[email protected]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb2/igt@[email protected]

* igt@gem_exec_schedule@preempt-queue-contexts-blt:
- shard-tglb: [INCOMPLETE][67] ([fdo#111606] / [fdo#111677]) -> [PASS][68]
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb6/igt@[email protected]
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb5/igt@[email protected]

* igt@gem_exec_schedule@preemptive-hang-bsd:
- shard-iclb: [SKIP][69] ([fdo#112146]) -> [PASS][70] +4 similar issues
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb2/igt@[email protected]
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb5/igt@[email protected]

* igt@gem_exec_suspend@basic-s3:
- shard-tglb: [INCOMPLETE][71] ([fdo#111736] / [fdo#111850]) -> [PASS][72]
[71]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb3/igt@[email protected]
[72]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb5/igt@[email protected]

* igt@gem_userptr_blits@dmabuf-unsync:
- shard-hsw: [DMESG-WARN][73] ([fdo#111870]) -> [PASS][74]
[73]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-hsw4/igt@[email protected]
[74]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-hsw1/igt@[email protected]

* igt@gem_userptr_blits@map-fixed-invalidate-busy:
- shard-snb: [DMESG-WARN][75] ([fdo#110789] / [fdo#111870]) -> [PASS][76]
[75]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-snb4/igt@[email protected]
[76]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-snb4/igt@[email protected]

* igt@gem_workarounds@suspend-resume:
- shard-kbl: [DMESG-WARN][77] ([fdo#103313]) -> [PASS][78]
[77]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-kbl4/igt@[email protected]
[78]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-kbl2/igt@[email protected]

* igt@i915_pm_rpm@system-suspend:
- shard-tglb: [INCOMPLETE][79] ([fdo#111747] / [fdo#111850]) -> [PASS][80]
[79]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb3/igt@[email protected]
[80]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb4/igt@[email protected]

* igt@i915_selftest@live_hangcheck:
- shard-snb: [INCOMPLETE][81] ([fdo#105411]) -> [PASS][82]
[81]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-snb4/igt@i915_selftest@live_hangcheck.html
[82]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-snb4/igt@i915_selftest@live_hangcheck.html

* igt@i915_suspend@sysfs-reader:
- shard-apl: [DMESG-WARN][83] ([fdo#108566]) -> [PASS][84] +2 similar issues
[83]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-apl6/igt@[email protected]
[84]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-apl3/igt@[email protected]

* igt@kms_atomic_transition@plane-all-modeset-transition:
- shard-hsw: [DMESG-WARN][85] ([fdo#102614]) -> [PASS][86]
[85]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-hsw5/igt@[email protected]
[86]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-hsw4/igt@[email protected]

* igt@kms_color@pipe-a-gamma:
- shard-skl: [FAIL][87] ([fdo#104782]) -> [PASS][88]
[87]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl4/igt@[email protected]
[88]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl3/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-128x128-offscreen:
- shard-skl: [FAIL][89] ([fdo#103232]) -> [PASS][90]
[89]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl4/igt@[email protected]
[90]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl3/igt@[email protected]

* igt@kms_draw_crc@draw-method-rgb565-mmap-gtt-untiled:
- shard-skl: [FAIL][91] ([fdo#103184] / [fdo#103232]) -> [PASS][92] +1 similar issue
[91]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl4/igt@[email protected]
[92]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl3/igt@[email protected]

* igt@kms_flip@flip-vs-suspend:
- shard-hsw: [INCOMPLETE][93] ([fdo#103540]) -> [PASS][94]
[93]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-hsw4/igt@[email protected]
[94]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-hsw2/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-indfb-plflip-blt:
- shard-tglb: [FAIL][95] ([fdo#103167]) -> [PASS][96] +1 similar issue
[95]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb7/igt@[email protected]
[96]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite:
- shard-iclb: [FAIL][97] ([fdo#103167]) -> [PASS][98] +4 similar issues
[97]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-iclb7/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite.html
[98]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-iclb7/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-pwrite.html

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-kbl: [DMESG-WARN][99] ([fdo#108566]) -> [PASS][100] +8 similar issues
[99]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-kbl7/igt@[email protected]
[100]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-kbl7/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-suspend:
- shard-tglb: [INCOMPLETE][101] ([fdo#111832] / [fdo#111850] / [fdo#111884]) -> [PASS][102]
[101]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb8/igt@[email protected]
[102]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb9/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-1p-offscren-pri-shrfb-draw-blt:
- shard-skl: [FAIL][103] ([fdo#103167]) -> [PASS][104]
[103]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-skl4/igt@[email protected]
[104]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-skl3/igt@[email protected]

* igt@kms_frontbuffer_tracking@psr-suspend:
- shard-tglb: [INCOMPLETE][105] ([fdo#111832] / [fdo#111850]) -> [PASS][106] +1 similar issue
[105]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_7288/shard-tglb1/igt@[email protected]
[106]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_15176/shard-tglb6/igt@kms_frontbuffer_tracking

== Logs ==

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