Re: [libvirt] [PATCH 0/6] VFIO mdev aggregated resources handling

2019-11-05 Thread Zhenyu Wang
On 2019.11.05 14:10:42 -0700, Alex Williamson wrote:
> On Thu, 24 Oct 2019 13:08:23 +0800
> Zhenyu Wang  wrote:
> 
> > Hi,
> > 
> > This is a refresh for previous send of this series. I got impression that
> > some SIOV drivers would still deploy their own create and config method so
> > stopped effort on this. But seems this would still be useful for some other
> > SIOV driver which may simply want capability to aggregate resources. So 
> > here's
> > refreshed series.
> > 
> > Current mdev device create interface depends on fixed mdev type, which get 
> > uuid
> > from user to create instance of mdev device. If user wants to use customized
> > number of resource for mdev device, then only can create new mdev type for 
> > that
> > which may not be flexible. This requirement comes not only from to be able 
> > to
> > allocate flexible resources for KVMGT, but also from Intel scalable IO
> > virtualization which would use vfio/mdev to be able to allocate arbitrary
> > resources on mdev instance. More info on [1] [2] [3].
> > 
> > To allow to create user defined resources for mdev, it trys to extend mdev
> > create interface by adding new "aggregate=xxx" parameter following UUID, for
> > target mdev type if aggregation is supported, it can create new mdev device
> > which contains resources combined by number of instances, e.g
> > 
> > echo ",aggregate=10" > create
> > 
> > VM manager e.g libvirt can check mdev type with "aggregation" attribute 
> > which
> > can support this setting. If no "aggregation" attribute found for mdev type,
> > previous behavior is still kept for one instance allocation. And new sysfs
> > attribute "aggregated_instances" is created for each mdev device to show 
> > allocated number.
> 
> Given discussions we've had recently around libvirt interacting with
> mdev, I think that libvirt would rather have an abstract interface via
> mdevctl[1].  Therefore can you evaluate how mdevctl would support this
> creation extension?  It seems like it would fit within the existing
> mdev and mdevctl framework if aggregation were simply a sysfs attribute
> for the device.  For example, the mdevctl steps might look like this:
> 
> mdevctl define -u UUID -p PARENT -t TYPE
> mdevctl modify -u UUID --addattr=mdev/aggregation --value=2
> mdevctl start -u UUID
> 
> When mdevctl starts the mdev, it will first create it using the
> existing mechanism, then apply aggregation attribute, which can consume
> the necessary additional instances from the parent device, or return an
> error, which would unwind and return a failure code to the caller
> (libvirt).  I think the vendor driver would then have freedom to decide
> when the attribute could be modified, for instance it would be entirely
> reasonable to return -EBUSY if the user attempts to modify the
> attribute while the mdev device is in-use.  Effectively aggregation
> simply becomes a standardized attribute with common meaning.  Thoughts?
> [cc libvirt folks for their impression] Thanks,

I think one problem is that before mdevctl start to create mdev you
don't know what vendor attributes are, as we apply mdev attributes
after create. You may need some lookup depending on parent.. I think
making aggregation like other vendor attribute for mdev might be the
simplest way, but do we want to define its behavior in formal? e.g
like previous discussed it should show maxium instances for aggregation, etc.

The behavior change for driver is that previously aggregation is
handled at create time, but for sysfs attr it should handle any
resource allocation before it's really in-use. I think some SIOV
driver which already requires some specific config should be ok,
but not sure for other driver which might not be explored in this before.
Would that be a problem? Kevin?

Thanks

> 
> Alex
> 
> [1] https://github.com/mdevctl/mdevctl
> 
> > References:
> > [1] 
> > https://software.intel.com/en-us/download/intel-virtualization-technology-for-directed-io-architecture-specification
> > [2] 
> > https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification
> > [3] https://schd.ws/hosted_files/lc32018/00/LC3-SIOV-final.pdf
> > 
> > Zhenyu Wang (6):
> >   vfio/mdev: Add new "aggregate" parameter for mdev create
> >   vfio/mdev: Add "aggregation" attribute for supported mdev type
> >   vfio/mdev: Add "aggregated_instances" attribute for supported mdev
> > device
> >   Documentation/driver-api/vfio-mediated-device.rst: Update for
> > vfio/mdev aggregation support
> > 

Re: [PATCH v3 2/2] drm/i915/gvt: export migration_version to mdev sysfs for Intel vGPU

