Re: [libvirt] [PATCH v2 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU
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 "i915_drv.h" > + > +static bool is_compatible(const char *self, const char *remote) > +{ > + if (strlen(remote) != strlen(self)) > + return false; > + > + return (strncmp(self, remote, strlen(self))) ? false : true; > +} > + > +ssize_t intel_gvt_get_vfio_device_version_len(struct drm_i915_private > *dev_priv) > +{ > + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) > + return -ENODEV; > + > +
[libvirt] [PATCH v2 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU
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 "i915_drv.h" + +static bool is_compatible(const char *self, const char *remote) +{ + if (strlen(remote) != strlen(self)) + return false; + + return (strncmp(self, remote, strlen(self))) ? false : true; +} + +ssize_t intel_gvt_get_vfio_device_version_len(struct drm_i915_private *dev_priv) +{ + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) + return -ENODEV; + + return PAGE_SIZE; +} + +ssize_t intel_gvt_get_vfio_device_version(struct drm_i915_private *dev_priv, + char *buf, const char *mdev_type) +{ + int cnt = 0, ret = 0; + const char *str = NULL; + + /* currently only gen8 & gen9 are supported */ + if
[libvirt] [PATCH v2 1/2] vfio/mdev: add version attribute for mdev device
version attribute is used to check two mdev devices' compatibility. The key point of this version attribute is that it's rw. User space has no need to understand internal of device version and no need to compare versions by itself. Compared to reading version strings from both two mdev devices being checked, user space only reads from one mdev device's version attribute. After getting its version string, user space writes this string into the other mdev device's version attribute. Vendor driver of mdev device whose version attribute being written will check device compatibility of the two mdev devices for user space and return success for compatibility or errno for incompatibility. So two readings of version attributes + checking in user space are now changed to one reading + one writing of version attributes + checking in vendor driver. Format and length of version strings are now private to vendor driver who can define them freely. __ user space /\ \ / \write / read \ __/__ ___\|/___ | version | | version |-->check compatibility --- --- mdev device A mdev device B This version attribute is optional. If a mdev device does not provide with a version attribute, this mdev device is incompatible to all other mdev devices. Live migration is able to take advantage of this version attribute. Before user space actually starts live migration, it can first check whether two mdev devices are compatible. v2: 1. added detailed intent and usage 2. made definition of version string completely private to vendor driver (Alex Williamson) 3. abandoned changes to sample mdev drivers (Alex Williamson) 4. mandatory --> optional (Cornelia Huck) 5. added description for errno (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" Cc: Neo Jia Cc: Kirti Wankhede Cc: Daniel P. Berrangé Cc: Christophe de Dinechin Signed-off-by: Yan Zhao --- Documentation/vfio-mediated-device.txt | 140 + 1 file changed, 140 insertions(+) diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-mediated-device.txt index c3f69bcaf96e..013a764968eb 100644 --- a/Documentation/vfio-mediated-device.txt +++ b/Documentation/vfio-mediated-device.txt @@ -202,6 +202,7 @@ Directories and files under the sysfs for Each Physical Device | | |--- available_instances | | |--- device_api | | |--- description + | | |--- version | | |--- [devices] | |--- [] | | |--- create @@ -209,6 +210,7 @@ Directories and files under the sysfs for Each Physical Device | | |--- available_instances | | |--- device_api | | |--- description + | | |--- version | | |--- [devices] | |--- [] | |--- create @@ -216,6 +218,7 @@ Directories and files under the sysfs for Each Physical Device | |--- available_instances | |--- device_api | |--- description + | |--- version | |--- [devices] * [mdev_supported_types] @@ -246,6 +249,143 @@ Directories and files under the sysfs for Each Physical Device This attribute should show the number of devices of type that can be created. +* version + + This attribute is rw, and is optional. + It is used to check device compatibility between two mdev devices and is + accessed in pairs between the two mdev devices being checked. + The intent of this attribute is to make an mdev device's version opaque to + user space, so instead of reading two mdev devices' version strings and + comparing in userspace, user space should only read one mdev device's version + attribute, and writes this version string into the other mdev device's version + attribute. Then vendor driver of mdev device whose version attribute being + written would check the incoming version string and tell user space whether + the two mdev devices are compatible via return value. That's why this + attribute is writable. + + when reading this attribute, it should show device version string of + the device of type . + + This string is private to vendor driver itself. Vendor driver is able to + freely define format and length of device version string. + e.g. It can use a combination of pciid of parent device + mdev type. + + When writing a string to this attribute, vendor driver should analyze this + string and check whether the mdev device being identified by this string is + compatible with the mdev device for this attribute. vendor driver should then + return written string's length if it regards the two mdev devices are + compatible; vendor driver should return negative errno if it regards the two + mdev devices are not compatible. + + User space should treat ANY of below
[libvirt] [PATCH v2 0/2] introduction of version attribute for VFIO live migration
This patchset introduces a version attribute under sysfs of VFIO Mediated devices. This version attribute is used to check whether two mdev devices are compatible. user space software can take advantage of this version attribute to determine whether to launch live migration between two mdev devices. Patch 1 defines version attribute in Documentation/vfio-mediated-device.txt Patch 2 uses GVT as an example to show how to expose version attribute and check device compatibility in vendor driver. v2: 1. renamed patched 1 2. made definition of device version string completely private to vendor driver 3. abandoned changes to sample mdev drivers 4. described intent and usage of version attribute more clearly. Yan Zhao (2): vfio/mdev: add version attribute for mdev device drm/i915/gvt: export mdev device version to sysfs for Intel vGPU Documentation/vfio-mediated-device.txt| 135 ++ drivers/gpu/drm/i915/gvt/Makefile | 2 +- drivers/gpu/drm/i915/gvt/device_version.c | 84 ++ drivers/gpu/drm/i915/gvt/gvt.c| 51 drivers/gpu/drm/i915/gvt/gvt.h| 6 + 5 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/i915/gvt/device_version.c -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list