Re: [Intel-gfx] [PATCH V6 3/6] mdev: introduce device specific ops

2019-11-01 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Wednesday, October 30, 2019 1:45 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V6 3/6] mdev: introduce device specific ops
> 
> Currently, except for the create and remove, the rest of mdev_parent_ops is
> designed for vfio-mdev driver only and may not help for kernel mdev driver.
> 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.
> 
> Signed-off-by: Jason Wang 
> ---
[ ..]

> diff --git a/include/linux/vfio_mdev_ops.h b/include/linux/vfio_mdev_ops.h
> new file mode 100644 index ..3907c5371c2b
> --- /dev/null
> +++ b/include/linux/vfio_mdev_ops.h
> @@ -0,0 +1,52 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * VFIO Mediated device definition
> + */
> +
> +#ifndef VFIO_MDEV_H
> +#define VFIO_MDEV_H
> +
I should have noticed this before. :-(
APIs exposed are by the mdev module and named with mdev_ prefix.
And file name is _ops.h,

We should name this file as mdev_vfio_ops.h

And #define should be MDEV_VFIO_OPS_H

> +#include 
> +
> +/**
> + * struct vfio_mdev_device_ops - Structure to be registered for each
s/vfio_mdev_device_ops/mdev_vfio_device_ops/

Similarly for virtio in future patches.

> + * 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
> diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index
> 115bc5074656..1afec20bf0c5 100644
> --- a/samples/vfio-mdev/mbochs.c
> +++ b/samples/vfio-mdev/mbochs.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -516,6 +517,8 @@ static int mbochs_reset(struc

Re: [Intel-gfx] [PATCH V6 1/6] mdev: class id support

2019-11-01 Thread Parav Pandit


> -Original Message-
> From: kvm-ow...@vger.kernel.org  On Behalf
> Of Jason Wang
> Sent: Wednesday, October 30, 2019 1:45 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V6 1/6] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, the first 
> driver
> could be virtio-mdev. This means we need to add device class id support in bus
> match method to pair the mdev device and mdev driver correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev device with
> the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  .../driver-api/vfio-mediated-device.rst   |  5 
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  1 +
>  drivers/s390/cio/vfio_ccw_ops.c   |  1 +
>  drivers/s390/crypto/vfio_ap_ops.c |  1 +
>  drivers/vfio/mdev/mdev_core.c | 16 
>  drivers/vfio/mdev/mdev_driver.c   | 25 +++
>  drivers/vfio/mdev/mdev_private.h  |  1 +
>  drivers/vfio/mdev/vfio_mdev.c |  6 +
>  include/linux/mdev.h  |  8 ++
>  include/linux/mod_devicetable.h   |  8 ++
>  samples/vfio-mdev/mbochs.c|  1 +
>  samples/vfio-mdev/mdpy.c  |  1 +
>  samples/vfio-mdev/mtty.c  |  1 +
>  13 files changed, 75 insertions(+)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 25eb7d5b834b..6709413bee29 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -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_driverdriver;
> +  const struct mdev_class_id *id_table;
>   };
> 
>  A mediated bus driver for mdev should use this structure in the function 
> calls
> @@ -170,6 +172,9 @@ that a driver should use to unregister itself with the
> mdev core driver::
> 
>   extern void mdev_unregister_device(struct device *dev);
> 
> +It is also required to specify the class_id in create() callback through::
> +
> + int mdev_set_class(struct mdev_device *mdev, u16 id);
> 
>  Mediated Device Management Interface Through sysfs
> ==
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 343d79c1cb7e..6420f0dbd31b 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct
> mdev_device *mdev)
>dev_name(mdev_dev(mdev)));
>   ret = 0;
> 
> + mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
>  out:
>   return ret;
>  }
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index f0d71ab77c50..cf2c013ae32f 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj,
> struct mdev_device *mdev)
>

Re: [Intel-gfx] [PATCH V5 1/6] mdev: class id support

2019-10-23 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Wednesday, October 23, 2019 8:08 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V5 1/6] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, the first 
> driver
> could be virtio-mdev. This means we need to add device class id support in bus
> match method to pair the mdev device and mdev driver correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev device with
> the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  .../driver-api/vfio-mediated-device.rst   |  5 +
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  1 +
>  drivers/s390/cio/vfio_ccw_ops.c   |  1 +
>  drivers/s390/crypto/vfio_ap_ops.c |  1 +
>  drivers/vfio/mdev/mdev_core.c | 18 +++
>  drivers/vfio/mdev/mdev_driver.c   | 22 +++
>  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, 74 insertions(+)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 25eb7d5b834b..6709413bee29 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -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_driverdriver;
> +  const struct mdev_class_id *id_table;
>   };
> 
>  A mediated bus driver for mdev should use this structure in the function 
> calls
> @@ -170,6 +172,9 @@ that a driver should use to unregister itself with the
> mdev core driver::
> 
>   extern void mdev_unregister_device(struct device *dev);
> 
> +It is also required to specify the class_id in create() callback through::
> +
> + int mdev_set_class(struct mdev_device *mdev, u16 id);
> 
>  Mediated Device Management Interface Through sysfs
> ==
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 343d79c1cb7e..6420f0dbd31b 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct
> mdev_device *mdev)
>dev_name(mdev_dev(mdev)));
>   ret = 0;
> 
> + mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
>  out:
>   return ret;
>  }
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index f0d71ab77c50..cf2c013ae32f 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -129,6 +129,7 @@ static int vfio_ccw_mdev_create(struct kobject *kobj,
> struct mdev_device *mdev)
>  priva

Re: [Intel-gfx] [PATCH V4 2/6] modpost: add support for mdev class id

2019-10-21 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Thursday, October 17, 2019 5:49 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V4 2/6] modpost: add support for mdev class id
> 
> Add support to parse mdev class id table.
> 
> Signed-off-by: Jason Wang 
> ---
>  drivers/vfio/mdev/vfio_mdev.c |  2 ++
>  scripts/mod/devicetable-offsets.c |  3 +++
>  scripts/mod/file2alias.c  | 10 ++
>  3 files changed, 15 insertions(+)
> 
> diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
> index 7b24ee9cb8dd..cb701cd646f0 100644
> --- a/drivers/vfio/mdev/vfio_mdev.c
> +++ b/drivers/vfio/mdev/vfio_mdev.c
> @@ -125,6 +125,8 @@ static const 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,
> diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-
> offsets.c
> index 054405b90ba4..6cbb1062488a 100644
> --- a/scripts/mod/devicetable-offsets.c
> +++ b/scripts/mod/devicetable-offsets.c
> @@ -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;
>  }
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index
> c91eba751804..d365dfe7c718 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -1335,6 +1335,15 @@ static int do_wmi_entry(const char *filename,
> void *symval, char *alias)
>   return 1;
>  }
> 
> +/* looks like: "mdev:cN" */
> +static int do_mdev_entry(const char *filename, void *symval, char
> +*alias) {
> + DEF_FIELD(symval, mdev_class_id, id);
> +
> + sprintf(alias, "mdev:c%02X", id);
> + return 1;
> +}
> +
>  /* Does namelen bytes of name exactly match the symbol? */  static bool
> sym_is(const char *name, unsigned namelen, const char *symbol)  { @@ -
> 1407,6 +1416,7 @@ static const struct devtable devtable[] = {
>   {"typec", SIZE_typec_device_id, do_typec_entry},
>   {"tee", SIZE_tee_client_device_id, do_tee_entry},
>   {"wmi", SIZE_wmi_device_id, do_wmi_entry},
> + {"mdev", SIZE_mdev_class_id, do_mdev_entry},
>  };
> 
>  /* Create MODULE_ALIAS() statements.
> --
> 2.19.1
Reviewed-by: Parav Pandit 
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH V4 3/6] mdev: introduce device specific ops

2019-10-21 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Thursday, October 17, 2019 5:49 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V4 3/6] mdev: introduce device specific ops
> 
> Currently, except for the create and remove, the rest of mdev_parent_ops is
> designed for vfio-mdev driver only and may not help for kernel mdev driver.
> 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.
> 
> Signed-off-by: Jason Wang 
> ---
>  .../driver-api/vfio-mediated-device.rst   | 25 +
>  MAINTAINERS   |  1 +
>  drivers/gpu/drm/i915/gvt/kvmgt.c  | 18 ---
>  drivers/s390/cio/vfio_ccw_ops.c   | 18 ---
>  drivers/s390/crypto/vfio_ap_ops.c | 14 +++--
>  drivers/vfio/mdev/mdev_core.c | 18 +--
>  drivers/vfio/mdev/mdev_private.h  |  1 +
>  drivers/vfio/mdev/vfio_mdev.c | 37 ++---
>  include/linux/mdev.h  | 45 
>  include/linux/vfio_mdev.h | 52 +++
>  samples/vfio-mdev/mbochs.c| 20 ---
>  samples/vfio-mdev/mdpy.c  | 20 ---
>  samples/vfio-mdev/mtty.c  | 18 ---
>  13 files changed, 184 insertions(+), 103 deletions(-)  create mode 100644
> include/linux/vfio_mdev.h
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index f9a78d75a67a..0cca84d19603 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -152,11 +152,22 @@ callbacks per mdev parent device, per mdev type,
> or any other categorization.
>  Vendor drivers are expected to be fully asynchronous in this respect or
> provide their own internal resource protection.)
> 
> -The callbacks in the mdev_parent_ops structure are as follows:
> -
> -* open: open callback of mediated device
> -* close: close callback of mediated device
> -* ioctl: ioctl callback of mediated device
> +As multiple types of mediated devices may be supported, the device must
> +set up the class id and the device specific callbacks in create()
> +callback. E.g for vfio-mdev device it needs to be done through:
> +
> +int mdev_set_vfio_ops(struct mdev_device *mdev,
> +  const struct vfio_mdev_ops *vfio_ops);
> +
> +The class id (set to MDEV_CLASS_ID_VFIO) is used to match a device with
> +an mdev driver via its id table. The device specific callbacks
> +(specified in *ops) are obtainable via mdev_get_dev_ops() (for use by
> +the mdev bus driver). A vfio-mdev device (class id MDEV_CLASS_ID_VFIO)
> +uses the following device-specific ops:
> +
> +* open: open callback of vfio mediated device
> +* close: close callback of vfio mediated device
> +* ioctl: ioctl callback of vfio mediated device
>  * read : read emulation callback
>  * write: write emulation callback
>  * mmap: mmap emulation callback
> @@ -167,10 +178,6 @@ register itself with the mdev core driver::
>   extern int  mdev_register_device(struct device *dev,
>const struct mdev_parent_ops *ops);
> 
> -It is also required to specify the class_id in create() callback through::
> -
> - int mdev_set_class(struct mdev_device *mdev, u16 id);
> -
>  However, the mdev_parent_ops structure is not required in the function call
> that a driver should use to unregister itself w

Re: [Intel-gfx] [PATCH V4 1/6] mdev: class id support

2019-10-21 Thread Parav Pandit


> -Original Message-
> From: kvm-ow...@vger.kernel.org  On Behalf
> Of Jason Wang
> Sent: Thursday, October 17, 2019 5:49 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; stefa...@redhat.com; Jason Wang
> 
> Subject: [PATCH V4 1/6] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, the first
> driver could be virtio-mdev. This means we need to add device class id
> support in bus match method to pair the mdev device and mdev driver
> correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev device
> with the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  .../driver-api/vfio-mediated-device.rst   |  7 +-
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  1 +
>  drivers/s390/cio/vfio_ccw_ops.c   |  1 +
>  drivers/s390/crypto/vfio_ap_ops.c |  1 +
>  drivers/vfio/mdev/mdev_core.c | 18 +++
>  drivers/vfio/mdev/mdev_driver.c   | 22 +++
>  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, 75 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 25eb7d5b834b..f9a78d75a67a 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -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_driverdriver;
> +  const struct mdev_class_id *id_table;
>   };
> 
>  A mediated bus driver for mdev should use this structure in the function
> calls @@ -165,12 +167,15 @@ register itself with the mdev core driver::
>   extern int  mdev_register_device(struct device *dev,
>const struct mdev_parent_ops *ops);
> 
> +It is also required to specify the class_id in create() callback through::
> +
> + int mdev_set_class(struct mdev_device *mdev, u16 id);
> +
>  However, the mdev_parent_ops structure is not required in the function call
> that a driver should use to unregister itself with the mdev core driver::
> 
>   extern void mdev_unregister_device(struct device *dev);
> 
> -
>  Mediated Device Management Interface Through sysfs
> ==
> 
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 343d79c1cb7e..6420f0dbd31b 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj,
> struct mdev_device *mdev)
>dev_name(mdev_dev(mdev)));
>   ret = 0;
> 
> + mdev_set_class(mdev, MDEV_CLASS_ID_VFIO);
>  out:
>   return ret;
>

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

2019-10-17 Thread Parav Pandit


> -Original Message-
> From: Alex Williamson 
> Sent: Wednesday, October 16, 2019 11:53 AM
> To: Parav Pandit 
> Cc: Cornelia Huck ; Jason Wang
> ; k...@vger.kernel.org; linux-s...@vger.kernel.org;
> linux-ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; m...@redhat.com; tiwei@intel.com;
> virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> maxime.coque...@redhat.com; cunming.li...@intel.com;
> zhihong.w...@intel.com; rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com
> Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> 
> On Wed, 16 Oct 2019 15:31:25 +
> Parav Pandit  wrote:
> 
> > > -Original Message-
> > > From: Cornelia Huck 
> > > Sent: Wednesday, October 16, 2019 3:53 AM
> > > To: Parav Pandit 
> > > Cc: Alex Williamson ; Jason Wang
> > > ; k...@vger.kernel.org;
> > > linux-s...@vger.kernel.org; linux-ker...@vger.kernel.org;
> > > dri-de...@lists.freedesktop.org; intel- g...@lists.freedesktop.org;
> > > intel-gvt-...@lists.freedesktop.org;
> > > kwankh...@nvidia.com; m...@redhat.com; tiwei@intel.com;
> > > virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> > > maxime.coque...@redhat.com; cunming.li...@intel.com;
> > > zhihong.w...@intel.com; rob.mil...@broadcom.com;
> > > xiao.w.w...@intel.com; haotian.w...@sifive.com;
> > > zhen...@linux.intel.com; zhi.a.w...@intel.com;
> > > jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> > > rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> > > far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> > > ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> > > borntrae...@de.ibm.com; akrow...@linux.ibm.com;
> > > fre...@linux.ibm.com; lingshan....@intel.com; Ido Shamay
> > > ; epere...@redhat.com; l...@redhat.com;
> > > christophe.de.dinec...@gmail.com; kevin.t...@intel.com
> > > Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> > >
> > > On Wed, 16 Oct 2019 05:50:08 +
> > > Parav Pandit  wrote:
> > >
> > > > Hi Alex,
> > > >
> > > > > -Original Message-
> > > > > From: Alex Williamson 
> > > > > Sent: Tuesday, October 15, 2019 12:27 PM
> > > > > To: Jason Wang 
> > > > > Cc: Cornelia Huck ; k...@vger.kernel.org;
> > > > > linux- s...@vger.kernel.org; linux-ker...@vger.kernel.org; dri-
> > > > > de...@lists.freedesktop.org; intel-gfx@lists.freedesktop.org;
> > > > > intel-gvt- d...@lists.freedesktop.org; kwankh...@nvidia.com;
> > > > > m...@redhat.com; tiwei@intel.com;
> > > > > virtualizat...@lists.linux-foundation.org;
> > > > > net...@vger.kernel.org; maxime.coque...@redhat.com;
> > > > > cunming.li...@intel.com; zhihong.w...@intel.com;
> > > > > rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> > > > > haotian.w...@sifive.com; zhen...@linux.intel.com;
> > > > > zhi.a.w...@intel.com; jani.nik...@linux.intel.com;
> > > > > joonas.lahti...@linux.intel.com; rodrigo.v...@intel.com;
> > > > > airl...@linux.ie; dan...@ffwll.ch; far...@linux.ibm.com;
> > > > > pa...@linux.ibm.com; seb...@linux.ibm.com;
> > > > > ober...@linux.ibm.com; heiko.carst...@de.ibm.com;
> > > > > g...@linux.ibm.com; borntrae...@de.ibm.com;
> > > > > akrow...@linux.ibm.com; fre...@linux.ibm.com;
> > > > > lingshan@intel.com; Ido Shamay ;
> > > > > epere...@redhat.com; l...@redhat.com; Parav Pandit
> > > > > ; christophe.de.dinec...@gmail.com;
> > > > > kevin.t...@intel.com
> > > > > Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> > > > >
> > > > > On Tue, 15 Oct 2019 20:17:01 +0800 Jason Wang
> > > &g

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

2019-10-17 Thread Parav Pandit


> -Original Message-
> From: Alex Williamson 
> Sent: Wednesday, October 16, 2019 5:38 PM
> To: Parav Pandit 
> Cc: Cornelia Huck ; Jason Wang
> ; k...@vger.kernel.org; linux-s...@vger.kernel.org;
> linux-ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; m...@redhat.com; tiwei@intel.com;
> virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> maxime.coque...@redhat.com; cunming.li...@intel.com;
> zhihong.w...@intel.com; rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com
> Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> 
> On Wed, 16 Oct 2019 20:48:06 +
> Parav Pandit  wrote:
> 
> > > From: Alex Williamson  On Wed, 16 Oct
> > > 2019 15:31:25 + Parav Pandit  wrote:
> > > > > From: Cornelia Huck  Parav Pandit
> > > > >  wrote:
> > > > > > > From: Alex Williamson  On Tue,
> > > > > > > 15 Oct 2019 20:17:01 +0800 Jason Wang 
> > > > > > > wrote:
> > > > > > >
> > > > > > > > On 2019/10/15 下午6:41, Cornelia Huck wrote:
> > > > > > > > > Apologies if that has already been discussed, but do we
> > > > > > > > > want a
> > > > > > > > > 1:1 relationship between id and ops, or can different
> > > > > > > > > devices with the same id register different ops?
> > > > > > > >
> > > > > > > >
> > > > > > > > I think we have a N:1 mapping between id and ops, e.g we
> > > > > > > > want both virtio-mdev and vhost-mdev use a single set of device
> ops.
> > > > > > >
> > > > > > > The contents of the ops structure is essentially defined by
> > > > > > > the id, which is why I was leaning towards them being defined
> together.
> > > > > > > They are effectively interlocked, the id defines which mdev
> "endpoint"
> > > > > > > driver is loaded and that driver requires mdev_get_dev_ops()
> > > > > > > to return the structure required by the driver.  I wish
> > > > > > > there was a way we could incorporate type checking here.  We
> > > > > > > toyed with the idea of having the class in the same
> > > > > > > structure as the ops, but I think this approach was chosen
> > > > > > > for simplicity.  We could still do
> > > something like:
> > > > > > >
> > > > > > > int mdev_set_class_struct(struct device *dev, const struct
> > > > > > > mdev_class_struct *class);
> > > > > > >
> > > > > > > struct mdev_class_struct {
> > > > > > >   u16 id;
> > > > > > >   union {
> > > > > > >   struct vfio_mdev_ops vfio_ops;
> > > > > > >   struct virtio_mdev_ops virtio_ops;
> > > > > > >   };
> > > > > > > };
> > > > > > >
> > > > > > > Maybe even:
> > > > > > >
> > > > > > > struct vfio_mdev_ops *mdev_get_vfio_ops(struct mdev_device
> > > > > > > *mdev)
> > > {
> > > > > > >   BUG_ON(mdev->class.id != MDEV_ID_VFIO);
> > > > > > >   return >class.vfio_ops; }
> > > > > > >
> > > > > > > The match callback would of course just use the mdev->class.id
> value.
> > > > > > > Functionally equivalent, but maybe better type characteristics.
> > > > > > > Thanks,
> > > > > > >
> > > > > > > Alex
> > > > > >
> > > > > > We have 3 use cases of mdev.
> > > > > > 1. current mdev binding to vfio_mdev 2. mdev bind

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

2019-10-16 Thread Parav Pandit


> -Original Message-
> From: Cornelia Huck 
> Sent: Wednesday, October 16, 2019 3:53 AM
> To: Parav Pandit 
> Cc: Alex Williamson ; Jason Wang
> ; k...@vger.kernel.org; linux-s...@vger.kernel.org;
> linux-ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; m...@redhat.com; tiwei@intel.com;
> virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> maxime.coque...@redhat.com; cunming.li...@intel.com;
> zhihong.w...@intel.com; rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com
> Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> 
> On Wed, 16 Oct 2019 05:50:08 +
> Parav Pandit  wrote:
> 
> > Hi Alex,
> >
> > > -Original Message-
> > > From: Alex Williamson 
> > > Sent: Tuesday, October 15, 2019 12:27 PM
> > > To: Jason Wang 
> > > Cc: Cornelia Huck ; k...@vger.kernel.org; linux-
> > > s...@vger.kernel.org; linux-ker...@vger.kernel.org; dri-
> > > de...@lists.freedesktop.org; intel-gfx@lists.freedesktop.org;
> > > intel-gvt- d...@lists.freedesktop.org; kwankh...@nvidia.com;
> > > m...@redhat.com; tiwei@intel.com;
> > > virtualizat...@lists.linux-foundation.org;
> > > net...@vger.kernel.org; maxime.coque...@redhat.com;
> > > cunming.li...@intel.com; zhihong.w...@intel.com;
> > > rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> > > haotian.w...@sifive.com; zhen...@linux.intel.com;
> > > zhi.a.w...@intel.com; jani.nik...@linux.intel.com;
> > > joonas.lahti...@linux.intel.com; rodrigo.v...@intel.com;
> > > airl...@linux.ie; dan...@ffwll.ch; far...@linux.ibm.com;
> > > pa...@linux.ibm.com; seb...@linux.ibm.com; ober...@linux.ibm.com;
> > > heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> > > borntrae...@de.ibm.com; akrow...@linux.ibm.com;
> > > fre...@linux.ibm.com; lingshan@intel.com; Ido Shamay
> > > ; epere...@redhat.com; l...@redhat.com; Parav
> > > Pandit ; christophe.de.dinec...@gmail.com;
> > > kevin.t...@intel.com
> > > Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> > >
> > > On Tue, 15 Oct 2019 20:17:01 +0800
> > > Jason Wang  wrote:
> > >
> > > > On 2019/10/15 下午6:41, Cornelia Huck wrote:
> > > > > On Fri, 11 Oct 2019 16:15:54 +0800 Jason Wang
> > > > >  wrote:
> 
> > > > >> @@ -167,9 +176,10 @@ register itself with the mdev core driver::
> > > > >>  extern int  mdev_register_device(struct device *dev,
> > > > >>   const struct
> > > > >> mdev_parent_ops *ops);
> > > > >>
> > > > >> -It is also required to specify the class_id through::
> > > > >> +It is also required to specify the class_id and device
> > > > >> +specific ops
> > > through::
> > > > >>
> > > > >> -extern int mdev_set_class(struct device *dev, u16 id);
> > > > >> +extern int mdev_set_class(struct device *dev, u16 id,
> > > > >> +  const void *ops);
> > > > > Apologies if that has already been discussed, but do we want a
> > > > > 1:1 relationship between id and ops, or can different devices
> > > > > with the same id register different ops?
> > > >
> > > >
> > > > I think we have a N:1 mapping between id and ops, e.g we want both
> > > > virtio-mdev and vhost-mdev use a single set of device ops.
> > >
> > > The contents of the ops structure is essentially defined by the id,
> > > which is why I was leaning towards them being defined together.
> > > They are effectively interlocked, the id defines which mdev "endpoint"
> > > driver is loaded and that driver requires mdev_get_dev_ops() to
> > > return the structure required by the driver.  I wish there was a way
> > > w

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

2019-10-16 Thread Parav Pandit
Hi Alex,

> -Original Message-
> From: Alex Williamson 
> Sent: Tuesday, October 15, 2019 12:27 PM
> To: Jason Wang 
> Cc: Cornelia Huck ; k...@vger.kernel.org; linux-
> s...@vger.kernel.org; linux-ker...@vger.kernel.org; dri-
> de...@lists.freedesktop.org; intel-gfx@lists.freedesktop.org; intel-gvt-
> d...@lists.freedesktop.org; kwankh...@nvidia.com; m...@redhat.com;
> tiwei@intel.com; virtualizat...@lists.linux-foundation.org;
> net...@vger.kernel.org; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com
> Subject: Re: [PATCH V3 4/7] mdev: introduce device specific ops
> 
> On Tue, 15 Oct 2019 20:17:01 +0800
> Jason Wang  wrote:
> 
> > On 2019/10/15 下午6:41, Cornelia Huck wrote:
> > > On Fri, 11 Oct 2019 16:15:54 +0800
> > > Jason Wang  wrote:
> > >
> > >> Currently, except for the create and remove, the rest of
> > >> mdev_parent_ops is designed for vfio-mdev driver only and may not
> > >> help for kernel mdev driver. With the help of class id, this patch
> > >> introduces device specific callbacks inside mdev_device structure.
> > >> This allows different set of callback to be used by vfio-mdev and
> > >> virtio-mdev.
> > >>
> > >> Signed-off-by: Jason Wang 
> > >> ---
> > >>   .../driver-api/vfio-mediated-device.rst   | 22 +---
> > >>   MAINTAINERS   |  1 +
> > >>   drivers/gpu/drm/i915/gvt/kvmgt.c  | 18 ---
> > >>   drivers/s390/cio/vfio_ccw_ops.c   | 18 ---
> > >>   drivers/s390/crypto/vfio_ap_ops.c | 14 +++--
> > >>   drivers/vfio/mdev/mdev_core.c |  9 +++-
> > >>   drivers/vfio/mdev/mdev_private.h  |  1 +
> > >>   drivers/vfio/mdev/vfio_mdev.c | 37 ++---
> > >>   include/linux/mdev.h  | 42 +++
> > >>   include/linux/vfio_mdev.h | 52 +++
> > >>   samples/vfio-mdev/mbochs.c| 20 ---
> > >>   samples/vfio-mdev/mdpy.c  | 21 +---
> > >>   samples/vfio-mdev/mtty.c  | 18 ---
> > >>   13 files changed, 177 insertions(+), 96 deletions(-)
> > >>   create mode 100644 include/linux/vfio_mdev.h
> > >>
> > >> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> > >> b/Documentation/driver-api/vfio-mediated-device.rst
> > >> index 2035e48da7b2..553574ebba73 100644
> > >> --- a/Documentation/driver-api/vfio-mediated-device.rst
> > >> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> > >> @@ -152,11 +152,20 @@ callbacks per mdev parent device, per mdev
> type, or any other categorization.
> > >>   Vendor drivers are expected to be fully asynchronous in this respect or
> > >>   provide their own internal resource protection.)
> > >>
> > >> -The callbacks in the mdev_parent_ops structure are as follows:
> > >> +In order to support multiple types of device/driver, device needs
> > >> +to provide both class_id and device_ops through:
> > > "As multiple types of mediated devices may be supported, the device
> > > needs to set up the class id and the device specific callbacks via:"
> > >
> > > ?
> > >
> > >>
> > >> -* open: open callback of mediated device
> > >> -* close: close callback of mediated device
> > >> -* ioctl: ioctl callback of mediated device
> > >> +void mdev_set_class(struct mdev_device *mdev, u16 id, const
> > >> + void *ops);
> > >> +
> > >> +The class_id is used to be paired with ids in id_table in
> > >> +mdev_driver structure for probing the correct driver.
> > > "The class id  (specified in id) is used to match a device with an
>

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

2019-10-16 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Friday, October 11, 2019 3:16 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; Jason Wang 
> Subject: [PATCH V3 1/7] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, the first
> driver could be virtio-mdev. This means we need to add device class id
> support in bus match method to pair the mdev device and mdev driver
> correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev device
> with the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  Documentation/driver-api/vfio-mediated-device.rst |  7 ++-
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  1 +
>  drivers/s390/cio/vfio_ccw_ops.c   |  1 +
>  drivers/s390/crypto/vfio_ap_ops.c |  1 +
>  drivers/vfio/mdev/mdev_core.c | 11 +++
>  drivers/vfio/mdev/mdev_driver.c   | 14 ++
>  drivers/vfio/mdev/mdev_private.h  |  1 +
>  drivers/vfio/mdev/vfio_mdev.c |  6 ++
>  include/linux/mdev.h  |  8 
>  include/linux/mod_devicetable.h   |  8 
>  samples/vfio-mdev/mbochs.c|  1 +
>  samples/vfio-mdev/mdpy.c  |  1 +
>  samples/vfio-mdev/mtty.c  |  1 +
>  13 files changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 25eb7d5b834b..2035e48da7b2 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -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_driverdriver;
> +  const struct mdev_class_id *id_table;
>   };
> 
>  A mediated bus driver for mdev should use this structure in the function
> calls @@ -165,12 +167,15 @@ register itself with the mdev core driver::
>   extern int  mdev_register_device(struct device *dev,
>const struct mdev_parent_ops *ops);
> 
> +It is also required to specify the class_id through::
> +
> + extern int mdev_set_class(struct device *dev, u16 id);
Drop extern.
In actual API you have correct signature, i.e. struct mdev_device.
s/struct device/struct mdev_device.

> +
>  However, the mdev_parent_ops structure is not required in the function call
> that a driver should use to unregister itself with the mdev core driver::
> 
>   extern void mdev_unregister_device(struct device *dev);
> 
> -
>  Mediated Device Management Interface Through sysfs
> ==
> 
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 343d79c1cb7e..17e9d4634c84 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -678,6 +678,7 @@ static int intel_vgpu_create(struct kobject *kobj,
> struct mdev_device *mdev)
>dev_name(mdev_dev(mdev)));
>   ret = 0;
> 
> + mdev_set_class(mdev, MDEV_ID_VFIO

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

2019-10-16 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Friday, October 11, 2019 3:16 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com; Jason Wang 
> Subject: [PATCH V3 2/7] mdev: bus uevent support
> 
> This patch adds bus uevent support for mdev bus in order to allow
> cooperation with userspace.
> 
> Signed-off-by: Jason Wang 
> ---
>  drivers/vfio/mdev/mdev_driver.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/vfio/mdev/mdev_driver.c
> b/drivers/vfio/mdev/mdev_driver.c index b7c40ce86ee3..319d886ffaf7
> 100644
> --- a/drivers/vfio/mdev/mdev_driver.c
> +++ b/drivers/vfio/mdev/mdev_driver.c
> @@ -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,
>  };
> --
> 2.19.1
Reviewed-by: Parav Pandit 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH V2 6/8] mdev: introduce virtio device and its device ops

2019-09-27 Thread Parav Pandit
Hi Alex,


> -Original Message-
> From: Alex Williamson 
> Sent: Tuesday, September 24, 2019 6:07 PM
> To: Jason Wang 
> Cc: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; m...@redhat.com; tiwei@intel.com;
> virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; christophe.de.dinec...@gmail.com;
> kevin.t...@intel.com
> Subject: Re: [PATCH V2 6/8] mdev: introduce virtio device and its device ops
> 
> On Tue, 24 Sep 2019 21:53:30 +0800
> Jason Wang  wrote:
> 
> > This patch implements basic support for mdev driver that supports
> > virtio transport for kernel virtio driver.
> >
> > Signed-off-by: Jason Wang 
> > ---
> >  include/linux/mdev.h|   2 +
> >  include/linux/virtio_mdev.h | 145
> > 
> >  2 files changed, 147 insertions(+)
> >  create mode 100644 include/linux/virtio_mdev.h
> >
> > diff --git a/include/linux/mdev.h b/include/linux/mdev.h index
> > 3414307311f1..73ac27b3b868 100644
> > --- a/include/linux/mdev.h
> > +++ b/include/linux/mdev.h
> > @@ -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,
> 

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
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

2019-09-23 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Monday, September 23, 2019 8:03 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; Jason Wang 
> Subject: [PATCH 2/6] mdev: introduce device specific ops
> 
> Currently, except for the create and remove. The rest of mdev_parent_ops is
> designed for vfio-mdev driver only and may not help for kernel mdev driver.
> Follow the class id support by previous patch, this patch introduces device
> specific ops pointer inside parent ops which points to device specific ops 
> (e.g
> vfio ops). This allows the future drivers like virtio-mdev to implement its 
> own
> device specific ops.
> 
> Signed-off-by: Jason Wang 
> ---
>  .../driver-api/vfio-mediated-device.rst   |  4 +-
>  MAINTAINERS   |  1 +
>  drivers/gpu/drm/i915/gvt/kvmgt.c  | 15 +++---
>  drivers/s390/cio/vfio_ccw_ops.c   | 15 --
>  drivers/s390/crypto/vfio_ap_ops.c | 11 ++--
>  drivers/vfio/mdev/vfio_mdev.c | 31 ++-
>  include/linux/mdev.h  | 36 ++---
>  include/linux/vfio_mdev.h | 53 +++
>  samples/vfio-mdev/mbochs.c| 17 +++---
>  samples/vfio-mdev/mdpy.c  | 17 +++---
>  samples/vfio-mdev/mtty.c  | 15 --
>  11 files changed, 138 insertions(+), 77 deletions(-)  create mode 100644
> include/linux/vfio_mdev.h
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 0e052072e1d8..3ab00e48212f 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -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 diff --git a/MAINTAINERS
> b/MAINTAINERS index b2326dece28e..89832b316500 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -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
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 19d51a35f019..8ea86b1e69f1 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -42,6 +42,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
> 
>  #include 
> @@ -1600,20 +1601,22 @@ static const struct attribute_group
> *intel_vgpu_groups[] = {
>   NULL,
>  };
> 
> -static struct mdev_parent_ops intel_vgpu_ops = {
> - .mdev_attr_groups   = intel_vgpu_groups,
> - .create = intel_vgpu_create,
> - .remove = intel_vgpu_remove,
> -
> +static struct vfio_mdev_parent_ops intel_vfio_vgpu_ops = {

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

>   .open   = intel_vgpu_open,
>   .release= intel_vgpu_release,
> -
>   .read   = intel_vgpu_read,
>   .write  = intel_vgpu_write,
>   .mmap   

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

2019-09-23 Thread Parav Pandit
Hi Jason,

> -Original Message-
> From: Jason Wang 
> Sent: Monday, September 23, 2019 8:03 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; Jason Wang 
> Subject: [PATCH 1/6] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, one example is
> virtio-mdev[1] driver. This means we need to add device class id support in 
> bus
> match method to pair the mdev device and mdev driver correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev parent with
> the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  Documentation/driver-api/vfio-mediated-device.rst |  7 +--
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  2 +-
>  drivers/s390/cio/vfio_ccw_ops.c   |  2 +-
>  drivers/s390/crypto/vfio_ap_ops.c |  3 ++-
>  drivers/vfio/mdev/mdev_core.c | 14 --
>  drivers/vfio/mdev/mdev_driver.c   | 14 ++
>  drivers/vfio/mdev/mdev_private.h  |  1 +
>  drivers/vfio/mdev/vfio_mdev.c |  6 ++
>  include/linux/mdev.h  |  7 ++-
>  include/linux/mod_devicetable.h   |  8 
>  samples/vfio-mdev/mbochs.c|  2 +-
>  samples/vfio-mdev/mdpy.c  |  2 +-
>  samples/vfio-mdev/mtty.c  |  2 +-
>  13 files changed, 59 insertions(+), 11 deletions(-)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst
> b/Documentation/driver-api/vfio-mediated-device.rst
> index 25eb7d5b834b..0e052072e1d8 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -102,12 +102,14 @@ structure to represent a mediated device's driver::
>* @probe: called when new device created
>* @remove: called when device removed
>* @driver: device driver structure
> +  * @id_table: the ids serviced by this driver.
No full stop at the end.

>*/
>   struct mdev_driver {
>const char *name;
>int  (*probe)  (struct device *dev);
>void (*remove) (struct device *dev);
>struct device_driverdriver;
> +  const struct mdev_class_id *id_table;
>   };
> 
>  A mediated bus driver for mdev should use this structure in the function 
> calls
> @@ -116,7 +118,7 @@ to register and unregister itself with the core driver:
>  * Register::
> 
>  extern int  mdev_register_driver(struct mdev_driver *drv,
> -struct module *owner);
> + struct module *owner);
> 
Unrelated change in this patch.

>  * Unregister::
> 
> @@ -163,7 +165,8 @@ A driver should use the mdev_parent_ops structure in
> the function call to  register itself with the mdev core driver::
> 
>   extern int  mdev_register_device(struct device *dev,
> -  const struct mdev_parent_ops *ops);
> +  const struct mdev_parent_ops *ops,
> +  u8 class_id);
> 
Cover letter from Change-V2 says that it class_id changed from " use u16 
instead u8 for class id"
But it is still u8 here?