2019-05-28 Thread Zhenyu Wang
On 2019.05.26 23:44:37 -0400, Yan Zhao wrote:
> This feature implements the migration_version attribute for Intel's vGPU
> mdev devices.
> 
> migration_version attribute is rw.
> It's used to check migration compatibility for two mdev devices of the
> same mdev type.
> migration_version string is defined by vendor driver and opaque to
> userspace.
> 
> For Intel vGPU of gen8 and gen9, the format of migration_version string
> is:
>   ---.
> 
> For future platforms, the format of migration_version string is to be
> expanded to include more meta data to identify Intel vGPUs for live
> migration compatibility check
> 
> For old platforms, and for GVT not supporting vGPU live migration
> feature, -ENODEV is returned on read(2)/write(2) of migration_version
> attribute.
> For vGPUs running old GVT who do not expose migration_version
> attribute, live migration is regarded as not supported for those vGPUs.
> 
> Cc: Alex Williamson 
> Cc: Erik Skultety 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Cornelia Huck 
> Cc: "Tian, Kevin" 
> Cc: Zhenyu Wang 
> Cc: "Wang, Zhi A" 
> c: Neo Jia 
> Cc: Kirti Wankhede 
> 
> Signed-off-by: Yan Zhao 
> 
> ---
> v3:
> 1. renamed version to migration_version
> (Christophe de Dinechin, Cornelia Huck, Alex Williamson)
> 2. instead of generating migration version strings each time, storing
> them in vgpu types generated during initialization.
> (Zhenyu Wang, Cornelia Huck)
> 3. replaced multiple snprintf to one big snprintf in
> intel_gvt_get_vfio_migration_version()
> (Dr. David Alan Gilbert)
> 4. printed detailed error log
> (Alex Williamson, Erik Skultety, Cornelia Huck, Dr. David Alan Gilbert)
> 5. incorporated  into migration_version string
> (Alex Williamson)
> 6. do not use ifndef macro to switch off migration_version attribute
> (Zhenyu Wang)
> 
> v2:
> 1. removed 32 common part of version string
> (Alex Williamson)
> 2. do not register version attribute for GVT not supporting live
> migration.(Cornelia Huck)
> 3. for platforms out of gen8, gen9, return -EINVAL --> -ENODEV for
> incompatible. (Cornelia Huck)
> ---
>  drivers/gpu/drm/i915/gvt/Makefile|   2 +-
>  drivers/gpu/drm/i915/gvt/gvt.c   |  39 +
>  drivers/gpu/drm/i915/gvt/gvt.h   |   5 +
>  drivers/gpu/drm/i915/gvt/migration_version.c | 167 +++
>  drivers/gpu/drm/i915/gvt/vgpu.c  |  13 +-
>  5 files changed, 223 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/gvt/migration_version.c
> 
> diff --git a/drivers/gpu/drm/i915/gvt/Makefile 
> b/drivers/gpu/drm/i915/gvt/Makefile
> index 271fb46d4dd0..a9d561c93ab8 100644
> --- a/drivers/gpu/drm/i915/gvt/Makefile
> +++ b/drivers/gpu/drm/i915/gvt/Makefile
> @@ -3,7 +3,7 @@ GVT_DIR := gvt
>  GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o 
> firmware.o \
>   interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
>   execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o 
> debugfs.o \
> - fb_decoder.o dmabuf.o page_track.o
> + fb_decoder.o dmabuf.o page_track.o migration_version.o
>  
>  ccflags-y+= -I$(src) -I$(src)/$(GVT_DIR)
>  i915-y   += $(addprefix $(GVT_DIR)/, 
> $(GVT_SOURCE))
> diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
> index 43f4242062dd..be2980e8ac75 100644
> --- a/drivers/gpu/drm/i915/gvt/gvt.c
> +++ b/drivers/gpu/drm/i915/gvt/gvt.c
> @@ -105,14 +105,53 @@ static ssize_t description_show(struct kobject *kobj, 
> struct device *dev,
>  type->weight);
>  }
>  
> +static ssize_t migration_version_show(struct kobject *kobj, struct device 
> *dev,
> + char *buf)
> +{
> + struct intel_vgpu_type *type;
> + void *gvt = kdev_to_i915(dev)->gvt;
> +
> + type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
> + if (!type || !type->migration_version) {
> + gvt_err("Does not support migraion on type %s. Please search 
> previous detailed log\n",
> + kobject_name(kobj));
> + return -ENODEV;
> + }
> +
> + return snprintf(buf, strlen(type->migration_version) + 2,
> + "%s\n", type->migration_version);
> +}
> +
> +static ssize_t migration_version_store(struct kobject *kobj, struct device 
> *dev,
> + const char *buf, size_t count)
> +{
> + int ret = 0;
> + struct intel_vgpu_type *type;
> + void *gvt = kdev_to_i915(dev)->gvt;
> +
> + type = intel_gvt_find

Re: [libvirt] [PATCH v2 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU

2019-05-06 Thread Zhenyu Wang
On 2019.05.06 11:20:32 +0800, Zhenyu Wang wrote:
> On 2019.05.05 21:51:02 -0400, Yan Zhao wrote:
> > This feature implements the version attribute for Intel's vGPU mdev
> > devices.
> > 
> > version attribute is rw.
> > It's used to check device compatibility for two mdev devices.
> > version string format and length are private for vendor driver. vendor
> > driver is able to define them freely.
> > 
> > For Intel vGPU of gen8 and gen9, the mdev device version
> > consists of 3 fields: "vendor id" + "device id" + "mdev type".
> > 
> > Reading from a vGPU's version attribute, a string is returned in below
> > format: --. e.g.
> > 8086-193b-i915-GVTg_V5_2.
> > 
> > Writing a string to a vGPU's version attribute will trigger GVT to check
> > whether a vGPU identified by the written string is compatible with
> > current vGPU owning this version attribute. errno is returned if the two
> > vGPUs are incompatible. The length of written string is returned in
> > compatible case.
> > 
> > For other platforms, and for GVT not supporting vGPU live migration
> > feature, errnos are returned when read/write of mdev devices' version
> > attributes.
> > 
> > For old GVT versions where no version attributes exposed in sysfs, it is
> > regarded as not supporting vGPU live migration.
> > 
> > For future platforms, besides the current 2 fields in vendor proprietary
> > part, more fields may be added to identify Intel vGPU well for live
> > migration purpose.
> > 
> > v2:
> > 1. removed 32 common part of version string
> > (Alex Williamson)
> > 2. do not register version attribute for GVT not supporting live
> > migration.(Cornelia Huck)
> > 3. for platforms out of gen8, gen9, return -EINVAL --> -ENODEV for
> > incompatible. (Cornelia Huck)
> > 
> > Cc: Alex Williamson 
> > Cc: Erik Skultety 
> > Cc: "Dr. David Alan Gilbert" 
> > Cc: Cornelia Huck 
> > Cc: "Tian, Kevin" 
> > Cc: Zhenyu Wang 
> > Cc: "Wang, Zhi A" 
> > c: Neo Jia 
> > Cc: Kirti Wankhede 
> > 
> > Signed-off-by: Yan Zhao 
> > ---
> >  drivers/gpu/drm/i915/gvt/Makefile |  2 +-
> >  drivers/gpu/drm/i915/gvt/device_version.c | 87 +++
> >  drivers/gpu/drm/i915/gvt/gvt.c| 51 +
> >  drivers/gpu/drm/i915/gvt/gvt.h|  6 ++
> >  4 files changed, 145 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/gpu/drm/i915/gvt/device_version.c
> > 
> > diff --git a/drivers/gpu/drm/i915/gvt/Makefile 
> > b/drivers/gpu/drm/i915/gvt/Makefile
> > index 271fb46d4dd0..54e209a23899 100644
> > --- a/drivers/gpu/drm/i915/gvt/Makefile
> > +++ b/drivers/gpu/drm/i915/gvt/Makefile
> > @@ -3,7 +3,7 @@ GVT_DIR := gvt
> >  GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o 
> > firmware.o \
> > interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
> > execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o 
> > debugfs.o \
> > -   fb_decoder.o dmabuf.o page_track.o
> > +   fb_decoder.o dmabuf.o page_track.o device_version.o
> >  
> >  ccflags-y  += -I$(src) -I$(src)/$(GVT_DIR)
> >  i915-y += $(addprefix $(GVT_DIR)/, 
> > $(GVT_SOURCE))
> > diff --git a/drivers/gpu/drm/i915/gvt/device_version.c 
> > b/drivers/gpu/drm/i915/gvt/device_version.c
> > new file mode 100644
> > index ..bd4cdcbdba95
> > --- /dev/null
> > +++ b/drivers/gpu/drm/i915/gvt/device_version.c
> > @@ -0,0 +1,87 @@
> > +/*
> > + * Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the 
> > "Software"),
> > + * to deal in the Software without restriction, including without 
> > limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the 
> > next
> > + * paragraph) shall be included in all copies or substantial portions of 
> > the
> > + * Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY O

Re: [libvirt] [PATCH v2 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU

2019-05-05 Thread Zhenyu Wang
On 2019.05.05 21:51:02 -0400, Yan Zhao wrote:
> This feature implements the version attribute for Intel's vGPU mdev
> devices.
> 
> version attribute is rw.
> It's used to check device compatibility for two mdev devices.
> version string format and length are private for vendor driver. vendor
> driver is able to define them freely.
> 
> For Intel vGPU of gen8 and gen9, the mdev device version
> consists of 3 fields: "vendor id" + "device id" + "mdev type".
> 
> Reading from a vGPU's version attribute, a string is returned in below
> format: --. e.g.
> 8086-193b-i915-GVTg_V5_2.
> 
> Writing a string to a vGPU's version attribute will trigger GVT to check
> whether a vGPU identified by the written string is compatible with
> current vGPU owning this version attribute. errno is returned if the two
> vGPUs are incompatible. The length of written string is returned in
> compatible case.
> 
> For other platforms, and for GVT not supporting vGPU live migration
> feature, errnos are returned when read/write of mdev devices' version
> attributes.
> 
> For old GVT versions where no version attributes exposed in sysfs, it is
> regarded as not supporting vGPU live migration.
> 
> For future platforms, besides the current 2 fields in vendor proprietary
> part, more fields may be added to identify Intel vGPU well for live
> migration purpose.
> 
> v2:
> 1. removed 32 common part of version string
> (Alex Williamson)
> 2. do not register version attribute for GVT not supporting live
> migration.(Cornelia Huck)
> 3. for platforms out of gen8, gen9, return -EINVAL --> -ENODEV for
> incompatible. (Cornelia Huck)
> 
> Cc: Alex Williamson 
> Cc: Erik Skultety 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Cornelia Huck 
> Cc: "Tian, Kevin" 
> Cc: Zhenyu Wang 
> Cc: "Wang, Zhi A" 
> c: Neo Jia 
> Cc: Kirti Wankhede 
> 
> Signed-off-by: Yan Zhao 
> ---
>  drivers/gpu/drm/i915/gvt/Makefile |  2 +-
>  drivers/gpu/drm/i915/gvt/device_version.c | 87 +++
>  drivers/gpu/drm/i915/gvt/gvt.c| 51 +
>  drivers/gpu/drm/i915/gvt/gvt.h|  6 ++
>  4 files changed, 145 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/i915/gvt/device_version.c
> 
> diff --git a/drivers/gpu/drm/i915/gvt/Makefile 
> b/drivers/gpu/drm/i915/gvt/Makefile
> index 271fb46d4dd0..54e209a23899 100644
> --- a/drivers/gpu/drm/i915/gvt/Makefile
> +++ b/drivers/gpu/drm/i915/gvt/Makefile
> @@ -3,7 +3,7 @@ GVT_DIR := gvt
>  GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o 
> firmware.o \
>   interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
>   execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o 
> debugfs.o \
> - fb_decoder.o dmabuf.o page_track.o
> + fb_decoder.o dmabuf.o page_track.o device_version.o
>  
>  ccflags-y+= -I$(src) -I$(src)/$(GVT_DIR)
>  i915-y   += $(addprefix $(GVT_DIR)/, 
> $(GVT_SOURCE))
> diff --git a/drivers/gpu/drm/i915/gvt/device_version.c 
> b/drivers/gpu/drm/i915/gvt/device_version.c
> new file mode 100644
> index ..bd4cdcbdba95
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/gvt/device_version.c
> @@ -0,0 +1,87 @@
> +/*
> + * Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
> THE
> + * SOFTWARE.
> + *
> + * Authors:
> + *Yan Zhao 
> + */
> +#include 
> +#include "

Re: [libvirt] [PATCH 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU

2019-04-22 Thread Zhenyu Wang
On 2019.04.19 04:35:59 -0400, Yan Zhao wrote:
> This feature implements the version attribute for Intel's vGPU mdev
> devices.
> 
> version attribute is rw. It is queried by userspace software like libvirt
> to check whether two vGPUs are compatible for live migration.
> 
> It consists of two parts: common part and vendor proprietary part.
> common part: 32 bit. lower 16 bits is vendor id and higher 16 bits
>  identifies device type. e.g., for pci device, it is
>  "pci vendor id" | (VFIO_DEVICE_FLAGS_PCI << 16).
> vendor proprietary part: this part is varied in length. vendor driver can
>  specify any string to identify a device.
> 
> For Intel vGPU of gen8 and gen9, the vendor proprietary part currently
> consists of 2 fields: "device id" + "mdev type".
> 
> Reading from a vGPU's version attribute, a string is returned in below
> format: 00028086--. e.g.
> 00028086-193b-i915-GVTg_V5_2.
> 
> Writing a string to a vGPU's version attribute will trigger GVT to check
> whether a vGPU identified by the written string is compatible with
> current vGPU owning this version attribute. errno is returned if the two
> vGPUs are incompatible. The length of written string is returned in
> compatible case.
> 
> For other platforms, and for GVT not supporting vGPU live migration
> feature, errnos are returned when read/write of mdev devices' version
> attributes.
> 
> For old GVT versions where no version attributes exposed in sysfs, it is
> regarded as not supporting vGPU live migration.
> 
> For future platforms, besides the current 2 fields in vendor proprietary
> part, more fields may be added to identify Intel vGPU well for live
> migration purpose.
> 
> Cc: Alex Williamson 
> Cc: Erik Skultety 
> Cc: "Dr. David Alan Gilbert" 
> Cc: Cornelia Huck 
> Cc: "Tian, Kevin" 
> Cc: Zhenyu Wang 
> Cc: "Wang, Zhi A" 
> c: Neo Jia 
> Cc: Kirti Wankhede 
> 
> Signed-off-by: Yan Zhao 
> ---
>  drivers/gpu/drm/i915/gvt/Makefile |  2 +-
>  drivers/gpu/drm/i915/gvt/device_version.c | 94 +++
>  drivers/gpu/drm/i915/gvt/gvt.c| 55 +
>  drivers/gpu/drm/i915/gvt/gvt.h|  6 ++
>  4 files changed, 156 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/i915/gvt/device_version.c
> 
> diff --git a/drivers/gpu/drm/i915/gvt/Makefile 
> b/drivers/gpu/drm/i915/gvt/Makefile
> index 271fb46d4dd0..54e209a23899 100644
> --- a/drivers/gpu/drm/i915/gvt/Makefile
> +++ b/drivers/gpu/drm/i915/gvt/Makefile
> @@ -3,7 +3,7 @@ GVT_DIR := gvt
>  GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o 
> firmware.o \
>   interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
>   execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o 
> debugfs.o \
> - fb_decoder.o dmabuf.o page_track.o
> + fb_decoder.o dmabuf.o page_track.o device_version.o
>  
>  ccflags-y+= -I$(src) -I$(src)/$(GVT_DIR)
>  i915-y   += $(addprefix $(GVT_DIR)/, 
> $(GVT_SOURCE))
> diff --git a/drivers/gpu/drm/i915/gvt/device_version.c 
> b/drivers/gpu/drm/i915/gvt/device_version.c
> new file mode 100644
> index ..c64010d2bc54
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/gvt/device_version.c
> @@ -0,0 +1,94 @@
> +/*
> + * Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
> THE
> + * SOFTWARE.
> + */
> +#include 
> +#

[libvirt] [PATCH v3 2/6] vfio/mdev: Add "aggregation" attribute for supported mdev type

2018-10-17 Thread Zhenyu Wang
For supported mdev driver to create aggregated device, this creates
new "aggregation" attribute for target type, which will show maximum
number of instance resources that can be aggregated.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 drivers/vfio/mdev/mdev_core.c| 19 +++
 drivers/vfio/mdev/mdev_private.h |  2 ++
 drivers/vfio/mdev/mdev_sysfs.c   | 22 ++
 include/linux/mdev.h |  8 
 4 files changed, 51 insertions(+)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 545c52ec7618..8f8bbb72e5d9 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -161,6 +161,25 @@ static int mdev_device_remove_cb(struct device *dev, void 
*data)
return mdev_device_remove(dev, data ? *(bool *)data : true);
 }
 
+int mdev_max_aggregated_instances(struct kobject *kobj, struct device *dev,
+ unsigned int *m)
+{
+   struct mdev_parent *parent;
+   struct mdev_type *type = to_mdev_type(kobj);
+   int ret;
+
+   parent = mdev_get_parent(type->parent);
+   if (!parent)
+   return -EINVAL;
+
+   if (parent->ops->max_aggregated_instances) {
+   ret = parent->ops->max_aggregated_instances(kobj, dev, m);
+   } else
+   ret = -EINVAL;
+   mdev_put_parent(parent);
+   return ret;
+}
+
 /*
  * mdev_register_device : Register a device
  * @dev: device structure representing parent device.
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index e90d295d3927..f1289db75884 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -63,4 +63,6 @@ int  mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid,
unsigned int instances);
 int  mdev_device_remove(struct device *dev, bool force_remove);
 
+int  mdev_max_aggregated_instances(struct kobject *kobj, struct device *dev,
+  unsigned int *m);
 #endif /* MDEV_PRIVATE_H */
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index aefed0c8891b..a329d6ab6cb9 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -103,6 +103,18 @@ static ssize_t create_store(struct kobject *kobj, struct 
device *dev,
 
 MDEV_TYPE_ATTR_WO(create);
 
+static ssize_t
+aggregation_show(struct kobject *kobj, struct device *dev, char *buf)
+{
+   unsigned int m;
+
+   if (mdev_max_aggregated_instances(kobj, dev, ))
+   return sprintf(buf, "1\n");
+   else
+   return sprintf(buf, "%u\n", m);
+}
+MDEV_TYPE_ATTR_RO(aggregation);
+
 static void mdev_type_release(struct kobject *kobj)
 {
struct mdev_type *type = to_mdev_type(kobj);
@@ -145,6 +157,14 @@ struct mdev_type *add_mdev_supported_type(struct 
mdev_parent *parent,
if (ret)
goto attr_create_failed;
 
+   if (parent->ops->create_with_instances &&
+   parent->ops->max_aggregated_instances) {
+   ret = sysfs_create_file(>kobj,
+   _type_attr_aggregation.attr);
+   if (ret)
+   goto attr_aggregate_failed;
+   }
+
type->devices_kobj = kobject_create_and_add("devices", >kobj);
if (!type->devices_kobj) {
ret = -ENOMEM;
@@ -165,6 +185,8 @@ struct mdev_type *add_mdev_supported_type(struct 
mdev_parent *parent,
 attrs_failed:
kobject_put(type->devices_kobj);
 attr_devices_failed:
+   sysfs_remove_file(>kobj, _type_attr_aggregation.attr);
+attr_aggregate_failed:
sysfs_remove_file(>kobj, _type_attr_create.attr);
 attr_create_failed:
kobject_del(>kobj);
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index c12c0bfc5598..66cfdb0bf0d6 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -39,6 +39,11 @@ struct mdev_device;
  *   that is being created
  *  @instances: number of instances to aggregate
  * Returns integer: success (0) or error (< 0)
+ * @max_aggregated_instances: Return max number for aggregated resources
+ * @kobj: kobject of type
+ *  @dev: mdev parent device for target type
+ *  @max: return max number of instances which can 
aggregate
+ * Returns integer: success (0) or error (< 0)
  * @remove:Called to free resources in parent device's driver for a
  * a mediated device. It is mandatory to provide 'remove'
  * ops.
@@ -82,6 +87,9 @@ struct mdev_parent_ops {
int (*create_with_instances)(struct kobject *kobj,
 

[libvirt] [PATCH v3 5/6] Documentation/ABI/testing/sysfs-bus-vfio-mdev: Update for vfio/mdev aggregation support

2018-10-17 Thread Zhenyu Wang
Update vfio/mdev ABI description for new aggregation attributes.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 Documentation/ABI/testing/sysfs-bus-vfio-mdev | 25 +++
 1 file changed, 25 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-vfio-mdev 
b/Documentation/ABI/testing/sysfs-bus-vfio-mdev
index 452dbe39270e..192fe06e60d0 100644
--- a/Documentation/ABI/testing/sysfs-bus-vfio-mdev
+++ b/Documentation/ABI/testing/sysfs-bus-vfio-mdev
@@ -85,6 +85,24 @@ Users:
a particular  that can help in understanding the
features provided by that type of mediated device.
 
+What:   /sys/.../mdev_supported_types//aggregation
+Date:   October 2018
+Contact:Zhenyu Wang 
+Description:
+   Reading this attribute will show number of mdev instances
+   that can be aggregated to assign for one mdev device.
+   This is optional attribute. If this attribute exists that
+   means driver supports to aggregate target mdev type's
+   resources assigned for one mdev device.
+Users:
+   Userspace applications interested in creating mediated
+   device with aggregated type instances. Userspace application
+   should check the number of aggregation instances that could
+   be created before creating mediated device by applying this,
+   e.g
+   # echo "83b8f4f2-509f-382f-3c1e-e6bfe0fa1001,aggregate=XX" > \
+  /sys/devices/foo/mdev_supported_types/foo-1/create
+
 What:   /sys/...///
 Date:   October 2016
 Contact:Kirti Wankhede 
@@ -109,3 +127,10 @@ Description:
is active and the vendor driver doesn't support hot unplug.
Example:
# echo 1 > /sys/bus/mdev/devices//remove
+
+What:   /sys/...///aggregated_instances
+Date:   October 2018
+Contact:    Zhenyu Wang 
+Description:
+   This attributes shows number of aggregated instances if this
+   mediated device was created with "aggregate" parameter.
\ No newline at end of file
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 4/6] Documentation/vfio-mediated-device.txt: Update for vfio/mdev aggregation support

2018-10-17 Thread Zhenyu Wang
Update vfio/mdev doc on new "aggregate" create parameter, new "aggregation"
attribute and "aggregated_instances" attribute for mdev device.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 Documentation/vfio-mediated-device.txt | 44 ++
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/Documentation/vfio-mediated-device.txt 
b/Documentation/vfio-mediated-device.txt
index c3f69bcaf96e..cf4849a34c9f 100644
--- a/Documentation/vfio-mediated-device.txt
+++ b/Documentation/vfio-mediated-device.txt
@@ -211,12 +211,20 @@ Directories and files under the sysfs for Each Physical 
Device
   | |   |--- description
   | |   |--- [devices]
   | |--- []
-  |  |--- create
-  |  |--- name
-  |  |--- available_instances
-  |  |--- device_api
-  |  |--- description
-  |  |--- [devices]
+  | ||--- create
+  | ||--- name
+  | ||--- available_instances
+  | ||--- device_api
+  | ||--- description
+  | ||--- [devices]
+  | |--- []
+  | ||--- create
+  | ||--- name
+  | ||--- available_instances
+  | ||--- device_api
+  | ||--- description
+  | ||--- 
+  | ||--- [devices]
 
 * [mdev_supported_types]
 
@@ -260,6 +268,23 @@ Directories and files under the sysfs for Each Physical 
Device
   This attribute should show brief features/description of the type. This is
   optional attribute.
 
+* 
+
+   is an optional attributes to show max number that the
+  instance resources of [] can be aggregated to be assigned
+  for one mdev device. No  attribute means driver doesn't
+  support to aggregate instance resoures for one mdev device.
+   may be less than available_instances which depends on
+  driver.  number can't exceed available_instances.
+
+  Set number of instances by appending "aggregate=N" parameter for
+  create attribute. By default without "aggregate=N" parameter it
+  will create one instance as normal.
+
+Example::
+
+   # echo ",aggregate=N" > create
+
 Directories and Files Under the sysfs for Each mdev Device
 --
 
@@ -268,6 +293,7 @@ Directories and Files Under the sysfs for Each mdev Device
   |- [parent phy device]
   |--- [$MDEV_UUID]
  |--- remove
+|--- 
  |--- mdev_type {link to its type}
  |--- vendor-specific-attributes [optional]
 
@@ -281,6 +307,12 @@ Example::
 
# echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove
 
+*  (read only)
+
+For mdev created with aggregate parameter, this shows number of
+instances assigned for this mdev. For normal type this attribute will
+not exist.
+
 Mediated device Hot plug
 
 
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 1/6] vfio/mdev: Add new "aggregate" parameter for mdev create

2018-10-17 Thread Zhenyu Wang
For special mdev type which can aggregate instances for mdev device,
this extends mdev create interface by allowing extra "aggregate=xxx"
parameter, which is passed to mdev device model to be able to create
bundled number of instances for target mdev device.

v2: create new create_with_instances operator for vendor driver
v3:
- Change parameter name as "aggregate="
- Fix new interface comments.
- Parameter checking for new option, pass UUID string only to
  parse and properly end parameter for kstrtouint() conversion.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 drivers/vfio/mdev/mdev_core.c| 21 +
 drivers/vfio/mdev/mdev_private.h |  4 +++-
 drivers/vfio/mdev/mdev_sysfs.c   | 32 
 include/linux/mdev.h | 11 +++
 4 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 0212f0ee8aea..545c52ec7618 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -104,12 +104,17 @@ static inline void mdev_put_parent(struct mdev_parent 
*parent)
 }
 
 static int mdev_device_create_ops(struct kobject *kobj,
- struct mdev_device *mdev)
+ struct mdev_device *mdev,
+ unsigned int instances)
 {
struct mdev_parent *parent = mdev->parent;
int ret;
 
-   ret = parent->ops->create(kobj, mdev);
+   if (instances > 1) {
+   ret = parent->ops->create_with_instances(kobj, mdev,
+instances);
+   } else
+   ret = parent->ops->create(kobj, mdev);
if (ret)
return ret;
 
@@ -276,7 +281,8 @@ static void mdev_device_release(struct device *dev)
kfree(mdev);
 }
 
-int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
+int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid,
+  unsigned int instances)
 {
int ret;
struct mdev_device *mdev, *tmp;
@@ -287,6 +293,12 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
if (!parent)
return -EINVAL;
 
+   if (instances > 1 &&
+   !parent->ops->create_with_instances) {
+   ret = -EINVAL;
+   goto mdev_fail;
+   }
+
mutex_lock(_list_lock);
 
/* Check for duplicate */
@@ -316,6 +328,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
mdev->dev.bus = _bus_type;
mdev->dev.release = mdev_device_release;
dev_set_name(>dev, "%pUl", uuid.b);
+   mdev->type_instances = instances;
 
ret = device_register(>dev);
if (ret) {
@@ -323,7 +336,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
goto mdev_fail;
}
 
-   ret = mdev_device_create_ops(kobj, mdev);
+   ret = mdev_device_create_ops(kobj, mdev, instances);
if (ret)
goto create_fail;
 
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index b5819b7d7ef7..e90d295d3927 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -33,6 +33,7 @@ struct mdev_device {
struct kref ref;
struct list_head next;
struct kobject *type_kobj;
+   unsigned int type_instances;
bool active;
 };
 
@@ -58,7 +59,8 @@ void parent_remove_sysfs_files(struct mdev_parent *parent);
 int  mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
 void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
 
-int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le 
uuid);
+int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid,
+   unsigned int instances);
 int  mdev_device_remove(struct device *dev, bool force_remove);
 
 #endif /* MDEV_PRIVATE_H */
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 249472f05509..aefed0c8891b 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -54,14 +54,21 @@ static const struct sysfs_ops mdev_type_sysfs_ops = {
 static ssize_t create_store(struct kobject *kobj, struct device *dev,
const char *buf, size_t count)
 {
-   char *str;
+   char *str, *param, *opt = NULL;
uuid_le uuid;
int ret;
+   unsigned int instances = 1;
 
-   if ((count < UUID_STRING_LEN) || (count > UUID_STRING_LEN + 1))
+   if (count < UUID_STRING_LEN)
return -EINVAL;
 
-   str = kstrndup(buf, count, GFP_KERNEL);
+   if

[libvirt] [PATCH v3 6/6] drm/i915/gvt: Add new type with aggregation support

2018-10-17 Thread Zhenyu Wang
New aggregation type is created for KVMGT which can be used
to combine minimal resource number for target instances, to create
user defined number of resources. For KVMGT, aggregated resource
is determined by memory and fence resource allocation for target
number of instances.

v2:
- apply for new hooks

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 drivers/gpu/drm/i915/gvt/gvt.h   | 11 +--
 drivers/gpu/drm/i915/gvt/kvmgt.c | 53 --
 drivers/gpu/drm/i915/gvt/vgpu.c  | 56 ++--
 3 files changed, 112 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index 31f6cdbe5c42..cb318079fa74 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -241,6 +241,9 @@ struct intel_vgpu {
 struct intel_gvt_gm {
unsigned long vgpu_allocated_low_gm_size;
unsigned long vgpu_allocated_high_gm_size;
+   unsigned long low_avail;
+   unsigned long high_avail;
+   unsigned long fence_avail;
 };
 
 struct intel_gvt_fence {
@@ -292,13 +295,15 @@ struct intel_gvt_firmware {
 
 #define NR_MAX_INTEL_VGPU_TYPES 20
 struct intel_vgpu_type {
-   char name[16];
+   const char *drv_name;
+   char name[32];
unsigned int avail_instance;
unsigned int low_gm_size;
unsigned int high_gm_size;
unsigned int fence;
unsigned int weight;
enum intel_vgpu_edid resolution;
+   unsigned int aggregation;
 };
 
 struct intel_gvt {
@@ -484,7 +489,7 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
 struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
 void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
 struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
-struct intel_vgpu_type *type);
+struct intel_vgpu_type *type, unsigned 
int);
 void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
 void intel_gvt_release_vgpu(struct intel_vgpu *vgpu);
 void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
@@ -563,7 +568,7 @@ struct intel_gvt_ops {
int (*emulate_mmio_write)(struct intel_vgpu *, u64, void *,
unsigned int);
struct intel_vgpu *(*vgpu_create)(struct intel_gvt *,
-   struct intel_vgpu_type *);
+ struct intel_vgpu_type *, unsigned 
int);
void (*vgpu_destroy)(struct intel_vgpu *vgpu);
void (*vgpu_release)(struct intel_vgpu *vgpu);
void (*vgpu_reset)(struct intel_vgpu *);
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index c1072143da1d..841ad5437c4a 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -501,7 +501,9 @@ static void kvmgt_put_vfio_device(void *vgpu)
vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device);
 }
 
-static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
+static int intel_vgpu_create_internal(struct kobject *kobj,
+ struct mdev_device *mdev,
+ unsigned int instances)
 {
struct intel_vgpu *vgpu = NULL;
struct intel_vgpu_type *type;
@@ -520,7 +522,14 @@ static int intel_vgpu_create(struct kobject *kobj, struct 
mdev_device *mdev)
goto out;
}
 
-   vgpu = intel_gvt_ops->vgpu_create(gvt, type);
+   if (instances > type->aggregation) {
+   gvt_vgpu_err("wrong aggregation specified for type %s\n",
+   kobject_name(kobj));
+   ret = -EINVAL;
+   goto out;
+   }
+
+   vgpu = intel_gvt_ops->vgpu_create(gvt, type, instances);
if (IS_ERR_OR_NULL(vgpu)) {
ret = vgpu == NULL ? -EFAULT : PTR_ERR(vgpu);
gvt_err("failed to create intel vgpu: %d\n", ret);
@@ -540,6 +549,44 @@ static int intel_vgpu_create(struct kobject *kobj, struct 
mdev_device *mdev)
return ret;
 }
 
+static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
+{
+   return intel_vgpu_create_internal(kobj, mdev, 1);
+}
+
+static int intel_vgpu_create_with_instances(struct kobject *kobj,
+   struct mdev_device *mdev,
+   unsigned int instances)
+{
+   return intel_vgpu_create_internal(kobj, mdev, instances);
+}
+
+static int intel_vgpu_max_aggregated_instances(struct kobject *kobj,
+  struct device *dev,
+  unsigned int *max)
+{
+   struct intel_vgpu_type *type;
+   struct intel_gvt *gvt;
+   int ret = 0;
+
+   gvt = kde

[libvirt] [PATCH v3 3/6] vfio/mdev: Add "aggregated_instances" attribute for supported mdev device

2018-10-17 Thread Zhenyu Wang
For mdev device created by "aggregate" parameter, this creates new mdev
device attribute "aggregated_instances" to show number of aggregated
instances allocated.

v2:
- change attribute name as "aggregated_instances"

v3:
- create only for aggregated allocation

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Cc: Cornelia Huck 
Signed-off-by: Zhenyu Wang 
---
 drivers/vfio/mdev/mdev_sysfs.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index a329d6ab6cb9..f03bdfbf5a42 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -292,7 +292,17 @@ static ssize_t remove_store(struct device *dev, struct 
device_attribute *attr,
return count;
 }
 
+static ssize_t
+aggregated_instances_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+   struct mdev_device *mdev = to_mdev_device(dev);
+   return sprintf(buf, "%u\n", mdev->type_instances);
+}
+
 static DEVICE_ATTR_WO(remove);
+static DEVICE_ATTR_RO(aggregated_instances);
 
 static const struct attribute *mdev_device_attrs[] = {
_attr_remove.attr,
@@ -301,6 +311,7 @@ static const struct attribute *mdev_device_attrs[] = {
 
 int  mdev_create_sysfs_files(struct device *dev, struct mdev_type *type)
 {
+   struct mdev_device *mdev = to_mdev_device(dev);
int ret;
 
ret = sysfs_create_link(type->devices_kobj, >kobj, dev_name(dev));
@@ -315,8 +326,17 @@ int  mdev_create_sysfs_files(struct device *dev, struct 
mdev_type *type)
if (ret)
goto create_files_failed;
 
+   if (mdev->type_instances > 1) {
+   ret = sysfs_create_file(>kobj,
+   _attr_aggregated_instances.attr);
+   if (ret)
+   goto create_aggregated_failed;
+   }
+
return ret;
 
+create_aggregated_failed:
+   sysfs_remove_files(>kobj, mdev_device_attrs);
 create_files_failed:
sysfs_remove_link(>kobj, "mdev_type");
 type_link_failed:
-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 0/6] VFIO mdev aggregated resources handling

2018-10-17 Thread Zhenyu Wang
Current mdev device create interface depends on fixed mdev type, which get uuid
from user to create instance of mdev device. If user wants to use customized
number of resource for mdev device, then only can create new mdev type for that
which may not be flexible. This requirement comes not only from to be able to
allocate flexible resources for KVMGT, but also from Intel scalable IO
virtualization which would use vfio/mdev to be able to allocate arbitrary
resources on mdev instance. More info on [1] [2] [3].

To allow to create user defined resources for mdev, it trys to extend mdev
create interface by adding new "aggregate=xxx" parameter following UUID, for
target mdev type if aggregation is supported, it can create new mdev device
which contains resources combined by number of instances, e.g

echo ",aggregate=10" > create

VM manager e.g libvirt can check mdev type with "aggregation" attribute which
can support this setting. If no "aggregation" attribute found for mdev type,
previous behavior is still kept for one instance allocation. And new sysfs
attribute "aggregated_instances" is created for each mdev device to show 
allocated number.

References:
[1] 
https://software.intel.com/en-us/download/intel-virtualization-technology-for-directed-io-architecture-specification
[2] 
https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification
  
[3] https://schd.ws/hosted_files/lc32018/00/LC3-SIOV-final.pdf

v2:
  - Add new create_with_instances driver hook
  - Update doc for new attributes

v3:
  - Rename parameter and attribute names from review
  - Make "aggregation" attribute to show maxium resource number
for aggregation
  - Check driver hooks for attribute create validation
  - Update doc and ABI spec

Zhenyu Wang (6):
  vfio/mdev: Add new "aggregate" parameter for mdev create
  vfio/mdev: Add "aggregation" attribute for supported mdev type
  vfio/mdev: Add "aggregated_instances" attribute for supported mdev
device
  Documentation/vfio-mediated-device.txt: Update for vfio/mdev
aggregation support
  Documentation/ABI/testing/sysfs-bus-vfio-mdev: Update for vfio/mdev
aggregation support
  drm/i915/gvt: Add new type with aggregation support

 Documentation/ABI/testing/sysfs-bus-vfio-mdev | 25 +++
 Documentation/vfio-mediated-device.txt| 44 +--
 drivers/gpu/drm/i915/gvt/gvt.h| 11 ++-
 drivers/gpu/drm/i915/gvt/kvmgt.c  | 53 -
 drivers/gpu/drm/i915/gvt/vgpu.c   | 56 +-
 drivers/vfio/mdev/mdev_core.c | 40 +-
 drivers/vfio/mdev/mdev_private.h  |  6 +-
 drivers/vfio/mdev/mdev_sysfs.c| 74 ++-
 include/linux/mdev.h  | 19 +
 9 files changed, 305 insertions(+), 23 deletions(-)

-- 
2.19.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 1/1] Add attribute single_usage_restriction for mdev type-id

2018-10-10 Thread Zhenyu Wang
On 2018.10.10 23:22:20 +, Tian, Kevin wrote:
> > From: Alex Williamson
> > Sent: Thursday, October 11, 2018 4:39 AM
> > 
> > On Tue, 9 Oct 2018 01:40:17 +0530
> > Kirti Wankhede  wrote:
> > 
> > > Generally a single instance of mdev device, a share of physical device, is
> > > assigned to user space application or a VM. There are cases when
> > multiple
> > > instances of mdev devices of same or different types are required by user
> > > space application or VM. For example in case of vGPU, multiple mdev
> > devices
> > > of type which represents whole GPU can be assigned to one instance of
> > > application or VM.
> > >
> > > All types of mdev devices may not support assigning multiple mdev
> > devices
> > > to a user space application. In that case vendor driver can fail open()
> > > call of mdev device. But there is no way to know User space application to
> > > about the configuration supported by vendor driver.
> > >
> > > To expose supported configuration, vendor driver should add
> > > 'single_usage_restriction' attribute to type-id directory. Returning Y for
> > > this attribute indicates vendor driver has restriction of single mdev
> > > device of particular  assigned to one user space application.
> > > Returning N indicates that multiple mdev devices of particular 
> > > can be assigned to one user space application.
> > >
> > > User space application should read if 'single_usage_restriction' attibute
> > > is present in  directory of all mdev devices which are going to 
> > > be
> > > used. If all read N then user space application can proceed with multiple
> > > mdev devices.
> > >
> > > This is optional and readonly attribute.
> > >
> > > Signed-off-by: Kirti Wankhede 
> > > Reviewed-by: Neo Jia 
> > > ---
> > >  Documentation/ABI/testing/sysfs-bus-vfio-mdev | 16 
> > >  1 file changed, 16 insertions(+)
> > >
> > > diff --git a/Documentation/ABI/testing/sysfs-bus-vfio-mdev
> > b/Documentation/ABI/testing/sysfs-bus-vfio-mdev
> > > index 452dbe39270e..3aca352a70e5 100644
> > > --- a/Documentation/ABI/testing/sysfs-bus-vfio-mdev
> > > +++ b/Documentation/ABI/testing/sysfs-bus-vfio-mdev
> > > @@ -85,6 +85,22 @@ Users:
> > >   a particular  that can help in understanding the
> > >   features provided by that type of mediated device.
> > >
> > > +What:/sys/.../mdev_supported_types/ > id>/single_usage_restriction
> > > +Date:   October 2018
> > > +Contact:Kirti Wankhede 
> > > +Description:
> > > + Reading this attribute will return Y or N. Returning Y
> > indicates
> > > + vendor driver has restriction of single mdev device of this
> > > + particular  assigned to one user space application.
> > > + Returning N indicates that multiple mdev devices of
> > particular
> > > +  can be assigned to one user space application.
> > > + This is optional and readonly attribute.
> > > +Users:
> > > + User space application should read if
> > 'single_usage_restriction'
> > > + attibute is present in  directory of all mdev devices
> > > + which are going to be used. If all read N then user space
> > > + application can proceed with multiple mdev devices.
> > 
> > But we don't say what userspace should do when this optional attribute
> > is not present.  Do we know of any cases other than the NVIDIA GRID
> > vGPU drivers that have this restriction?  Intel folks, are multiple
> > GVT-g mdevs currently allowed in a VM?  I don't think the libvirt
> > algorithm is going to be as simple as suggested here and we should
> > probably understand what it really needs to be.
> 
> technically I don't see a restriction in GVT-g side, i.e. multiple GVT-g
> mdevs can be assigned to same VM. But the fact is that Intel GPU is 
> integrated thus just one per platform. Then guest i915 driver may have 
> problem to operate multiple vGPUs if with some assumption on integrated
> part. I don't think we verified such configuration. Zhenyu?
>

yeah, as current intel gpu is single device, even guest i915 driver could
operate but user space gfx driver is not ready for multiple devices, so won't
be useful now.

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 0/4] New mdev type handling for aggregated resources

2018-10-07 Thread Zhenyu Wang
On 2018.10.08 03:19:25 +, Tian, Kevin wrote:
> Hi, Zhenyu,
> 
> curious about the progress of this series. Is there still some open remaining
> or a new version coming soon?
> 

I had new version almost ready before my vacation, planned to send after be 
back.
So will refresh this later. Sorry for any delay as was trying to close several
gvt issues.

Thanks.

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 0/4] New mdev type handling for aggregated resources

2018-07-29 Thread Zhenyu Wang
On 2018.07.27 16:45:55 +0200, Erik Skultety wrote:
> On Thu, Jul 26, 2018 at 06:04:10PM +0200, Cornelia Huck wrote:
> > On Thu, 26 Jul 2018 17:43:45 +0200
> > Erik Skultety  wrote:
> >
> > > On Thu, Jul 26, 2018 at 05:30:07PM +0200, Cornelia Huck wrote:
> > > > One thing I noticed is that we have seem to have an optional (?)
> > > > vendor-driver created "aggregation" attribute (which always prints
> > > > "true" in the Intel driver). Would it be better or worse for libvirt if
> > > > it contained some kind of upper boundary or so? Additionally, would it
> > >
> > > Can you be more specific? Although, I wouldn't argue against data that 
> > > conveys
> > > some information, since I would treat the mere presence of the optional
> > > attribute as a supported feature that we can expose. Therefore, additional
> > > *structured* data which sets clear limits to a certain feature is only a 
> > > plus
> > > that we can expose to the users/management layer.
> >
> > My question is what would be easiest for libvirt:
> >
> > - "aggregation" attribute only present when driver supports aggregation
> >   (possibly containing max number of resources to be aggregated)
> > - "aggregation" attribute always present; contains '1' if driver does
> >   not support aggregation and 'm' if driver can aggregate 'm' resources
> 
> Both are fine from libvirt's POV, but IMHO the former makes a bit more sense
> and I'm in favour of that one, IOW the presence of an attribute denotes a new
> functionality which we can report, if it's missing, the feature is clearly
> lacking- I don't think we (libvirt) should be reporting the value 1 explicitly
> in the XML if the feature is missing, we can assume 1 as the default.
> 

Good I'll adhere to that, thanks!

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 4/4] Documentation/vfio-mediated-device.txt: update for aggregation attribute

2018-07-26 Thread Zhenyu Wang
On 2018.07.26 17:46:40 +0200, Cornelia Huck wrote:
> On Fri, 20 Jul 2018 10:19:28 +0800
> Zhenyu Wang  wrote:
> 
> > Update mdev doc on new aggregration attribute and instances attribute
> > for mdev.
> > 
> > Cc: Kirti Wankhede 
> > Cc: Alex Williamson 
> > Cc: Kevin Tian 
> > Signed-off-by: Zhenyu Wang 
> > ---
> >  Documentation/vfio-mediated-device.txt | 39 ++
> >  1 file changed, 33 insertions(+), 6 deletions(-)
> > 
> > diff --git a/Documentation/vfio-mediated-device.txt 
> > b/Documentation/vfio-mediated-device.txt
> > index c3f69bcaf96e..9ec9495dcbe7 100644
> > --- a/Documentation/vfio-mediated-device.txt
> > +++ b/Documentation/vfio-mediated-device.txt
> > @@ -211,12 +211,20 @@ Directories and files under the sysfs for Each 
> > Physical Device
> >| |   |--- description
> >| |   |--- [devices]
> >| |--- []
> > -  |  |--- create
> > -  |  |--- name
> > -  |  |--- available_instances
> > -  |  |--- device_api
> > -  |  |--- description
> > -  |  |--- [devices]
> > +  | ||--- create
> > +  | ||--- name
> > +  | ||--- available_instances
> > +  | ||--- device_api
> > +  | ||--- description
> > +  | ||--- [devices]
> > +  | |--- []
> > +  | ||--- create
> > +  | ||--- name
> > +  | ||--- available_instances
> > +  | ||--- device_api
> > +  | ||--- description
> > +  | ||--- 
> > +  | ||--- [devices]
> >  
> >  * [mdev_supported_types]
> >  
> > @@ -260,6 +268,19 @@ Directories and files under the sysfs for Each 
> > Physical Device
> >This attribute should show brief features/description of the type. This 
> > is
> >optional attribute.
> >  
> > +* 
> > +
> > +  The description is to show feature for one instance of the type. 
> > 
> 
> You are talking about "one instance" here. Can this be different for
> the same type with different physical devices?
>

I would expect for normal mdev types, driver might expose like x2, x4, x8 types
which split hw resource equally. But for type with aggregation feature, it can
set user wanted number of instances. Sorry maybe my use of word was not clear, 
how
about "one example of type"?

> > +  is an optional attributes to show that []'s instances can be
> > +  aggregated to be assigned for one mdev device. Set number of instances by
> > +  appending "instances=N" parameter for create. Instances number can't 
> > exceed
> > +  available_instances number. Without "instances=N" parameter will be 
> > default
> > +  one instance to create.
> 
> Could there be a case where available_instances is n, but aggregation
> is only supported for a value m < n? If yes, should m be discoverable
> via the "aggregation" attribute?
>

I don't think there could be a case for that. As for aggregation type,
it represents minimal resource allocated for a singleton, I can't see
any reason for possible m < n.

Thanks.

> > +
> > +Example::
> > +
> > +   # echo ",instances=N" > create
> > +
> >  Directories and Files Under the sysfs for Each mdev Device
> >  --
> >  
> > @@ -268,6 +289,7 @@ Directories and Files Under the sysfs for Each mdev 
> > Device
> >|- [parent phy device]
> >|--- [$MDEV_UUID]
> >   |--- remove
> > +|--- instances
> >   |--- mdev_type {link to its type}
> >   |--- vendor-specific-attributes [optional]
> >  
> > @@ -281,6 +303,11 @@ Example::
> >  
> > # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove
> >  
> > +* instances
> > +
> > +For aggregation type show number of instances assigned for this mdev. For 
> > normal
> > +type or default will just show one instance.
> > +
> >  Mediated device Hot plug
> >  
> >  
> 

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 0/4] New mdev type handling for aggregated resources

2018-07-26 Thread Zhenyu Wang
On 2018.07.24 11:44:40 -0600, Alex Williamson wrote:
> On Fri, 20 Jul 2018 10:19:24 +0800
> Zhenyu Wang  wrote:
> 
> > Current mdev device create interface depends on fixed mdev type, which get 
> > uuid
> > from user to create instance of mdev device. If user wants to use customized
> > number of resource for mdev device, then only can create new mdev type for 
> > that
> > which may not be flexible. This requirement comes not only from to be able 
> > to
> > allocate flexible resources for KVMGT, but also from Intel scalable IO
> > virtualization which would use vfio/mdev to be able to allocate arbitrary
> > resources on mdev instance. More info on [1] [2] [3].
> > 
> > To allow to create user defined resources for mdev, it trys to extend mdev
> > create interface by adding new "instances=xxx" parameter following uuid, for
> > target mdev type if aggregation is supported, it can create new mdev device
> > which contains resources combined by number of instances, e.g
> > 
> > echo ",instances=10" > create
> > 
> > VM manager e.g libvirt can check mdev type with "aggregation" attribute 
> > which
> > can support this setting. If no "aggregation" attribute found for mdev type,
> > previous behavior is still kept for one instance allocation. And new sysfs
> > attribute "instances" is created for each mdev device to show allocated 
> > number.
> > 
> > This trys to create new KVMGT type with minimal vGPU resources which can be
> > combined with "instances=x" setting to allocate for user wanted resources.
> 
> "instances" makes me think this is arg helps to create multiple mdev
> instances rather than consuming multiple instances for a single mdev.
> You're already exposing the "aggregation" attribute, so doesn't
> "aggregate" perhaps make more sense as the create option?  We're asking
> the driver to aggregate $NUM instances into a single mdev.  The mdev
> attribute should then perhaps also be "aggregated_instances".

yeah that seems better.

> 
> The next user question for the interface might be what aspect of the
> device gets multiplied by this aggregation?  In i915 I see you're
> multiplying the memory sizes by the instance, but clearly the
> resolution doesn't change.  I assume this is sort of like mdev types
> themselves, ie. some degree of what a type means is buried in the
> implementation and some degree of what some number of those types
> aggregated together means is impossible to describe generically.
>

yeah, the purpose was to increase memory resource only, but due to current
free formatted 'description', can't have a meaningful expression for that,
and not sure if libvirt likes to understand vendor specific behavior e.g
for intel vGPU?

> We're also going to need to add aggregation to the checklist for device
> compatibility for migration, for example 1) is it the same mdev_type,
> 1a) are the aggregation counts the same (new), 2) is the host driver
> compatible (TBD).
>

