From nobody Mon May 13 03:57:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1586757880; cv=none; d=zohomail.com; s=zohoarc; b=KdicHcqB395/xYAEdwnZK5HdLSUPtIIDltFl7Lu4XpnuQf8HzATN4RC/JJi+mHl/e2MURVZZZ2R/XTCy9XOgZoxS6C6R1VgqQqWWB6r9WDxAlImRZHTX/Zfb8G9bJA5Sg5/VbkWhISRkgGIXAVWwOR3OvW5QKumyCes5eqLIjAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586757880; 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; bh=MJ3CrtSgXmeW7eiO0Hyhhi0taEVTQ67lsRyScvT5xQY=; b=WPTu3RutR0UifhI6MZeN8jGbeEU+Sii3dKLFS9lCOw3JLcud4Sy6WchAlMLVjuFC6zq/2wuAykY2e7IQ47gwuDBD7CSBcDzvJYuXQQjWDofhnVT8FDXZ5M5FvxVNxIMitWk+rCSGX+Dg0+UR5yUz283ag4NINkwEVG86rPyQqH8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1586757880218638.2879502117844; Sun, 12 Apr 2020 23:04:40 -0700 (PDT) Received: from localhost ([::1]:40610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsD0-0007Es-Sn for importer@patchew.org; Mon, 13 Apr 2020 02:04:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57650) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsCN-0006pf-6o for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:04:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNsCL-0000yS-8z for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:03:59 -0400 Received: from mga03.intel.com ([134.134.136.65]:30371) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jNsCL-0000xj-1Q for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:03:57 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 23:03:55 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.16]) by fmsmga008.fm.intel.com with ESMTP; 12 Apr 2020 23:03:48 -0700 IronPort-SDR: 83sGulHiurM/yIxE3PqMuJ2zohqzQw3jsSN+MeCtjAXzYVYN6MPw6vrP3x5ZYrQ4ESzIJPLoSV MxMDe8kAX5CQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: z+0HOU69jei098SSeSutY5Rei2Llm3kZRcVPTTqJjFp4sXn0qI63LlAxr5XpUfVmCleoF6dxxX Quj74UvirE2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="245065624" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Subject: [PATCH v5 1/4] vfio/mdev: add migration_version attribute for mdev (under mdev_type node) Date: Mon, 13 Apr 2020 01:54:03 -0400 Message-Id: <20200413055403.27203-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200413055201.27053-1-yan.y.zhao@intel.com> References: <20200413055201.27053-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: FreeBSD 9.x [fuzzy] X-Received-From: 134.134.136.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cjia@nvidia.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, libvir-list@redhat.com, Zhengxiao.zx@alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, kwankhede@nvidia.com, eauger@redhat.com, corbet@lwn.net, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , xin.zeng@intel.com, dgilbert@redhat.com, zhenyuw@linux.intel.com, dinechin@redhat.com, alex.williamson@redhat.com, changpeng.liu@intel.com, berrange@redhat.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" 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. Currently, it is able to read/write migration_version attribute under two places: (1) under mdev_type node userspace is able to know whether two mdev devices are compatible before a mdev device is created. userspace also 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. (2) under mdev device node userspace is able to know whether two mdev devices are compatible after they are all created. But it does not need to check mdev type and device creation parameter for aggregation as device vendor driver would have incorporated those information into the migration_version attribute. __ userspace /\ \ / \write / read \ ________/__________ ___\|/_____________ | migration_version | | migration_version |-->check migration --------------------- --------------------- compatibility mdev device A mdev device B This patch is for mdev documentation about the first place (under mdev_type node) 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 Reviewed-by: Cornelia Huck Signed-off-by: Yan Zhao --- v5: updated commit message a little to indicate this patch is for migration_version attribute under mdev_type node 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) --- .../driver-api/vfio-mediated-device.rst | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentat= ion/driver-api/vfio-mediated-device.rst index 25eb7d5b834b..2d1f3c0f3c8f 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -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 From nobody Mon May 13 03:57:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1586757882; cv=none; d=zohomail.com; s=zohoarc; b=CNApqJlDF0SYQguB0Am4Oc/gTKybj5fcg0YCw0sGNESSRbjOrC4Qx9ia+cVlca2QBYWgPV5rJ8ZDOX3ofT8eY08BpBSYOmj1HTyEocH6ZPhUr4ME5BrSDnxOR/nZPzevyoMDz4kKIwJWy8PYs1k3yf16q6Xm5KNpTQXO+IJ1qg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586757882; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=1J0JORmjrDsZHGPoZA4SbJ3IS/roacqo71Bx/HYsfsM=; b=cH0dOMVYW0OnyJQsrBwxvKzoGFa8SaXc7DTi/3n2SKOhtlzw6YXpoRXc2Dx+wn2MYBVgL14BPUVDfPHfUtp0tH6vHZGbXipGOd4hUre2x/GE3r84fwjso/aAK6YvqAIpoxnkhqigd8shVyegUwnRAwhp4sHhiFIWDiCwvyQJvm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1586757882405638.3235872689309; Sun, 12 Apr 2020 23:04:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-e8BjqD9FPoeuWCy0cN-r4w-1; Mon, 13 Apr 2020 02:04:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B6D5DB60; Mon, 13 Apr 2020 06:04:33 +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 1755D9F985; Mon, 13 Apr 2020 06:04:33 +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 8ECEF18089CD; Mon, 13 Apr 2020 06:04:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03D64Vcx012459 for ; Mon, 13 Apr 2020 02:04:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 10F8710E60DE; Mon, 13 Apr 2020 06:04:31 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CDA110E60D8 for ; Mon, 13 Apr 2020 06:04:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6AA998046E2 for ; Mon, 13 Apr 2020 06:04:28 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-qLL1UShtPvGm5gF4ADkT2A-1; Mon, 13 Apr 2020 02:04:24 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 23:04:21 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.16]) by fmsmga008.fm.intel.com with ESMTP; 12 Apr 2020 23:04:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586757881; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1J0JORmjrDsZHGPoZA4SbJ3IS/roacqo71Bx/HYsfsM=; b=P4uG0GAiRyR926VpCBngu33/JfeROsgk2HjslWC8WDlDRa4pfs7VruGxf1gmA0Gv+HDdBH 7nd4eaTOtku6KJsukOMEFn9ObE3YkKQoS88WLONr2FGIXoNiIt8/AUQeXcy57nD1oDjZ5Y JG0JeiIU+QZy6rydMiM9/K002cgyX5g= X-MC-Unique: e8BjqD9FPoeuWCy0cN-r4w-1 X-MC-Unique: qLL1UShtPvGm5gF4ADkT2A-1 IronPort-SDR: zbno0dS5x52S226dDuf0DnKGYJvmDAvfP9mPIbvKHdTbh/ZcNNl4rHPtlc34YISQVW7pEegt1y aZrlkLK31VkA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: K3DgIRTWAeIzcfBdfRA7WdCna4AeUWc7sbK1ycZAorzxXybi2+7e6mYPbEqcriVTdUoSj5ET1Y RVYy7NTUADQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="245065749" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Subject: [PATCH v5 2/4] drm/i915/gvt: export migration_version to mdev sysfs (under mdev_type node) Date: Mon, 13 Apr 2020 01:54:36 -0400 Message-Id: <20200413055436.27261-1-yan.y.zhao@intel.com> In-Reply-To: <20200413055201.27053-1-yan.y.zhao@intel.com> References: <20200413055201.27053-1-yan.y.zhao@intel.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03D64Vcx012459 X-loop: libvir-list@redhat.com Cc: cjia@nvidia.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, libvir-list@redhat.com, Zhengxiao.zx@alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, kwankhede@nvidia.com, eauger@redhat.com, corbet@lwn.net, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , xin.zeng@intel.com, 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 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch implements the mdev_type part of migration_version attribute for Intel's vGPU mdev devices. migration_version attribute under mdev_type node is rw. It is located at /sys/class/mdev_bus/0000:00:02.0/mdev_supported_types/$MDEV_TYPE/ or /sys/devices/pci0000:00/0000:00:02.0/mdev_supported_types/$MDEV_TYPE/ 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 Acked-by: Cornelia Huck Acked-by: Zhenyu Wang Signed-off-by: Yan Zhao --- v5: updated commit message to indicate this patch introduces migration_version attributes under mdev_type sysfs directory 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 9c5bc39a2095..11c6aba0bf0a 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 migrate.o + fb_decoder.o dmabuf.o page_track.o migrate.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 d89dbc29bb96..fb464e3b2a57 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.c +++ b/drivers/gpu/drm/i915/gvt/gvt.c @@ -106,14 +106,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 c60df1e1d613..b26e42596565 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -277,6 +277,7 @@ struct intel_vgpu_type { unsigned int fence; unsigned int weight; enum intel_vgpu_edid resolution; + char *migration_version; }; =20 struct intel_gvt { @@ -709,6 +710,10 @@ int submit_context(struct intel_vgpu *vgpu, struct execlist_ctx_descriptor_format *desc, bool emulate_schedule_in); =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..ded43b7d9e95 --- /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->gt->i915; + 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->gt->i915; + + /* 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 72d22d97bc37..38b2575b39b7 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 From nobody Mon May 13 03:57:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1586757960; cv=none; d=zohomail.com; s=zohoarc; b=L0Z+8hCNNxHajd/mFzMVvo/jcaijaOOdDplS6mPxpwe2TiFbGM8sXdTpyEBsm6ncctk6NO72QNGGA7p7frStvXo8/GhOmBpGu75eK3I1GMN42AjsK3PMd4IvRspyxrtFscfDmvJ6m3PN8hwCDRfkZCPk3Uec3BGqCdhmAKpbNGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586757960; 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; bh=M+CntJuZ/zKA1GBpMJILa1a8BsYoQvx3fVg/abRY0jA=; b=i33iez6O5NpBhOmehEbdYEmyApmC7BEANrO8T3FsP+0eV/uPSGNAKzHgACwOayLM2DTNue5LN5sgrLeCfTwpO58O1hSusedHf7BhfcaTxOPGWQmZTjvl48jVlp7v64KStc2DFbyie/9JQJaH6I5h8k3RDvRLzStgSHl0eUpsnuE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1586757960022165.85856261466597; Sun, 12 Apr 2020 23:06:00 -0700 (PDT) Received: from localhost ([::1]:40645 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsEI-00011T-Sl for importer@patchew.org; Mon, 13 Apr 2020 02:05:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57848) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsDS-0008SX-Pq for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNsDR-0001OP-C4 for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:06 -0400 Received: from mga04.intel.com ([192.55.52.120]:41109) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jNsDR-0001Nv-4M for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:05 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 23:04:49 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.16]) by fmsmga008.fm.intel.com with ESMTP; 12 Apr 2020 23:04:43 -0700 IronPort-SDR: fJXSLePCJePo3pXxxxRGdMDsZEmHkHYA5HE1a+8hXpdxBhtCzmMci+qGi5S48SxvJdx2jQqF9+ 0P7r0aDgdtHA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: MbFwKnGaaMwEyGnfsS5ROLnyX35cXTl0aIVx4vYCD8SaZ6Q+Nm5+ioJ8P7BmoI3lVcpfUdSGfE s40BgPxp5wWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="245065840" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Subject: [PATCH v5 3/4] vfio/mdev: add migration_version attribute for mdev (under mdev device node) Date: Mon, 13 Apr 2020 01:55:04 -0400 Message-Id: <20200413055504.27311-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200413055201.27053-1-yan.y.zhao@intel.com> References: <20200413055201.27053-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: FreeBSD 9.x [fuzzy] X-Received-From: 192.55.52.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cjia@nvidia.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, libvir-list@redhat.com, Zhengxiao.zx@alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, kwankhede@nvidia.com, eauger@redhat.com, corbet@lwn.net, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , xin.zeng@intel.com, dgilbert@redhat.com, zhenyuw@linux.intel.com, dinechin@redhat.com, alex.williamson@redhat.com, changpeng.liu@intel.com, berrange@redhat.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" 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. Currently, it is able to read/write migration_version attribute under two places: (1) under mdev_type node userspace is able to know whether two mdev devices are compatible before a mdev device is created. userspace also 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. (2) under mdev device node userspace is able to know whether two mdev devices are compatible after they are all created. But it does not need to check mdev type and device creation parameter for aggregation as device vendor driver would have incorporated those information into the migration_version attribute. __ userspace /\ \ / \write / read \ ________/__________ ___\|/_____________ | migration_version | | migration_version |-->check migration --------------------- --------------------- compatibility mdev device A mdev device B This patch is for mdev documentation about the second place (under mdev device node) 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 --- .../driver-api/vfio-mediated-device.rst | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentat= ion/driver-api/vfio-mediated-device.rst index 2d1f3c0f3c8f..efbadfd51b7e 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -383,6 +383,7 @@ Directories and Files Under the sysfs for Each mdev Dev= ice |--- remove |--- mdev_type {link to its type} |--- vendor-specific-attributes [optional] + |--- migration_verion [optional] =20 * remove (write only) =20 @@ -394,6 +395,75 @@ Example:: =20 # echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove =20 +* migration_version (rw, optional) + It is used to check migration compatibility between two mdev devices. + Absence of this attribute means the mdev device does not support migrati= on. + + This attribute provides a way to check migration compatibility between t= wo + mdev devices from userspace after device created. The intended usage 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 use the migration_version attribute to confirm source to target + compatibility. + + Reading/Writing Attribute Data: + read(2) will fail if a mdev device does not support migration and otherw= ise + succeed and return migration_version string of the mdev device. + + This migration_version string is vendor defined and opaque to the + userspace. Vendor is free to include whatever they feel is relevan= t. + 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 w= ith + vendor specific errno. + + Errno: + -An errno on read(2) indicates the mdev devicedoes not support migration; + -An errno on write(2) indicates the mdev devices are incompatible or the + target 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: + (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: + (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) Retrieve the mdev source migration_version: + + # cat /sys/bus/mdev/devices/$mdev_UUID1/migration_version + + If reading the source migration_version generates an error, migration is= not + possible. + + (2) 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/$mdev_UUID2/migration_version + + If this write fails, the source and target migration versions are not + compatible or the target does not support migration. + + Mediated device Hot plug ------------------------ =20 --=20 2.17.1 From nobody Mon May 13 03:57:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=1586757989; cv=none; d=zohomail.com; s=zohoarc; b=XIjBPbzoGQ3Q3v9rN92r5k0si6QSuvqL/huSfR8yURhCWofO5zcUWx+RFQxli2BsJK75BRkl9R8/IQqNandI2SiwY8DMSkL/7bR5II9L/DVmyJ2jvFfmU8TaWTvDaUQxPSRbRgeVSHCib931MATVeUK0Jm+XLoanOlqyIbdX/s8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586757989; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=AkyBfEcaj9/7lBPDRDdTeke8ojZLQ92tLu/PwX+778w=; b=NAtIEWuePwTVFSyW824klm4D6aisVxCOLuxt3I/5nlKvbKYOv7dqfdV3SPXY5OJUcRo5AUXsMIHPBt3GSiwBUZkVWP2Lan+/eCrADo6+LYsdF9PUGB33EP+FWqsFiFNUxw5DArRWMDnhfZ78lb6Ed6AaKeubh+SNbUo+ltG7914= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1586757989059504.17726445235996; Sun, 12 Apr 2020 23:06:29 -0700 (PDT) Received: from localhost ([::1]:40646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsEl-0001l6-UM for importer@patchew.org; Mon, 13 Apr 2020 02:06:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57878) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNsDg-0000OT-EI for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNsDf-0001WD-5q for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:20 -0400 Received: from mga09.intel.com ([134.134.136.24]:11040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jNsDe-0001Vs-Ua for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:05:19 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 23:05:17 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.16]) by fmsmga008.fm.intel.com with ESMTP; 12 Apr 2020 23:05:10 -0700 IronPort-SDR: lF6U5BX3AUJpKrqgfu2mQ8U1ge/siY1ydJIu7xF1a2QPZC2vlX9txCOkpT+1hvxMFcTxgUTebh DwaHjotvGRjQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: roeKVt03RrchyMNuA8CrXSyOrbiZ5X+JKJ9kqReJE3JUUjKofhNcZ7rvaWNpS8f5VdpZlMviVm 2Are1mH2PCgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="245065924" From: Yan Zhao To: intel-gvt-dev@lists.freedesktop.org Subject: [PATCH v5 4/4] drm/i915/gvt: export migration_version to mdev sysfs (under mdev device node) Date: Mon, 13 Apr 2020 01:55:32 -0400 Message-Id: <20200413055532.27363-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200413055201.27053-1-yan.y.zhao@intel.com> References: <20200413055201.27053-1-yan.y.zhao@intel.com> X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 134.134.136.24 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cjia@nvidia.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, libvir-list@redhat.com, Zhengxiao.zx@alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, kwankhede@nvidia.com, eauger@redhat.com, corbet@lwn.net, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , xin.zeng@intel.com, dgilbert@redhat.com, zhenyuw@linux.intel.com, dinechin@redhat.com, alex.williamson@redhat.com, changpeng.liu@intel.com, berrange@redhat.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" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" mdev device par of migration_version attribute for Intel vGPU is rw. It is located at /sys/bus/pci/devices/0000\:00\:02.0/$mdev_UUID/migration_version, or /sys/bus/mdev/devices/$mdev_UUID/migration_version It's used to check migration compatibility for two vGPUs. 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 software versions, e.g. when vGPUs have aggregations, it may also include aggregation count into migration_version string of a vGPU. 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 --- drivers/gpu/drm/i915/gvt/gvt.h | 2 ++ drivers/gpu/drm/i915/gvt/kvmgt.c | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/gpu/drm/i915/gvt/gvt.h b/drivers/gpu/drm/i915/gvt/gvt.h index b26e42596565..664efc83f82e 100644 --- a/drivers/gpu/drm/i915/gvt/gvt.h +++ b/drivers/gpu/drm/i915/gvt/gvt.h @@ -205,6 +205,8 @@ struct intel_vgpu { struct idr object_idr; =20 u32 scan_nonprivbb; + + char *migration_version; }; =20 static inline void *intel_vgpu_vdev(struct intel_vgpu *vgpu) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kv= mgt.c index 2f2d4c40f966..4903599cb0ef 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -728,8 +728,13 @@ static int intel_vgpu_create(struct kobject *kobj, str= uct mdev_device *mdev) kvmgt_vdev(vgpu)->mdev =3D mdev; mdev_set_drvdata(mdev, vgpu); =20 + vgpu->migration_version =3D + intel_gvt_get_vfio_migration_version(gvt, type->name); + gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n", dev_name(mdev_dev(mdev))); + + ret =3D 0; =20 out: @@ -744,6 +749,7 @@ static int intel_vgpu_remove(struct mdev_device *mdev) return -EBUSY; =20 intel_gvt_ops->vgpu_destroy(vgpu); + kfree(vgpu->migration_version); return 0; } =20 @@ -1964,8 +1970,57 @@ static const struct attribute_group intel_vgpu_group= =3D { .attrs =3D intel_vgpu_attrs, }; =20 +static ssize_t migration_version_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mdev_device *mdev =3D mdev_from_dev(dev); + struct intel_vgpu *vgpu =3D mdev_get_drvdata(mdev); + + if (!vgpu->migration_version) { + gvt_vgpu_err("Migration not supported on this vgpu. Please search previo= us detailed log\n"); + return -ENODEV; + } + + return snprintf(buf, strlen(vgpu->migration_version) + 2, + "%s\n", vgpu->migration_version); + +} + +static ssize_t migration_version_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct mdev_device *mdev =3D mdev_from_dev(dev); + struct intel_vgpu *vgpu =3D mdev_get_drvdata(mdev); + struct intel_gvt *gvt =3D vgpu->gvt; + int ret =3D 0; + + if (!vgpu->migration_version) { + gvt_vgpu_err("Migration not supported on this vgpu. Please search previo= us detailed log\n"); + return -ENODEV; + } + + ret =3D intel_gvt_check_vfio_migration_version(gvt, + vgpu->migration_version, buf); + return (ret < 0 ? ret : count); +} + +static DEVICE_ATTR_RW(migration_version); + +static struct attribute *intel_vgpu_migration_attrs[] =3D { + &dev_attr_migration_version.attr, + NULL, +}; +/* this group has no name, so will be displayed + * immediately under sysfs node of the mdev device + */ +static const struct attribute_group intel_vgpu_group_empty_name =3D { + .attrs =3D intel_vgpu_migration_attrs, +}; + static const struct attribute_group *intel_vgpu_groups[] =3D { &intel_vgpu_group, + &intel_vgpu_group_empty_name, NULL, }; =20 --=20 2.17.1