From nobody Thu Apr 25 00:53:25 2024 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=1559263948; cv=none; d=zoho.com; s=zohoarc; b=X3pSnACo+sb3ITVfDwWuFZzb7trO2bgDE/oN1IiypfKC9qdIPwgR3YtnfnfngxXTvETmMJXjEuvBfEzxdbt291cCqkLm3Er1vvm/vAymZXPHuc/lK7s7xmgIht3lffxGLsXxwEv3LtI5NoTkzsWKwU8gjiEG54MfFBrOk0b94nY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559263948; 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=MPGcoPfLGI5loaowCjMv0wR3Uz8bqBhjSBOqzzGUyF0=; b=Tzd9jkNoHfAFd0tFUUwdASKtvlbRzDfBmy76FEHz15TJ4hNBtafanRm5zA6ME0jfL5DegMrfXhRAhNJdeGfh+3uEgxhUg9ikVCx3qlu1nOr9YhkNQDtI1YIwiNNlq33IpGOf5z9moP8uY89cyD+vF/4yAYWAjDvp4yVyIyg7/Og= 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 1559263948339449.56364196687616; Thu, 30 May 2019 17:52:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6516083F44; Fri, 31 May 2019 00:52:26 +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 0847C88B14; Fri, 31 May 2019 00:52:26 +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 828E254D3D; Fri, 31 May 2019 00:52:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4V0qNPP023720 for ; Thu, 30 May 2019 20:52:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55E5D9085; Fri, 31 May 2019 00:52:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 570BD19493; Fri, 31 May 2019 00:52:14 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 7239F3082E6A; Fri, 31 May 2019 00:52:05 +0000 (UTC) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2019 17:52:04 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.9]) by fmsmga007.fm.intel.com with ESMTP; 30 May 2019 17:51:59 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Date: Thu, 30 May 2019 20:45:59 -0400 Message-Id: <20190531004559.24581-1-yan.y.zhao@intel.com> In-Reply-To: <20190531004438.24528-1-yan.y.zhao@intel.com> References: <20190531004438.24528-1-yan.y.zhao@intel.com> MIME-Version: 1.0 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.46]); Fri, 31 May 2019 00:52:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 31 May 2019 00:52:07 +0000 (UTC) for IP:'134.134.136.126' DOMAIN:'mga18.intel.com' HELO:'mga18.intel.com' FROM:'yan.y.zhao@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 134.134.136.126 mga18.intel.com 134.134.136.126 mga18.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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, 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 v4 1/2] vfio/mdev: add migration_version attribute for mdev device 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: , Content-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 31 May 2019 00:52:26 +0000 (UTC) migration_version attribute is used to check migration compatibility between two mdev devices of the same mdev type. The key is that it's rw and its data is opaque to userspace. Userspace reads migration_version of mdev device at source side and writes the value to migration_version attribute of mdev device at target side. It judges migration compatibility according to whether the read and write operations succeed or fail. As this attribute is under mdev_type node, userspace is able to know whether two mdev devices are compatible before a mdev device is created. userspace needs to check whether the two mdev devices are of the same mdev type before checking the migration_version attribute. It also needs to check device creation parameters if aggregation is supported in future. __ userspace /\ \ / \write / read \ ________/__________ ___\|/_____________ | migration_version | | migration_version |-->check migration --------------------- --------------------- compatibility mdev device A mdev device B 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=C3=A9 Cc: Christophe de Dinechin Signed-off-by: Yan Zhao Reviewed-by: Cornelia Huck --- v4: fixed a typo. (Cornelia Huck) v3: 1. renamed version to migration_version (Christophe de Dinechin, Cornelia Huck, Alex Williamson) 2. let errno to be freely defined by vendor driver (Alex Williamson, Erik Skultety, Cornelia Huck, Dr. David Alan Gilbert) 3. let checking mdev_type be prerequisite of migration compatibility check. (Alex Williamson) 4. reworded example usage section. (most of this section came from Alex Williamson) 5. reworded attribute intention section (Cornelia Huck) 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) --- Documentation/vfio-mediated-device.txt | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-me= diated-device.txt index c3f69bcaf96e..1241e1cee64e 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 + | | |--- migration_version | | |--- [devices] | |--- [] | | |--- create @@ -209,6 +210,7 @@ Directories and files under the sysfs for Each Physical= Device | | |--- available_instances | | |--- device_api | | |--- description + | | |--- migration_version | | |--- [devices] | |--- [] | |--- create @@ -216,6 +218,7 @@ Directories and files under the sysfs for Each Physical= Device | |--- available_instances | |--- device_api | |--- description + | |--- migration_version | |--- [devices] =20 * [mdev_supported_types] @@ -246,6 +249,116 @@ Directories and files under the sysfs for Each Physic= al Device This attribute should show the number of devices of type that = can be created. =20 +* migration_version + + This attribute is rw, and is optional. + It is used to check migration compatibility between two mdev devices of = the + same mdev type. Absence of this attribute means the device of type + does not support migration. + This attribute provides a way to check migration compatibility between t= wo + mdev devices from userspace even before device creation. The intended us= age is + for userspace to read the migration_version attribute from one mdev devi= ce and + then writing that value to the migration_version attribute of the other = mdev + device. The second mdev device indicates compatibility via the return co= de of + the write operation. This makes compatibility between mdev devices compl= etely + vendor-defined and opaque to userspace. Userspace should do nothing more + than verify the mdev types match and then use the migration_version attr= ibute + to confirm source to target compatibility. + + Reading/Writing Attribute Data: + read(2) will fail if device of type does not support migration= and + otherwise succeed and return migration_version string of the dev= ice of + type . + + This migration_version string is vendor defined and opaque to the + userspace. Vendor is free to include whatever they feel is relev= ant. + e.g. -. + + Restrictions on this migration_version string: + 1. It should only contain ascii characters + 2. MAX Length is PATH_MAX (4096) + + write(2) expects migration_version string of source mdev device, and will + succeed if it is determined to be compatible and otherwise fail = with + vendor specific errno. + + Errno: + -An errno on read(2) indicates the device of type does not sup= port + migration; + -An errno on write(2) indicates the devices are incompatible or the targ= et + doesn't support migration. + Vendor driver is free to define specific errno and is suggested to + print detailed error in syslog for diagnose purpose. + + Userspace should treat ANY of below conditions as two mdev devices not + compatible: + (0) The mdev devices are not of the same type + (1) any one of the two mdev devices does not have a migration_version + attribute + (2) error when reading from migration_version attribute of one mdev devi= ce + (3) error when writing migration_version string of one mdev device to + migration_version attribute of the other mdev device + + Userspace should regard two mdev devices compatible when ALL of below + conditions are met: + (0) The mdev devices are of the same type + (1) success when reading from migration_version attribute of one mdev de= vice. + (2) success when writing migration_version string of one mdev device to + migration_version attribute of the other mdev device. + + Example Usage: + (1) Compare mdev types: + + The mdev type of an instantiated device can be read from the mdev_type l= ink + within the device instance in sysfs, for example: + + # basename $(readlink -f /sys/bus/mdev/devices/$MDEV_UUID/mdev_type/) + + The mdev types available on a given host system can also be found through + /sys/class/mdev_bus, for example: + + # ls /sys/class/mdev_bus/*/mdev_supported_types/ + + Migration is only possible between devices of the same mdev type. + + (2) Retrieve the mdev source migration_version: + + The migration_version information can either be read from the mdev_type = link + on an instantiated device: + + # cat /sys/bus/mdev/devices/$UUID1/mdev_type/migration_version + + Or it can be read from the mdev type definition, for example: + + # cat /sys/class/mdev_bus/*/mdev_supported_types/$MDEV_TYPE/migration_ve= rsion + + If reading the source migration_version generates an error, migration is= not + possible. + NB, there might be several parent devices for a given mdev type on a host + system, each may support or expose different migration_versions. + Matching the specific mdev type to a parent may become important in such + configurations. + + (3) Test source migration_version at target: + + Given a migration_version as outlined above, its compatibility to an + instantiated device of the same mdev type can be tested as: + # echo $VERSION > /sys/bus/mdev/devices/$UUID2/mdev_type/migration_versi= on + + If this write fails, the source and target migration versions are not + compatible or the target does not support migration. + + Compatibility can also be tested prior to target device creation using t= he + mdev type definition for a parent device with a previously found matchin= g mdev + type, for example: + + # echo $VERSION > \ + /sys/class/mdev_bus/$PARENT/mdev_supported_types/$MDEV_TYPE/migration_ve= rsion + + Again, an error writing the migration_version indicates that an instance= of + this mdev type would not support a migration from the provided migration + version. + * [device] =20 This directory contains links to the devices of type that have= been --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 00:53:25 2024 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=1559263992; cv=none; d=zoho.com; s=zohoarc; b=Ii7QWSqfXZZzVBzhud00ZPW6TBIYxg2FgpLdKd+Xpp3VFHWHaM7CTgcyyRBNNet5g3VN5lAGt63WOfdFZxdtI/Eo+mRYsahxCkmm0V8tn0mfJsDyGN7c0XgH//HsAwgZeD4W+ubVxsU7gIfrAmBd7zLdUEAV6l8rBv283Yy9Qhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559263992; 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=FPedXlu478TVKUNsvG/maRzPvTP5glDGNQziTbZP3WM=; b=S6rZAXL9gcqFPwoA23kwBW+dhV9Lg8bmlOwoTyRSHtI9qwmLcJhHHFeZt89kJzCxHdiCzG47ONZRX8/DovgfgWEYfawWRnF6gsDbcAKdIYv5jvloJg+ex77S3NhpAGePKRtnjrrJLTUlPlUk5sFgWOQHtUNXiS+qcu8HcDCmRkc= 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 1559263992583520.9499834940675; Thu, 30 May 2019 17:53:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 086FE3084243; Fri, 31 May 2019 00:53:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC8B15C2FA; Fri, 31 May 2019 00:53:10 +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 8B0231806B0F; Fri, 31 May 2019 00:53:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4V0r9qL023776 for ; Thu, 30 May 2019 20:53:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 35CD7643D9; Fri, 31 May 2019 00:53:09 +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 BF418643EE; Fri, 31 May 2019 00:53:02 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 B87EEC058CC0; Fri, 31 May 2019 00:53:00 +0000 (UTC) Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2019 17:53:00 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.9]) by fmsmga007.fm.intel.com with ESMTP; 30 May 2019 17:52:55 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Date: Thu, 30 May 2019 20:47:08 -0400 Message-Id: <20190531004708.24632-1-yan.y.zhao@intel.com> In-Reply-To: <20190531004438.24528-1-yan.y.zhao@intel.com> References: <20190531004438.24528-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]); Fri, 31 May 2019 00:53:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 31 May 2019 00:53:01 +0000 (UTC) for IP:'192.55.52.43' DOMAIN:'mga05.intel.com' HELO:'mga05.intel.com' FROM:'yan.y.zhao@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 192.55.52.43 mga05.intel.com 192.55.52.43 mga05.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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, 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 v4 2/2] drm/i915/gvt: export migration_version to mdev 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 31 May 2019 00:53:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Cornelia Huck Acked-by: Zhenyu Wang --- v4: 1. fixed Indentation/spell issues and reworded several error messages (Cornelia Huck) 2. added kfree(version) in snprintf failure case (Zhenyu Wang) 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 | 170 +++++++++++++++++++ drivers/gpu/drm/i915/gvt/vgpu.c | 13 +- 5 files changed, 226 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/M= akefile index ea8324abc784..a4143510ea22 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 migration_version.o =20 ccflags-y +=3D -I $(srctree)/$(src) -I $(srctree)/$(src)/$(GVT_DIR)/ i915-y +=3D $(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..35fb3c20eb0e 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); } =20 +static ssize_t migration_version_show(struct kobject *kobj, struct device = *dev, + char *buf) +{ + struct intel_vgpu_type *type; + void *gvt =3D kdev_to_i915(dev)->gvt; + + type =3D intel_gvt_find_vgpu_type(gvt, kobject_name(kobj)); + if (!type || !type->migration_version) { + gvt_err("Migration not supported on type %s. Please search previous deta= iled 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 =3D 0; + struct intel_vgpu_type *type; + void *gvt =3D kdev_to_i915(dev)->gvt; + + type =3D intel_gvt_find_vgpu_type(gvt, kobject_name(kobj)); + if (!type || !type->migration_version) { + gvt_err("Migration not supported on type %s. Please search previous deta= iled log\n", + kobject_name(kobj)); + return -ENODEV; + } + + ret =3D intel_gvt_check_vfio_migration_version(gvt, + type->migration_version, buf); + + return (ret < 0 ? ret : count); +} + static MDEV_TYPE_ATTR_RO(available_instances); static MDEV_TYPE_ATTR_RO(device_api); static MDEV_TYPE_ATTR_RO(description); +static MDEV_TYPE_ATTR_RW(migration_version); =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, + &mdev_type_attr_migration_version.attr, NULL, }; =20 diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index b54f2bdc13a4..3a5643ffa982 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -296,6 +296,7 @@ struct intel_vgpu_type { unsigned int fence; unsigned int weight; enum intel_vgpu_edid resolution; + char *migration_version; }; =20 struct intel_gvt { @@ -687,6 +688,10 @@ 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_check_vfio_migration_version(struct intel_gvt *gvt, + const char *self, const char *remote); +char *intel_gvt_get_vfio_migration_version(struct intel_gvt *gvt, + const char *vgpu_type); =20 #include "trace.h" #include "mpt.h" diff --git a/drivers/gpu/drm/i915/gvt/migration_version.c b/drivers/gpu/drm= /i915/gvt/migration_version.c new file mode 100644 index 000000000000..97ebb1093ea6 --- /dev/null +++ b/drivers/gpu/drm/i915/gvt/migration_version.c @@ -0,0 +1,170 @@ +/* + * 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" +#include "gvt.h" + +#define INV_SOFTWARE_VERSION (-1U) +#define VENDOR_ID_LEN (4) +#define DEVICE_ID_LEN (4) +#define VGPU_TYPE_LEN (16) +#define SOFTWARE_VER_LEN (8) + +/* total length of vfio migration version string. + * never exceed limit of PATH_MAX (4096) + */ +#define MIGRATION_VERSION_TOTAL_LEN (VENDOR_ID_LEN + DEVICE_ID_LEN + \ + VGPU_TYPE_LEN + SOFTWARE_VER_LEN + 4) + +#define GVT_VFIO_MIGRATION_SOFTWARE_VERSION INV_SOFTWARE_VERSION + + +#define PRINTF_FORMAT "%04x-%04x-%s-%08x" +#define SCANF_FORMAT "%x-%x-%16[^-]-%x" + +enum incompatible_reason { + IREASON_WRONG_REMOTE_FORMAT =3D 0, + IREASON_HARDWARE_MISMATCH, + IREASON_SOFTWARE_VERSION_MISMATCH, + IREASON_VGPU_TYPE_MISMATCH, +}; + +static const char *const incompatible_reason_str[] =3D { + [IREASON_WRONG_REMOTE_FORMAT] =3D + "wrong string format. probably wrong GVT version", + [IREASON_HARDWARE_MISMATCH] =3D + "physical device not matched", + [IREASON_SOFTWARE_VERSION_MISMATCH] =3D + "migration software version not matched", + [IREASON_VGPU_TYPE_MISMATCH] =3D + "vgpu type not matched" +}; + +static bool is_compatible(const char *local, const char *remote) +{ + bool ret; + + ret =3D sysfs_streq(local, remote); + + if (!ret) { + int vid_l =3D 0, did_l =3D 0, vid_r =3D 0, did_r =3D 0; + char type_l[VGPU_TYPE_LEN], type_r[VGPU_TYPE_LEN]; + u32 sv_l =3D 0, sv_r =3D 0; + int rl =3D 0, rr =3D 0; + enum incompatible_reason reason =3D IREASON_WRONG_REMOTE_FORMAT; + + memset(type_l, 0, sizeof(type_l)); + memset(type_r, 0, sizeof(type_r)); + + rl =3D sscanf(local, SCANF_FORMAT, + &vid_l, &did_l, type_l, &sv_l); + rr =3D sscanf(remote, SCANF_FORMAT, + &vid_r, &did_r, type_r, &sv_r); + + if (rl =3D=3D rr) { + if (vid_l !=3D vid_r || did_l !=3D did_r) + reason =3D IREASON_HARDWARE_MISMATCH; + else if (sv_l !=3D sv_r) + reason =3D IREASON_SOFTWARE_VERSION_MISMATCH; + else if (strncmp(type_l, type_r, VGPU_TYPE_LEN)) + reason =3D IREASON_VGPU_TYPE_MISMATCH; + } + + gvt_err("Migration version mismatched. Possible reason: %s. Local migrat= ion version:%s, Remote migration version:%s\n", + incompatible_reason_str[reason], local, remote); + + } + return ret; + +} + + +char * +intel_gvt_get_vfio_migration_version(struct intel_gvt *gvt, + const char *vgpu_type) +{ + int cnt =3D 0; + struct drm_i915_private *dev_priv =3D gvt->dev_priv; + char *version =3D NULL; + + /* currently only gen8 & gen9 are supported */ + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) { + gvt_err("Local hardware does not support migration on %d\n", + INTEL_INFO(dev_priv)->gen); + return NULL; + } + + if (GVT_VFIO_MIGRATION_SOFTWARE_VERSION =3D=3D INV_SOFTWARE_VERSION) { + gvt_err("Local GVT does not support migration\n"); + return NULL; + } + + version =3D kzalloc(MIGRATION_VERSION_TOTAL_LEN, GFP_KERNEL); + + if (unlikely(!version)) { + gvt_err("cannot allocate memory for local migration version %s\n", + vgpu_type); + return NULL; + } + + /* vendor id + device id + vgpu type + software version */ + cnt =3D snprintf(version, MIGRATION_VERSION_TOTAL_LEN, PRINTF_FORMAT, + PCI_VENDOR_ID_INTEL, + INTEL_DEVID(dev_priv), + vgpu_type, + GVT_VFIO_MIGRATION_SOFTWARE_VERSION); + + if (cnt) + return version; + + gvt_err("cannot generate local migration version for type %s\n", + vgpu_type); + kfree(version); + return NULL; +} + +ssize_t intel_gvt_check_vfio_migration_version(struct intel_gvt *gvt, + const char *self, const char *remote) +{ + struct drm_i915_private *dev_priv =3D gvt->dev_priv; + + /* currently only gen8 & gen9 are supported */ + if (!IS_GEN(dev_priv, 8) && !IS_GEN(dev_priv, 9)) { + gvt_err("Local hardware does not support migration on %d\n", + INTEL_INFO(dev_priv)->gen); + return -ENODEV; + } + + if (GVT_VFIO_MIGRATION_SOFTWARE_VERSION =3D=3D INV_SOFTWARE_VERSION) { + gvt_err("Local GVT does not support migration\n"); + return -ENODEV; + } + + if (!is_compatible(self, remote)) + return -EINVAL; + + return 0; +} diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgp= u.c index 44ce3c2b9ac1..7642b21641bd 100644 --- a/drivers/gpu/drm/i915/gvt/vgpu.c +++ b/drivers/gpu/drm/i915/gvt/vgpu.c @@ -155,13 +155,18 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) sprintf(gvt->types[i].name, "GVTg_V5_%s", vgpu_types[i].name); =20 - gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u re= s %s\n", + gvt->types[i].migration_version =3D + intel_gvt_get_vfio_migration_version(gvt, + gvt->types[i].name); + gvt_dbg_core("type[%d]: %s avail %u low %u high %u fence %u weight %u re= s %s, migratio_version:%s\n", i, gvt->types[i].name, gvt->types[i].avail_instance, gvt->types[i].low_gm_size, gvt->types[i].high_gm_size, gvt->types[i].fence, gvt->types[i].weight, - vgpu_edid_str(gvt->types[i].resolution)); + vgpu_edid_str(gvt->types[i].resolution), + (gvt->types[i].migration_version ? + gvt->types[i].migration_version : "null")); } =20 gvt->num_types =3D i; @@ -170,6 +175,10 @@ int intel_gvt_init_vgpu_types(struct intel_gvt *gvt) =20 void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt) { + int i; + + for (i =3D 0; i < gvt->num_types; i++) + kfree(gvt->types[i].migration_version); kfree(gvt->types); } =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list