Right, will check with Zhi on that.

> The count handling in create_store(), particularly MDEV_CREATE_OPT_LEN
> looks a little suspicious.  I think we should just be validating that
> the string before the ',' or the entire string if there is no comma is
> UUID length.  Pass only that to uuid_le_to_bin().  We can then strncmp
> as you have for "instances=" (or "aggregate=") but then let's be sure
> to end the string we pass to kstrtouint(), ie. assume there could be
> further args.

Original purpose was to limit the length of string to accept, but can take
this way without issue I think.

> 
> Documentation/ABI/testing/sysfs-bus-vfio-mdev also needs to be updated
> with this series.

Ok.

Thanks

> 
> I'm curious what libvirt folks and Kirti think of this, it looks like
> it has a nice degree of backwards compatibility, both in the sysfs
> interface and the vendor driver interface.  Thanks,
> 
> Alex

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 0/4] New mdev type handling for aggregated resources

2018-07-19 Thread Zhenyu Wang
Current mdev device create interface depends on fixed mdev type, which get uuid
from user to create instance of mdev device. If user wants to use customized
number of resource for mdev device, then only can create new mdev type for that
which may not be flexible. This requirement comes not only from to be able to
allocate flexible resources for KVMGT, but also from Intel scalable IO
virtualization which would use vfio/mdev to be able to allocate arbitrary
resources on mdev instance. More info on [1] [2] [3].

To allow to create user defined resources for mdev, it trys to extend mdev
create interface by adding new "instances=xxx" parameter following uuid, for
target mdev type if aggregation is supported, it can create new mdev device
which contains resources combined by number of instances, e.g

echo ",instances=10" > create

VM manager e.g libvirt can check mdev type with "aggregation" attribute which
can support this setting. If no "aggregation" attribute found for mdev type,
previous behavior is still kept for one instance allocation. And new sysfs
attribute "instances" is created for each mdev device to show allocated number.

This trys to create new KVMGT type with minimal vGPU resources which can be
combined with "instances=x" setting to allocate for user wanted resources.

References:
[1] 
https://software.intel.com/en-us/download/intel-virtualization-technology-for-directed-io-architecture-specification
[2] 
https://software.intel.com/en-us/download/intel-scalable-io-virtualization-technical-specification
[3] https://schd.ws/hosted_files/lc32018/00/LC3-SIOV-final.pdf  

v2:
  - Add new create_with_instances driver hook
  - Update doc for new attributes

Zhenyu Wang (4):
  vfio/mdev: Add new instances parameter for mdev create
  vfio/mdev: Add mdev device instances attribute
  drm/i915/gvt: Add new aggregation type support
  Documentation/vfio-mediated-device.txt: update for aggregation
attribute

 Documentation/vfio-mediated-device.txt | 39 +++---
 drivers/gpu/drm/i915/gvt/gvt.c | 26 +---
 drivers/gpu/drm/i915/gvt/gvt.h | 14 ---
 drivers/gpu/drm/i915/gvt/kvmgt.c   | 30 +++---
 drivers/gpu/drm/i915/gvt/vgpu.c| 56 ++
 drivers/vfio/mdev/mdev_core.c  | 19 +++--
 drivers/vfio/mdev/mdev_private.h   |  6 ++-
 drivers/vfio/mdev/mdev_sysfs.c | 42 ---
 include/linux/mdev.h   | 10 +
 9 files changed, 203 insertions(+), 39 deletions(-)

-- 
2.18.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 2/4] vfio/mdev: Add mdev device instances attribute

2018-07-19 Thread Zhenyu Wang
For mdev device, create new sysfs attribute "instances" to show
number of instances allocated for possible aggregation type.
For compatibility default or without aggregated allocation, the
number is 1.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Signed-off-by: Zhenyu Wang 
---
 drivers/vfio/mdev/mdev_core.c| 1 +
 drivers/vfio/mdev/mdev_private.h | 1 +
 drivers/vfio/mdev/mdev_sysfs.c   | 8 
 3 files changed, 10 insertions(+)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index e69db302a4f2..f0478fc372d8 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -326,6 +326,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid,