>  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::
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c
> b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 23aa3e50cbf8..19d51a35f019 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/d

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

2019-09-23 Thread Parav Pandit


> -Original Message-
> From: Jason Wang 
> Sent: Monday, September 23, 2019 8:03 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; Jason Wang 
> Subject: [PATCH 4/6] virtio: introduce a mdev based transport
> 
> This patch introduces a new mdev transport for virtio. This is used to use 
> kernel
> virtio driver to drive the mediated device that is capable of populating
> virtqueue directly.
> 
> A new virtio-mdev driver will be registered to the mdev bus, when a new 
> virtio-
> mdev device is probed, it will register the device with mdev based config ops.
> This means it is a software transport between mdev driver and mdev device.
> The transport was implemented through device specific opswhich is a part of
> mdev_parent_ops now.
> 
> Signed-off-by: Jason Wang 
> ---
>  MAINTAINERS |   1 +
>  drivers/vfio/mdev/Kconfig   |   7 +
>  drivers/vfio/mdev/Makefile  |   1 +
>  drivers/vfio/mdev/virtio_mdev.c | 416 
>  4 files changed, 425 insertions(+)
>  create mode 100644 drivers/vfio/mdev/virtio_mdev.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 89832b316500..820ec250cc52 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -17202,6 +17202,7 @@ F:include/linux/virtio*.h
>  F:   include/uapi/linux/virtio_*.h
>  F:   drivers/crypto/virtio/
>  F:   mm/balloon_compaction.c
> +F:   drivers/vfio/mdev/virtio_mdev.c
> 
>  VIRTIO BLOCK AND SCSI DRIVERS
>  M:   "Michael S. Tsirkin" 
> diff --git a/drivers/vfio/mdev/Kconfig b/drivers/vfio/mdev/Kconfig index
> 5da27f2100f9..c488c31fc137 100644
> --- a/drivers/vfio/mdev/Kconfig
> +++ b/drivers/vfio/mdev/Kconfig
> @@ -16,3 +16,10 @@ config VFIO_MDEV_DEVICE
>   default n
>   help
> VFIO based driver for Mediated devices.
> +
> +config VIRTIO_MDEV_DEVICE
> + tristate "VIRTIO driver for Mediated devices"
> + depends on VFIO_MDEV && VIRTIO
> + default n
> + help
> +   VIRTIO based driver for Mediated devices.
> diff --git a/drivers/vfio/mdev/Makefile b/drivers/vfio/mdev/Makefile index
> 101516fdf375..99d31e29c23e 100644
> --- a/drivers/vfio/mdev/Makefile
> +++ b/drivers/vfio/mdev/Makefile
> @@ -4,3 +4,4 @@ mdev-y := mdev_core.o mdev_sysfs.o mdev_driver.o
> 
>  obj-$(CONFIG_VFIO_MDEV) += mdev.o
>  obj-$(CONFIG_VFIO_MDEV_DEVICE) += vfio_mdev.o
> +obj-$(CONFIG_VIRTIO_MDEV_DEVICE) += virtio_mdev.o
> diff --git a/drivers/vfio/mdev/virtio_mdev.c b/drivers/vfio/mdev/virtio_mdev.c
> new file mode 100644 index ..919a082adc9c
> --- /dev/null
> +++ b/drivers/vfio/mdev/virtio_mdev.c
> @@ -0,0 +1,416 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * VIRTIO based driver for Mediated device
> + *
> + * Copyright (c) 2019, Red Hat. All rights reserved.
> + * Author: Jason Wang 
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "mdev_private.h"
> +
> +#define DRIVER_VERSION  "0.1"
> +#define DRIVER_AUTHOR   "Red Hat Corporation"
> +#define DRIVER_DESC "VIRTIO based driver for Mediated device"
> +
> +#define to_virtio_mdev_device(dev) \
> + container_of(dev, struct virtio_mdev_device, vdev)
> +
> +struct virtio_mdev_device {
> + struct virtio_device vdev;
> + struct mdev_device *mdev;
> + unsigned long version;
> +
> + struct virtqueue **vqs;
Every lock must need a comment to describe what it locks.
I don't see this lock is used in this patch. Please introduce in the patch that 
uses it.
> + spinlock_t lock;
> +};
> +
> +s

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

