mdev based hardware virtio offloading support
Subsystems (17)
v2 cover mdev based hardware virtio offloading support
Hi all:
There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.
Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.
A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.
Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with id_talbe claimed by the driver. On top, this seris also decouple device specific parents ops out of the common ones.
Pktgen test was done with virito-net + mvnet loop back device.
Please review.
[1] https://lkml.org/lkml/2019/9/16/869
Changes from 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 (8):
vringh: fix copy direction of vringh_iov_push_kern()
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework
.../driver-api/vfio-mediated-device.rst | 7 +- MAINTAINERS | 2 + 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 | 19 + drivers/vfio/mdev/mdev_driver.c | 22 + drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 45 +- drivers/vhost/vringh.c | 8 +- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++ include/linux/mdev.h | 52 +- include/linux/mod_devicetable.h | 8 + include/linux/vfio_mdev.h | 52 ++ include/linux/virtio_mdev.h | 145 ++++ samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mbochs.c | 20 +- samples/vfio-mdev/mdpy.c | 20 +- samples/vfio-mdev/mtty.c | 18 +- samples/vfio-mdev/mvnet.c | 692 ++++++++++++++++++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 10 + 25 files changed, 1524 insertions(+), 84 deletions(-) create mode 100644 drivers/virtio/virtio_mdev.c create mode 100644 include/linux/vfio_mdev.h create mode 100644 include/linux/virtio_mdev.h create mode 100644 samples/vfio-mdev/mvnet.c
Signature · 1 line
2.19.1
PATCH v2 1/8 vringh: fix copy direction of vringh_iov_push_kern()
We want to copy from iov to buf, so the direction was wrong.
--- drivers/vhost/vringh.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/vhost/vringh.c +7 -1
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)return 0 ; } +static inline int kern_xfer (void *dst,void *src,size_t len) +{ +memcpy (dst, src, len); +return 0 ; +} +/** * vringh_init_kern - initialize a vringh for a kernelspace vring. * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);ssize_t vringh_iov_push_kern (struct vringh_kiov *wiov,const void *src,size_t len) { -return vringh_iov_xfer (wiov, (void *)src, len, xfer_kern); +return vringh_iov_xfer (wiov, (void *)src, len, kern_xfer); }EXPORT_SYMBOL (vringh_iov_push_kern);
Signature · 1 line
2.19.1
PATCH v2 1/8 vringh: fix copy direction of vringh_iov_push_kern()
In reply to Jason WangWe want to copy from iov to buf, so the direction was wrong.
--- drivers/vhost/vringh.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/vhost/vringh.c +7 -1
@@ -852,6 +852,12 @@ static inline int xfer_kern(void *src, void *dst, size_t len)return 0 ; } +static inline int kern_xfer (void *dst,void *src,size_t len) +{ +memcpy (dst, src, len); +return 0 ; +} +/** * vringh_init_kern - initialize a vringh for a kernelspace vring. * @vrh: the vringh to initialize.
@@ -958,7 +964,7 @@ EXPORT_SYMBOL(vringh_iov_pull_kern);ssize_t vringh_iov_push_kern (struct vringh_kiov *wiov,const void *src,size_t len) { -return vringh_iov_xfer (wiov, (void *)src, len, xfer_kern); +return vringh_iov_xfer (wiov, (void *)src, len, kern_xfer); }EXPORT_SYMBOL (vringh_iov_push_kern);
Signature · 1 line
2.19.1
PATCH v2 2/8 mdev: class id support
In reply to Jason WangMdev 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 parent with the match method for mdev bus.
--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)
Documentation/driver-api/vfio-mediated-device.rst +3 -0
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls
@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
drivers/s390/crypto/vfio_ap_ops.c +1 -0
@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }
drivers/vfio/mdev/mdev_core.c +7 -0
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;
@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0.
drivers/vfio/mdev/mdev_driver.c +14 -0
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; } +static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id) +return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };
drivers/vfio/mdev/mdev_private.h +1 -0
@@ -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
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )
include/linux/mdev.h +8 -0
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {
@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
@@ -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
@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:
samples/vfio-mdev/mdpy.c +1 -0
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
samples/vfio-mdev/mtty.c +1 -0
@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; }
Signature · 6 lines
2.19.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 2/8] mdev: class id support
Quoted 8 lines · On Tue, 24 Sep 2019 21:53:26 +0800 Jason Wang <[email protected]> wrote:
Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.
Description needs to be revised from v1, class_id is no longer on the parent.
Quoted 37 lines
Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +2
-0@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls
Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172
Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::
Unintended extra line? Doesn't seem to match surrounding formatting.
Calling mdev_set_class_id() as part of create seems relatively fundamental to the vendor driver with this change, it should be added to the documentation.
Quoted 68 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +7
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0. drivers/vfio/mdev/mdev_driver.c +0
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; }
drivers/vfio/mdev/mdev_driver.c static int mdev_remove(struct device *dev) · line 80
Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +9
-0+static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id)
With the proposed API here, mdev->class_id can be NULL, do we allow devices to exist in that state or should mdev_device_create() generate an error if the .create() callback doesn't register a type? Or a warn_once and assume MDEV_ID_VFIO? The latter seems pretty sketchy when we get to patch 5/8. Thanks,
Alex
Quoted 133 lines
drivers/vfio/mdev/mdev_driver.c +5
-0+return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +8
-0@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */ include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +1
-0@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; }
Re: [PATCH V2 2/8] mdev: class id support
Quoted 9 lines · Alex Williamson
Quoted 6 lines · On Tue, 24 Sep 2019 21:53:26 +0800 Jason Wang <[email protected]> wrote:
Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, 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 4 lines
Quoted 2 lines
So this patch adds
id_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Description needs to be revised from v1,
class_idis no longer on the parent.
Yes, will fix.
Quoted 40 lines
Quoted 40 lines
Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +2
-0@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172
Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +1
-0+ However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::Unintended extra line? Doesn't seem to match surrounding formatting.
Calling
mdev_set_class_id()as part of create seems relatively fundamental to the vendor driver with this change, it should be added to the documentation.
Right.
Quoted 70 lines
Quoted 70 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +7
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0. drivers/vfio/mdev/mdev_driver.c +0
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; }
Quoted 14 lines
drivers/vfio/mdev/mdev_driver.c static int mdev_remove(struct device *dev) · line 80
Quoted 9 lines
drivers/vfio/mdev/mdev_driver.c +9
-0+static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id)With the proposed API here,
mdev->class_idcan be NULL, do we allow devices to exist in that state or shouldmdev_device_create()generate an error if the .create() callback doesn't register a type? Or awarn_onceand assumeMDEV_ID_VFIO? The latter seems pretty sketchy when we get to patch 5/8. Thanks,
It looks to me the error from mdev_device_create() is better.
Thanks
Quoted 132 lines
Alex
Quoted 129 lines
drivers/vfio/mdev/mdev_driver.c +5
-0+return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +8
-0@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */ include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +0
-0@@ -770,6 +770,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)list_add (&mdev_state->next, &mdev_devices_list);mutex_unlock (&mdev_list_lock);
Quoted 4 lines
samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct mdev_device *mdev) · line 776
Quoted 4 lines
samples/vfio-mdev/mtty.c +1
-0+mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH V2 2/8] mdev: class id support
In reply to Alex WilliamsonQuoted 9 lines · Alex Williamson
Quoted 6 lines · On Tue, 24 Sep 2019 21:53:26 +0800 Jason Wang <[email protected]> wrote:
Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, 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 4 lines
Quoted 2 lines
So this patch adds
id_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Description needs to be revised from v1,
class_idis no longer on the parent.
Yes, will fix.
Quoted 40 lines
Quoted 40 lines
Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +2
-0@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops);
Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172
Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +1
-0+ However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::Unintended extra line? Doesn't seem to match surrounding formatting.
Calling
mdev_set_class_id()as part of create seems relatively fundamental to the vendor driver with this change, it should be added to the documentation.
Right.
Quoted 70 lines
Quoted 70 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +7
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0. drivers/vfio/mdev/mdev_driver.c +0
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; }
Quoted 14 lines
drivers/vfio/mdev/mdev_driver.c static int mdev_remove(struct device *dev) · line 80
Quoted 9 lines
drivers/vfio/mdev/mdev_driver.c +9
-0+static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id)With the proposed API here,
mdev->class_idcan be NULL, do we allow devices to exist in that state or shouldmdev_device_create()generate an error if the .create() callback doesn't register a type? Or awarn_onceand assumeMDEV_ID_VFIO? The latter seems pretty sketchy when we get to patch 5/8. Thanks,
It looks to me the error from mdev_device_create() is better.
Thanks
Quoted 132 lines
Alex
Quoted 129 lines
drivers/vfio/mdev/mdev_driver.c +5
-0+return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +8
-0@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */ include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +0
-0@@ -770,6 +770,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)list_add (&mdev_state->next, &mdev_devices_list);mutex_unlock (&mdev_list_lock);
Quoted 4 lines
samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct mdev_device *mdev) · line 776
Quoted 4 lines
samples/vfio-mdev/mtty.c +1
-0+mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 2/8] mdev: class id support
In reply to Jason WangQuoted 8 lines · On Tue, 24 Sep 2019 21:53:26 +0800 Jason Wang <[email protected]> wrote:
Mdev bus only supports vfio driver right now, so it doesn't implement match method. But in the future, we may add drivers other than vfio, 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.
Description needs to be revised from v1, class_id is no longer on the parent.
Quoted 37 lines
Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +2
-0@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls
Documentation/driver-api/vfio-mediated-device.rst register itself with the mdev core driver:: · line 172
Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::
Unintended extra line? Doesn't seem to match surrounding formatting.
Calling mdev_set_class_id() as part of create seems relatively fundamental to the vendor driver with this change, it should be added to the documentation.
Quoted 68 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +7
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0. drivers/vfio/mdev/mdev_driver.c +0
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; }
drivers/vfio/mdev/mdev_driver.c static int mdev_remove(struct device *dev) · line 80
Quoted 10 lines
drivers/vfio/mdev/mdev_driver.c +9
-0+static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id)
With the proposed API here, mdev->class_id can be NULL, do we allow devices to exist in that state or should mdev_device_create() generate an error if the .create() callback doesn't register a type? Or a warn_once and assume MDEV_ID_VFIO? The latter seems pretty sketchy when we get to patch 5/8. Thanks,
Alex
Quoted 133 lines
drivers/vfio/mdev/mdev_driver.c +5
-0+return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +8
-0@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */ include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +1
-0@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; }
RE: [PATCH V2 2/8] mdev: class id support
In reply to Jason WangQuoted 122 lines
From: Jason Wang
Sent: Tuesday, September 24, 2019 9:53 PMMdev 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -102,12 +102,14 @@ structure to represent a mediated device'sdriver::
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structureDocumentation/driver-api/vfio-mediated-device.rst +2
-0+ * @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 functioncalls
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the functioncall
that a driver should use to unregister itself with the mdev core driver::drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret;}
drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +6
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {drivers/vfio/mdev/mdev_core.c +0
-0return &mdev->dev;
drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 145
Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1
-0@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data) * mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. + * @id: device id.
class id.
Quoted 163 lines
drivers/vfio/mdev/mdev_core.c +0
-0* * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0.
drivers/vfio/mdev/mdev_driver.c +14
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; } +static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id) +return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +1
-0@@ -118,6 +118,7 @@ struct mdev_type_attributemdev_type_attr_##_name = \ * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct
mdev_driver{include/linux/mdev.h +7
-0@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /*
MDEV_H*/include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ;
err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev ); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +1
-1@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; } --
Quoted 1 line
2.19.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH V2 2/8] mdev: class id support
Quoted 112 lines · Kevin
Quoted 112 lines
From: Jason Wang
Sent: Tuesday, September 24, 2019 9:53 PMMdev 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -102,12 +102,14 @@ structure to represent a mediated device'sdriver::
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structureDocumentation/driver-api/vfio-mediated-device.rst +2
-0+ * @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 functioncalls
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the functioncall
that a driver should use to unregister itself with the mdev core driver::drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret;}
drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +0
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata);
Quoted 16 lines
Quoted 10 lines
drivers/vfio/mdev/mdev_core.c +6
-0+void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {drivers/vfio/mdev/mdev_core.c +0
-0return &mdev->dev;drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 145
Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1
-0@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data) * mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. + * @id: device id.class id.
Right, will fix.
Thanks
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 2/8] mdev: class id support
In reply to Tian, KevinQuoted 112 lines · Kevin
Quoted 112 lines
From: Jason Wang
Sent: Tuesday, September 24, 2019 9:53 PMMdev 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -102,12 +102,14 @@ structure to represent a mediated device'sdriver::
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structureDocumentation/driver-api/vfio-mediated-device.rst +2
-0+ * @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 functioncalls
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the functioncall
that a driver should use to unregister itself with the mdev core driver::drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret;}
drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +0
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata);
Quoted 16 lines
Quoted 10 lines
drivers/vfio/mdev/mdev_core.c +6
-0+void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {drivers/vfio/mdev/mdev_core.c +0
-0return &mdev->dev;drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 145
Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1
-0@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data) * mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. + * @id: device id.class id.
Right, will fix.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RE: [PATCH V2 2/8] mdev: class id support
In reply to Jason WangQuoted 122 lines
From: Jason Wang
Sent: Tuesday, September 24, 2019 9:53 PMMdev 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_tabletomdev_driverandclass_idfor mdev parent with the match method for mdev bus.Signed-off-by Jason Wang <[email protected]>--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -102,12 +102,14 @@ structure to represent a mediated device'sdriver::
* @probe: called when new device created
* @remove: called when device removed
* @driver: device driver structureDocumentation/driver-api/vfio-mediated-device.rst +2
-0+ * @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 functioncalls
Documentation/driver-api/vfio-mediated-device.rst +1
-0@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the functioncall
that a driver should use to unregister itself with the mdev core driver::drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret;}
drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }drivers/vfio/mdev/mdev_core.c +6
-0@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {drivers/vfio/mdev/mdev_core.c +0
-0return &mdev->dev;
drivers/vfio/mdev/mdev_core.c static int mdev_device_remove_cb(struct device · line 145
Quoted 5 lines
drivers/vfio/mdev/mdev_core.c +1
-0@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data) * mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. + * @id: device id.
class id.
Quoted 164 lines
drivers/vfio/mdev/mdev_core.c +0
-0* * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0.
drivers/vfio/mdev/mdev_driver.c +14
-0@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; } +static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id) +return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };drivers/vfio/mdev/mdev_private.h +1
-0@@ -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@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )include/linux/mdev.h +1
-0@@ -118,6 +118,7 @@ struct mdev_type_attributemdev_type_attr_##_name = \ * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct
mdev_driver{include/linux/mdev.h +7
-0@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /*
MDEV_H*/include/linux/mod_devicetable.h +8
-0@@ -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@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ;
err_mem:samples/vfio-mdev/mdpy.c +1
-0@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev ); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }samples/vfio-mdev/mtty.c +1
-1@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; } --2.19.1
PATCH v2 2/8 mdev: class id support
In reply to Jason WangMdev 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 parent with the match method for mdev bus.
--- Documentation/driver-api/vfio-mediated-device.rst | 3 +++ 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 | 7 +++++++ drivers/vfio/mdev/mdev_driver.c | 14 ++++++++++++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 6 ++++++ include/linux/mdev.h | 8 ++++++++ include/linux/mod_devicetable.h | 8 ++++++++ samples/vfio-mdev/mbochs.c | 1 + samples/vfio-mdev/mdpy.c | 1 + samples/vfio-mdev/mtty.c | 1 + 13 files changed, 53 insertions(+)
Documentation/driver-api/vfio-mediated-device.rst +3 -0
@@ -102,12 +102,14 @@ structure to represent a mediated device's driver:: * @probe: called when new device created * @remove: called when device removed * @driver: device driver structure + * @id_table: the ids serviced by this driver */ struct mdev_driver { const char *name; int (*probe) (struct device *dev); void (*remove) (struct device *dev); struct device_driver driver; + const struct mdev_class_id *id_table; }; A mediated bus driver for mdev should use this structure in the function calls
@@ -165,6 +167,7 @@ register itself with the mdev core driver:: extern int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops); + However, the mdev_parent_ops structure is not required in the function call that a driver should use to unregister itself with the mdev core driver::
drivers/gpu/drm/i915/gvt/kvmgt.c +1 -0
@@ -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_id (mdev,MDEV_ID_VFIO ); out:return ret; }
drivers/s390/cio/vfio_ccw_ops.c +1 -0
@@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.ssid, private->sch->schid.sch_no); +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
drivers/s390/crypto/vfio_ap_ops.c +1 -0
@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; }
drivers/vfio/mdev/mdev_core.c +7 -0
@@ -45,6 +45,12 @@ void mdev_set_drvdata(struct mdev_device *mdev, void *data) }EXPORT_SYMBOL (mdev_set_drvdata); +void mdev_set_class_id (struct mdev_device *mdev,u16 id) +{ + mdev->class_id = id; +} +EXPORT_SYMBOL (mdev_set_class_id); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;
@@ -135,6 +141,7 @@ static int mdev_device_remove_cb(struct device *dev, void *data)* mdev_register_device : Register a device * @dev: device structure representing parent device. * @ops: Parent device operation structure to be registered. +* @id: device id. * * Add device to list of registered parent devices. * Returns a negative value on error, otherwise 0.
drivers/vfio/mdev/mdev_driver.c +14 -0
@@ -69,8 +69,22 @@ static int mdev_remove(struct device *dev)return 0 ; } +static int mdev_match (struct device *dev,struct device_driver *drv) +{ +unsigned int i; +struct mdev_device *mdev =to_mdev_device (dev); +struct mdev_driver *mdrv =to_mdev_driver (drv); +const struct mdev_class_id *ids = mdrv->id_table; + +for (i =0 ; ids[i].id; i++) +if (ids[i].id == mdev->class_id) +return 1 ; +return 0 ; +} +struct bus_type mdev_bus_type = { .name ="mdev" , + .match = mdev_match, .probe = mdev_probe, .remove = mdev_remove, };
drivers/vfio/mdev/mdev_private.h +1 -0
@@ -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
@@ -120,10 +120,16 @@ static void vfio_mdev_remove(struct device *dev)vfio_del_group_dev (dev); } +static struct mdev_class_id id_table[] = { + {MDEV_ID_VFIO }, + {0 }, +}; +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe, .remove = vfio_mdev_remove, + .id_table = id_table, };static int __init vfio_mdev_init (void )
include/linux/mdev.h +8 -0
@@ -118,6 +118,7 @@ struct mdev_type_attribute mdev_type_attr_##_name = \* @probe: called when new device created * @remove: called when device removed * @driver: device driver structure +* @id_table: the ids serviced by this driver. * **/ struct mdev_driver {
@@ -125,12 +126,14 @@ struct mdev_driver {int (*probe)(struct device *dev);void (*remove)(struct device *dev);struct device_driver driver; +const struct mdev_class_id *id_table; };#define to_mdev_driver (drv) container_of(drv, struct mdev_driver, driver)void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);extern struct bus_type mdev_bus_type;
@@ -145,4 +148,9 @@ struct device *mdev_parent_dev(struct mdev_device *mdev);struct device *mdev_dev (struct mdev_device *mdev);struct mdev_device *mdev_from_dev (struct device *dev); +enum { +MDEV_ID_VFIO =1 , +/* New entries must be added here */ +}; +#endif /* MDEV_H */
include/linux/mod_devicetable.h +8 -0
@@ -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
@@ -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_id (mdev,MDEV_ID_VFIO );return 0 ; err_mem:
samples/vfio-mdev/mdpy.c +1 -0
@@ -269,6 +269,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev)mdpy_reset (mdev); mdpy_count++; +mdev_set_class_id (mdev,MDEV_ID_VFIO );return 0 ; }
samples/vfio-mdev/mtty.c +1 -0
@@ -770,6 +770,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_id (mdev,MDEV_ID_VFIO );return 0 ; }
Signature · 1 line
2.19.1
PATCH v2 3/8 mdev: bus uevent support
In reply to Jason WangThis patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.
--- drivers/vfio/mdev/mdev_driver.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +8 -0
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)return 0 ; } +static int mdev_uevent (struct device *dev,struct kobj_uevent_env *env) +{ +struct mdev_device *mdev =to_mdev_device (dev); + +return add_uevent_var (env,"MODALIAS=mdev:c%02X" , mdev->class_id); +} +struct bus_type mdev_bus_type = { .name ="mdev" , .match = mdev_match, + .uevent = mdev_uevent, .probe = mdev_probe, .remove = mdev_remove, };
Signature · 6 lines
2.19.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 3/8 mdev: bus uevent support
In reply to Jason WangThis patch adds bus uevent support for mdev bus in order to allow cooperation with userspace.
--- drivers/vfio/mdev/mdev_driver.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/vfio/mdev/mdev_driver.c +8 -0
@@ -82,9 +82,17 @@ static int mdev_match(struct device *dev, struct device_driver *drv)return 0 ; } +static int mdev_uevent (struct device *dev,struct kobj_uevent_env *env) +{ +struct mdev_device *mdev =to_mdev_device (dev); + +return add_uevent_var (env,"MODALIAS=mdev:c%02X" , mdev->class_id); +} +struct bus_type mdev_bus_type = { .name ="mdev" , .match = mdev_match, + .uevent = mdev_uevent, .probe = mdev_probe, .remove = mdev_remove, };
Signature · 1 line
2.19.1
PATCH v2 4/8 modpost: add support for mdev class id
In reply to Jason WangAdd support to parse mdev class id table.
--- drivers/vfio/mdev/vfio_mdev.c | 2 ++ scripts/mod/devicetable-offsets.c | 3 +++ scripts/mod/file2alias.c | 10 ++++++++++ 3 files changed, 15 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
@@ -125,6 +125,8 @@ static struct mdev_class_id id_table[] = { { 0 }, }; +MODULE_DEVICE_TABLE (mdev, id_table); +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe,
scripts/mod/devicetable-offsets.c +3 -0
@@ -231,5 +231,8 @@ int main(void)DEVID (wmi_device_id);DEVID_FIELD (wmi_device_id, guid_string); +DEVID (mdev_class_id); +DEVID_FIELD (mdev_class_id, id); +return 0 ; }
scripts/mod/file2alias.c +10 -0
@@ -1330,6 +1330,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)return 1 ; } +/* looks like: "mdev:cN" */ +static int do_mdev_entry (const char *filename,void *symval,char *alias) +{ +DEF_FIELD (symval, mdev_class_id, id); + +sprintf (alias,"mdev:c%02X" , id); +return 1 ; +} +/* Does namelen bytes of name exactly match the symbol? */ static bool sym_is (const char *name,unsigned namelen,const char *symbol) {
@@ -1402,6 +1411,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
PATCH v2 4/8 modpost: add support for mdev class id
In reply to Jason WangAdd support to parse mdev class id table.
--- drivers/vfio/mdev/vfio_mdev.c | 2 ++ scripts/mod/devicetable-offsets.c | 3 +++ scripts/mod/file2alias.c | 10 ++++++++++ 3 files changed, 15 insertions(+)
drivers/vfio/mdev/vfio_mdev.c +2 -0
@@ -125,6 +125,8 @@ static struct mdev_class_id id_table[] = { { 0 }, }; +MODULE_DEVICE_TABLE (mdev, id_table); +static struct mdev_driver vfio_mdev_driver = { .name ="vfio_mdev" , .probe = vfio_mdev_probe,
scripts/mod/devicetable-offsets.c +3 -0
@@ -231,5 +231,8 @@ int main(void)DEVID (wmi_device_id);DEVID_FIELD (wmi_device_id, guid_string); +DEVID (mdev_class_id); +DEVID_FIELD (mdev_class_id, id); +return 0 ; }
scripts/mod/file2alias.c +10 -0
@@ -1330,6 +1330,15 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)return 1 ; } +/* looks like: "mdev:cN" */ +static int do_mdev_entry (const char *filename,void *symval,char *alias) +{ +DEF_FIELD (symval, mdev_class_id, id); + +sprintf (alias,"mdev:c%02X" , id); +return 1 ; +} +/* Does namelen bytes of name exactly match the symbol? */ static bool sym_is (const char *name,unsigned namelen,const char *symbol) {
@@ -1402,6 +1411,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
PATCH v2 5/8 mdev: introduce device specific ops
In reply to Jason WangCurrently, 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 | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +3 -1
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.) -The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows: * open: open callback of mediated device * close: close callback of mediated device
MAINTAINERS +1 -0
@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +11 -6
@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h>
@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;
@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops); out:return ret; }
@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = { + .mdev_attr_groups = intel_vgpu_groups, + .create = intel_vgpu_create, + .remove = intel_vgpu_remove, +}; +static int kvmgt_host_init (struct device *dev,void *gvt,const void *ops) {struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +12 -5
@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h>
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ccw_mdev_create (struct kobject *kobj,struct mdev_device *mdev) { struct vfio_ccw_private *private =
@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, } } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,
@@ -587,6 +587,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 -3
@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h>
@@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ap_mdev_create (struct kobject *kobj,struct mdev_device *mdev) {struct ap_matrix_mdev *matrix_mdev;
@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )
drivers/vfio/mdev/mdev_core.c +12 -0
@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev, u16 id) }EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +1 -0
@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h"
@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev);int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ; - ret = parent->ops->open (mdev); + ret = ops->open (mdev);if (ret)module_put (THIS_MODULE );
@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (likely (parent->ops->release)) - parent->ops->release (mdev); +if (likely (ops->release)) + ops->release (mdev);module_put (THIS_MODULE ); }
@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data, unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ; -return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ; -return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->write)) +if (unlikely (!ops->write))return -EINVAL ; -return parent->ops->write (mdev, buf, count, ppos); +return ops->write (mdev, buf, count, ppos); }static int vfio_mdev_mmap (void *device_data,struct vm_area_struct *vma) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->mmap)) +if (unlikely (!ops->mmap))return -EINVAL ; -return parent->ops->mmap (mdev, vma); +return ops->mmap (mdev, vma); }static const struct vfio_device_ops vfio_mdev_dev_ops = {
include/linux/mdev.h +9 -33
66 lines not on this page · raw message
include/linux/vfio_mdev.h new file +52 -0
52 lines not on this page · raw message
samples/vfio-mdev/mbochs.c +13 -6
@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h>
@@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);
@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:
@@ -1419,12 +1423,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,
@@ -1433,6 +1432,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 -6
@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h"
@@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);
@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -726,12 +730,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,
@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops = { .mmap = mdpy_mmap, }; +static const struct mdev_parent_ops mdev_fops = { + .owner =THIS_MODULE , + .mdev_attr_groups = mdev_dev_groups, + .supported_type_groups = mdev_type_groups, + .create = mdpy_create, + .remove = mdpy_remove, +}; +static const struct file_operations vd_fops = { .owner =THIS_MODULE , };
samples/vfio-mdev/mtty.c +12 -5
@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h>
@@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;
@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }
@@ -1411,6 +1415,14 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,
@@ -1418,11 +1430,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
Re: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 30 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hDocumentation/driver-api/vfio-mediated-device.rst +0
-0
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 7 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.) -The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:
This is not accurate. device_ops is now on the mdev_device and is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping of class_id to mdev_device_ops callbacks.
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the class_id in the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?
Quoted 36 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVERdrivers/gpu/drm/i915/gvt/kvmgt.c +3
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> @@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;
drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);
This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {
.id = MDEV_ID_VFIO,
.open = intel_vgpu_open,
.release = intel_vgpu_release,
...And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used container_of to get to their callbacks?
Quoted 13 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-5out:return ret; }@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-1.open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = {
These could maybe be made const at the same time. Thanks,
Alex
Quoted 560 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +5
-0+ .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
-5@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h> @@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ccw_mdev_create (struct kobject *kobj,struct mdev_device *mdev) { struct vfio_ccw_private *private =@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, } } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,@@ -587,6 +587,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
-3@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h> @@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ap_mdev_create (struct kobject *kobj,struct mdev_device *mdev) {struct ap_matrix_mdev *matrix_mdev;@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )drivers/vfio/mdev/mdev_core.c +12
-0@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev, u16 id) }EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;drivers/vfio/mdev/mdev_private.h +1
-0@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct mdev_device, dev)drivers/vfio/mdev/vfio_mdev.c +19
-18@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" @@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev);int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ; - ret = parent->ops->open (mdev); + ret = ops->open (mdev);if (ret)module_put (THIS_MODULE );@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (likely (parent->ops->release)) - parent->ops->release (mdev); +if (likely (ops->release)) + ops->release (mdev);module_put (THIS_MODULE ); }@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data, unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ; -return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ; -return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->write)) +if (unlikely (!ops->write))return -EINVAL ; -return parent->ops->write (mdev, buf, count, ppos); +return ops->write (mdev, buf, count, ppos); }static int vfio_mdev_mmap (void *device_data,struct vm_area_struct *vma) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->mmap)) +if (unlikely (!ops->mmap))return -EINVAL ; -return parent->ops->mmap (mdev, vma); +return ops->mmap (mdev, vma); }static const struct vfio_device_ops vfio_mdev_dev_ops = {include/linux/mdev.h +9
-33@@ -10,6 +10,11 @@#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 ;/* @@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(struct device *dev);* @mdev: mdev_device device structure which is being * destroyed * Returns integer: success (0) or error (< 0) -* @open: Open mediated device. -* @mdev: mediated device. -* Returns integer: success (0) or error (< 0) -* @release: release mediated device -* @mdev: mediated device. -* @read: Read emulation callback -* @mdev: mediated device structure -* @buf: read buffer -* @count: number of bytes to read -* @ppos: address. -* Retuns number on bytes read on success or error. -* @write: Write emulation callback -* @mdev: mediated device structure -* @buf: write buffer -* @count: number of bytes to be written -* @ppos: address. -* Retuns number on bytes written on success or error. -* @ioctl: IOCTL callback -* @mdev: mediated device structure -* @cmd: ioctl command -* @arg: arguments to ioctl -* @mmap: mmap callback -* @mdev: mediated device structure -* @vma: vma structure +* @device_ops: Device specific emulation callback. +* * Parent device that support mediated device should be registered with mdev * module with mdev_parent_ops structure. **/ @@ -83,15 +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 */ @@ -133,6 +107,8 @@ struct mdev_driver {void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +const void *mdev_get_dev_ops (struct mdev_device *mdev); +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops);void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);include/linux/vfio_mdev.h new file +52
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VFIO Mediated device definition +*/ + +#ifndef VFIO_MDEV_H +#define VFIO_MDEV_H + +#include <linux/mdev.h> + +/** +* struct vfio_mdev_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 vfio_mdev_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
-6@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h> @@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:@@ -1419,12 +1423,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,@@ -1433,6 +1432,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
-6@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h" @@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -726,12 +730,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops = { .mmap = mdpy_mmap, }; +static const struct mdev_parent_ops mdev_fops = { + .owner =THIS_MODULE , + .mdev_attr_groups = mdev_dev_groups, + .supported_type_groups = mdev_type_groups, + .create = mdpy_create, + .remove = mdpy_remove, +}; +static const struct file_operations vd_fops = { .owner =THIS_MODULE , };samples/vfio-mdev/mtty.c +12
-5@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h> @@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }@@ -1411,6 +1415,14 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,@@ -1418,11 +1430,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)
Re: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 41 lines
From: Alex Williamson
Sent: Wednesday, September 25, 2019 7:07 AMQuoted 25 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hReview
Quoted 1 line
(quoted diff) +0
-0
b/Documentation/driver-api/vfio-mediated-device.rstDocumentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type,
Quoted 4 lines
index
a5bdc60d62a1..d50425b368bb100644Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type,or any other categorization.
Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.)
Quoted 9 lines
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1-The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:This is not accurate.
device_opsis now on themdev_deviceand is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping ofclass_idtomdev_device_opscallbacks.
there is also a mistake in include/Linux/mdev.h, where device_ops is still part of mdev_parent_ops in the comment line.
Quoted 60 lines
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the
class_idin the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?Review
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVER(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gvt/kvmgt.cQuoted 12 lines
index
f793252a3d2a..b274f5ee481f100644drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_put_vfio_device(void *vgpu) · line 649
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; + static int intel_vgpu_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj,
Quoted 3 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0{struct intel_vgpu *vgpu =NULL ;@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj,struct
mdev_device*mdev)drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .id = MDEV_ID_VFIO,drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0.open = intel_vgpu_open, .release = intel_vgpu_release,
Quoted 2 lines
And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used
container_ofto get to their callbacks?
or just make it explicit? e.g.
mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);
Quoted 629 lines
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group
Quoted 5 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0out:return ret; }@@ -1601,20 +1605,21 @@ static const struct attribute_group*intel_vgpu_groups[] = {
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-5NULL, }; -static struct mdev_parent_ops intel_vgpu_ops = { - .mdev_attr_groups = intel_vgpu_groups, - .create = intel_vgpu_create, - .remove = intel_vgpu_remove, - +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-1.open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = {These could maybe be made const at the same time. Thanks,
Alex
Review
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +5
-0+ .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;(quoted diff) +0
-0
b/drivers/s390/cio/vfio_ccw_ops.cdrivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[]
Quoted 12 lines
index
d258ef1fedb9..329d53c1f46b100644drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h> @@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[]= {
drivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[] = {
Quoted 6 lines
drivers/s390/cio/vfio_ccw_ops.c +2
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/s390/cio/vfio_ccw_ops.c static int vfio_ccw_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/cio/vfio_ccw_ops.c +0
-0{ struct vfio_ccw_private *private =@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/cio/vfio_ccw_ops.c static ssize_t vfio_ccw_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-0private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
mdev_device*mdev,drivers/s390/cio/vfio_ccw_ops.c static const struct mdev_parent_ops
Quoted 13 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-5} } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,@@ -587,6 +587,13 @@ static const struct mdev_parent_ops
vfio_ccw_mdev_ops= {Review
Quoted 14 lines
drivers/s390/cio/vfio_ccw_ops.c +7
-0.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);(quoted diff) +0
-0
b/drivers/s390/crypto/vfio_ap_ops.cdrivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct
Quoted 12 lines
index
2cfd96112aa0..3a89933f0d3e100644drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h> @@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct
ap_config_info*info,drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct ap_config_info *info,
Quoted 6 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/s390/crypto/vfio_ap_ops.c static int vfio_ap_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-0{struct ap_matrix_mdev *matrix_mdev;@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/crypto/vfio_ap_ops.c static ssize_t vfio_ap_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-0mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct
mdev_device*mdev,Review
Quoted 22 lines
drivers/s390/crypto/vfio_ap_ops.c +6
-3return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_core.cdrivers/vfio/mdev/mdev_core.c void mdev_set_class_id(struct mdev_device *mdev,
Quoted 4 lines
index
8764cf4a276d..6f35f2ced2c9100644drivers/vfio/mdev/mdev_core.c +0
-0@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev,u16 id)
Review
Quoted 19 lines
drivers/vfio/mdev/mdev_core.c +12
-0}EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_private.hdrivers/vfio/mdev/mdev_private.h struct mdev_device { · line 40
Quoted 11 lines
index
c65f436c1869..b666805f0b1f100644drivers/vfio/mdev/mdev_private.h +1
-0@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct
mdev_device, dev)Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 15 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2int 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 );drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) · line 47
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void
Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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,drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1-if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ;drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1-if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ;drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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)
drivers/vfio/mdev/vfio_mdev.c
Quoted 4 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1{struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);include/linux/mdev.h struct device *mdev_get_iommu_device(struct
Quoted 27 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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 +5
-0@@ -10,6 +10,11 @@#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 ;/* @@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(structdevice *dev);
include/linux/mdev.h struct device *mdev_get_iommu_device(struct · line 53
Quoted 1 line
include/linux/mdev.h +0
-0* @mdev: mdev_device device structure which is being
Quoted 19 lines
include/linux/mdev.h +0
-17* 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. include/linux/mdev.h struct device *mdev_get_iommu_device(struct device *dev);
Quoted 10 lines
include/linux/mdev.h +2
-7-* @ioctl: IOCTL callback -* @mdev: mediated device structure -* @cmd: ioctl command -* @arg: arguments to ioctl -* @mmap: mmap callback -* @mdev: mediated device structure -* @vma: vma structure +* @device_ops: Device specific emulation callback. +* * Parent device that support mediated device should be registered with mdev
Quoted 5 lines
include/linux/mdev.h +0
-0* module with mdev_parent_ops structure. **/ @@ -83,15 +66,6 @@ struct mdev_parent_ops {int (*create)(struct kobject *kobj,struct mdev_device *mdev);include/linux/mdev.h struct mdev_parent_ops { · line 94
Quoted 10 lines
include/linux/mdev.h +0
-9int (*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);
Quoted 57 lines
include/linux/mdev.h +2
-0};/* interface for exporting mdev supported type attributes */ @@ -133,6 +107,8 @@ struct mdev_driver {void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +const void *mdev_get_dev_ops (struct mdev_device *mdev); +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops);void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);include/linux/vfio_mdev.h new file +39
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VFIO Mediated device definition +*/ + +#ifndef VFIO_MDEV_H +#define VFIO_MDEV_H + +#include <linux/mdev.h> + +/** +* struct vfio_mdev_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 +*/ include/linux/vfio_mdev.h line 49
Quoted 10 lines
include/linux/vfio_mdev.h new file +10
-0+struct vfio_mdev_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);
samples/vfio-mdev/mbochs.c static int mbochs_reset(struct mdev_device
Quoted 16 lines
include/linux/vfio_mdev.h new file +3
-0+}; + +#endif samples/vfio-mdev/mbochs.c +1
-0@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h> @@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device*mdev)
samples/vfio-mdev/mbochs.c static int mbochs_create(struct kobject *kobj,
Quoted 9 lines
samples/vfio-mdev/mbochs.c +2
-0return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj,struct
mdev_device*mdev)samples/vfio-mdev/mbochs.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mbochs.c +1
-0mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:@@ -1419,12 +1423,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mbochs.c static const struct mdev_parent_ops
Quoted 14 lines
samples/vfio-mdev/mbochs.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,@@ -1433,6 +1432,14 @@ static const struct mdev_parent_ops
mdev_fops= {samples/vfio-mdev/mdpy.c static int mdpy_create(struct kobject *kobj, struct
Quoted 36 lines
samples/vfio-mdev/mbochs.c +8
-0.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 +3
-0@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h" @@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mdpy.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mdpy.c +1
-0mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -726,12 +730,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mdpy.c static const struct mdev_parent_ops mdev_fops
Quoted 14 lines
samples/vfio-mdev/mdpy.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops= {
samples/vfio-mdev/mtty.c static ssize_t mdev_access(struct mdev_device
Quoted 27 lines
samples/vfio-mdev/mdpy.c +8
-0.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 +1
-0@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h> @@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device*mdev, u8 *buf,
size_tcount,samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct
Quoted 9 lines
samples/vfio-mdev/mtty.c +2
-0return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mtty.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mtty.c +1
-0mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }@@ -1411,6 +1415,14 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mtty.c static const struct mdev_parent_ops
Quoted 15 lines
samples/vfio-mdev/mtty.c +8
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,@@ -1418,11 +1430,6 @@ static const struct mdev_parent_ops
mdev_fops= {Quoted 10 lines
samples/vfio-mdev/mtty.c +0
-5.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, };
Quoted 6 lines
samples/vfio-mdev/mtty.c static const struct mdev_parent_ops mdev_fops = { · line 1435
Quoted 1 line
samples/vfio-mdev/mtty.c +0
-0static void mtty_device_release (struct device *dev)_______________________________________________
intel-gvt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 239 lines · Kevin
Quoted 31 lines
From: Alex Williamson
Sent: Wednesday, September 25, 2019 7:07 AMQuoted 25 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hQuoted 8 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/Documentation/driver-api/vfio-mediated-device.rstDocumentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type,
Quoted 4 lines
index
a5bdc60d62a1..d50425b368bb100644Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type,or any other categorization.
Quoted 1 line
Documentation/driver-api/vfio-mediated-device.rst +0
-0Vendor drivers are expected to be fully asynchronous in this respector
Quoted 11 lines
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 6 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1provide their own internal resource protection.) -The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:This is not accurate.
device_opsis now on themdev_deviceand is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping ofclass_idtomdev_device_opscallbacks.there is also a mistake in
include/Linux/mdev.h, wheredevice_opsis still part ofmdev_parent_opsin the comment line.Quoted 54 lines
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the
class_idin the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?Review
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVER(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gvt/kvmgt.cQuoted 12 lines
index
f793252a3d2a..b274f5ee481f100644drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_put_vfio_device(void *vgpu) · line 649
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; + static int intel_vgpu_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj,
Quoted 3 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0{struct intel_vgpu *vgpu =NULL ;@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj,struct
mdev_device*mdev)drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
Quoted 8 lines
static const struct
vfio_mdev_device_opsintel_vfio_vgpu_dev_ops= {.id = MDEV_ID_VFIO, .open = intel_vgpu_open, .release = intel_vgpu_release, ...And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used
container_ofto get to their callbacks?or just make it explicit? e.g.
mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);Quoted 28 lines
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group
Quoted 5 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0out:return ret; }@@ -1601,20 +1605,21 @@ static const struct attribute_group*intel_vgpu_groups[] = {
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-5NULL, }; -static struct mdev_parent_ops intel_vgpu_ops = { - .mdev_attr_groups = intel_vgpu_groups, - .create = intel_vgpu_create, - .remove = intel_vgpu_remove, - +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-1.open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = {These could maybe be made const at the same time. Thanks,
Quoted 8 lines
Alex
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = {
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +5
-0+ .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)
Quoted 15 lines
Review
Quoted 3 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0{struct attribute **kvm_type_attrs;(quoted diff) +0
-0
b/drivers/s390/cio/vfio_ccw_ops.cQuoted 11 lines
index
d258ef1fedb9..329d53c1f46b100644drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h> Quoted 8 lines
drivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[]
Quoted 1 line
drivers/s390/cio/vfio_ccw_ops.c +0
-0@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[]= {
drivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[] = {
Quoted 6 lines
drivers/s390/cio/vfio_ccw_ops.c +2
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ccw_mdev_create(struct kobject *kobj, struct
mdev_deviceQuoted 56 lines
*mdev)
drivers/s390/cio/vfio_ccw_ops.c static int vfio_ccw_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/cio/vfio_ccw_ops.c +0
-0{ struct vfio_ccw_private *private =@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/cio/vfio_ccw_ops.c static ssize_t vfio_ccw_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-0private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
mdev_device*mdev,drivers/s390/cio/vfio_ccw_ops.c static const struct mdev_parent_ops
Quoted 13 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-5} } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,@@ -587,6 +587,13 @@ static const struct mdev_parent_ops
vfio_ccw_mdev_ops= {Review
Quoted 14 lines
drivers/s390/cio/vfio_ccw_ops.c +7
-0.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);(quoted diff) +0
-0
b/drivers/s390/crypto/vfio_ap_ops.cdrivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct
Quoted 12 lines
index
2cfd96112aa0..3a89933f0d3e100644drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h> @@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct
ap_config_info*info,
Quoted 110 lines
Quoted 6 lines
drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct ap_config_info *info,
Quoted 6 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ap_mdev_create(struct kobject *kobj, struct
mdev_deviceQuoted 102 lines
*mdev)
drivers/s390/crypto/vfio_ap_ops.c static int vfio_ap_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-0{struct ap_matrix_mdev *matrix_mdev;@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/crypto/vfio_ap_ops.c static ssize_t vfio_ap_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-0mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct
mdev_device*mdev,Review
Quoted 22 lines
drivers/s390/crypto/vfio_ap_ops.c +6
-3return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_core.cdrivers/vfio/mdev/mdev_core.c void mdev_set_class_id(struct mdev_device *mdev,
Quoted 4 lines
index
8764cf4a276d..6f35f2ced2c9100644drivers/vfio/mdev/mdev_core.c +0
-0@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev,u16 id)
Review
Quoted 19 lines
drivers/vfio/mdev/mdev_core.c +12
-0}EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_private.hdrivers/vfio/mdev/mdev_private.h struct mdev_device { · line 40
Quoted 11 lines
index
c65f436c1869..b666805f0b1f100644drivers/vfio/mdev/mdev_private.h +1
-0@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct
mdev_device, dev)Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;
RJM>] My understanding lately is that this call to try_module_get(THIS_MODULE) is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses of try_module_get(THIS_MODULE) in the kernel source but most if not all of them are latent bugs that should be cleaned up.
Quoted 240 lines
Quoted 38 lines
drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) · line 47
Quoted 12 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2- ret = parent->ops->open (mdev); + ret = ops->open (mdev);if (ret)module_put (THIS_MODULE );@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void
Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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,drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ; -return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }Quoted 17 lines
drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 6 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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,
Quoted 47 lines
drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1size_t count, loff_t *ppos) { struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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)
drivers/vfio/mdev/vfio_mdev.c
Quoted 4 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1{struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 25 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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 +5
-0@@ -10,6 +10,11 @@#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 ;Quoted 34 lines
include/linux/mdev.h struct device *mdev_get_iommu_device(struct
Quoted 2 lines
include/linux/mdev.h +0
-0/* @@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(structdevice *dev);
include/linux/mdev.h struct device *mdev_get_iommu_device(struct · line 53
Quoted 1 line
include/linux/mdev.h +0
-0* @mdev: mdev_device device structure which is being
Quoted 29 lines
include/linux/mdev.h +2
-24* destroyed * Returns integer: success (0) or error (< 0) -* @open: Open mediated device. -* @mdev: mediated device. -* Returns integer: success (0) or error (< 0) -* @release: release mediated device -* @mdev: mediated device. -* @read: Read emulation callback -* @mdev: mediated device structure -* @buf: read buffer -* @count: number of bytes to read -* @ppos: address. -* Retuns number on bytes read on success or error. -* @write: Write emulation callback -* @mdev: mediated device structure -* @buf: write buffer -* @count: number of bytes to be written -* @ppos: address. -* Retuns number on bytes written on success or error. -* @ioctl: IOCTL callback -* @mdev: mediated device structure -* @cmd: ioctl command -* @arg: arguments to ioctl -* @mmap: mmap callback -* @mdev: mediated device structure -* @vma: vma structure +* @device_ops: Device specific emulation callback. +* * Parent device that support mediated device should be registered with
Quoted 102 lines
mdev
Quoted 5 lines
include/linux/mdev.h +0
-0* module with mdev_parent_ops structure. **/ @@ -83,15 +66,6 @@ struct mdev_parent_ops {int (*create)(struct kobject *kobj,struct mdev_device *mdev);include/linux/mdev.h struct mdev_parent_ops { · line 94
Quoted 10 lines
include/linux/mdev.h +0
-9int (*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);
Quoted 57 lines
include/linux/mdev.h +2
-0};/* interface for exporting mdev supported type attributes */ @@ -133,6 +107,8 @@ struct mdev_driver {void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +const void *mdev_get_dev_ops (struct mdev_device *mdev); +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops);void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);include/linux/vfio_mdev.h new file +39
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VFIO Mediated device definition +*/ + +#ifndef VFIO_MDEV_H +#define VFIO_MDEV_H + +#include <linux/mdev.h> + +/** +* struct vfio_mdev_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 +*/ include/linux/vfio_mdev.h line 49
Quoted 10 lines
include/linux/vfio_mdev.h new file +10
-0+struct vfio_mdev_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);
samples/vfio-mdev/mbochs.c static int mbochs_reset(struct mdev_device
Quoted 16 lines
include/linux/vfio_mdev.h new file +3
-0+}; + +#endif samples/vfio-mdev/mbochs.c +1
-0@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h> @@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device*mdev)
Quoted 176 lines
Quoted 6 lines
samples/vfio-mdev/mbochs.c static int mbochs_reset(struct mdev_device *mdev)
Quoted 6 lines
samples/vfio-mdev/mbochs.c +2
-0return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int mbochs_create(struct kobject *kobj, struct mdev_device*mdev)
Quoted 168 lines
samples/vfio-mdev/mbochs.c static int mbochs_create(struct kobject *kobj,
Quoted 3 lines
samples/vfio-mdev/mbochs.c +0
-0{const struct mbochs_type *type =mbochs_find_type (kobj);@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj,struct
mdev_device*mdev)samples/vfio-mdev/mbochs.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mbochs.c +1
-0mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:@@ -1419,12 +1423,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mbochs.c static const struct mdev_parent_ops
Quoted 14 lines
samples/vfio-mdev/mbochs.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,@@ -1433,6 +1432,14 @@ static const struct mdev_parent_ops
mdev_fops= {samples/vfio-mdev/mdpy.c static int mdpy_create(struct kobject *kobj, struct
Quoted 36 lines
samples/vfio-mdev/mbochs.c +8
-0.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 +3
-0@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h" @@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mdpy.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mdpy.c +1
-0mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -726,12 +730,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mdpy.c static const struct mdev_parent_ops mdev_fops
Quoted 14 lines
samples/vfio-mdev/mdpy.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops= {
samples/vfio-mdev/mtty.c static ssize_t mdev_access(struct mdev_device
Quoted 27 lines
samples/vfio-mdev/mdpy.c +8
-0.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 +1
-0@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h> @@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device*mdev, u8 *buf,
size_tcount,samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct
Quoted 9 lines
samples/vfio-mdev/mtty.c +2
-0return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mtty.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mtty.c +1
-0mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }@@ -1411,6 +1415,14 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mtty.c static const struct mdev_parent_ops
Quoted 15 lines
samples/vfio-mdev/mtty.c +8
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,@@ -1418,11 +1430,6 @@ static const struct mdev_parent_ops
mdev_fops= {samples/vfio-mdev/mtty.c static const struct mdev_parent_ops mdev_fops = { · line 1435
Quoted 11 lines
samples/vfio-mdev/mtty.c +0
-5.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)_______________________________________________
intel-gvt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;
Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Michael S. Tsirkin
maintainerRe: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 44 lines · Alex Williamson
Quoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.
Quoted 7 lines
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
I think the latent bug refers not to module get per se, but to the module_put tied to it. E.g.:
static void vfio_mdev_release(void *device_data)
{
struct mdev_device *mdev = device_data;
struct mdev_parent *parent = mdev->parent;
if (likely(parent->ops->release))
parent->ops->release(mdev);
module_put(THIS_MODULE);Does anything prevent the module from unloading at this point? if not then ...
}
it looks like the implicit return (with instructions for argument pop and functuon return) here can get overwritten on module unload, causing a crash when executed.
IOW there's generally no way for module to keep a reference to itself: it can take a reference but it needs someone else to keep it and put.
Signature · 1 line
MST
Re: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 73 lines · On Thu, 26 Sep 2019 11:46:55 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.Quoted 7 lines
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
I think the latent bug refers not to module get per se, but to the
module_puttied to it. E.g.:static void
vfio_mdev_release(void *device_data){ struct mdev_device *mdev = device_data; struct mdev_parent *parent = mdev->parent; if (likely(parent->ops->release)) parent->ops->release(mdev); module_put(THIS_MODULE);Does anything prevent the module from unloading at this point? if not then ...
}
Quoted 7 lines
it looks like the implicit return (with instructions for argument pop and functuon return) here can get overwritten on module unload, causing a crash when executed.
IOW there's generally no way for module to keep a reference to itself: it can take a reference but it needs someone else to keep it and put.
I'd always assumed this would exit cleanly, but perhaps there is a latent race there. In any case, taking a module reference within the module in this case is better than not doing so, as the latter would potentially allow the module to be removed at any point in time, while the former only seems to expose acquire and release gaps. Add it to the todo list. Thanks,
Alex
Michael S. Tsirkin
maintainerRe: [PATCH V2 5/8] mdev: introduce device specific ops
Quoted 84 lines · Alex Williamson
Quoted 73 lines · On Thu, 26 Sep 2019 11:46:55 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.Quoted 7 lines
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
I think the latent bug refers not to module get per se, but to the
module_puttied to it. E.g.:static void
vfio_mdev_release(void *device_data){ struct mdev_device *mdev = device_data; struct mdev_parent *parent = mdev->parent; if (likely(parent->ops->release)) parent->ops->release(mdev); module_put(THIS_MODULE);Does anything prevent the module from unloading at this point? if not then ...
}
Quoted 7 lines
it looks like the implicit return (with instructions for argument pop and functuon return) here can get overwritten on module unload, causing a crash when executed.
IOW there's generally no way for module to keep a reference to itself: it can take a reference but it needs someone else to keep it and put.
Quoted 8 lines
I'd always assumed this would exit cleanly, but perhaps there is a latent race there. In any case, taking a module reference within the module in this case is better than not doing so, as the latter would potentially allow the module to be removed at any point in time, while the former only seems to expose acquire and release gaps. Add it to the todo list. Thanks,
Alex
Right. I agree with the stack overflow quote: as this example seems to show this is a latent bug.
But I also agree that just removing the reference isn't the right way to clean it up.
Signature · 5 lines
MST _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Michael S. Tsirkin
maintainerRe: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Alex WilliamsonQuoted 84 lines · Alex Williamson
Quoted 73 lines · On Thu, 26 Sep 2019 11:46:55 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.Quoted 7 lines
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
I think the latent bug refers not to module get per se, but to the
module_puttied to it. E.g.:static void
vfio_mdev_release(void *device_data){ struct mdev_device *mdev = device_data; struct mdev_parent *parent = mdev->parent; if (likely(parent->ops->release)) parent->ops->release(mdev); module_put(THIS_MODULE);Does anything prevent the module from unloading at this point? if not then ...
}
Quoted 7 lines
it looks like the implicit return (with instructions for argument pop and functuon return) here can get overwritten on module unload, causing a crash when executed.
IOW there's generally no way for module to keep a reference to itself: it can take a reference but it needs someone else to keep it and put.
Quoted 8 lines
I'd always assumed this would exit cleanly, but perhaps there is a latent race there. In any case, taking a module reference within the module in this case is better than not doing so, as the latter would potentially allow the module to be removed at any point in time, while the former only seems to expose acquire and release gaps. Add it to the todo list. Thanks,
Alex
Right. I agree with the stack overflow quote: as this example seems to show this is a latent bug.
But I also agree that just removing the reference isn't the right way to clean it up.
Signature · 1 line
MST
Re: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Rob Miller via VirtualizationQuoted 32 lines · On Wed, 25 Sep 2019 10:11:00 -0400 Rob Miller <[email protected]> wrote:
Quoted 22 lines
Quoted 22 lines
Review
Quoted 1 line · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 9 lines
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c line 35
Quoted 8 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ;
Quoted 9 lines
RJM>] My understanding lately is that this call to
try_module_get(THIS_MODULE)is no longer needed as is considered as a latent bug.
Quote from
https://stackoverflow.com/questions/1741415/linux-kernel-modules-when-to-use-try-module-get-module-put
:
There are a number of uses oftry_module_get(THIS_MODULE)in the kernel source but most if not all of them are latent bugs that should be cleaned up.
This use seems to fall exactly into the case where it is necessary, the open here is not a direct VFS call, it's an internal interface between modules. The user is interacting with filesystem objects from the vfio module and the module reference we're trying to acquire here is to the vfio-mdev module. Thanks,
Alex
Re: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Rob Miller via VirtualizationQuoted 14 lines · Rob Miller
Quoted 14 lines
Quoted 3 lines
mdev_set_class_id(mdev,
MDEV_ID_VFIO);
+ mdev_set_dev_ops(mdev,&intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct
vfio_mdev_device_opsintel_vfio_vgpu_dev_ops= { .id =MDEV_ID_VFIO,
.open =intel_vgpu_open, .release =intel_vgpu_release,
...
Quoted 7 lines
Quoted 1 line
And the set function passed &intel_vfio_vgpu_dev_ops.id
<http://intel_vfio_vgpu_dev_ops.id> and the mdev
Quoted 1 line
bus drivers used
container_ofto get to their callbacks?or just make it explicit? e.g.
mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);
Yes, this seems even better.
Will do this in V3.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RE: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Alex WilliamsonQuoted 41 lines
From: Alex Williamson
Sent: Wednesday, September 25, 2019 7:07 AMQuoted 25 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hReview
Quoted 1 line
(quoted diff) +0
-0
b/Documentation/driver-api/vfio-mediated-device.rstDocumentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type,
Quoted 4 lines
index
a5bdc60d62a1..d50425b368bb100644Documentation/driver-api/vfio-mediated-device.rst +0
-0@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type,or any other categorization.
Quoted 3 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.)
Quoted 9 lines
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1-The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:This is not accurate.
device_opsis now on themdev_deviceand is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping ofclass_idtomdev_device_opscallbacks.
there is also a mistake in include/Linux/mdev.h, where device_ops is still part of mdev_parent_ops in the comment line.
Quoted 60 lines
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the
class_idin the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?Review
Quoted 15 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVER(quoted diff) +0
-0
b/drivers/gpu/drm/i915/gvt/kvmgt.cQuoted 12 lines
index
f793252a3d2a..b274f5ee481f100644drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> drivers/gpu/drm/i915/gvt/kvmgt.c static void kvmgt_put_vfio_device(void *vgpu) · line 649
Quoted 6 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; + static int intel_vgpu_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj,
Quoted 3 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0{struct intel_vgpu *vgpu =NULL ;@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj,struct
mdev_device*mdev)drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .id = MDEV_ID_VFIO,drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0.open = intel_vgpu_open, .release = intel_vgpu_release,
Quoted 2 lines
And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used
container_ofto get to their callbacks?
or just make it explicit? e.g.
mdev_set_class(mdev, MDEV_ID_VFIO, &intel_vfio_vgpu_dev_ops);
Quoted 635 lines
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group
Quoted 5 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0out:return ret; }@@ -1601,20 +1605,21 @@ static const struct attribute_group*intel_vgpu_groups[] = {
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-5NULL, }; -static struct mdev_parent_ops intel_vgpu_ops = { - .mdev_attr_groups = intel_vgpu_groups, - .create = intel_vgpu_create, - .remove = intel_vgpu_remove, - +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-1.open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = {These could maybe be made const at the same time. Thanks,
Alex
Review
Quoted 9 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +5
-0+ .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;(quoted diff) +0
-0
b/drivers/s390/cio/vfio_ccw_ops.cdrivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[]
Quoted 12 lines
index
d258ef1fedb9..329d53c1f46b100644drivers/s390/cio/vfio_ccw_ops.c +1
-0@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h> @@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[]= {
drivers/s390/cio/vfio_ccw_ops.c static struct attribute_group *mdev_type_groups[] = {
Quoted 6 lines
drivers/s390/cio/vfio_ccw_ops.c +2
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/s390/cio/vfio_ccw_ops.c static int vfio_ccw_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/cio/vfio_ccw_ops.c +0
-0{ struct vfio_ccw_private *private =@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/cio/vfio_ccw_ops.c static ssize_t vfio_ccw_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-0private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct
mdev_device*mdev,drivers/s390/cio/vfio_ccw_ops.c static const struct mdev_parent_ops
Quoted 13 lines
drivers/s390/cio/vfio_ccw_ops.c +1
-5} } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,@@ -587,6 +587,13 @@ static const struct mdev_parent_ops
vfio_ccw_mdev_ops= {Review
Quoted 14 lines
drivers/s390/cio/vfio_ccw_ops.c +7
-0.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);(quoted diff) +0
-0
b/drivers/s390/crypto/vfio_ap_ops.cdrivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct
Quoted 12 lines
index
2cfd96112aa0..3a89933f0d3e100644drivers/s390/crypto/vfio_ap_ops.c +1
-0@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h> @@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct
ap_config_info*info,drivers/s390/crypto/vfio_ap_ops.c static void vfio_ap_matrix_init(struct ap_config_info *info,
Quoted 6 lines
drivers/s390/crypto/vfio_ap_ops.c +2
-0matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; + static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device*mdev)
drivers/s390/crypto/vfio_ap_ops.c static int vfio_ap_mdev_create(struct kobject
Quoted 3 lines
drivers/s390/crypto/vfio_ap_ops.c +0
-0{struct ap_matrix_mdev *matrix_mdev;@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject*kobj, struct
mdev_device*mdev)drivers/s390/crypto/vfio_ap_ops.c static ssize_t vfio_ap_mdev_ioctl(struct
Quoted 8 lines
drivers/s390/crypto/vfio_ap_ops.c +1
-0mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct
mdev_device*mdev,Review
Quoted 22 lines
drivers/s390/crypto/vfio_ap_ops.c +6
-3return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_core.cdrivers/vfio/mdev/mdev_core.c void mdev_set_class_id(struct mdev_device *mdev,
Quoted 4 lines
index
8764cf4a276d..6f35f2ced2c9100644drivers/vfio/mdev/mdev_core.c +0
-0@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev,u16 id)
Review
Quoted 19 lines
drivers/vfio/mdev/mdev_core.c +12
-0}EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;(quoted diff) +0
-0
b/drivers/vfio/mdev/mdev_private.hdrivers/vfio/mdev/mdev_private.h struct mdev_device { · line 40
Quoted 11 lines
index
c65f436c1869..b666805f0b1f100644drivers/vfio/mdev/mdev_private.h +1
-0@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct
mdev_device, dev)Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/vfio/mdev/vfio_mdev.cQuoted 12 lines
index
891cf83a2d9a..95efa054442f100644drivers/vfio/mdev/vfio_mdev.c +1
-0@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" drivers/vfio/mdev/vfio_mdev.c line 28
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 15 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2int 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 );drivers/vfio/mdev/vfio_mdev.c static int vfio_mdev_open(void *device_data) · line 47
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void
Quoted 9 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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,drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1-if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ;drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);Quoted 5 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1-if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ;drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);drivers/vfio/mdev/vfio_mdev.c static long vfio_mdev_unlocked_ioctl(void *device_data,
Quoted 10 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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)
drivers/vfio/mdev/vfio_mdev.c
Quoted 4 lines
drivers/vfio/mdev/vfio_mdev.c +1
-1{struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; + const struct vfio_mdev_device_ops *ops =
mdev_get_dev_ops(mdev);include/linux/mdev.h struct device *mdev_get_iommu_device(struct
Quoted 27 lines
drivers/vfio/mdev/vfio_mdev.c +2
-2-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 +5
-0@@ -10,6 +10,11 @@#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 ;/* @@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(structdevice *dev);
include/linux/mdev.h struct device *mdev_get_iommu_device(struct · line 53
Quoted 1 line
include/linux/mdev.h +0
-0* @mdev: mdev_device device structure which is being
Quoted 19 lines
include/linux/mdev.h +0
-17* 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. include/linux/mdev.h struct device *mdev_get_iommu_device(struct device *dev);
Quoted 10 lines
include/linux/mdev.h +2
-7-* @ioctl: IOCTL callback -* @mdev: mediated device structure -* @cmd: ioctl command -* @arg: arguments to ioctl -* @mmap: mmap callback -* @mdev: mediated device structure -* @vma: vma structure +* @device_ops: Device specific emulation callback. +* * Parent device that support mediated device should be registered with mdev
Quoted 5 lines
include/linux/mdev.h +0
-0* module with mdev_parent_ops structure. **/ @@ -83,15 +66,6 @@ struct mdev_parent_ops {int (*create)(struct kobject *kobj,struct mdev_device *mdev);include/linux/mdev.h struct mdev_parent_ops { · line 94
Quoted 10 lines
include/linux/mdev.h +0
-9int (*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);
Quoted 57 lines
include/linux/mdev.h +2
-0};/* interface for exporting mdev supported type attributes */ @@ -133,6 +107,8 @@ struct mdev_driver {void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +const void *mdev_get_dev_ops (struct mdev_device *mdev); +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops);void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);include/linux/vfio_mdev.h new file +39
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VFIO Mediated device definition +*/ + +#ifndef VFIO_MDEV_H +#define VFIO_MDEV_H + +#include <linux/mdev.h> + +/** +* struct vfio_mdev_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 +*/ include/linux/vfio_mdev.h line 49
Quoted 10 lines
include/linux/vfio_mdev.h new file +10
-0+struct vfio_mdev_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);
samples/vfio-mdev/mbochs.c static int mbochs_reset(struct mdev_device
Quoted 16 lines
include/linux/vfio_mdev.h new file +3
-0+}; + +#endif samples/vfio-mdev/mbochs.c +1
-0@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h> @@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device*mdev)
samples/vfio-mdev/mbochs.c static int mbochs_create(struct kobject *kobj,
Quoted 9 lines
samples/vfio-mdev/mbochs.c +2
-0return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj,struct
mdev_device*mdev)samples/vfio-mdev/mbochs.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mbochs.c +1
-0mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:@@ -1419,12 +1423,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mbochs.c static const struct mdev_parent_ops
Quoted 14 lines
samples/vfio-mdev/mbochs.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,@@ -1433,6 +1432,14 @@ static const struct mdev_parent_ops
mdev_fops= {samples/vfio-mdev/mdpy.c static int mdpy_create(struct kobject *kobj, struct
Quoted 36 lines
samples/vfio-mdev/mbochs.c +8
-0.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 +3
-0@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h" @@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mdpy.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mdpy.c +1
-0mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -726,12 +730,7 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mdpy.c static const struct mdev_parent_ops mdev_fops
Quoted 14 lines
samples/vfio-mdev/mdpy.c +1
-6NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops= {
samples/vfio-mdev/mtty.c static ssize_t mdev_access(struct mdev_device
Quoted 27 lines
samples/vfio-mdev/mdpy.c +8
-0.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 +1
-0@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h> @@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device*mdev, u8 *buf,
size_tcount,samples/vfio-mdev/mtty.c static int mtty_create(struct kobject *kobj, struct
Quoted 9 lines
samples/vfio-mdev/mtty.c +2
-0return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct
mdev_device*mdev)samples/vfio-mdev/mtty.c static struct attribute_group
Quoted 8 lines
samples/vfio-mdev/mtty.c +1
-0mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }@@ -1411,6 +1415,14 @@ static struct attribute_group*mdev_type_groups[] = {
samples/vfio-mdev/mtty.c static const struct mdev_parent_ops
Quoted 15 lines
samples/vfio-mdev/mtty.c +8
-0NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,@@ -1418,11 +1430,6 @@ static const struct mdev_parent_ops
mdev_fops= {samples/vfio-mdev/mtty.c static const struct mdev_parent_ops mdev_fops = { · line 1435
Quoted 11 lines
samples/vfio-mdev/mtty.c +0
-5.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)_______________________________________________
intel-gvt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev
Re: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Alex WilliamsonQuoted 36 lines · Alex Williamson
Quoted 33 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hDocumentation/driver-api/vfio-mediated-device.rst +0
-0@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.)
Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1-The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:This is not accurate.
device_opsis now on themdev_deviceand is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping ofclass_idtomdev_device_opscallbacks.
Yes.
Quoted 5 lines
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the
class_idin the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?
That seems much cleaner, let me try to do that in V3.
Quoted 51 lines
Quoted 37 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVERdrivers/gpu/drm/i915/gvt/kvmgt.c +3
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> @@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .id = MDEV_ID_VFIO,drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0.open = intel_vgpu_open, .release = intel_vgpu_release,
Quoted 2 lines
And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used
container_ofto get to their callbacks?
Yes, with the check of mdev_device_create() if nothing is set by the device.
Quoted 23 lines
Quoted 23 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-6out:return ret; }@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, };
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 1 line
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0+static struct mdev_parent_ops intel_vgpu_ops = {These could maybe be made const at the same time. Thanks,
Alex
Ok, let me fix.
Thanks
Re: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Alex WilliamsonQuoted 36 lines · Alex Williamson
Quoted 33 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hDocumentation/driver-api/vfio-mediated-device.rst +0
-0@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.)
Quoted 8 lines
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 4 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1-The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:This is not accurate.
device_opsis now on themdev_deviceand is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping ofclass_idtomdev_device_opscallbacks.
Yes.
Quoted 5 lines
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the
class_idin the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?
That seems much cleaner, let me try to do that in V3.
Quoted 51 lines
Quoted 37 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVERdrivers/gpu/drm/i915/gvt/kvmgt.c +3
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> @@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .id = MDEV_ID_VFIO,drivers/gpu/drm/i915/gvt/kvmgt.c +0
-0.open = intel_vgpu_open, .release = intel_vgpu_release,
Quoted 2 lines
And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used
container_ofto get to their callbacks?
Yes, with the check of mdev_device_create() if nothing is set by the device.
Quoted 23 lines
Quoted 23 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-6out:return ret; }@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, };
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 1 line
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0+static struct mdev_parent_ops intel_vgpu_ops = {These could maybe be made const at the same time. Thanks,
Alex
Ok, let me fix.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 5/8] mdev: introduce device specific ops
In reply to Jason WangQuoted 30 lines · On Tue, 24 Sep 2019 21:53:29 +0800 Jason Wang <[email protected]> wrote:
Currently, except for the create and remove, the rest of
mdev_parent_opsis 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 insidemdev_devicestructure. This allows different set of callback to be used by vfio-mdev and virtio-mdev.Signed-off-by Jason Wang <[email protected]>--- .../driver-api/vfio-mediated-device.rst | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.hDocumentation/driver-api/vfio-mediated-device.rst +0
-0
Documentation/driver-api/vfio-mediated-device.rst callbacks per mdev parent device, per mdev type, or any other categorization. · line 157
Quoted 7 lines
Documentation/driver-api/vfio-mediated-device.rst +3
-1@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.) -The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows:
This is not accurate. device_ops is now on the mdev_device and is an mdev bus driver specific structure of callbacks that must be registered for each mdev device by the parent driver during the create callback. There's a one to one mapping of class_id to mdev_device_ops callbacks.
That also suggests to me that we could be more clever in registering both of these with mdev-core. Can we embed the class_id in the ops structure in a common way so that the core can extract it and the bus drivers can access their specific callbacks?
Quoted 36 lines
Documentation/driver-api/vfio-mediated-device.rst +0
-0* open: open callback of mediated device * close: close callback of mediated deviceMAINTAINERS +1
-0@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVERdrivers/gpu/drm/i915/gvt/kvmgt.c +3
-0@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h> @@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;
drivers/gpu/drm/i915/gvt/kvmgt.c static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) · line 685
Quoted 4 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-0@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops);
This seems rather unrefined. We're registering interdependent data in separate calls. All drivers need to make both of these calls. I'm not sure if this is a good idea, but what if we had:
static const struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {
.id = MDEV_ID_VFIO,
.open = intel_vgpu_open,
.release = intel_vgpu_release,
...And the set function passed &intel_vfio_vgpu_dev_ops.id and the mdev bus drivers used container_of to get to their callbacks?
Quoted 13 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-5out:return ret; }@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = {
drivers/gpu/drm/i915/gvt/kvmgt.c static const struct attribute_group *intel_vgpu_groups[] = { · line 1617
Quoted 10 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +1
-1.open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = {
These could maybe be made const at the same time. Thanks,
Alex
Quoted 560 lines
drivers/gpu/drm/i915/gvt/kvmgt.c +5
-0+ .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
-5@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h> @@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ccw_mdev_create (struct kobject *kobj,struct mdev_device *mdev) { struct vfio_ccw_private *private =@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, } } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,@@ -587,6 +587,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
-3@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h> @@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ap_mdev_create (struct kobject *kobj,struct mdev_device *mdev) {struct ap_matrix_mdev *matrix_mdev;@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )drivers/vfio/mdev/mdev_core.c +12
-0@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev, u16 id) }EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;drivers/vfio/mdev/mdev_private.h +1
-0@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct mdev_device, dev)drivers/vfio/mdev/vfio_mdev.c +19
-18@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h" @@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev);int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ; - ret = parent->ops->open (mdev); + ret = ops->open (mdev);if (ret)module_put (THIS_MODULE );@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (likely (parent->ops->release)) - parent->ops->release (mdev); +if (likely (ops->release)) + ops->release (mdev);module_put (THIS_MODULE ); }@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data, unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ; -return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ; -return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->write)) +if (unlikely (!ops->write))return -EINVAL ; -return parent->ops->write (mdev, buf, count, ppos); +return ops->write (mdev, buf, count, ppos); }static int vfio_mdev_mmap (void *device_data,struct vm_area_struct *vma) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->mmap)) +if (unlikely (!ops->mmap))return -EINVAL ; -return parent->ops->mmap (mdev, vma); +return ops->mmap (mdev, vma); }static const struct vfio_device_ops vfio_mdev_dev_ops = {include/linux/mdev.h +9
-33@@ -10,6 +10,11 @@#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 ;/* @@ -48,30 +53,8 @@ struct device *mdev_get_iommu_device(struct device *dev);* @mdev: mdev_device device structure which is being * destroyed * Returns integer: success (0) or error (< 0) -* @open: Open mediated device. -* @mdev: mediated device. -* Returns integer: success (0) or error (< 0) -* @release: release mediated device -* @mdev: mediated device. -* @read: Read emulation callback -* @mdev: mediated device structure -* @buf: read buffer -* @count: number of bytes to read -* @ppos: address. -* Retuns number on bytes read on success or error. -* @write: Write emulation callback -* @mdev: mediated device structure -* @buf: write buffer -* @count: number of bytes to be written -* @ppos: address. -* Retuns number on bytes written on success or error. -* @ioctl: IOCTL callback -* @mdev: mediated device structure -* @cmd: ioctl command -* @arg: arguments to ioctl -* @mmap: mmap callback -* @mdev: mediated device structure -* @vma: vma structure +* @device_ops: Device specific emulation callback. +* * Parent device that support mediated device should be registered with mdev * module with mdev_parent_ops structure. **/ @@ -83,15 +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 */ @@ -133,6 +107,8 @@ struct mdev_driver {void *mdev_get_drvdata (struct mdev_device *mdev);void mdev_set_drvdata (struct mdev_device *mdev,void *data); +const void *mdev_get_dev_ops (struct mdev_device *mdev); +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops);void mdev_set_class_id (struct mdev_device *mdev,u16 id);const guid_t *mdev_uuid (struct mdev_device *mdev);include/linux/vfio_mdev.h new file +52
-0@@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VFIO Mediated device definition +*/ + +#ifndef VFIO_MDEV_H +#define VFIO_MDEV_H + +#include <linux/mdev.h> + +/** +* struct vfio_mdev_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 vfio_mdev_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
-6@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h> @@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:@@ -1419,12 +1423,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,@@ -1433,6 +1432,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
-6@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h" @@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }@@ -726,12 +730,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops = { .mmap = mdpy_mmap, }; +static const struct mdev_parent_ops mdev_fops = { + .owner =THIS_MODULE , + .mdev_attr_groups = mdev_dev_groups, + .supported_type_groups = mdev_type_groups, + .create = mdpy_create, + .remove = mdpy_remove, +}; +static const struct file_operations vd_fops = { .owner =THIS_MODULE , };samples/vfio-mdev/mtty.c +12
-5@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h> @@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }@@ -1411,6 +1415,14 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,@@ -1418,11 +1430,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)
PATCH v2 5/8 mdev: introduce device specific ops
In reply to Jason WangCurrently, 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 | 4 +- MAINTAINERS | 1 + 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 | 12 +++++ drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/vfio_mdev.c | 37 ++++++------- include/linux/mdev.h | 42 ++++----------- include/linux/vfio_mdev.h | 52 +++++++++++++++++++ samples/vfio-mdev/mbochs.c | 19 ++++--- samples/vfio-mdev/mdpy.c | 19 ++++--- samples/vfio-mdev/mtty.c | 17 ++++-- 13 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 include/linux/vfio_mdev.h
Documentation/driver-api/vfio-mediated-device.rst +3 -1
@@ -152,7 +152,9 @@ callbacks per mdev parent device, per mdev type, or any other categorization. Vendor drivers are expected to be fully asynchronous in this respect or provide their own internal resource protection.) -The callbacks in the mdev_parent_ops structure are as follows: +The device specific callbacks are referred through device_ops pointer +in mdev_parent_ops. For vfio-mdev device, its callbacks in device_ops +are as follows: * open: open callback of mediated device * close: close callback of mediated device
MAINTAINERS +1 -0
@@ -17075,6 +17075,7 @@ S: Maintained F: Documentation/driver-api/vfio-mediated-device.rst F: drivers/vfio/mdev/ F: include/linux/mdev.h +F: include/linux/vfio_mdev.h F: samples/vfio-mdev/ VFIO PLATFORM DRIVER
drivers/gpu/drm/i915/gvt/kvmgt.c +11 -6
@@ -42,6 +42,7 @@#include <linux/kvm_host.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/debugfs.h> #include <linux/nospec.h>
@@ -643,6 +644,8 @@ static void kvmgt_put_vfio_device(void *vgpu)vfio_device_put (((struct intel_vgpu *)vgpu)->vdev.vfio_device); } +static struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops; +static int intel_vgpu_create (struct kobject *kobj,struct mdev_device *mdev) {struct intel_vgpu *vgpu =NULL ;
@@ -679,6 +682,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ret =0 ;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &intel_vfio_vgpu_dev_ops); out:return ret; }
@@ -1601,20 +1605,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 struct vfio_mdev_device_ops intel_vfio_vgpu_dev_ops = { .open = intel_vgpu_open, .release = intel_vgpu_release, - .read = intel_vgpu_read, .write = intel_vgpu_write, .mmap = intel_vgpu_mmap, .ioctl = intel_vgpu_ioctl, }; +static struct mdev_parent_ops intel_vgpu_ops = { + .mdev_attr_groups = intel_vgpu_groups, + .create = intel_vgpu_create, + .remove = intel_vgpu_remove, +}; +static int kvmgt_host_init (struct device *dev,void *gvt,const void *ops) {struct attribute **kvm_type_attrs;
drivers/s390/cio/vfio_ccw_ops.c +12 -5
@@ -12,6 +12,7 @@#include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/nospec.h> #include <linux/slab.h>
@@ -110,6 +111,8 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ccw_mdev_create (struct kobject *kobj,struct mdev_device *mdev) { struct vfio_ccw_private *private =
@@ -130,6 +133,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) private->sch->schid.sch_no);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -575,11 +579,7 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev, } } -static const struct mdev_parent_ops vfio_ccw_mdev_ops = { - .owner =THIS_MODULE , - .supported_type_groups = mdev_type_groups, - .create = vfio_ccw_mdev_create, - .remove = vfio_ccw_mdev_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read,
@@ -587,6 +587,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 -3
@@ -16,6 +16,7 @@#include <linux/bitops.h> #include <linux/kvm_host.h> #include <linux/module.h> +#include <linux/vfio_mdev.h> #include <asm/kvm.h> #include <asm/zcrypt.h>
@@ -321,6 +322,8 @@ static void vfio_ap_matrix_init(struct ap_config_info *info, matrix->adm_max = info->apxa ? info->Nd :15 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int vfio_ap_mdev_create (struct kobject *kobj,struct mdev_device *mdev) {struct ap_matrix_mdev *matrix_mdev;
@@ -344,6 +347,7 @@ static int vfio_ap_mdev_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&matrix_dev->lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -1281,15 +1285,18 @@ static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,return ret; } +static const struct vfio_mdev_device_ops vfio_mdev_ops = { + .open = vfio_ap_mdev_open, + .release = vfio_ap_mdev_release, + .ioctl = vfio_ap_mdev_ioctl, +}; +static const struct mdev_parent_ops vfio_ap_matrix_ops = { .owner =THIS_MODULE , .supported_type_groups = vfio_ap_mdev_type_groups, .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, - .ioctl = vfio_ap_mdev_ioctl, };int vfio_ap_mdev_register (void )
drivers/vfio/mdev/mdev_core.c +12 -0
@@ -51,6 +51,18 @@ void mdev_set_class_id(struct mdev_device *mdev, u16 id) }EXPORT_SYMBOL (mdev_set_class_id); +const void *mdev_get_dev_ops (struct mdev_device *mdev) +{ +return mdev->device_ops; +} +EXPORT_SYMBOL (mdev_get_dev_ops); + +void mdev_set_dev_ops (struct mdev_device *mdev,const void *ops) +{ + mdev->device_ops = ops; +} +EXPORT_SYMBOL (mdev_set_dev_ops); +struct device *mdev_dev (struct mdev_device *mdev) {return &mdev->dev;
drivers/vfio/mdev/mdev_private.h +1 -0
@@ -34,6 +34,7 @@ struct mdev_device {struct device *iommu_device;bool active;u16 class_id; +const void *device_ops; };#define to_mdev_device (dev) container_of(dev, struct mdev_device, dev)
drivers/vfio/mdev/vfio_mdev.c +19 -18
@@ -14,6 +14,7 @@#include <linux/slab.h> #include <linux/vfio.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include "mdev_private.h"
@@ -24,16 +25,16 @@static int vfio_mdev_open (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev);int ret; -if (unlikely (!parent->ops->open)) +if (unlikely (!ops->open))return -EINVAL ;if (!try_module_get (THIS_MODULE ))return -ENODEV ; - ret = parent->ops->open (mdev); + ret = ops->open (mdev);if (ret)module_put (THIS_MODULE );
@@ -43,10 +44,10 @@ static int vfio_mdev_open(void *device_data)static void vfio_mdev_release (void *device_data) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (likely (parent->ops->release)) - parent->ops->release (mdev); +if (likely (ops->release)) + ops->release (mdev);module_put (THIS_MODULE ); }
@@ -55,47 +56,47 @@ static long vfio_mdev_unlocked_ioctl(void *device_data, unsigned int cmd, unsigned long arg) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->ioctl)) +if (unlikely (!ops->ioctl))return -EINVAL ; -return parent->ops->ioctl (mdev, cmd, arg); +return ops->ioctl (mdev, cmd, arg); }static ssize_t vfio_mdev_read (void *device_data,char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->read)) +if (unlikely (!ops->read))return -EINVAL ; -return parent->ops->read (mdev, buf, count, ppos); +return ops->read (mdev, buf, count, ppos); }static ssize_t vfio_mdev_write (void *device_data,const char __user *buf,size_t count,loff_t *ppos) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->write)) +if (unlikely (!ops->write))return -EINVAL ; -return parent->ops->write (mdev, buf, count, ppos); +return ops->write (mdev, buf, count, ppos); }static int vfio_mdev_mmap (void *device_data,struct vm_area_struct *vma) {struct mdev_device *mdev = device_data; -struct mdev_parent *parent = mdev->parent; +const struct vfio_mdev_device_ops *ops =mdev_get_dev_ops (mdev); -if (unlikely (!parent->ops->mmap)) +if (unlikely (!ops->mmap))return -EINVAL ; -return parent->ops->mmap (mdev, vma); +return ops->mmap (mdev, vma); }static const struct vfio_device_ops vfio_mdev_dev_ops = {
include/linux/mdev.h +9 -33
66 lines not on this page · raw message
include/linux/vfio_mdev.h new file +52 -0
52 lines not on this page · raw message
samples/vfio-mdev/mbochs.c +13 -6
@@ -30,6 +30,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/highmem.h>
@@ -516,6 +517,8 @@ static int mbochs_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mbochs_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mbochs_type *type =mbochs_find_type (kobj);
@@ -562,6 +565,7 @@ static int mbochs_create(struct kobject *kobj, struct mdev_device *mdev) mbochs_used_mbytes += type->mbytes;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; err_mem:
@@ -1419,12 +1423,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mbochs_create, - .remove = mbochs_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mbochs_open, .release = mbochs_close, .read = mbochs_read,
@@ -1433,6 +1432,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 -6
@@ -26,6 +26,7 @@#include <linux/iommu.h> #include <linux/sysfs.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <drm/drm_fourcc.h> #include "mdpy-defs.h"
@@ -226,6 +227,8 @@ static int mdpy_reset(struct mdev_device *mdev)return 0 ; } +static const struct vfio_mdev_device_ops vfio_mdev_ops; +static int mdpy_create (struct kobject *kobj,struct mdev_device *mdev) {const struct mdpy_type *type =mdpy_find_type (kobj);
@@ -270,6 +273,7 @@ static int mdpy_create(struct kobject *kobj, struct mdev_device *mdev) mdpy_count++;mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_mdev_ops);return 0 ; }
@@ -726,12 +730,7 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; -static const struct mdev_parent_ops mdev_fops = { - .owner =THIS_MODULE , - .mdev_attr_groups = mdev_dev_groups, - .supported_type_groups = mdev_type_groups, - .create = mdpy_create, - .remove = mdpy_remove, +static const struct vfio_mdev_device_ops vfio_mdev_ops = { .open = mdpy_open, .release = mdpy_close, .read = mdpy_read,
@@ -740,6 +739,14 @@ static const struct mdev_parent_ops mdev_fops = { .mmap = mdpy_mmap, }; +static const struct mdev_parent_ops mdev_fops = { + .owner =THIS_MODULE , + .mdev_attr_groups = mdev_dev_groups, + .supported_type_groups = mdev_type_groups, + .create = mdpy_create, + .remove = mdpy_remove, +}; +static const struct file_operations vd_fops = { .owner =THIS_MODULE , };
samples/vfio-mdev/mtty.c +12 -5
@@ -27,6 +27,7 @@#include <linux/ctype.h> #include <linux/file.h> #include <linux/mdev.h> +#include <linux/vfio_mdev.h> #include <linux/pci.h> #include <linux/serial.h> #include <uapi/linux/serial_reg.h>
@@ -723,6 +724,8 @@ static ssize_t mdev_access(struct mdev_device *mdev, u8 *buf, size_t count,return ret; } +static const struct vfio_mdev_device_ops vfio_dev_ops; +static int mtty_create (struct kobject *kobj,struct mdev_device *mdev) {struct mdev_state *mdev_state;
@@ -771,6 +774,7 @@ static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)mutex_unlock (&mdev_list_lock);mdev_set_class_id (mdev,MDEV_ID_VFIO ); +mdev_set_dev_ops (mdev, &vfio_dev_ops);return 0 ; }
@@ -1411,6 +1415,14 @@ static struct attribute_group *mdev_type_groups[] = { NULL, }; +static const struct vfio_mdev_device_ops vfio_dev_ops = { + .open = mtty_open, + .release = mtty_close, + .read = mtty_read, + .write = mtty_write, + .ioctl = mtty_ioctl, +}; +static const struct mdev_parent_ops mdev_fops = { .owner =THIS_MODULE , .dev_attr_groups = mtty_dev_groups,
@@ -1418,11 +1430,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
PATCH v2 6/8 mdev: introduce virtio device and its device ops
In reply to Jason WangThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.h
include/linux/mdev.h +2 -0
@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };
include/linux/virtio_mdev.h new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.19.1
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOST isn't used yet here. Also, given the strong interdependence between the class_id and the ops structure, we might wand to define them in the same place. Thanks,
Alex
Quoted 154 lines
include/linux/mdev.h +0
-0/* New entries must be added here */ };include/linux/virtio_mdev.h new file +145
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1 + +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the +* device +* @get_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_device_id: Get virtio device id +* @mdev: mediated device +* Returns u32: virtio device id +* @get_vendor_id: Get virtio vendor id +* @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 confiugration 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 confiugration 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_version: Get the version of virtio mdev device +* @mdev: mediated device +* Returns integer: version of the device +* @get_generation: Get device generaton +* @mdev: mediated device +* Returns u32: device generation +*/ +struct virtio_mdev_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); + +/* 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_queue_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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +}; + +#endif +
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 19 lines · Alex Williamson
Quoted 16 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);
Quoted 5 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here.
Yes, just want to reserve one but it look too early to do that.
Quoted 5 lines
Also, given the strong
interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,Alex
Yes, as you suggest in patch 5/8.
Thanks
Quoted 155 lines
Quoted 155 lines
include/linux/mdev.h +0
-0/* New entries must be added here */ };include/linux/virtio_mdev.h new file +145
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1 + +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the +* device +* @get_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_device_id: Get virtio device id +* @mdev: mediated device +* Returns u32: virtio device id +* @get_vendor_id: Get virtio vendor id +* @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 confiugration 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 confiugration 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_version: Get the version of virtio mdev device +* @mdev: mediated device +* Returns integer: version of the device +* @get_generation: Get device generaton +* @mdev: mediated device +* Returns u32: device generation +*/ +struct virtio_mdev_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); + +/* 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_queue_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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +}; + +#endif +
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonQuoted 19 lines · Alex Williamson
Quoted 16 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);
Quoted 5 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here.
Yes, just want to reserve one but it look too early to do that.
Quoted 5 lines
Also, given the strong
interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,Alex
Yes, as you suggest in patch 5/8.
Thanks
Quoted 147 lines
Quoted 147 lines
include/linux/mdev.h +0
-0/* New entries must be added here */ };include/linux/virtio_mdev.h new file +137
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1 + +struct virtio_mdev_callback { + irqreturn_t (*callback)(void *data); + void *private; +}; + +/** + * struct vfio_mdev_device_ops - Structure to be registered for each + * mdev device to register the device to virtio-mdev module. + * + * @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 interrut calback 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 features support by the + * device + * @get_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_device_id: Get virtio device id + * @mdev: mediated device + * Returns u32: virtio device id + * @get_vendor_id: Get virtio vendor id + * @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 confiugration 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 confiugration 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_version: Get the version of virtio mdev device + * @mdev: mediated device + * Returns integer: version of the device + * @get_generation: Get device generaton + * @mdev: mediated device + * Returns u32: device generation + */ +struct virtio_mdev_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); + + /* 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_queue_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, + void *buf, unsigned int len);
Quoted 8 lines
include/linux/virtio_mdev.h line 145
Quoted 8 lines
include/linux/virtio_mdev.h new file +8
-0+void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); + u32 (*get_generation)(struct mdev_device *mdev); +}; + +#endif +
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonQuoted 27 lines · Alex Williamson
Quoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang<[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,
Quoted 2 lines
Alex
Rethink about this, I believe it's better to define the device ops in their own headers, and one set of device ops could be used for two classes (e.g both virtio and vhost). And to avoid a duplicated ID definition. I tend to keep this in the common mdev.h header.
Thanks
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonQuoted 27 lines · Alex Williamson
Quoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang<[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,
Quoted 2 lines
Alex
Rethink about this, I believe it's better to define the device ops in their own headers, and one set of device ops could be used for two classes (e.g both virtio and vhost). And to avoid a duplicated ID definition. I tend to keep this in the common mdev.h header.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonHi Alex,
Quoted 45 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, September 24, 2019 6:07 PM
To: Jason Wang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2 6/8] mdev: introduce virtio device and its device opsQuoted 18 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h index renamed from include/linux/mdev.h +0
-0
3414307311f1..73ac27b3b868100644include/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);
Quoted 9 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,
When mlx5_core creates mdevs (parent->ops->create() and it wants to bind to mlx5 mdev driver (which does mdev_register_driver()), mlx5 core driver will publish MDEV_ID_MLX5_NET defined in central place as include/linux/mdev.h without any ops structure. Because such ops are not relevant. It uses usual, standard ops probe() remove() on the mdev (similar to a regular PCI device). So for VHOST case ops may be closely related to ID, but not for other type of ID.
Just want to make sure, that scope of ID covers this case.
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 66 lines · On Fri, 27 Sep 2019 16:25:13 +0000 Parav Pandit <[email protected]> wrote:
Hi Alex,
Quoted 45 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, September 24, 2019 6:07 PM
To: Jason Wang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2 6/8] mdev: introduce virtio device and its device opsQuoted 18 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h index renamed from include/linux/mdev.h +0
-0
3414307311f1..73ac27b3b868100644include/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);Quoted 9 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,When
mlx5_corecreates mdevs (parent->ops->create()and it wants to bind to mlx5 mdev driver (which doesmdev_register_driver()), mlx5 core driver will publishMDEV_ID_MLX5_NETdefined in central place asinclude/linux/mdev.hwithout any ops structure. Because such ops are not relevant. It uses usual, standard opsprobe()remove()on the mdev (similar to a regular PCI device). So for VHOST case ops may be closely related to ID, but not for other type of ID.
Quoted 1 line
Just want to make sure, that scope of ID covers this case.
AIUI, these device-ops are primarily meant to have 1:N multiplexing of the mdev bus driver. One mdev bus driver supports N vendor drivers via a common "protocol" defined by this structure. vfio-mdev supports GVT-g, GRID, and several sample drivers. I think Jason and Tiwei are attempting something similar if we have multiple vendors that may provide virtio/vhost parent drivers. If you have a 1:1 model with mlx5 where you're not trying to abstract a common channel between the mdev bus driver and the mdev vendor driver, then I suppose you might not use the device-ops capabilities of the mdev-core. Did I interpret the question correctly? I think that's probably fine, mdev-core shouldn't have any dependencies on the device-ops and we shouldn't really be dictating the bus/vendor link through mdev. Thanks,
Alex
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 67 lines · Alex Williamson
Quoted 64 lines · On Fri, 27 Sep 2019 16:25:13 +0000 Parav Pandit <[email protected]> wrote:
Hi Alex,
Quoted 45 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, September 24, 2019 6:07 PM
To: Jason Wang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2 6/8] mdev: introduce virtio device and its device opsQuoted 18 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h index renamed from include/linux/mdev.h +0
-0
3414307311f1..73ac27b3b868100644include/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);Quoted 8 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,When
mlx5_corecreates mdevs (parent->ops->create()and it wants to bind to mlx5 mdev driver (which doesmdev_register_driver()), mlx5 core driver will publishMDEV_ID_MLX5_NETdefined in central place asinclude/linux/mdev.hwithout any ops structure. Because such ops are not relevant. It uses usual, standard opsprobe()remove()on the mdev (similar to a regular PCI device). So for VHOST case ops may be closely related to ID, but not for other type of ID.
Quoted 7 lines
Quoted 1 line
Just want to make sure, that scope of ID covers this case.
AIUI, these device-ops are primarily meant to have 1:N multiplexing of the mdev bus driver. One mdev bus driver supports N vendor drivers via a common "protocol" defined by this structure. vfio-mdev supports GVT-g, GRID, and several sample drivers. I think Jason and Tiwei are attempting something similar if we have multiple vendors that may provide virtio/vhost parent drivers.
Exactly.
Quoted 4 lines
If you have a 1:1 model with
mlx5 where you're not trying to abstract a common channel between the mdev bus driver and the mdev vendor driver, then I suppose you might not use the device-ops capabilities of the mdev-core.
Yes, current proposed API allows NULL to be passed as device ops.
Thanks
Quoted 6 lines
Did I interpret
the question correctly? I think that's probably fine, mdev-core shouldn't have any dependencies on the device-ops and we shouldn't really be dictating the bus/vendor link through mdev. Thanks,Alex
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Parav PanditQuoted 66 lines · On Fri, 27 Sep 2019 16:25:13 +0000 Parav Pandit <[email protected]> wrote:
Hi Alex,
Quoted 45 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Tuesday, September 24, 2019 6:07 PM
To: Jason Wang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; intel- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ido Shamay <[email protected]>; [email protected]; [email protected]; Parav Pandit <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V2 6/8] mdev: introduce virtio device and its device opsQuoted 18 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h index renamed from include/linux/mdev.h +0
-0
3414307311f1..73ac27b3b868100644include/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);Quoted 9 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 4 lines
include/linux/mdev.h +2
-0enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,When
mlx5_corecreates mdevs (parent->ops->create()and it wants to bind to mlx5 mdev driver (which doesmdev_register_driver()), mlx5 core driver will publishMDEV_ID_MLX5_NETdefined in central place asinclude/linux/mdev.hwithout any ops structure. Because such ops are not relevant. It uses usual, standard opsprobe()remove()on the mdev (similar to a regular PCI device). So for VHOST case ops may be closely related to ID, but not for other type of ID.
Quoted 1 line
Just want to make sure, that scope of ID covers this case.
AIUI, these device-ops are primarily meant to have 1:N multiplexing of the mdev bus driver. One mdev bus driver supports N vendor drivers via a common "protocol" defined by this structure. vfio-mdev supports GVT-g, GRID, and several sample drivers. I think Jason and Tiwei are attempting something similar if we have multiple vendors that may provide virtio/vhost parent drivers. If you have a 1:1 model with mlx5 where you're not trying to abstract a common channel between the mdev bus driver and the mdev vendor driver, then I suppose you might not use the device-ops capabilities of the mdev-core. Did I interpret the question correctly? I think that's probably fine, mdev-core shouldn't have any dependencies on the device-ops and we shouldn't really be dictating the bus/vendor link through mdev. Thanks,
Alex
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonQuoted 27 lines · Alex Williamson
Quoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang<[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,
Quoted 2 lines
Alex
Rethink about this, consider we may have more types of devices supported in the future, moving all device_ops to mdev.h seems unnecessary. I prefer to keep the device_ops into their own headers.
Thanks
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Alex WilliamsonQuoted 27 lines · Alex Williamson
Quoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang<[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOSTisn't used yet here. Also, given the strong interdependence between theclass_idand the ops structure, we might wand to define them in the same place. Thanks,
Quoted 2 lines
Alex
Rethink about this, consider we may have more types of devices supported in the future, moving all device_ops to mdev.h seems unnecessary. I prefer to keep the device_ops into their own headers.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 15 lines · On Tue, 24 Sep 2019 21:53:30 +0800 Jason Wang <[email protected]> wrote:
This patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +0
-0
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct device *dev); · line 130
Quoted 5 lines
include/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,
MDEV_ID_VHOST isn't used yet here. Also, given the strong interdependence between the class_id and the ops structure, we might wand to define them in the same place. Thanks,
Alex
Quoted 154 lines
include/linux/mdev.h +0
-0/* New entries must be added here */ };include/linux/virtio_mdev.h new file +145
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1 + +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the +* device +* @get_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_device_id: Get virtio device id +* @mdev: mediated device +* Returns u32: virtio device id +* @get_vendor_id: Get virtio vendor id +* @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 confiugration 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 confiugration 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_version: Get the version of virtio mdev device +* @mdev: mediated device +* Returns integer: version of the device +* @get_generation: Get device generaton +* @mdev: mediated device +* Returns u32: device generation +*/ +struct virtio_mdev_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); + +/* 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_queue_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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +}; + +#endif +
RE: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 40 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +6
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]>
include/linux/virtio_mdev.h line 16
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1
Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
Quoted 69 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
Quoted 8 lines
+ * @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 confiugration
space
configuration (and similar typos downward)
Quoted 43 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +12
-0+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); + +/* 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_queue_max)(struct mdev_device *mdev); +u32 (*get_device_id)(struct mdev_device *mdev);
include/linux/virtio_mdev.h line 142
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};
I'm not sure how stable above ops are. Does it make sense if defining just two callbacks here, e.g. vq_ctrl and device_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
Thanks
Kevin
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +
Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 71 lines
Quoted 71 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device status
Quoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 47 lines
Quoted 47 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +15
-0+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); + +/* 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_queue_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);
Quoted 8 lines
include/linux/virtio_mdev.h line 142
Quoted 7 lines
include/linux/virtio_mdev.h new file +7
-0+void (*get_config)(struct mdev_device *mdev,unsigned int offset, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Quoted 4 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Thanks
Quoted 4 lines
Thanks
Kevin
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 201 lines · Jason Wang
Quoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 71 lines
Quoted 71 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device statusQuoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 47 lines
Quoted 47 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +15
-0+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); + +/* 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_queue_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);Quoted 8 lines
include/linux/virtio_mdev.h line 142
Quoted 7 lines
include/linux/virtio_mdev.h new file +7
-0+void (*get_config)(struct mdev_device *mdev,unsigned int offset, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
Quoted 2 lines
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 7 lines
Quoted 5 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
Quoted 12 lines
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Thanks
Quoted 4 lines
Thanks
Kevin
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 193 lines · Michael S. Tsirkin
Quoted 192 lines · Jason Wang
Quoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang<[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 70 lines
Quoted 70 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device statusQuoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 54 lines
Quoted 43 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +12
-0+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); + +/* 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_queue_max)(struct mdev_device *mdev); +u32 (*get_device_id)(struct mdev_device *mdev);include/linux/virtio_mdev.h line 142
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
Quoted 4 lines
Quoted 2 lines
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Yes, then I think we could probably have a version field inside e.g device_ops structure. Then it could be fetched from both kernel and userspace driver.
Thanks
Quoted 1 line
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 7 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 6 lines
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
my point was feature bits not a version number.
Quoted 1 line
Quoted 1 line
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 8 lines
Quoted 6 lines
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
my point was feature bits not a version number.
Something like backend_feature that current vhost_net did?
Thanks
Quoted 1 line
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 16 lines · Jason Wang
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
Quoted 9 lines
Quoted 1 line
my point was feature bits not a version number.
Something like
backend_featurethat currentvhost_netdid?Thanks
Quoted 1 line
right
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 16 lines · Jason Wang
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
Quoted 9 lines
Quoted 1 line
my point was feature bits not a version number.
Something like
backend_featurethat currentvhost_netdid?Thanks
Quoted 1 line
right
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Michael S. TsirkinQuoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 8 lines
Quoted 6 lines
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
my point was feature bits not a version number.
Something like backend_feature that current vhost_net did?
Thanks
Quoted 1 line
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 7 lines · Jason Wang
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 6 lines
Yes, then I think we could probably have a version field inside e.g
device_opsstructure. Then it could be fetched from both kernel and userspace driver.Thanks
my point was feature bits not a version number.
Quoted 1 line
Quoted 1 line
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Michael S. TsirkinQuoted 193 lines · Michael S. Tsirkin
Quoted 192 lines · Jason Wang
Quoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang<[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang<[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 70 lines
Quoted 70 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device statusQuoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 54 lines
Quoted 43 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +12
-0+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); + +/* 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_queue_max)(struct mdev_device *mdev); +u32 (*get_device_id)(struct mdev_device *mdev);include/linux/virtio_mdev.h line 142
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
Quoted 4 lines
Quoted 2 lines
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Yes, then I think we could probably have a version field inside e.g device_ops structure. Then it could be fetched from both kernel and userspace driver.
Thanks
Quoted 1 line
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 201 lines · Jason Wang
Quoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 71 lines
Quoted 71 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device statusQuoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 47 lines
Quoted 47 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +15
-0+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); + +/* 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_queue_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);Quoted 8 lines
include/linux/virtio_mdev.h line 142
Quoted 7 lines
include/linux/virtio_mdev.h new file +7
-0+void (*get_config)(struct mdev_device *mdev,unsigned int offset, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
Quoted 2 lines
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Given it's tied to virtio we probably want kernel+userspace feature bits?
Quoted 7 lines
Quoted 5 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
Quoted 12 lines
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Thanks
Quoted 4 lines
Thanks
Kevin
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RE: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 216 lines
From: Jason Wang
Sent: Wednesday, September 25, 2019 8:45 PMQuoted 14 lines · Kevin
Quoted 14 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hQuoted 5 lines
include/linux/mdev.h struct mdev_device *mdev_from_dev(struct
Quoted 5 lines
include/linux/mdev.h +0
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(structdevice
Quoted 22 lines
Quoted 22 lines
include/linux/mdev.h +2
-0*dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +7
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ Quoted 8 lines
include/linux/virtio_mdev.h
Quoted 8 lines
include/linux/virtio_mdev.h new file +8
-0+#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev"
Quoted 3 lines
include/linux/virtio_mdev.h line 16
Quoted 1 line
include/linux/virtio_mdev.h new file +1
-0+#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 71 lines
Quoted 71 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device statusQuoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 47 lines
Quoted 47 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +15
-0+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); + +/* 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_queue_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);Quoted 8 lines
include/linux/virtio_mdev.h line 142
Quoted 7 lines
include/linux/virtio_mdev.h new file +7
-0+void (*get_config)(struct mdev_device *mdev,unsigned int offset, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Quoted 4 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
Quoted 6 lines
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
I just thought doing so may provide better compatibility to the parent driver. Even when new op is introduced, a parent driver that was developed against the old set can still be loaded in the new kernel. It just returns error when unrecognized ops are routed through vq_ctrl and device_ctrl, if the userspace doesn't favor the exposed version value. But if above ops set is pretty stable, then this comment can be ignored.
Thanks
Kevin
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
Quoted 16 lines · Kevin
Quoted 10 lines
Quoted 2 lines
Quoted 1 line
+};
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Quoted 4 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?Quoted 6 lines
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Quoted 7 lines
I just thought doing so may provide better compatibility to the parent driver. Even when new op is introduced, a parent driver that was developed against the old set can still be loaded in the new kernel. It just returns error when unrecognized ops are routed through
vq_ctrlanddevice_ctrl, if the userspace doesn't favor the exposed version value. But if above ops set is pretty stable, then this comment can be ignored.
This is really good point, we should keep it stable as a real transport. And when there's major changes, we should advertise through version then we can provide a new set of functions.
Thanks
Quoted 3 lines
Thanks
Kevin
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Tian, KevinQuoted 16 lines · Kevin
Quoted 10 lines
Quoted 2 lines
Quoted 1 line
+};
I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Quoted 4 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?Quoted 6 lines
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Quoted 7 lines
I just thought doing so may provide better compatibility to the parent driver. Even when new op is introduced, a parent driver that was developed against the old set can still be loaded in the new kernel. It just returns error when unrecognized ops are routed through
vq_ctrlanddevice_ctrl, if the userspace doesn't favor the exposed version value. But if above ops set is pretty stable, then this comment can be ignored.
This is really good point, we should keep it stable as a real transport. And when there's major changes, we should advertise through version then we can provide a new set of functions.
Thanks
Quoted 3 lines
Thanks
Kevin
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Tian, KevinQuoted 44 lines · Kevin
Quoted 44 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)create mode 100644
include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +10
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]> +*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H +
Quoted 8 lines
include/linux/virtio_mdev.h line 16
Quoted 6 lines
include/linux/virtio_mdev.h new file +6
-0+#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
It could be a hint but basically it's a way for userspace driver compatibility. For kernel we don't need this.
Quoted 71 lines
Quoted 71 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
+ * @get_status: Get the device status
Quoted 8 lines
Quoted 7 lines
+ * @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 confiugration
spaceconfiguration (and similar typos downward)
Let me fix.
Quoted 47 lines
Quoted 47 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +15
-0+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); + +/* 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_queue_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);
Quoted 8 lines
include/linux/virtio_mdev.h line 142
Quoted 7 lines
include/linux/virtio_mdev.h new file +7
-0+void (*get_config)(struct mdev_device *mdev,unsigned int offset, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};I'm not sure how stable above ops are.
It's the kernel internal API, so there's no strict requirement for this. We will export a version value for userspace for compatibility.
Quoted 4 lines
Does it make sense if defining
just two callbacks here, e.g.vq_ctrlanddevice_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
My understanding is that it introduce another indirection, you still need to differ from different command, and it's less flexible than direct callback.
What's the value of doing this?
Thanks
Quoted 4 lines
Thanks
Kevin
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
RE: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
In reply to Jason WangQuoted 40 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:54 PMThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
Signed-off-by Jason Wang <[email protected]>--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.hinclude/linux/mdev.h +2
-0@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };include/linux/virtio_mdev.h new file +6
-0@@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Virtio mediated device driver +* +* Copyright 2019, Red Hat Corp. +* Author: Jason Wang <[email protected]>
include/linux/virtio_mdev.h line 16
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+*/ +#ifndef _LINUX_VIRTIO_MDEV_H +#define _LINUX_VIRTIO_MDEV_H + +#include <linux/interrupt.h> +#include <linux/mdev.h> +#include <uapi/linux/vhost.h> + +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" +#define VIRTIO_MDEV_VERSION 0x1
Just be curious. is this version identical to virtio spec version that below callbacks are created for, or just irrelevant?
Quoted 69 lines
include/linux/virtio_mdev.h new file +29
-0+ +struct virtio_mdev_callback { +irqreturn_t (*callback)(void *data); +void *private; +}; + +/** +* struct vfio_mdev_device_ops - Structure to be registered for each +* mdev device to register the device to virtio-mdev module. +* +* @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 interrut calback 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 features support by the
+ * device
+ * @get_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_device_id: Get virtio device id
+ * @mdev: mediated device
+ * Returns u32: virtio device id
+ * @get_vendor_id: Get virtio vendor id
+ * @mdev: mediated device
+ * Returns u32: virtio vendor id
Quoted 8 lines
+ * @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 confiugration
space
configuration (and similar typos downward)
Quoted 43 lines
+ * @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 confiugration 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_version: Get the version of virtio mdev device
+ * @mdev: mediated device
+ * Returns integer: version of the device
+ * @get_generation: Get device generaton
+ * @mdev: mediated device
+ * Returns u32: device generation
+ */include/linux/virtio_mdev.h new file +10
-0+struct virtio_mdev_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, boolready);
include/linux/virtio_mdev.h new file +12
-0+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); + +/* 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_queue_max)(struct mdev_device *mdev); +u32 (*get_device_id)(struct mdev_device *mdev);
include/linux/virtio_mdev.h line 142
Quoted 10 lines
include/linux/virtio_mdev.h new file +10
-0+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, +void *buf,unsigned int len); +void (*set_config)(struct mdev_device *mdev,unsigned int offset, +const void *buf,unsigned int len); +int (*get_version)(struct mdev_device *mdev); +u32 (*get_generation)(struct mdev_device *mdev); +};
I'm not sure how stable above ops are. Does it make sense if defining just two callbacks here, e.g. vq_ctrl and device_ctrl, and then let the vendor driver to handle specific ops in each category (similar to how ioctl works)?
Thanks
Kevin
PATCH v2 6/8 mdev: introduce virtio device and its device ops
In reply to Jason WangThis patch implements basic support for mdev driver that supports virtio transport for kernel virtio driver.
--- include/linux/mdev.h | 2 + include/linux/virtio_mdev.h | 145 ++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 include/linux/virtio_mdev.h
include/linux/mdev.h +2 -0
@@ -126,6 +126,8 @@ struct mdev_device *mdev_from_dev(struct device *dev);enum {MDEV_ID_VFIO =1 , +MDEV_ID_VIRTIO =2 , +MDEV_ID_VHOST =3 ,/* New entries must be added here */ };
include/linux/virtio_mdev.h new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v2 7/8 virtio: introduce a mdev based transport
In reply to Jason WangThis patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.
A new virtio-mdev driver will be registered to the mdev bus, when a new virtio-mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.
--- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++++++++++++++++++++++++++ 3 files changed, 425 insertions(+) create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +7 -0
@@ -43,6 +43,13 @@ config VIRTIO_PCI_LEGACY If unsure, say Y. +config VIRTIO_MDEV_DEVICE + tristate "VIRTIO driver for Mediated devices" + depends on VFIO_MDEV && VIRTIO + default n + help + VIRTIO based driver for Mediated devices. + config VIRTIO_PMEM tristate "Support for virtio pmem driver" depends on VIRTIO
drivers/virtio/Makefile +1 -0
@@ -6,3 +6,4 @@ virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o +obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +417 -0
417 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
PATCH v2 7/8 virtio: introduce a mdev based transport
In reply to Jason WangThis patch introduces a new mdev transport for virtio. This is used to use kernel virtio driver to drive the mediated device that is capable of populating virtqueue directly.
A new virtio-mdev driver will be registered to the mdev bus, when a new virtio-mdev device is probed, it will register the device with mdev based config ops. This means it is a software transport between mdev driver and mdev device. The transport was implemented through device specific opswhich is a part of mdev_parent_ops now.
--- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++++++++++++++++++++++++++ 3 files changed, 425 insertions(+) create mode 100644 drivers/virtio/virtio_mdev.c
drivers/virtio/Kconfig +7 -0
@@ -43,6 +43,13 @@ config VIRTIO_PCI_LEGACY If unsure, say Y. +config VIRTIO_MDEV_DEVICE + tristate "VIRTIO driver for Mediated devices" + depends on VFIO_MDEV && VIRTIO + default n + help + VIRTIO based driver for Mediated devices. + config VIRTIO_PMEM tristate "Support for virtio pmem driver" depends on VIRTIO
drivers/virtio/Makefile +1 -0
@@ -6,3 +6,4 @@ virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o +obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
drivers/virtio/virtio_mdev.c new file +417 -0
417 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v2 8/8 docs: sample driver to demonstrate how to implement virtio-mdev framework
In reply to Jason WangThis sample driver creates mdev device that simulate virtio net device over virtio mdev transport. The device is implemented through vringh and workqueue. A device specific dma ops is to make sure HVA is used directly as the IOVA. This should be sufficient for kernel virtio driver to work.
Only 'virtio' type is supported right now. I plan to add 'vhost' type on top which requires some virtual IOMMU implemented in this sample driver.
--- MAINTAINERS | 1 + samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mvnet.c | 692 +++++++++++++++++++++++++++++++++++++ 4 files changed, 701 insertions(+) create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
@@ -17202,6 +17202,7 @@ F: include/linux/virtio*.h F: include/uapi/linux/virtio_*.h F: drivers/crypto/virtio/ F: mm/balloon_compaction.c +F: samples/vfio-mdev/mvnet.c VIRTIO BLOCK AND SCSI DRIVERS M: "Michael S. Tsirkin" <[email protected]>
samples/Kconfig +7 -0
@@ -131,6 +131,13 @@ config SAMPLE_VFIO_MDEV_MDPY mediated device. It is a simple framebuffer and supports the region display interface (VFIO_GFX_PLANE_TYPE_REGION). +config SAMPLE_VIRTIO_MDEV_NET + tristate "Build virtio mdev net example mediated device sample code -- loadable modules only" + depends on VIRTIO_MDEV_DEVICE && VHOST_RING && m + help + Build a networking sample device for use as a virtio + mediated device. + config SAMPLE_VFIO_MDEV_MDPY_FB tristate "Build VFIO mdpy example guest fbdev driver -- loadable module only" depends on FB && m
samples/vfio-mdev/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_VFIO_MDEV_MTTY) += mtty.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY) += mdpy.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY_FB) += mdpy-fb.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MBOCHS) += mbochs.o +obj-$(CONFIG_SAMPLE_VIRTIO_MDEV_NET) += mvnet.o
samples/vfio-mdev/mvnet.c new file +692 -0
692 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v2 8/8 docs: sample driver to demonstrate how to implement virtio-mdev framework
In reply to Jason WangThis sample driver creates mdev device that simulate virtio net device over virtio mdev transport. The device is implemented through vringh and workqueue. A device specific dma ops is to make sure HVA is used directly as the IOVA. This should be sufficient for kernel virtio driver to work.
Only 'virtio' type is supported right now. I plan to add 'vhost' type on top which requires some virtual IOMMU implemented in this sample driver.
--- MAINTAINERS | 1 + samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mvnet.c | 692 +++++++++++++++++++++++++++++++++++++ 4 files changed, 701 insertions(+) create mode 100644 samples/vfio-mdev/mvnet.c
MAINTAINERS +1 -0
@@ -17202,6 +17202,7 @@ F: include/linux/virtio*.h F: include/uapi/linux/virtio_*.h F: drivers/crypto/virtio/ F: mm/balloon_compaction.c +F: samples/vfio-mdev/mvnet.c VIRTIO BLOCK AND SCSI DRIVERS M: "Michael S. Tsirkin" <[email protected]>
samples/Kconfig +7 -0
@@ -131,6 +131,13 @@ config SAMPLE_VFIO_MDEV_MDPY mediated device. It is a simple framebuffer and supports the region display interface (VFIO_GFX_PLANE_TYPE_REGION). +config SAMPLE_VIRTIO_MDEV_NET + tristate "Build virtio mdev net example mediated device sample code -- loadable modules only" + depends on VIRTIO_MDEV_DEVICE && VHOST_RING && m + help + Build a networking sample device for use as a virtio + mediated device. + config SAMPLE_VFIO_MDEV_MDPY_FB tristate "Build VFIO mdpy example guest fbdev driver -- loadable module only" depends on FB && m
samples/vfio-mdev/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_SAMPLE_VFIO_MDEV_MTTY) += mtty.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY) += mdpy.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MDPY_FB) += mdpy-fb.o obj-$(CONFIG_SAMPLE_VFIO_MDEV_MBOCHS) += mbochs.o +obj-$(CONFIG_SAMPLE_VIRTIO_MDEV_NET) += mvnet.o
samples/vfio-mdev/mvnet.c new file +692 -0
692 lines not on this page · raw message
Signature · 1 line
2.19.1
Patchwork
CI✗ Fi.CI.CHECKPATCH: warning for mdev based hardware virtio offloading support (rev3)
In reply to Jason Wang== Series Details ==
== Series Details ==
Series: mdev based hardware virtio offloading support (rev3)
URL : https://patchwork.freedesktop.org/series/66989/
State : warning
== Summary ==
$ dim checkpatch origin/drm-tip 6346e474d4a5 vringh: fix copy direction of vringh_iov_push_kern() 1f34e53afc28 mdev: class id support 3c4ddc86a519 mdev: bus uevent support eb320bc12b94 modpost: add support for mdev class id 96bc50618f39 mdev: introduce device specific ops -:422: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #422: new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 542 lines checked7645552e98b2 mdev: introduce virtio device and its device ops
-:25: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #25:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 153 lines checked6a3638fcef65 virtio: introduce a mdev based transport
-:26: WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully #26: FILE: drivers/virtio/Kconfig:46:
+config VIRTIO_MDEV_DEVICE
-:46: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #46:
new file mode 100644
-:106: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #106: FILE: drivers/virtio/virtio_mdev.c:56:
+static void virtio_mdev_get(struct virtio_device *vdev, unsigned offset,
-:107: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #107: FILE: drivers/virtio/virtio_mdev.c:57:
+ void *buf, unsigned len)
-:115: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #115: FILE: drivers/virtio/virtio_mdev.c:65:
+static void virtio_mdev_set(struct virtio_device *vdev, unsigned offset,
-:116: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #116: FILE: drivers/virtio/virtio_mdev.c:66:
+ const void *buf, unsigned len)
-:183: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #183: FILE: drivers/virtio/virtio_mdev.c:133:
+virtio_mdev_setup_vq(struct virtio_device *vdev, unsigned index,
-:262: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #262: FILE: drivers/virtio/virtio_mdev.c:212:
+
+}
-:294: WARNING:UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned' #294: FILE: drivers/virtio/virtio_mdev.c:244:
+static int virtio_mdev_find_vqs(struct virtio_device *vdev, unsigned nvqs,
total: 0 errors, 8 warnings, 1 checks, 434 lines checkedd4e1d237c373 docs: sample driver to demonstrate how to implement virtio-mdev framework -:39: WARNING:CONFIG_DESCRIPTION: please write a paragraph that describes the config symbol fully #39: FILE: samples/Kconfig:134:
+config SAMPLE_VIRTIO_MDEV_NET
-:59: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #59:
new file mode 100644
-:147: CHECK:UNCOMMENTED_DEFINITION: spinlock_t definition without comment #147: FILE: samples/vfio-mdev/mvnet.c:84:
+ spinlock_t lock;
-:180: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #180: FILE: samples/vfio-mdev/mvnet.c:117:
+ vringh_init_kern(&vq->vring, mvnet_features, MVNET_QUEUE_MAX,
+ false, 0, 0, 0);
-:285: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!addr" #285: FILE: samples/vfio-mdev/mvnet.c:222:
+ if (addr == NULL)
-:288: CHECK:SPACING: No space is necessary after a cast #288: FILE: samples/vfio-mdev/mvnet.c:225:
+ *dma_addr = (dma_addr_t) addr;
-:318: CHECK:ALLOC_SIZEOF_STRUCT: Prefer kzalloc(sizeof(*mvnet)...) over kzalloc(sizeof(struct mvnet_state)...) #318: FILE: samples/vfio-mdev/mvnet.c:255:
+ mvnet = kzalloc(sizeof(struct mvnet_state), GFP_KERNEL);
-:319: CHECK:COMPARISON_TO_NULL: Comparison to NULL could be written "!mvnet" #319: FILE: samples/vfio-mdev/mvnet.c:256:
+ if (mvnet == NULL)
-:376: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #376: FILE: samples/vfio-mdev/mvnet.c:313:
+sample_mvnet_dev_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
total: 0 errors, 2 warnings, 7 checks, 716 lines checked
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for mdev based hardware virtio offloading support (rev3)
In reply to Jason Wang== Series Details ==
== Series Details ==
Series: mdev based hardware virtio offloading support (rev3)
URL : https://patchwork.freedesktop.org/series/66989/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_6948 -> Patchwork_14516
====================================================
Summary
-------
**SUCCESS**
No regressions found.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/
Known issues
------------
Here are the changes found in Patchwork_14516 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@kms_chamelium@hdmi-hpd-fast:
- fi-kbl-7500u: [PASS][1] -> [FAIL][2] ([fdo#111407])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/fi-kbl-7500u/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/fi-kbl-7500u/igt@[email protected]
#### Possible fixes ####
* igt@gem_exec_suspend@basic-s4-devices:
- fi-blb-e6850: [INCOMPLETE][3] ([fdo#107718]) -> [PASS][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/fi-blb-e6850/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/fi-blb-e6850/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#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#110566]: https://bugs.freedesktop.org/show_bug.cgi?id=110566
[fdo#111407]: https://bugs.freedesktop.org/show_bug.cgi?id=111407
[fdo#111735]: https://bugs.freedesktop.org/show_bug.cgi?id=111735
Participating hosts (52 -> 46)
------------------------------
Additional (1): fi-icl-dsi
Missing (7): fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-icl-y fi-byt-clapper fi-bdw-samus
Build changes
-------------
* CI: CI-20190529 -> None
* Linux: CI_DRM_6948 -> Patchwork_14516
CI-20190529: 20190529
CI_DRM_6948: 485ca160d8ffac7ffb5be5e76fa12ad46a7e5a19 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5201: 3c1633abec14679300d52eeaf9fb7b63e435e51e @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14516: d4e1d237c373a6058e1094b6edd2095e78c01c6c @ git://anongit.freedesktop.org/gfx-ci/linux
== Linux commits ==
d4e1d237c373 docs: sample driver to demonstrate how to implement virtio-mdev framework 6a3638fcef65 virtio: introduce a mdev based transport7645552e98b2 mdev: introduce virtio device and its device ops 96bc50618f39 mdev: introduce device specific opseb320bc12b94 modpost: add support for mdev class id3c4ddc86a519 mdev: bus uevent support1f34e53afc28 mdev: class id support6346e474d4a5 vringh: fix copy direction of vringh_iov_push_kern()
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.IGT: success for mdev based hardware virtio offloading support (rev3)
In reply to Jason Wang== Series Details ==
== Series Details ==
Series: mdev based hardware virtio offloading support (rev3)
URL : https://patchwork.freedesktop.org/series/66989/
State : success
== Summary ==
CI Bug Log - changes from CI_DRM_6948_full -> Patchwork_14516_full
====================================================
Summary
-------
**SUCCESS**
No regressions found.
Known issues
------------
Here are the changes found in Patchwork_14516_full that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@gem_ctx_isolation@vcs1-clean:
- shard-iclb: [PASS][1] -> [SKIP][2] ([fdo#109276]) +7 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb1/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb3/igt@[email protected]
* igt@gem_ctx_shared@exec-single-timeline-bsd:
- shard-iclb: [PASS][3] -> [SKIP][4] ([fdo#110841])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb8/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@[email protected]
* igt@gem_exec_schedule@preemptive-hang-bsd:
- shard-iclb: [PASS][5] -> [SKIP][6] ([fdo#111325]) +3 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@[email protected]
* igt@i915_pm_rps@waitboost:
- shard-glk: [PASS][7] -> [FAIL][8] ([fdo#102250])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-glk3/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-glk9/igt@[email protected]
* igt@i915_selftest@live_hangcheck:
- shard-iclb: [PASS][9] -> [INCOMPLETE][10] ([fdo#107713] / [fdo#108569])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb5/igt@i915_selftest@live_hangcheck.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb2/igt@i915_selftest@live_hangcheck.html
* igt@i915_suspend@forcewake:
- shard-skl: [PASS][11] -> [INCOMPLETE][12] ([fdo#104108])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl9/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl9/igt@[email protected]
* igt@kms_cursor_crc@pipe-a-cursor-suspend:
- shard-skl: [PASS][13] -> [INCOMPLETE][14] ([fdo#110741])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl9/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl4/igt@[email protected]
* igt@kms_flip@flip-vs-expired-vblank-interruptible:
- shard-glk: [PASS][15] -> [FAIL][16] ([fdo#105363])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-glk5/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-glk5/igt@[email protected]
* igt@kms_flip@flip-vs-suspend-interruptible:
- shard-skl: [PASS][17] -> [INCOMPLETE][18] ([fdo#109507])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl6/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl7/igt@[email protected]
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-mmap-gtt:
- shard-iclb: [PASS][19] -> [INCOMPLETE][20] ([fdo#107713])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb4/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-mmap-gtt.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb7/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-pri-shrfb-draw-mmap-gtt.html
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-blt:
- shard-iclb: [PASS][21] -> [FAIL][22] ([fdo#103167]) +5 similar issues
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb3/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb8/igt@[email protected]
* igt@kms_plane@plane-panning-bottom-right-suspend-pipe-b-planes:
- shard-apl: [PASS][23] -> [DMESG-WARN][24] ([fdo#108566]) +4 similar issues
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl1/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl2/igt@[email protected]
- shard-kbl: [PASS][25] -> [INCOMPLETE][26] ([fdo#103665])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-kbl7/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-kbl1/igt@[email protected]
* igt@kms_plane_alpha_blend@pipe-a-constant-alpha-min:
- shard-skl: [PASS][27] -> [FAIL][28] ([fdo#108145])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl4/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl8/igt@[email protected]
* igt@kms_psr@psr2_cursor_plane_move:
- shard-iclb: [PASS][29] -> [SKIP][30] ([fdo#109441]) +1 similar issue
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb2/igt@kms_psr@psr2_cursor_plane_move.html
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@kms_psr@psr2_cursor_plane_move.html
* igt@kms_setmode@basic:
- shard-apl: [PASS][31] -> [FAIL][32] ([fdo#99912])
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl1/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl1/igt@[email protected]
#### Possible fixes ####
* igt@gem_ctx_isolation@rcs0-s3:
- shard-apl: [DMESG-WARN][33] ([fdo#108566]) -> [PASS][34] +3 similar issues
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl2/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl3/igt@[email protected]
* igt@gem_ctx_isolation@vecs0-s3:
- shard-skl: [INCOMPLETE][35] ([fdo#104108]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl9/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl9/igt@[email protected]
* igt@gem_ctx_switch@rcs0-heavy-queue:
- shard-iclb: [INCOMPLETE][37] ([fdo#107713]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb7/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb6/igt@[email protected]
* igt@gem_eio@reset-stress:
- shard-snb: [FAIL][39] ([fdo#109661]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-snb1/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-snb2/igt@[email protected]
* igt@gem_exec_schedule@wide-bsd:
- shard-iclb: [SKIP][41] ([fdo#111325]) -> [PASS][42] +4 similar issues
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb1/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb3/igt@[email protected]
* igt@gem_pipe_control_store_loop@reused-buffer:
- shard-apl: [INCOMPLETE][43] ([fdo#103927]) -> [PASS][44] +1 similar issue
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl6/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl3/igt@[email protected]
* igt@gem_tiled_swapping@non-threaded:
- shard-apl: [DMESG-WARN][45] ([fdo#108686]) -> [PASS][46]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl8/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl4/igt@[email protected]
* {igt@i915_pm_dc@dc5-dpms}:
- shard-iclb: [FAIL][47] ([fdo#111795 ]) -> [PASS][48]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb3/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb8/igt@[email protected]
* igt@kms_flip@flip-vs-suspend-interruptible:
- shard-hsw: [INCOMPLETE][49] ([fdo#103540]) -> [PASS][50]
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-hsw5/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-hsw5/igt@[email protected]
* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-render:
- shard-iclb: [FAIL][51] ([fdo#103167]) -> [PASS][52]
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb2/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-render.html
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-render.html
* igt@kms_frontbuffer_tracking@fbcpsr-slowdraw:
- shard-iclb: [INCOMPLETE][53] ([fdo#106978] / [fdo#107713]) -> [PASS][54]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb7/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb5/igt@[email protected]
* igt@kms_psr2_su@frontbuffer:
- shard-iclb: [SKIP][55] ([fdo#109642] / [fdo#111068]) -> [PASS][56]
[55]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb4/igt@[email protected]
[56]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb2/igt@[email protected]
* igt@kms_psr@psr2_cursor_plane_onoff:
- shard-iclb: [SKIP][57] ([fdo#109441]) -> [PASS][58]
[57]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb6/igt@kms_psr@psr2_cursor_plane_onoff.html
[58]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb2/igt@kms_psr@psr2_cursor_plane_onoff.html
* igt@kms_setmode@basic:
- shard-glk: [FAIL][59] ([fdo#99912]) -> [PASS][60]
[59]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-glk4/igt@[email protected]
[60]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-glk6/igt@[email protected]
* igt@kms_vblank@pipe-a-ts-continuation-dpms-suspend:
- shard-kbl: [INCOMPLETE][61] ([fdo#103665]) -> [PASS][62]
[61]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-kbl6/igt@[email protected]
[62]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-kbl7/igt@[email protected]
* igt@perf@polling:
- shard-skl: [FAIL][63] ([fdo#110728]) -> [PASS][64]
[63]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-skl6/igt@[email protected]
[64]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-skl10/igt@[email protected]
* igt@prime_vgem@fence-wait-bsd2:
- shard-iclb: [SKIP][65] ([fdo#109276]) -> [PASS][66] +15 similar issues
[65]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb8/igt@[email protected]
[66]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@[email protected]
#### Warnings ####
* igt@gem_mocs_settings@mocs-reset-bsd2:
- shard-iclb: [SKIP][67] ([fdo#109276]) -> [FAIL][68] ([fdo#111330])
[67]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-iclb6/igt@[email protected]
[68]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-iclb4/igt@[email protected]
* igt@kms_cursor_crc@pipe-a-cursor-suspend:
- shard-apl: [INCOMPLETE][69] ([fdo#103927]) -> [DMESG-WARN][70] ([fdo#108566])
[69]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6948/shard-apl1/igt@[email protected]
[70]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/shard-apl7/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#102250]: https://bugs.freedesktop.org/show_bug.cgi?id=102250
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103540]: https://bugs.freedesktop.org/show_bug.cgi?id=103540
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
[fdo#106978]: https://bugs.freedesktop.org/show_bug.cgi?id=106978
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#108569]: https://bugs.freedesktop.org/show_bug.cgi?id=108569
[fdo#108686]: https://bugs.freedesktop.org/show_bug.cgi?id=108686
[fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109507]: https://bugs.freedesktop.org/show_bug.cgi?id=109507
[fdo#109642]: https://bugs.freedesktop.org/show_bug.cgi?id=109642
[fdo#109661]: https://bugs.freedesktop.org/show_bug.cgi?id=109661
[fdo#110548]: https://bugs.freedesktop.org/show_bug.cgi?id=110548
[fdo#110728]: https://bugs.freedesktop.org/show_bug.cgi?id=110728
[fdo#110741]: https://bugs.freedesktop.org/show_bug.cgi?id=110741
[fdo#110841]: https://bugs.freedesktop.org/show_bug.cgi?id=110841
[fdo#111068]: https://bugs.freedesktop.org/show_bug.cgi?id=111068
[fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
[fdo#111330]: https://bugs.freedesktop.org/show_bug.cgi?id=111330
[fdo#111795 ]: https://bugs.freedesktop.org/show_bug.cgi?id=111795
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912
Participating hosts (9 -> 9)
------------------------------
No changes in participating hosts
Build changes
-------------
* CI: CI-20190529 -> None
* Linux: CI_DRM_6948 -> Patchwork_14516
CI-20190529: 20190529
CI_DRM_6948: 485ca160d8ffac7ffb5be5e76fa12ad46a7e5a19 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5201: 3c1633abec14679300d52eeaf9fb7b63e435e51e @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14516: d4e1d237c373a6058e1094b6edd2095e78c01c6c @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14516/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 18 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:53 PMHi all:
There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (
virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.
Quoted 8 lines
A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.
Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with
id_talbeclaimed by the driver. On top, this seris also decouple
id_table claimed ... this series ...
Quoted 84 lines
device specific parents ops out of the common ones.
Pktgen test was done with virito-net + mvnet loop back device.
Please review.
[1] https://lkml.org/lkml/2019/9/16/869
Changes from V1:
- move
virtio_mdev.ctodrivers/virtio
- storeclass_idinmdev_deviceinstead ofmdev_parent
- storedevice_opsinmdev_deviceinstead ofmdev_parent
- reorder the patch, vringh fix comes first
- really silent compiling warnings
- really switch to use u16 forclass_id
- uevent and modpost support for mdevclass_id
- vraious tweaks per comments from ParavChanges from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseveMDEV_ID_VHOSTfor 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 logChanges from RFC-V1:
- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- splitdevice_opsinto seperate headers
- drop themdev_set_dma_ops()
- usedevice_opsto implement the transport API, then it's not a part of UAPI any more
- useGFP_ATOMICin mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet deviceJason Wang (8):
vringh: fix copy direction ofvringh_iov_push_kern()
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework.../driver-api/vfio-mediated-device.rst | 7 +- MAINTAINERS | 2 + 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 | 19 + drivers/vfio/mdev/mdev_driver.c | 22 + drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 45 +- drivers/vhost/vringh.c | 8 +- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++ include/linux/mdev.h | 52 +- include/linux/mod_devicetable.h | 8 + include/linux/vfio_mdev.h | 52 ++ include/linux/virtio_mdev.h | 145 ++++ samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mbochs.c | 20 +- samples/vfio-mdev/mdpy.c | 20 +- samples/vfio-mdev/mtty.c | 18 +- samples/vfio-mdev/mvnet.c | 692 ++++++++++++++++++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 10 + 25 files changed, 1524 insertions(+), 84 deletions(-) create mode 100644 drivers/virtio/virtio_mdev.c create mode 100644 include/linux/vfio_mdev.h create mode 100644 include/linux/virtio_mdev.h create mode 100644 samples/vfio-mdev/mvnet.c--
2.19.1
Quoted 22 lines · Kevin
Quoted 22 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:53 PMHi all:
There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (
virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.
A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.
Quoted 5 lines
Quoted 4 lines
Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with
id_talbeclaimed by the driver. On top, this seris also decouple
id_tableclaimed ... this series ...
Let me fix in V3.
Thanks
Quoted 85 lines
Quoted 85 lines
device specific parents ops out of the common ones.
Pktgen test was done with virito-net + mvnet loop back device.
Please review.
[1] https://lkml.org/lkml/2019/9/16/869
Changes from V1:
- move
virtio_mdev.ctodrivers/virtio
- storeclass_idinmdev_deviceinstead ofmdev_parent
- storedevice_opsinmdev_deviceinstead ofmdev_parent
- reorder the patch, vringh fix comes first
- really silent compiling warnings
- really switch to use u16 forclass_id
- uevent and modpost support for mdevclass_id
- vraious tweaks per comments from ParavChanges from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseveMDEV_ID_VHOSTfor 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 logChanges from RFC-V1:
- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- splitdevice_opsinto seperate headers
- drop themdev_set_dma_ops()
- usedevice_opsto implement the transport API, then it's not a part of UAPI any more
- useGFP_ATOMICin mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet deviceJason Wang (8):
vringh: fix copy direction ofvringh_iov_push_kern()
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework.../driver-api/vfio-mediated-device.rst | 7 +- MAINTAINERS | 2 + 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 | 19 + drivers/vfio/mdev/mdev_driver.c | 22 + drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 45 +- drivers/vhost/vringh.c | 8 +- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++ include/linux/mdev.h | 52 +- include/linux/mod_devicetable.h | 8 + include/linux/vfio_mdev.h | 52 ++ include/linux/virtio_mdev.h | 145 ++++ samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mbochs.c | 20 +- samples/vfio-mdev/mdpy.c | 20 +- samples/vfio-mdev/mtty.c | 18 +- samples/vfio-mdev/mvnet.c | 692 ++++++++++++++++++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 10 + 25 files changed, 1524 insertions(+), 84 deletions(-) create mode 100644 drivers/virtio/virtio_mdev.c create mode 100644 include/linux/vfio_mdev.h create mode 100644 include/linux/virtio_mdev.h create mode 100644 samples/vfio-mdev/mvnet.c--
2.19.1
Quoted 22 lines · Kevin
Quoted 22 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:53 PMHi all:
There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (
virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.
A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.
Quoted 5 lines
Quoted 4 lines
Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with
id_talbeclaimed by the driver. On top, this seris also decouple
id_tableclaimed ... this series ...
Let me fix in V3.
Thanks
Quoted 83 lines
Quoted 83 lines
device specific parents ops out of the common ones.
Pktgen test was done with virito-net + mvnet loop back device.
Please review.
[1] https://lkml.org/lkml/2019/9/16/869
Changes from V1:
- move
virtio_mdev.ctodrivers/virtio
- storeclass_idinmdev_deviceinstead ofmdev_parent
- storedevice_opsinmdev_deviceinstead ofmdev_parent
- reorder the patch, vringh fix comes first
- really silent compiling warnings
- really switch to use u16 forclass_id
- uevent and modpost support for mdevclass_id
- vraious tweaks per comments from ParavChanges from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseveMDEV_ID_VHOSTfor 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 logChanges from RFC-V1:
- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- splitdevice_opsinto seperate headers
- drop themdev_set_dma_ops()
- usedevice_opsto implement the transport API, then it's not a part of UAPI any more
- useGFP_ATOMICin mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet deviceJason Wang (8):
vringh: fix copy direction ofvringh_iov_push_kern()
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework.../driver-api/vfio-mediated-device.rst | 7 +- MAINTAINERS | 2 + 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 | 19 + drivers/vfio/mdev/mdev_driver.c | 22 + drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 45 +- drivers/vhost/vringh.c | 8 +- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++ include/linux/mdev.h | 52 +- include/linux/mod_devicetable.h | 8 + include/linux/vfio_mdev.h | 52 ++ include/linux/virtio_mdev.h | 145 ++++ samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mbochs.c | 20 +- samples/vfio-mdev/mdpy.c | 20 +- samples/vfio-mdev/mtty.c | 18 +- samples/vfio-mdev/mvnet.c | 692 ++++++++++++++++++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 10 + 25 files changed, 1524 insertions(+), 84 deletions(-) create mode 100644 drivers/virtio/virtio_mdev.c create mode 100644 include/linux/vfio_mdev.h create mode 100644 include/linux/virtio_mdev.h create mode 100644 samples/vfio-mdev/mvnet.c
Quoted 2 lines
Quoted 2 lines
--
2.19.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 18 lines
From: Jason Wang [mailto:[email protected]]
Sent: Tuesday, September 24, 2019 9:53 PMHi all:
There are hardware that can do virtio datapath offloading while having its own control path. This path tries to implement a mdev based unified API to support using kernel virtio driver to drive those devices. This is done by introducing a new mdev transport for virtio (
virtio_mdev) and register itself as a new kind of mdev driver. Then it provides a unified way for kernel virtio driver to talk with mdev device implementation.Though the series only contains kernel driver support, the goal is to make the transport generic enough to support userspace drivers. This means vhost-mdev[1] could be built on top as well by resuing the transport.
Quoted 8 lines
A sample driver is also implemented which simulate a virito-net loopback ethernet device on top of vringh + workqueue. This could be used as a reference implementation for real hardware driver.
Consider mdev framework only support VFIO device and driver right now, this series also extend it to support other types. This is done through introducing class id to the device and pairing it with
id_talbeclaimed by the driver. On top, this seris also decouple
id_table claimed ... this series ...
Quoted 84 lines
device specific parents ops out of the common ones.
Pktgen test was done with virito-net + mvnet loop back device.
Please review.
[1] https://lkml.org/lkml/2019/9/16/869
Changes from V1:
- move
virtio_mdev.ctodrivers/virtio
- storeclass_idinmdev_deviceinstead ofmdev_parent
- storedevice_opsinmdev_deviceinstead ofmdev_parent
- reorder the patch, vringh fix comes first
- really silent compiling warnings
- really switch to use u16 forclass_id
- uevent and modpost support for mdevclass_id
- vraious tweaks per comments from ParavChanges from RFC-V2:
- silent compile warnings on some specific configuration
- use u16 instead u8 for class id
- reseveMDEV_ID_VHOSTfor 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 logChanges from RFC-V1:
- rename device id to class id
- add docs for class id and device specific ops (device_ops)
- splitdevice_opsinto seperate headers
- drop themdev_set_dma_ops()
- usedevice_opsto implement the transport API, then it's not a part of UAPI any more
- useGFP_ATOMICin mvnet sample device and other tweaks
- set_vring_base/get_vring_base support for mvnet deviceJason Wang (8):
vringh: fix copy direction ofvringh_iov_push_kern()
mdev: class id support
mdev: bus uevent support
modpost: add support for mdev class id
mdev: introduce device specific ops
mdev: introduce virtio device and its device ops
virtio: introduce a mdev based transport
docs: sample driver to demonstrate how to implement virtio-mdev
framework.../driver-api/vfio-mediated-device.rst | 7 +- MAINTAINERS | 2 + 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 | 19 + drivers/vfio/mdev/mdev_driver.c | 22 + drivers/vfio/mdev/mdev_private.h | 2 + drivers/vfio/mdev/vfio_mdev.c | 45 +- drivers/vhost/vringh.c | 8 +- drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mdev.c | 417 +++++++++++ include/linux/mdev.h | 52 +- include/linux/mod_devicetable.h | 8 + include/linux/vfio_mdev.h | 52 ++ include/linux/virtio_mdev.h | 145 ++++ samples/Kconfig | 7 + samples/vfio-mdev/Makefile | 1 + samples/vfio-mdev/mbochs.c | 20 +- samples/vfio-mdev/mdpy.c | 20 +- samples/vfio-mdev/mtty.c | 18 +- samples/vfio-mdev/mvnet.c | 692 ++++++++++++++++++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 10 + 25 files changed, 1524 insertions(+), 84 deletions(-) create mode 100644 drivers/virtio/virtio_mdev.c create mode 100644 include/linux/vfio_mdev.h create mode 100644 include/linux/virtio_mdev.h create mode 100644 samples/vfio-mdev/mvnet.c--
2.19.1