mdev->dev.bus = _bus_type;
mdev->dev.release = mdev_device_release;
dev_set_name(>dev, "%pUl", uuid.b);
+   mdev->type_instances = instances;
 
ret = device_register(>dev);
if (ret) {
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index c9d3fe04e273..aa0b4b64c503 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -33,6 +33,7 @@ struct mdev_device {
struct kref ref;
struct list_head next;
struct kobject *type_kobj;
+   unsigned int type_instances;
bool active;
 };
 
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index a06e5b7c69d3..5a417a20e774 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -268,10 +268,18 @@ static ssize_t remove_store(struct device *dev, struct 
device_attribute *attr,
return count;
 }
 
+static ssize_t instances_show(struct device *dev, struct device_attribute 
*attr, char *buf)
+{
+   struct mdev_device *mdev = to_mdev_device(dev);
+   return sprintf(buf, "%u\n", mdev->type_instances);
+}
+
 static DEVICE_ATTR_WO(remove);
+static DEVICE_ATTR_RO(instances);
 
 static const struct attribute *mdev_device_attrs[] = {
_attr_remove.attr,
+   _attr_instances.attr,
NULL,
 };
 
-- 
2.18.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 3/4] drm/i915/gvt: Add new aggregation type support

2018-07-19 Thread Zhenyu Wang
New aggregation type is created for KVMGT which can be used
with new mdev create "instances=xxx" parameter to combine
minimal resource number for target instances, which can create
user defined number of resources. For KVMGT, aggregated resource
is determined by memory and fence resource allocation for target
number of instances.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Signed-off-by: Zhenyu Wang 
---
 drivers/gpu/drm/i915/gvt/gvt.c   | 26 ---
 drivers/gpu/drm/i915/gvt/gvt.h   | 14 +---
 drivers/gpu/drm/i915/gvt/kvmgt.c | 30 ++---
 drivers/gpu/drm/i915/gvt/vgpu.c  | 56 
 4 files changed, 104 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index 712f9d14e720..21600447b029 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -57,7 +57,7 @@ static struct intel_vgpu_type 
*intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
for (i = 0; i < gvt->num_types; i++) {
t = >types[i];
if (!strncmp(t->name, name + strlen(driver_name) + 1,
-   sizeof(t->name)))
+   strlen(t->name)))
return t;
}
 
@@ -105,9 +105,16 @@ static ssize_t description_show(struct kobject *kobj, 
struct device *dev,
   type->weight);
 }
 
+static ssize_t aggregation_show(struct kobject *kobj, struct device *dev,
+   char *buf)
+{
+   return sprintf(buf, "%s\n", "true");
+}
+
 static MDEV_TYPE_ATTR_RO(available_instances);
 static MDEV_TYPE_ATTR_RO(device_api);
 static MDEV_TYPE_ATTR_RO(description);
+static MDEV_TYPE_ATTR_RO(aggregation);
 
 static struct attribute *gvt_type_attrs[] = {
_type_attr_available_instances.attr,
@@ -116,14 +123,20 @@ static struct attribute *gvt_type_attrs[] = {
NULL,
 };
 
+static struct attribute *gvt_type_aggregate_attrs[] = {
+   _type_attr_available_instances.attr,
+   _type_attr_device_api.attr,
+   _type_attr_description.attr,
+   _type_attr_aggregation.attr,
+   NULL,
+};
+
 static struct attribute_group *gvt_vgpu_type_groups[] = {
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
 };
 
-static bool intel_get_gvt_attrs(struct attribute ***type_attrs,
-   struct attribute_group ***intel_vgpu_type_groups)
+static bool intel_get_gvt_attrs(struct attribute_group 
***intel_vgpu_type_groups)
 {
-   *type_attrs = gvt_type_attrs;
*intel_vgpu_type_groups = gvt_vgpu_type_groups;
return true;
 }
@@ -142,7 +155,10 @@ static bool intel_gvt_init_vgpu_type_groups(struct 
intel_gvt *gvt)
goto unwind;
 
group->name = type->name;
-   group->attrs = gvt_type_attrs;
+   if (type->aggregation)
+   group->attrs = gvt_type_aggregate_attrs;
+   else
+   group->attrs = gvt_type_attrs;
gvt_vgpu_type_groups[i] = group;
}
 
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index 9a9671522774..8848587f638f 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -241,6 +241,9 @@ struct intel_vgpu {
 struct intel_gvt_gm {
unsigned long vgpu_allocated_low_gm_size;
unsigned long vgpu_allocated_high_gm_size;
+   unsigned long low_avail;
+   unsigned long high_avail;
+   unsigned long fence_avail;
 };
 
 struct intel_gvt_fence {
@@ -292,13 +295,14 @@ struct intel_gvt_firmware {
 
 #define NR_MAX_INTEL_VGPU_TYPES 20
 struct intel_vgpu_type {
-   char name[16];
+   char name[32];
unsigned int avail_instance;
unsigned int low_gm_size;
unsigned int high_gm_size;
unsigned int fence;
unsigned int weight;
enum intel_vgpu_edid resolution;
+   bool aggregation;  /* fine-grained resource type with aggregation 
capability */
 };
 
 struct intel_gvt {
@@ -484,7 +488,8 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
 struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
 void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
 struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
-struct intel_vgpu_type *type);
+struct intel_vgpu_type *type,
+unsigned int);
 void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
 void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
 unsigned int engine_mask);
@@ -562,15 +567,14 @@ struct intel_gvt_ops {
int (*emulate_mmio_write)(struct intel_vgpu *, u64, void *,
unsigned int);
struct intel_vgpu *(*vgpu_create)(struc

[libvirt] [PATCH v2 1/4] vfio/mdev: Add new instances parameter for mdev create

2018-07-19 Thread Zhenyu Wang
For special mdev type which can aggregate instances for mdev device,
this extends mdev create interface by allowing extra "instances=xxx"
parameter, which is passed to mdev device model to be able to create
arbitrary bundled number of instances for target mdev device.

v2: create new create_with_instances operator for vendor driver

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Signed-off-by: Zhenyu Wang 
---
 drivers/vfio/mdev/mdev_core.c| 18 +
 drivers/vfio/mdev/mdev_private.h |  5 -
 drivers/vfio/mdev/mdev_sysfs.c   | 34 ++--
 include/linux/mdev.h | 10 ++
 4 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 0212f0ee8aea..e69db302a4f2 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -104,12 +104,16 @@ static inline void mdev_put_parent(struct mdev_parent 
*parent)
 }
 
 static int mdev_device_create_ops(struct kobject *kobj,
- struct mdev_device *mdev)
+ struct mdev_device *mdev,
+ unsigned int instances)
 {
struct mdev_parent *parent = mdev->parent;
int ret;
 
-   ret = parent->ops->create(kobj, mdev);
+   if (instances > 1)
+   ret = parent->ops->create_with_instances(kobj, mdev, instances);
+   else
+   ret = parent->ops->create(kobj, mdev);
if (ret)
return ret;
 
@@ -276,7 +280,8 @@ static void mdev_device_release(struct device *dev)
kfree(mdev);
 }
 
-int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
+int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid,
+  unsigned int instances)
 {
int ret;
struct mdev_device *mdev, *tmp;
@@ -287,6 +292,11 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
if (!parent)
return -EINVAL;
 
+   if (instances > 1 && !parent->ops->create_with_instances) {
+   ret = -EINVAL;
+   goto mdev_fail;
+   }
+
mutex_lock(_list_lock);
 
/* Check for duplicate */
@@ -323,7 +333,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
goto mdev_fail;
}
 