2019-09-23 Thread Parav Pandit
Hi Jason,


> -Original Message-
> From: Jason Wang 
> Sent: Monday, September 23, 2019 8:03 AM
> To: k...@vger.kernel.org; linux-s...@vger.kernel.org; linux-
> ker...@vger.kernel.org; dri-de...@lists.freedesktop.org; intel-
> g...@lists.freedesktop.org; intel-gvt-...@lists.freedesktop.org;
> kwankh...@nvidia.com; alex.william...@redhat.com; m...@redhat.com;
> tiwei@intel.com
> Cc: virtualizat...@lists.linux-foundation.org; net...@vger.kernel.org;
> coh...@redhat.com; maxime.coque...@redhat.com;
> cunming.li...@intel.com; zhihong.w...@intel.com;
> rob.mil...@broadcom.com; xiao.w.w...@intel.com;
> haotian.w...@sifive.com; zhen...@linux.intel.com; zhi.a.w...@intel.com;
> jani.nik...@linux.intel.com; joonas.lahti...@linux.intel.com;
> rodrigo.v...@intel.com; airl...@linux.ie; dan...@ffwll.ch;
> far...@linux.ibm.com; pa...@linux.ibm.com; seb...@linux.ibm.com;
> ober...@linux.ibm.com; heiko.carst...@de.ibm.com; g...@linux.ibm.com;
> borntrae...@de.ibm.com; akrow...@linux.ibm.com; fre...@linux.ibm.com;
> lingshan@intel.com; Ido Shamay ;
> epere...@redhat.com; l...@redhat.com; Parav Pandit
> ; Jason Wang 
> Subject: [PATCH 1/6] mdev: class id support
> 
> Mdev bus only supports vfio driver right now, so it doesn't implement match
> method. But in the future, we may add drivers other than vfio, one example is
> virtio-mdev[1] driver. This means we need to add device class id support in 
> bus
> match method to pair the mdev device and mdev driver correctly.
> 
> So this patch adds id_table to mdev_driver and class_id for mdev parent with
> the match method for mdev bus.
> 
> Signed-off-by: Jason Wang 
> ---
>  Documentation/driver-api/vfio-mediated-device.rst |  7 +--
>  drivers/gpu/drm/i915/gvt/kvmgt.c  |  2 +-
>  drivers/s390/cio/vfio_ccw_ops.c   |  2 +-
>  drivers/s390/crypto/vfio_ap_ops.c |  3 ++-
>  drivers/vfio/mdev/mdev_core.c | 14 --
>  drivers/vfio/mdev/mdev_driver.c   | 14 ++
>  drivers/vfio/mdev/mdev_private.h  |  1 +
>  drivers/vfio/mdev/vfio_mdev.c |  6 ++
>  include/linux/mdev.h  |  7 ++-
>  include/linux/mod_devicetable.h   |  8 
>  samples/vfio-mdev/mbochs.c|  2 +-
>  samples/vfio-mdev/mdpy.c  |  2 +-
>  samples/vfio-mdev/mtty.c  |  2 +-
>  13 files changed, 59 insertions(+), 11 deletions(-)
> 
You additionally need modpost support for id table integration to modifo, 
modprobe and other tools.
A small patch similar to this one [1] is needed.
Please include in the series.

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


___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx