From nobody Thu Apr 25 21:55:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1557107759; cv=none; d=zoho.com; s=zohoarc; b=Wedtve1voObjuaKYdthwVUwA3oyYXMa5tetvTh3bURXvRNN45IjzuM+kbISDttatztNMYIF3cmQSdzbNzdoRvjHhaJKOAwDR/2Ezmw9+0arKsN9mD9DEt7q45vkY63EA3I90AtM747I3GV9qz+m/c0rI4M5dLBBVTraNewKqLTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557107759; 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=5qUjJHNOPuTyaLhYrpOdyBK9t8HIMeUrFPPg5V8QKms=; b=YnjHrG9dh2jPmZpDuFgDXceWykgQcDJk9uyAfjoiAZHSgJ0Z10Rgv0BXe+pfL5Qc5Rf69A7LphRfEfFdFENnEbBHFWfdK6kkc0wGMomDSLql979PoJrUSI1xSMMX6qNzOTiEoS+Zez4uTg6sQch+T3SA/d9TLOnNSri8NxH2KUk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557107759706642.8257330764566; Sun, 5 May 2019 18:55:59 -0700 (PDT) Received: from localhost ([127.0.0.1]:48820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNSrD-00066L-IT for importer@patchew.org; Sun, 05 May 2019 21:55:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNSqO-0005j0-Ds for qemu-devel@nongnu.org; Sun, 05 May 2019 21:55:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNSqM-0006lu-JX for qemu-devel@nongnu.org; Sun, 05 May 2019 21:55:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:2406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNSqM-0006lW-AI for qemu-devel@nongnu.org; Sun, 05 May 2019 21:55:02 -0400 Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 May 2019 18:55:00 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.9]) by orsmga006.jf.intel.com with ESMTP; 05 May 2019 18:54:55 -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="141618245" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Date: Sun, 5 May 2019 21:49:04 -0400 Message-Id: <20190506014904.3621-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506014514.3555-1-yan.y.zhao@intel.com> References: <20190506014514.3555-1-yan.y.zhao@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [PATCH v2 1/2] vfio/mdev: add version attribute for mdev device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, alex.williamson@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 Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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=C3=A9 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-me= diated-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] =20 * [mdev_supported_types] @@ -246,6 +249,143 @@ 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 +* 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 ve= rsion + attribute, and writes this version string into the other mdev device's v= ersion + attribute. Then vendor driver of mdev device whose version attribute bei= ng + written would check the incoming version string and tell user space whet= her + 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 th= is + 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 conditions as two mdev devices not + compatible: + (1) any one of the two mdev devices does not have a version attribute + (2) error when read from one mdev device's version attribute + (3) error when write one mdev device's version string to the other mdev + device's version attribute + + User space should regard two mdev devices compatible when ALL of below + conditions are met: + (1) success when read from one mdev device's version attribute. + (2) success when write one mdev device's version string to the other mdev + device's version attribute + + Errno: + If vendor driver wants to claim a mdev device incompatible to all other = mdev + devices, it should not register version attribute for this mdev device. = But if + a vendor driver has already registered version attribute and it wants to= claim + a mdev device incompatible to all other mdev devices, it needs to return + -ENODEV on access to this mdev device's version attribute. + If a mdev device is only incompatible to certain mdev devices, write of + incompatible mdev devices's version strings to its version attribute sho= uld + return -EINVAL; + + This attribute can be taken advantage of by live migration. + If user space detects two mdev devices are compatible through version + attribute, it can start migration between the two mdev devices, otherwis= e it + should abort its migration attempts between the two mdev devices. + + Example Usage: + case 1: + source side mdev device is of uuid 5ac1fb20-2bbf-4842-bb7e-36c58c3be9cd, + its mdev type is i915-GVTg_V5_4. pci id of parent device is 8086-193b. + target side mdev device is if of uuid 882cc4da-dede-11e7-9180-078a62063a= b1, + its mdev type is i915-GVTg_V5_4. pci id of parent device is 8086-193b. + + # readlink /sys/bus/pci/devices/0000\:00\:02.0/\ + 5ac1fb20-2bbf-4842-bb7e-36c58c3be9cd/mdev_type + ../mdev_supported_types/i915-GVTg_V5_4 + + # readlink /sys/bus/pci/devices/0000\:00\:02.0/\ + 882cc4da-dede-11e7-9180-078a62063ab1/mdev_type + ../mdev_supported_types/i915-GVTg_V5_4 + + (1) read source side mdev device's version. + #cat \ + /sys/bus/pci/devices/0000\:00\:02.0/5ac1fb20-2bbf-4842-bb7e-36c58c3be9= cd/\ + mdev_type/version + 8086-193b-i915-GVTg_V5_4 + + (2) write source side mdev device's version string into target side mdev + device's version attribute. + # echo 8086-193b-i915-GVTg_V5_4 > + /sys/bus/pci/devices/0000\:00\:02.0/882cc4da-dede-11e7-9180-078a62063ab= 1/\ + mdev_type/version + # echo $? + 0 + + in this case, user space's write to target side mdev device's version + attribute returns success to indicate the two mdev devices are compatibl= e. + + case 2: + source side mdev device is of uuid 5ac1fb20-2bbf-4842-bb7e-36c58c3be9cd, + its mdev type is i915-GVTg_V5_4. pci id of parent device is 8086-193b. + target side mdev device is if of uuid 882cc4da-dede-11e7-9180-078a62063a= b1, + its mdev type is i915-GVTg_V5_4. pci id of parent device is 8086-191b. + + # readlink /sys/bus/pci/devices/0000\:00\:02.0/\ + 5ac1fb20-2bbf-4842-bb7e-36c58c3be9cd/mdev_type + ../mdev_supported_types/i915-GVTg_V5_4 + + # readlink /sys/bus/pci/devices/0000\:00\:02.0/\ + 882cc4da-dede-11e7-9180-078a62063ab1/mdev_type + ../mdev_supported_types/i915-GVTg_V5_4 + + (1) read source side mdev device's version. + #cat \ + /sys/bus/pci/devices/0000\:00\:02.0/5ac1fb20-2bbf-4842-bb7e-36c58c3be9= cd/\ + mdev_type/version + 8086-193b-i915-GVTg_V5_4 + + (2) write source side mdev device's version string into target side mdev + device's version attribute. + # echo 8086-193b-i915-GVTg_V5_4 > + /sys/bus/pci/devices/0000\:00\:02.0/882cc4da-dede-11e7-9180-078a62063ab= 1/\ + mdev_type/version + -bash: echo: write error: Invalid argument + + in this case, user space's write to target side mdev device's version + attribute returns error to indicate the two mdev devices are incompatibl= e. + (incompatible because pci ids of the two mdev devices' parent devices are + different). + + case 3: + source side mdev device is of uuid 5ac1fb20-2bbf-4842-bb7e-36c58c3be9cd, + its mdev type is i915-GVTg_V5_4. pci id of parent device is 8086-193b. + But vendor driver does not provide version attribute for this device. + + (1) read source side mdev device's version. + #cat \ + /sys/bus/pci/devices/0000\:00\:02.0/5ac1fb20-2bbf-4842-bb7e-36c58c3be9= cd/\ + mdev_type/version + cat: '/sys/bus/pci/devices/0000:00:02.0/5ac1fb20-2bbf-4842-bb7e-36c58c3b= e9cd/\ + mdev_type/version': No such file or directory + + in this case, user space reads source side mdev device's version attribu= te + which does not exist however. user space regards the two mdev devices as= not + compatible and will not start migration between the two mdev devices. + + * [device] =20 This directory contains links to the devices of type that have= been --=20 2.17.1 From nobody Thu Apr 25 21:55:11 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=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