-   ret = mdev_device_create_ops(kobj, mdev);
+   ret = mdev_device_create_ops(kobj, mdev, instances);
if (ret)
goto create_fail;
 
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index b5819b7d7ef7..c9d3fe04e273 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -52,13 +52,16 @@ struct mdev_type {
 #define to_mdev_type(_kobj)\
container_of(_kobj, struct mdev_type, kobj)
 
+#define MDEV_CREATE_OPT_LEN 32
+
 int  parent_create_sysfs_files(struct mdev_parent *parent);
 void parent_remove_sysfs_files(struct mdev_parent *parent);
 
 int  mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
 void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
 
-int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le 
uuid);
+int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid,
+   unsigned int instances);
 int  mdev_device_remove(struct device *dev, bool force_remove);
 
 #endif /* MDEV_PRIVATE_H */
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 249472f05509..a06e5b7c69d3 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -54,11 +54,15 @@ static const struct sysfs_ops mdev_type_sysfs_ops = {
 static ssize_t create_store(struct kobject *kobj, struct device *dev,
const char *buf, size_t count)
 {
-   char *str;
+   char *str, *opt = NULL;
uuid_le uuid;
int ret;
+   unsigned int instances = 1;
 
-   if ((count < UUID_STRING_LEN) || (count > UUID_STRING_LEN + 1))
+   if (count < UUID_STRING_LEN)
+   return -EINVAL;
+
+   if (count > UUID_STRING_LEN + 1 + MDEV_CREATE_OPT_LEN)
return -EINVAL;
 
str = kstrndup(buf, count, GFP_KERNEL);
@@ -66,13 +70,31 @@ static ssize_t create_store(struct kobject *kobj, struct 
device *dev,
return -ENOMEM;
 
ret = uuid_le_to_bin(str, );
-   kfree(str);
-   if (ret)
+   if (ret) {
+   kfree(str);
return ret;
+   }
 
-   ret = mdev_device_create(kobj, dev, uuid);
-   if (ret)
+   if (count > UUID_STRING_LEN + 1) {
+   opt = str + UUID_STRING_LEN;
+   if (*opt++ != ',' ||
+   strncmp(opt, "instances=", 10)) 

[libvirt] [PATCH v2 4/4] Documentation/vfio-mediated-device.txt: update for aggregation attribute

2018-07-19 Thread Zhenyu Wang
Update mdev doc on new aggregration attribute and instances attribute
for mdev.

Cc: Kirti Wankhede 
Cc: Alex Williamson 
Cc: Kevin Tian 
Signed-off-by: Zhenyu Wang 
---
 Documentation/vfio-mediated-device.txt | 39 ++
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/Documentation/vfio-mediated-device.txt 
b/Documentation/vfio-mediated-device.txt
index c3f69bcaf96e..9ec9495dcbe7 100644
--- a/Documentation/vfio-mediated-device.txt
+++ b/Documentation/vfio-mediated-device.txt
@@ -211,12 +211,20 @@ Directories and files under the sysfs for Each Physical 
Device
   | |   |--- description
   | |   |--- [devices]
   | |--- []
-  |  |--- create
-  |  |--- name
-  |  |--- available_instances
-  |  |--- device_api
-  |  |--- description
-  |  |--- [devices]
+  | ||--- create
+  | ||--- name
+  | ||--- available_instances
+  | ||--- device_api
+  | ||--- description
+  | ||--- [devices]
+  | |--- []
+  | ||--- create
+  | ||--- name
+  | ||--- available_instances
+  | ||--- device_api
+  | ||--- description
+  | ||--- 
+  | ||--- [devices]
 
 * [mdev_supported_types]
 
@@ -260,6 +268,19 @@ Directories and files under the sysfs for Each Physical 
Device
   This attribute should show brief features/description of the type. This is
   optional attribute.
 
+* 
+
+  The description is to show feature for one instance of the type. 

+  is an optional attributes to show that []'s instances can be
+  aggregated to be assigned for one mdev device. Set number of instances by
+  appending "instances=N" parameter for create. Instances number can't exceed
+  available_instances number. Without "instances=N" parameter will be default
+  one instance to create.
+
+Example::
+
+   # echo ",instances=N" > create
+
 Directories and Files Under the sysfs for Each mdev Device
 --
 
@@ -268,6 +289,7 @@ Directories and Files Under the sysfs for Each mdev Device
   |- [parent phy device]
   |--- [$MDEV_UUID]
  |--- remove
+|--- instances
  |--- mdev_type {link to its type}
  |--- vendor-specific-attributes [optional]
 
@@ -281,6 +303,11 @@ Example::
 
# echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove
 
+* instances
+
+For aggregation type show number of instances assigned for this mdev. For 
normal
+type or default will just show one instance.
+
 Mediated device Hot plug
 
 
-- 
2.18.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH 0/2] Add new mdev type for aggregated resources

2018-06-22 Thread Zhenyu Wang
On 2018.06.21 09:00:28 -0600, Alex Williamson wrote:
> On Thu, 21 Jun 2018 19:57:38 +0530
> Kirti Wankhede  wrote:
> 
> > On 6/20/2018 1:10 PM, Zhenyu Wang wrote:
> > > Current mdev device create interface depends on fixed mdev type, which 
> > > get uuid
> > > from user to create instance of mdev device. If user wants to use 
> > > customized
> > > number of resource for mdev device, then only can create new mdev type 
> > > for that
> > > which may not be flexible.
> > > 
> > > To allow to create user defined resources for mdev, this RFC trys
> > > to extend mdev create interface by adding new "instances=xxx" parameter
> > > following uuid, for target mdev type if aggregation is supported, it can
> > > create new mdev device which contains resources combined by number of
> > > instances, e.g
> > > 
> > > echo ",instances=10" > create  
> > 
> > This seems orthogonal to the way mdev types are meant to be used. Vendor
> > driver can provide the possible types to provide flexibility to the users.
> 
> I think the goal here is to define how we create a type that supports
> arbitrary combinations of resources where the total number of those
> resources my be sufficiently large that the parent driver enumerating
> them all is not feasible.
> 
> > Secondly, not always all resources defined for a particular mdev type
> > can be multiplied, for example, a mdev type for vGPU that supports 2
> > heads, that can't be multiplied to use with 20 heads.

yeah, for vGPU we actually can have flexible config for memory size but
currently fixed by type definition. Although like for display config, we
are just sticking with 1 head config even for aggregate type.

> 
> Not all types need to define themselves this way, aiui this is an
> optional extension.  Userspace can determine if this feature is
> available with the new attribute and if they're not aware of the new
> attribute, we operate in a backwards compatible mode where 'echo $UUID >
> create' consumes one instance of that type.  Mdev, like vfio, is device
> agnostic, so while a vGPU example may have scaling issues that need to
> be ironed out to implement this, those don't immediately negate the
> value of this proposal.  Thanks,
> 

yep, backward compatible is always ensured by this, so for no
aggregation attrib type, still keep current behavior, driver should
refuse "instances=" if set by user. One thing I'm concern is that
looks currently without changing mdev create ops interface, can't
carry that option for driver, or should we do with more general parameter?

thanks

> 
> > > VM manager e.g libvirt can check mdev type with "aggregation" attribute
> > > which can support this setting. And new sysfs attribute "instances" is
> > > created for each mdev device to show allocated number. Default number
> > > of 1 or no "instances" file can be used for compatibility check.
> > > 
> > > This RFC trys to create new KVMGT type with minimal vGPU resources which
> > > can be combined with "instances=x" setting to allocate for user wanted 
> > > resources.
> > > 
> > > Zhenyu Wang (2):
> > >   vfio/mdev: Add new instances parameters for mdev create
> > >   drm/i915/gvt: Add new aggregation type
> > > 
> > >  drivers/gpu/drm/i915/gvt/gvt.c   | 26 ---
> > >  drivers/gpu/drm/i915/gvt/gvt.h   | 14 +---
> > >  drivers/gpu/drm/i915/gvt/kvmgt.c |  9 +++--
> > >  drivers/gpu/drm/i915/gvt/vgpu.c  | 56 
> > >  drivers/s390/cio/vfio_ccw_ops.c  |  3 +-
> > >  drivers/vfio/mdev/mdev_core.c| 11 ---
> > >  drivers/vfio/mdev/mdev_private.h |  6 +++-
> > >  drivers/vfio/mdev/mdev_sysfs.c   | 42 
> > >  include/linux/mdev.h |  3 +-
> > >  samples/vfio-mdev/mbochs.c   |  3 +-
> > >  samples/vfio-mdev/mdpy.c |  3 +-
> > >  samples/vfio-mdev/mtty.c |  3 +-
> > >  12 files changed, 141 insertions(+), 38 deletions(-)
> > >   
> 

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [RFC PATCH 2/2] drm/i915/gvt: Add new aggregation type

2018-06-20 Thread Zhenyu Wang
New aggregation type is created for KVMGT which can be used with
new mdev create "instances=xxx" parameter to combine minimal resource
number for target instances, which can create user defined number
of resources.

User space checks whether there's "aggregation" attribute for mdev
type and "instances" parameter can't be larger than "avail_instances".

Cc: Alex Williamson 
Cc: Kirti Wankhede 
Signed-off-by: Zhenyu Wang 
---
 drivers/gpu/drm/i915/gvt/gvt.c   | 26 ---
 drivers/gpu/drm/i915/gvt/gvt.h   | 14 +---
 drivers/gpu/drm/i915/gvt/kvmgt.c |  6 ++--
 drivers/gpu/drm/i915/gvt/vgpu.c  | 56 
 4 files changed, 81 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c
index 4e65266e7b95..ae90bd368b3f 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.c
+++ b/drivers/gpu/drm/i915/gvt/gvt.c
@@ -57,7 +57,7 @@ static struct intel_vgpu_type 
*intel_gvt_find_vgpu_type(struct intel_gvt *gvt,
for (i = 0; i < gvt->num_types; i++) {
t = >types[i];
if (!strncmp(t->name, name + strlen(driver_name) + 1,
-   sizeof(t->name)))
+   strlen(t->name)))
return t;
}
 
@@ -105,9 +105,16 @@ static ssize_t description_show(struct kobject *kobj, 
struct device *dev,
   type->weight);
 }
 
+static ssize_t aggregation_show(struct kobject *kobj, struct device *dev,
+   char *buf)
+{
+   return sprintf(buf, "%s\n", "true");
+}
+
 static MDEV_TYPE_ATTR_RO(available_instances);
 static MDEV_TYPE_ATTR_RO(device_api);
 static MDEV_TYPE_ATTR_RO(description);
+static MDEV_TYPE_ATTR_RO(aggregation);
 
 static struct attribute *gvt_type_attrs[] = {
_type_attr_available_instances.attr,
@@ -116,14 +123,20 @@ static struct attribute *gvt_type_attrs[] = {
NULL,
 };
 
+static struct attribute *gvt_type_aggregate_attrs[] = {
+   _type_attr_available_instances.attr,
+   _type_attr_device_api.attr,
+   _type_attr_description.attr,
+   _type_attr_aggregation.attr,
+   NULL,
+};
+
 static struct attribute_group *gvt_vgpu_type_groups[] = {
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
 };
 
-static bool intel_get_gvt_attrs(struct attribute ***type_attrs,
-   struct attribute_group ***intel_vgpu_type_groups)
+static bool intel_get_gvt_attrs(struct attribute_group 
***intel_vgpu_type_groups)
 {
-   *type_attrs = gvt_type_attrs;
*intel_vgpu_type_groups = gvt_vgpu_type_groups;
return true;
 }
@@ -142,7 +155,10 @@ static bool intel_gvt_init_vgpu_type_groups(struct 
intel_gvt *gvt)
goto unwind;
 
group->name = type->name;
-   group->attrs = gvt_type_attrs;
+   if (type->aggregation)
+   group->attrs = gvt_type_aggregate_attrs;
+   else
+   group->attrs = gvt_type_attrs;
gvt_vgpu_type_groups[i] = group;
}
 
diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h
index de2a3a2580be..c0320b95804c 100644
--- a/drivers/gpu/drm/i915/gvt/gvt.h
+++ b/drivers/gpu/drm/i915/gvt/gvt.h
@@ -241,6 +241,9 @@ struct intel_vgpu {
 struct intel_gvt_gm {
unsigned long vgpu_allocated_low_gm_size;
unsigned long vgpu_allocated_high_gm_size;
+   unsigned long low_avail;
+   unsigned long high_avail;
+   unsigned long fence_avail;
 };
 
 struct intel_gvt_fence {
@@ -290,13 +293,14 @@ struct intel_gvt_firmware {
 
 #define NR_MAX_INTEL_VGPU_TYPES 20
 struct intel_vgpu_type {
-   char name[16];
+   char name[32];
unsigned int avail_instance;
unsigned int low_gm_size;
unsigned int high_gm_size;
unsigned int fence;
unsigned int weight;
enum intel_vgpu_edid resolution;
+   bool aggregation;  /* fine-grained resource type with aggregation 
capability */
 };
 
 struct intel_gvt {
@@ -482,7 +486,8 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
 struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
 void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
 struct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt,
-struct intel_vgpu_type *type);
+struct intel_vgpu_type *type,
+unsigned int);
 void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
 void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
 unsigned int engine_mask);
@@ -560,15 +565,14 @@ struct intel_gvt_ops {
int (*emulate_mmio_write)(struct intel_vgpu *, u64, void *,
unsigned int);
struct in

[libvirt] [RFC PATCH 0/2] Add new mdev type for aggregated resources

2018-06-20 Thread Zhenyu Wang
Current mdev device create interface depends on fixed mdev type, which get uuid
from user to create instance of mdev device. If user wants to use customized
number of resource for mdev device, then only can create new mdev type for that
which may not be flexible.

To allow to create user defined resources for mdev, this RFC trys
to extend mdev create interface by adding new "instances=xxx" parameter
following uuid, for target mdev type if aggregation is supported, it can
create new mdev device which contains resources combined by number of
instances, e.g

echo ",instances=10" > create

VM manager e.g libvirt can check mdev type with "aggregation" attribute
which can support this setting. And new sysfs attribute "instances" is
created for each mdev device to show allocated number. Default number
of 1 or no "instances" file can be used for compatibility check.

This RFC trys to create new KVMGT type with minimal vGPU resources which
can be combined with "instances=x" setting to allocate for user wanted 
resources.

Zhenyu Wang (2):
  vfio/mdev: Add new instances parameters for mdev create
  drm/i915/gvt: Add new aggregation type

 drivers/gpu/drm/i915/gvt/gvt.c   | 26 ---
 drivers/gpu/drm/i915/gvt/gvt.h   | 14 +---
 drivers/gpu/drm/i915/gvt/kvmgt.c |  9 +++--
 drivers/gpu/drm/i915/gvt/vgpu.c  | 56 
 drivers/s390/cio/vfio_ccw_ops.c  |  3 +-
 drivers/vfio/mdev/mdev_core.c| 11 ---
 drivers/vfio/mdev/mdev_private.h |  6 +++-
 drivers/vfio/mdev/mdev_sysfs.c   | 42 
 include/linux/mdev.h |  3 +-
 samples/vfio-mdev/mbochs.c   |  3 +-
 samples/vfio-mdev/mdpy.c |  3 +-
 samples/vfio-mdev/mtty.c |  3 +-
 12 files changed, 141 insertions(+), 38 deletions(-)

-- 
2.18.0.rc2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH 1/2] vfio/mdev: Add new instances parameters for mdev create

2018-06-20 Thread Zhenyu Wang
For special mdev type which can aggregate instances for mdev device,
this extends mdev create interface by allowing extra "instances=xxx"
parameter, which is passed to mdev device model to be able to create
arbitrary bundled number of instances for target mdev device.

For created mdev device, also create new sysfs attr "instances" to
show. For compatibility, current default instances is 1.

Cc: Alex Williamson 
Cc: Kirti Wankhede 
Signed-off-by: Zhenyu Wang 
---
 drivers/gpu/drm/i915/gvt/kvmgt.c |  3 ++-
 drivers/s390/cio/vfio_ccw_ops.c  |  3 ++-
 drivers/vfio/mdev/mdev_core.c| 11 ++---
 drivers/vfio/mdev/mdev_private.h |  6 -
 drivers/vfio/mdev/mdev_sysfs.c   | 42 +++-
 include/linux/mdev.h |  3 ++-
 samples/vfio-mdev/mbochs.c   |  3 ++-
 samples/vfio-mdev/mdpy.c |  3 ++-
 samples/vfio-mdev/mtty.c |  3 ++-
 9 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index df4e4a07db3d..4a543e23b9a0 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -444,7 +444,8 @@ static void kvmgt_put_vfio_device(void *vgpu)
vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device);
 }
 
