From nobody Mon Feb 9 14:02:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1557107824; cv=none; d=zoho.com; s=zohoarc; b=MkcdVeCWCMU+risuOSaNZyPhB19FfCH0FDmWfDyEr+BsvBlLRqz54pEBk76CRdWM5Cf7qMOYEnzbWYMk5muecRfEBbknDL96nXsqp1h3z2NZsk0bfOhXzr1kjuHTmHW+W82ah+82nVIzz7kA0BEZzbWMjfTUENbC4dfOGSi6IO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557107824; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KiZs4rCLKMGfSEXKPMpbl9Q8mhdcDTLnJWWmoRsIgKY=; b=dut3PAWd48P6Drk5WZrsxQ2KPzYt6PWG5BuFo9F2xbHIlIT5d2n1hABibJw7d5Va3LUPJNY2URKd8QJXAQUvRSQMSzQAGMUgirEGkIm0eyo/Vj79mvl/fYJ3i/CmHQqSVRjLy9f6Wp+YT4BGUm7e0xrhH5bamxyKofazm77MxY8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557107824908191.77046137581158; Sun, 5 May 2019 18:57:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CDD53084032; Mon, 6 May 2019 01:57:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DCA05D71B; Mon, 6 May 2019 01:57:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 30D9841F3D; Mon, 6 May 2019 01:57:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x461v0bN008502 for ; Sun, 5 May 2019 21:57:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DF1B7C43D; Mon, 6 May 2019 01:57:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AABB5D71B; Mon, 6 May 2019 01:56:52 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E37C2C05B1CD; Mon, 6 May 2019 01:56:49 +0000 (UTC) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 May 2019 18:56:49 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.9]) by orsmga006.jf.intel.com with ESMTP; 05 May 2019 18:56:43 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,435,1549958400"; d="scan'208";a="141618473" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Date: Sun, 5 May 2019 21:51:02 -0400 Message-Id: <20190506015102.3691-1-yan.y.zhao@intel.com> In-Reply-To: <20190506014514.3555-1-yan.y.zhao@intel.com> References: <20190506014514.3555-1-yan.y.zhao@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 06 May 2019 01:56:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 06 May 2019 01:56:50 +0000 (UTC) for IP:'134.134.136.31' DOMAIN:'mga06.intel.com' HELO:'mga06.intel.com' FROM:'yan.y.zhao@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.31 mga06.intel.com 134.134.136.31 mga06.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: cjia@nvidia.com, kvm@vger.kernel.org, aik@ozlabs.ru, Zhengxiao.zx@alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, kwankhede@nvidia.com, eauger@redhat.com, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, libvir-list@redhat.com, arei.gonglei@huawei.com, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , dgilbert@redhat.com, zhenyuw@linux.intel.com, dinechin@redhat.com, changpeng.liu@intel.com, cohuck@redhat.com, linux-kernel@vger.kernel.org, zhi.a.wang@intel.com, jonathan.davies@nutanix.com, shaopeng.he@intel.com Subject: [libvirt] [PATCH v2 2/2] drm/i915/gvt: export mdev device version to sysfs for Intel vGPU X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 06 May 2019 01:57:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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/M= akefile index 271fb46d4dd0..54e209a23899 100644 --- a/drivers/gpu/drm/i915/gvt/Makefile +++ b/drivers/gpu/drm/i915/gvt/Makefile @@ -3,7 +3,7 @@ GVT_DIR :=3D gvt GVT_SOURCE :=3D gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o firmw= are.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 =20 ccflags-y +=3D -I$(src) -I$(src)/$(GVT_DIR) i915-y +=3D $(addprefix $(GVT_DIR)/, $(GVT_SOURCE)) diff --git a/drivers/gpu/drm/i915/gvt/device_version.c b/drivers/gpu/drm/i9= 15/gvt/device_version.c new file mode 100644 index 000000000000..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 limitati= on + * 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 ne= xt + * paragraph) shall be included in all copies or substantial portions of t= he + * 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 OT= HER + * 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) !=3D 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_pri= v, + char *buf, const char *mdev_type) +{ + int cnt =3D 0, ret =3D 0; + const char *str =3D NULL; + + /* currently only gen8 & gen9 are supported */ + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) + return -ENODEV; + + /* vendor id + device id + mdev type */ + /* vendor id */ + cnt =3D snprintf(buf, 5, "%04x", PCI_VENDOR_ID_INTEL); + buf +=3D cnt; + ret +=3D cnt; + + /* device id */ + cnt =3D snprintf(buf, 6, "-%04x", INTEL_DEVID(dev_priv)); + buf +=3D cnt; + ret +=3D cnt; + + /* mdev type */ + str =3D mdev_type; + cnt =3D snprintf(buf, strlen(str) + 3, "-%s\n", mdev_type); + buf +=3D cnt; + ret +=3D cnt; + + return ret; +} + +ssize_t intel_gvt_check_vfio_device_version(struct drm_i915_private *dev_p= riv, + const char *self, const char *remote) +{ + + /* currently only gen8 & gen9 are supported */ + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) + return -ENODEV; + + if (!is_compatible(self, remote)) + return -EINVAL; + + return 0; +} diff --git a/drivers/gpu/drm/i915/gvt/gvt.c b/drivers/gpu/drm/i915/gvt/gvt.c index 43f4242062dd..19f16eec5a4c 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.c +++ b/drivers/gpu/drm/i915/gvt/gvt.c @@ -105,14 +105,65 @@ static ssize_t description_show(struct kobject *kobj,= struct device *dev, type->weight); } =20 +#ifdef GVT_MIGRATION_VERSION +static ssize_t version_show(struct kobject *kobj, struct device *dev, + char *buf) +{ + struct drm_i915_private *i915 =3D kdev_to_i915(dev); + const char *mdev_type =3D kobject_name(kobj); + + return intel_gvt_get_vfio_device_version(i915, buf, mdev_type); +} + +static ssize_t version_store(struct kobject *kobj, struct device *dev, + const char *buf, size_t count) +{ + char *remote =3D NULL, *self =3D NULL; + int len, ret =3D 0; + struct drm_i915_private *i915 =3D kdev_to_i915(dev); + const char *mdev_type =3D kobject_name(kobj); + + len =3D intel_gvt_get_vfio_device_version_len(i915); + if (len < 0) + return len; + + self =3D kmalloc(len, GFP_KERNEL); + if (!self) + return -ENOMEM; + + ret =3D intel_gvt_get_vfio_device_version(i915, self, mdev_type); + if (ret < 0) + goto out; + + remote =3D kstrndup(buf, count, GFP_KERNEL); + if (!remote) { + ret =3D -ENOMEM; + goto out; + } + + ret =3D intel_gvt_check_vfio_device_version(i915, self, remote); + +out: + kfree(self); + kfree(remote); + return (ret < 0 ? ret : count); +} +#endif + static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(device_api); static MDEV_TYPE_ATTR_RO(description); +#ifdef GVT_MIGRATION_VERSION +static MDEV_TYPE_ATTR_RW(version); +#endif =20 static struct attribute *gvt_type_attrs[] =3D { &mdev_type_attr_available_instances.attr, &mdev_type_attr_device_api.attr, &mdev_type_attr_description.attr, +#ifdef GVT_MIGRATION_VERSION + &mdev_type_attr_version.attr, +#endif NULL, }; =20 diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index f5a328b5290a..4062f6b26acf 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -687,6 +687,12 @@ void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *= vgpu); int intel_gvt_debugfs_init(struct intel_gvt *gvt); void intel_gvt_debugfs_clean(struct intel_gvt *gvt); =20 +ssize_t intel_gvt_get_vfio_device_version(struct drm_i915_private *i915, + char *buf, const char *mdev_type); +ssize_t intel_gvt_check_vfio_device_version(struct drm_i915_private *dev_p= riv, + const char *self, const char *remote); +ssize_t +intel_gvt_get_vfio_device_version_len(struct drm_i915_private *dev_priv); =20 #include "trace.h" #include "mpt.h" --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list