-static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
+static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev,
+unsigned int instances)
 {
struct intel_vgpu *vgpu = NULL;
struct intel_vgpu_type *type;
diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 41eeb57d68a3..4c37826ec9d0 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -106,7 +106,8 @@ static struct attribute_group *mdev_type_groups[] = {
NULL,
 };
 
-static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)
+static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev,
+   unsigned int instances)
 {
struct vfio_ccw_private *private =
dev_get_drvdata(mdev_parent_dev(mdev));
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 0212f0ee8aea..98b0a78e6832 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -104,12 +104,13 @@ static inline void mdev_put_parent(struct mdev_parent 
*parent)
 }
 
 static int mdev_device_create_ops(struct kobject *kobj,
- struct mdev_device *mdev)
+ struct mdev_device *mdev,
+ unsigned int instances)
 {
struct mdev_parent *parent = mdev->parent;
int ret;
 
-   ret = parent->ops->create(kobj, mdev);
+   ret = parent->ops->create(kobj, mdev, instances);
if (ret)
return ret;
 
@@ -276,7 +277,8 @@ static void mdev_device_release(struct device *dev)
kfree(mdev);
 }
 
-int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
+int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid,
+  unsigned int instances)
 {
int ret;
struct mdev_device *mdev, *tmp;
@@ -316,6 +318,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
mdev->dev.bus = _bus_type;
mdev->dev.release = mdev_device_release;
dev_set_name(>dev, "%pUl", uuid.b);
+   mdev->type_instances = instances;
 
ret = device_register(>dev);
if (ret) {
@@ -323,7 +326,7 @@ int mdev_device_create(struct kobject *kobj, struct device 
*dev, uuid_le uuid)
goto mdev_fail;
}
 
-   ret = mdev_device_create_ops(kobj, mdev);
+   ret = mdev_device_create_ops(kobj, mdev, instances);
if (ret)
goto create_fail;
 
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index b5819b7d7ef7..aa0b4b64c503 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -33,6 +33,7 @@ struct mdev_device {
struct kref ref;
struct list_head next;
struct kobject *type_kobj;
+   unsigned int type_instances;
bool active;
 };
 
@@ -52,13 +53,16 @@ struct mdev_type {
 #define to_mdev_type(_kobj)\
container_of(_kobj, struct mdev_type, kobj)
 
+#define MDEV_CREATE_OPT_LEN 32
+
 int  parent_create_sysfs_files(struct mdev_parent *parent);
 void parent_remove_sysfs_files(struct mdev_parent *parent);
 
 int  mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
 void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
 
-int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le 
uuid);
+int  mdev_device_create(struct kobject *kobj, struct device *dev, uuid

Re: [libvirt] [PATCH 0/3] sample: vfio mdev display devices.

2018-04-19 Thread Zhenyu Wang
On 2018.04.19 10:40:18 +0200, Gerd Hoffmann wrote:
>   Hi,
> 
> > Erik Skultety brought up a good question today regarding how libvirt is
> > meant to handle these different flavors of display interfaces and
> > knowing whether a given mdev device has display support at all.  It
> > seems that we cannot simply use the default display=auto because
> > libvirt needs to specifically configure gl support for a dmabuf type
> > interface versus not having such a requirement for a region interface,
> > perhaps even removing the emulated graphics in some cases (though I
> > don't think we have boot graphics through either solution yet).
> 
> Correct, no boot graphics yet.  The option to disable emulated graphics
> should be added nevertheless.  It's an option after all, you don't have
> to use it.
> 
> But after install things usually work just fine, it just takes a little
> longer for the guest display to show up..  There is also the option to
> add a serial console to the guest for boot loader access.
> 
> > Additionally, GVT-g seems to need the x-igd-opregion support
> > enabled(?), which is a non-starter for libvirt as it's an experimental
> > option!
> 
> Windows guests need it, yes.  And it seems we have still have to add igd
> opregion support to ovmf as only bios guests are working.  Or hack up a
> efi rom doing that.  But patching ovmf is probably alot easier because
> it already has support code for fw_cfg access.
> 
> Linux i915.ko is happy without opregion.
>

yeah, that's true.

> > So I was ready to return and suggest that maybe libvirt should probe
> > the device to know about these ancillary configuration details, but
> > then I remembered that both mdev vGPU vendors had external dependencies
> > to even allow probing the device.  KVMGT will fail to open the device
> > if it's not associated with an instance of KVM and NVIDIA vGPU, I
> > believe, will fail if the vGPU manager process cannot find the QEMU
> > instance to extract the VM UUID.  (Both of these were bad ideas)
> 
> Oops.  I've trapped into the kvm issue too.  Wondering what the reason
> is, shouldn't this work with tcg too?
> 
> But, yes, that indeed pretty much kills the "just let libvirt use the
> probe ioctl" idea.

I also don't like that strict link and although now KVM is the only upstream
hypervisor GVT supports, we shouldn't require a must available instance for
some device info access.

> 
> > The existing device_api file reports "vfio-pci", so we base the device
> > API info in a directory named vfio-pci.  We're specifically exposing
> > device information, so we have a device directory.  We have a GFX_PLANE
> > query ioctl, so we have a gfx_plane sub-directory.  I imagine the
> > dmabuf and region files here expose either Y/N or 1/0.
> 
> Do we want tie this to vfio-pci?  All existing devices are actually pci,
> and the qemu code only works for vfio-pci devices too.  But at vfio api
> level there is no vfio-pci dependency I'm aware of, and I think we
> shouldn't add one without a good reason.
> 
> Should we just add a gfx_plane_api file maybe?  Which would be a
> comma-separated list of interfaces, listed in order of preference in
> case multiple are supported.

Or a 'feature' file with defined string list for those capabilities?
Might be easier to extend in future.

> 
> > anything other than mdev.  This inconsistency with physically assigned
> > devices has been one of my arguments against enhancing mdev sysfs.
> > 
> > Thanks to anyone still reading this.  Ideas how we might help libvirt
> > fill this information void so that they can actually configure a VM
> > with a display device?  Thanks,
> 
> Well, no good idea for the physical assigned device case.
> 
> cheers,
>   Gerd
> 
> PS: Any comment on the sample driver patches?  Or should I take the lack
> of comments as "no news is good news, they are queued up already"?
> ___
> intel-gvt-dev mailing list
> intel-gvt-...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list