From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686560; cv=none; d=zohomail.com; s=zohoarc; b=HKWKdHeAofcz5RGOTecje1gA55eFwQiDcalKawfzHcQBAb/Fra9jmv1VRJyYOS0II06uL4a21hxIJeU/HVy3CCpZQcLXGrYtUaXa0BEOItJdqFpiA+lb2gW8VljjOFn/bn73bCuTA19c2YSIrJOe44o5SdIWI6/09Vvk37MuljY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686560; h=Content-Type: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=uxcaLOxg2xj3rhyMw3x1Xx+lhz+xb710FD3fnDcqF/w=; b=NfGakRQkWYrNSDnuyAvIzys9VjS+p9mHi6ogIdH4UG6mKKujbjrklgywCEG5w/eZRPYHGwODCoZF++HQi7jr9KklR5hPdUYWxVnfz8YkS8ywRVWh8m0TavWgOULc5DsadVuLXtPzV2s7xTLKxNbPDedNITnuYaxa3ki9szl5wDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686560723890.1405312148456; Sat, 20 Jun 2020 13:56:00 -0700 (PDT) Received: from localhost ([::1]:38356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkWt-0004o5-91 for importer@patchew.org; Sat, 20 Jun 2020 16:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkVn-0003gl-QR for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:54:51 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkVl-00009E-PS for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:54:51 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:35 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:54:48 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:54:41 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:54:33 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:54:48 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 01/17] vfio: Add function to unmap VFIO region Date: Sun, 21 Jun 2020 01:51:10 +0530 Message-ID: <1592684486-18511-2-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686475; bh=uxcaLOxg2xj3rhyMw3x1Xx+lhz+xb710FD3fnDcqF/w=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=pWZETH8Le3RjFH8LZRudOspPLfgxPAdVGlqfsRES4Hfwgqksxpzse/xCdplyFDF42 zlaDyJiZIpm5/r7xrS6FyZcr26ePURGaEZ1Z1+GGPx7sEqaqzn6Fb1Vpm6yxua+Br8 rBhM1z1oU40ZNMjlUIRIpm6EEm7INC1cwUHcYnp+OYYOWmTvX2glR8fW9lwHGkhg1X 4Q24h+i3a+kGLck4ekF6UBNmYHvoH0NBJK61tc9Mx9PwhAQ0NFyxth6ebKc4u3bxF4 uyTvLfzVuh71TM7g8nhY3yAUBCdjY6XasFAmRW9ZcilXL2WxoOnCjK4C25FhdJUMzL 4Y32d1MKCZUmg== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This function will be used for migration region. Migration region is mmaped when migration starts and will be unmapped when migration is complete. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Cornelia Huck --- hw/vfio/common.c | 32 ++++++++++++++++++++++++++++---- hw/vfio/trace-events | 1 + include/hw/vfio/vfio-common.h | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3593b3c0c4..90e9a854d82c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -925,6 +925,18 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasede= v, VFIORegion *region, return 0; } =20 +static void vfio_subregion_unmap(VFIORegion *region, int index) +{ + trace_vfio_region_unmap(memory_region_name(®ion->mmaps[index].mem), + region->mmaps[index].offset, + region->mmaps[index].offset + + region->mmaps[index].size - 1); + memory_region_del_subregion(region->mem, ®ion->mmaps[index].mem); + munmap(region->mmaps[index].mmap, region->mmaps[index].size); + object_unparent(OBJECT(®ion->mmaps[index].mem)); + region->mmaps[index].mmap =3D NULL; +} + int vfio_region_mmap(VFIORegion *region) { int i, prot =3D 0; @@ -955,10 +967,7 @@ int vfio_region_mmap(VFIORegion *region) region->mmaps[i].mmap =3D NULL; =20 for (i--; i >=3D 0; i--) { - memory_region_del_subregion(region->mem, ®ion->mmaps[i]= .mem); - munmap(region->mmaps[i].mmap, region->mmaps[i].size); - object_unparent(OBJECT(®ion->mmaps[i].mem)); - region->mmaps[i].mmap =3D NULL; + vfio_subregion_unmap(region, i); } =20 return ret; @@ -983,6 +992,21 @@ int vfio_region_mmap(VFIORegion *region) return 0; } =20 +void vfio_region_unmap(VFIORegion *region) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + if (region->mmaps[i].mmap) { + vfio_subregion_unmap(region, i); + } + } +} + void vfio_region_exit(VFIORegion *region) { int i; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index b1ef55a33ffd..8cdc27946cb8 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -111,6 +111,7 @@ vfio_region_mmap(const char *name, unsigned long offset= , unsigned long end) "Reg vfio_region_exit(const char *name, int index) "Device %s, region %d" vfio_region_finalize(const char *name, int index) "Device %s, region %d" vfio_region_mmaps_set_enabled(const char *name, bool enabled) "Region %s m= maps enabled: %d" +vfio_region_unmap(const char *name, unsigned long offset, unsigned long en= d) "Region %s unmap [0x%lx - 0x%lx]" vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) = "Device %s region %d: %d sparse mmap entries" vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long en= d) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%0x8" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index fd564209ac71..8d7a0fbb1046 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -171,6 +171,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, int index, const char *name); int vfio_region_mmap(VFIORegion *region); void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); +void vfio_region_unmap(VFIORegion *region); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686586; cv=none; d=zohomail.com; s=zohoarc; b=nCW2hziidVWMuNqbSzH02NBsYl9hVRI2XLw7BjhcUyn1CCZou0LpMqo13bx4dXMgl1kDiB5Cl0ooXaMNDYiw0vRhNTaUxoOTCVZSuCt/W7xCtzyOvYJswGlR5uONlEXMSlJErIsYCp85cnErZpmLFuW7Ct+iJWmfXS8Z9U/0o5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686586; h=Content-Type: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=Da8mKP5ZnV2jAjo7jKzVHldy8AV0QmK3mO36MohlkqY=; b=NXm6jtIopbDckPPT9MeNd0tUev15gPvNZ/SRGW3UKIqwcqh8JwN++yDrwRCnynry8v2v2D854c9U+84gO3poD4xDzUSe1vo5rvnm7t3OwXYZ/1IDCSrxuYJLXhFRiuShsX5rfe4mbprLFTbjNzp+tsGLk2RjgwMODEvPVSoK1yw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686586217730.2359296497395; Sat, 20 Jun 2020 13:56:26 -0700 (PDT) Received: from localhost ([::1]:39800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkXI-0005TQ-Va for importer@patchew.org; Sat, 20 Jun 2020 16:56:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkW2-00042c-L0 for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:06 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkW0-0000AQ-9O for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:06 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:19 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:02 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:54:48 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:54:41 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 20 Jun 2020 13:55:02 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 02/17] vfio: Add vfio_get_object callback to VFIODeviceOps Date: Sun, 21 Jun 2020 01:51:11 +0530 Message-ID: <1592684486-18511-3-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686459; bh=Da8mKP5ZnV2jAjo7jKzVHldy8AV0QmK3mO36MohlkqY=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=Crk/OuadXMapgPXqEP3YEBxTCV/9s1cM0lbcdkyDLsE9/X4/6b8Z/0NBPiL71LpvI 2EK8YEpH5IiPqiWejdQNBRmo2ogxhhrMofb1KpeUHGCHBvZ3ZhLxkxZMB2S0jTTPM9 HJiiIDPsGmjqd8l7yP++smejqn5Gdc2d2lrGpDSNv1q+bujsBT4ri3jFo/Pl+5dBGj gG1ofVGMQtUP7ex/uvChOg8leFSfrkoS+kFhdB3XAHGrUzmlxuk0hDUkR/OAd7TNqp jeX1UTeJPZzEkPwMTBU2kHU8sGGoj3YHwfs9QxbDvcHJtGEMXrfyO5Tx6oek6cuo+u V+5nqGniCZrvg== 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; Received-SPF: pass client-ip=216.228.121.64; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate25.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:55:03 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hook vfio_get_object callback for PCI devices. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Suggested-by: Cornelia Huck Reviewed-by: Cornelia Huck --- hw/vfio/pci.c | 8 ++++++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 9 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6838bcc4b307..27f8872db2b1 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2400,10 +2400,18 @@ static void vfio_pci_compute_needs_reset(VFIODevice= *vbasedev) } } =20 +static Object *vfio_pci_get_object(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + + return OBJECT(vdev); +} + static VFIODeviceOps vfio_pci_ops =3D { .vfio_compute_needs_reset =3D vfio_pci_compute_needs_reset, .vfio_hot_reset_multi =3D vfio_pci_hot_reset_multi, .vfio_eoi =3D vfio_intx_eoi, + .vfio_get_object =3D vfio_pci_get_object, }; =20 int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8d7a0fbb1046..74261feaeac9 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -119,6 +119,7 @@ struct VFIODeviceOps { void (*vfio_compute_needs_reset)(VFIODevice *vdev); int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); + Object *(*vfio_get_object)(VFIODevice *vdev); }; =20 typedef struct VFIOGroup { --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686667; cv=none; d=zohomail.com; s=zohoarc; b=mplo6n9WJE8CEM8EWBOwg66RdS86UChQj1gJvxCA+KKi6/0xKCORYOR0iVi2a7RKRg79+bEAOK684qDStzk8pH9O/cM9JeZcwwuX1law/aDjHkYW5EYgbdiKMS2XWgeTx682q4kG5OlQ7ZtA9Buj68YB4YvM+MjSTMqyvsEc2TE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686667; h=Content-Type: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=wUTRJ0qGXCZ82E1rgat24p0UEpbFdKm4+rAJ9bxJl1A=; b=Rj1bDVbcahqIDhX0KOjj5pF3UhsK6tfuE/i4Qy7vKFfrCo5HTBPKEVSeyUKtkw+X5WGF5WTofZwAcN7618X2E7R27ccNgw08vEH5MKkbsxHfj2yc4xVgqkUkyUueEwGKjVEzzjrKJ7JYXeMDCDDBmyXTLfzooffY471afxwPP4s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686667073933.9869305879113; Sat, 20 Jun 2020 13:57:47 -0700 (PDT) Received: from localhost ([::1]:46442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkYb-0008OQ-TM for importer@patchew.org; Sat, 20 Jun 2020 16:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkW6-0004AC-RI for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:10 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:18936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkW4-0000Ai-OE for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:10 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:53:38 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:07 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:54:59 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:54:52 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:55:07 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 03/17] vfio: Add save and load functions for VFIO PCI devices Date: Sun, 21 Jun 2020 01:51:12 +0530 Message-ID: <1592684486-18511-4-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686418; bh=wUTRJ0qGXCZ82E1rgat24p0UEpbFdKm4+rAJ9bxJl1A=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=bTnD45M46xsFGEIFxS4DaZ2w2TVaDgTyIqm6amCwQLVOzZ1c2ZRNQL9v9oU0DmBvr s3TMI6645tInsQrNxJYHk2v84DJ9D7PapTdHKwZVNHgqnAik0R9iNJoezsQ7GKoEnY r9P9BuxFB8NCZUW8U2qW9ZZYdk3CEUDAyrf2t48wR0jcOCNvaHpV5z+SAmn3Oh/ZHZ b8V8pACSRSYzDxd8Rbjm7LQ3IeShZMlJR25+plgFghoLQPfIKsKN94bBu96Ei5vM7b 3r31COitJSB80GoNI6DPKny172CUYIEwyvzDsvldJsdtJBqcyDkQ4uAkk+upOpPVHA bNv4F2ZPBvWCA== 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; Received-SPF: pass client-ip=216.228.121.143; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate24.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:43 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These functions save and restore PCI device specific data - config space of PCI device. Tested save and restore with MSI and MSIX type. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/pci.c | 95 +++++++++++++++++++++++++++++++++++++++= ++++ include/hw/vfio/vfio-common.h | 2 + 2 files changed, 97 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 27f8872db2b1..5ba340aee1d4 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -41,6 +41,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/blocker.h" +#include "migration/qemu-file.h" =20 #define TYPE_VFIO_PCI "vfio-pci" #define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI) @@ -2407,11 +2408,105 @@ static Object *vfio_pci_get_object(VFIODevice *vba= sedev) return OBJECT(vdev); } =20 +static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + PCIDevice *pdev =3D &vdev->pdev; + + qemu_put_buffer(f, vdev->emulated_config_bits, vdev->config_size); + qemu_put_buffer(f, vdev->pdev.wmask, vdev->config_size); + pci_device_save(pdev, f); + + qemu_put_be32(f, vdev->interrupt); + if (vdev->interrupt =3D=3D VFIO_INT_MSIX) { + msix_save(pdev, f); + } +} + +static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + PCIDevice *pdev =3D &vdev->pdev; + uint32_t interrupt_type; + uint16_t pci_cmd; + int i, ret; + + qemu_get_buffer(f, vdev->emulated_config_bits, vdev->config_size); + qemu_get_buffer(f, vdev->pdev.wmask, vdev->config_size); + + ret =3D pci_device_load(pdev, f); + if (ret) { + return ret; + } + + /* retore pci bar configuration */ + pci_cmd =3D pci_default_read_config(pdev, PCI_COMMAND, 2); + vfio_pci_write_config(pdev, PCI_COMMAND, + pci_cmd & (!(PCI_COMMAND_IO | PCI_COMMAND_MEMORY))= , 2); + for (i =3D 0; i < PCI_ROM_SLOT; i++) { + uint32_t bar =3D pci_default_read_config(pdev, + PCI_BASE_ADDRESS_0 + i * 4,= 4); + + vfio_pci_write_config(pdev, PCI_BASE_ADDRESS_0 + i * 4, bar, 4); + } + + interrupt_type =3D qemu_get_be32(f); + + if (interrupt_type =3D=3D VFIO_INT_MSI) { + uint32_t msi_flags, msi_addr_lo, msi_addr_hi =3D 0, msi_data; + bool msi_64bit; + + /* restore msi configuration */ + msi_flags =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_FLAGS,= 2); + msi_64bit =3D (msi_flags & PCI_MSI_FLAGS_64BIT); + + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_FLAGS, + msi_flags & (!PCI_MSI_FLAGS_ENABLE), 2); + + msi_addr_lo =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_ADDRESS_LO= , 4); + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_ADDRESS_LO, + msi_addr_lo, 4); + + if (msi_64bit) { + msi_addr_hi =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_ADDRESS_HI= , 4); + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_ADDRESS_HI, + msi_addr_hi, 4); + } + + msi_data =3D pci_default_read_config(pdev, + pdev->msi_cap + (msi_64bit ? PCI_MSI_DATA_64 : PCI_MSI_DAT= A_32), + 2); + + vfio_pci_write_config(pdev, + pdev->msi_cap + (msi_64bit ? PCI_MSI_DATA_64 : PCI_MSI_DAT= A_32), + msi_data, 2); + + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_FLAGS, + msi_flags | PCI_MSI_FLAGS_ENABLE, 2); + } else if (interrupt_type =3D=3D VFIO_INT_MSIX) { + uint16_t offset; + + offset =3D pci_default_read_config(pdev, + pdev->msix_cap + PCI_MSIX_FLAGS + 1= , 2); + /* load enable bit and maskall bit */ + vfio_pci_write_config(pdev, pdev->msix_cap + PCI_MSIX_FLAGS + 1, + offset, 2); + msix_load(pdev, f); + } + vfio_pci_write_config(pdev, PCI_COMMAND, pci_cmd, 2); + return 0; +} + static VFIODeviceOps vfio_pci_ops =3D { .vfio_compute_needs_reset =3D vfio_pci_compute_needs_reset, .vfio_hot_reset_multi =3D vfio_pci_hot_reset_multi, .vfio_eoi =3D vfio_intx_eoi, .vfio_get_object =3D vfio_pci_get_object, + .vfio_save_config =3D vfio_pci_save_config, + .vfio_load_config =3D vfio_pci_load_config, }; =20 int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 74261feaeac9..d69a7f3ae31e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -120,6 +120,8 @@ struct VFIODeviceOps { int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); + void (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f); + int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 typedef struct VFIOGroup { --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686696; cv=none; d=zohomail.com; s=zohoarc; b=Mfz6/8O4QR99yRbLmfT+NxHCLNv8QVNWgxmOk1M3i+MEwiGarz63aqg3Yx/hw8cDBiX+w0dk+NcH4oGMt7OzfDv3s0yT4PIx30HwuGSwL7ASWSTE8ule5UWYyAu/dU5uql4xy7A+y1vFoYtv284Nc8GWNkZqCMTsSaX3/2V/ouM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686696; h=Content-Type: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=T6Xexq3AvQOPVom49r7gvm/sws73zJekamGm5C/7nos=; b=cWdP5CJ+QEUL+1RhSGcww/8getObK0ImC8gbEw8S6/I5LHniTyy292S8iWmaBCqdyxSPmzn7MggknIrK2KH+iCTxYyWOApvG5YfTjgojlhZ0Vh7Hdort53Lg2hW2BVAEKsio+VKCDSV9qHzp74Gmraa8oa5Y1YB88Zk4f+z2u7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686696557331.6467845166719; Sat, 20 Jun 2020 13:58:16 -0700 (PDT) Received: from localhost ([::1]:48202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkZ5-00013S-Bs for importer@patchew.org; Sat, 20 Jun 2020 16:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWE-0004K2-FX for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:18 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWC-0000Eo-0n for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:18 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:55:02 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:14 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:08 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:00 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:55:14 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 04/17] vfio: Add migration region initialization and finalize function Date: Sun, 21 Jun 2020 01:51:13 +0530 Message-ID: <1592684486-18511-5-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686502; bh=T6Xexq3AvQOPVom49r7gvm/sws73zJekamGm5C/7nos=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=rLzChjizMAxZtFAZRaDoHRGDiGYV5VTcrn+i/XUH2NSbn94FVf79bESdBXYwBt6c+ Kek9pqXg6DFs+4BEJ8lkVPKUvcYOJsRjZbbU8GBGjp3ru+8m2bvAYXegEXS3HKrlQd UUp0gVS3H6a6bnKX/jI6wZyJKfurJx65fdxfu+c3Vh9PKHPbqHddrmHXurCNxa6vSD PYaq3W7u3znEaP0pbX4tE2AaKgjHsvQXufqCs40ExaU7KBvVQBvvWyW9j+6OiufQvO 59X+cJc5UCeduhtSP1ki84h6c32d55iZ/Ur+AnwN1QJITS23/fl+MhZutzKl8fETGk rfhuuqM+CIt7Q== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Whether the VFIO device supports migration or not is decided based of migration region query. If migration region query is successful and migrati= on region initialization is successful then migration is supported else migration is blocked. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Acked-by: Dr. David Alan Gilbert --- hw/vfio/Makefile.objs | 2 +- hw/vfio/migration.c | 142 ++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 3 + include/hw/vfio/vfio-common.h | 9 +++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 hw/vfio/migration.c diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs index 9bb1c09e8477..8b296c889ed9 100644 --- a/hw/vfio/Makefile.objs +++ b/hw/vfio/Makefile.objs @@ -1,4 +1,4 @@ -obj-y +=3D common.o spapr.o +obj-y +=3D common.o spapr.o migration.o obj-$(CONFIG_VFIO_PCI) +=3D pci.o pci-quirks.o display.o obj-$(CONFIG_VFIO_CCW) +=3D ccw.o obj-$(CONFIG_VFIO_PLATFORM) +=3D platform.o diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c new file mode 100644 index 000000000000..48ac385d80a7 --- /dev/null +++ b/hw/vfio/migration.c @@ -0,0 +1,142 @@ +/* + * Migration support for VFIO devices + * + * Copyright NVIDIA, Inc. 2020 + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#include "hw/vfio/vfio-common.h" +#include "cpu.h" +#include "migration/migration.h" +#include "migration/qemu-file.h" +#include "migration/register.h" +#include "migration/blocker.h" +#include "migration/misc.h" +#include "qapi/error.h" +#include "exec/ramlist.h" +#include "exec/ram_addr.h" +#include "pci.h" +#include "trace.h" + +static void vfio_migration_region_exit(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + + if (!migration) { + return; + } + + if (migration->region.size) { + vfio_region_exit(&migration->region); + vfio_region_finalize(&migration->region); + } +} + +static int vfio_migration_region_init(VFIODevice *vbasedev, int index) +{ + VFIOMigration *migration =3D vbasedev->migration; + Object *obj =3D NULL; + int ret =3D -EINVAL; + + if (!vbasedev->ops->vfio_get_object) { + return ret; + } + + obj =3D vbasedev->ops->vfio_get_object(vbasedev); + if (!obj) { + return ret; + } + + ret =3D vfio_region_setup(obj, vbasedev, &migration->region, index, + "migration"); + if (ret) { + error_report("%s: Failed to setup VFIO migration region %d: %s", + vbasedev->name, index, strerror(-ret)); + goto err; + } + + if (!migration->region.size) { + ret =3D -EINVAL; + error_report("%s: Invalid region size of VFIO migration region %d:= %s", + vbasedev->name, index, strerror(-ret)); + goto err; + } + + return 0; + +err: + vfio_migration_region_exit(vbasedev); + return ret; +} + +static int vfio_migration_init(VFIODevice *vbasedev, + struct vfio_region_info *info) +{ + int ret; + + vbasedev->migration =3D g_new0(VFIOMigration, 1); + + ret =3D vfio_migration_region_init(vbasedev, info->index); + if (ret) { + error_report("%s: Failed to initialise migration region", + vbasedev->name); + g_free(vbasedev->migration); + vbasedev->migration =3D NULL; + } + + return ret; +} + +/* ---------------------------------------------------------------------- = */ + +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) +{ + struct vfio_region_info *info; + Error *local_err =3D NULL; + int ret; + + ret =3D vfio_get_dev_region_info(vbasedev, VFIO_REGION_TYPE_MIGRATION, + VFIO_REGION_SUBTYPE_MIGRATION, &info); + if (ret) { + goto add_blocker; + } + + ret =3D vfio_migration_init(vbasedev, info); + if (ret) { + goto add_blocker; + } + + trace_vfio_migration_probe(vbasedev->name, info->index); + g_free(info); + return 0; + +add_blocker: + error_setg(&vbasedev->migration_blocker, + "VFIO device doesn't support migration"); + g_free(info); + + ret =3D migrate_add_blocker(vbasedev->migration_blocker, &local_err); + if (local_err) { + error_propagate(errp, local_err); + error_free(vbasedev->migration_blocker); + vbasedev->migration_blocker =3D NULL; + } + return ret; +} + +void vfio_migration_finalize(VFIODevice *vbasedev) +{ + if (vbasedev->migration_blocker) { + migrate_del_blocker(vbasedev->migration_blocker); + error_free(vbasedev->migration_blocker); + vbasedev->migration_blocker =3D NULL; + } + + vfio_migration_region_exit(vbasedev); + g_free(vbasedev->migration); +} diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 8cdc27946cb8..fd034ac53684 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -143,3 +143,6 @@ vfio_display_edid_link_up(void) "" vfio_display_edid_link_down(void) "" vfio_display_edid_update(uint32_t prefx, uint32_t prefy) "%ux%u" vfio_display_edid_write_error(void) "" + +# migration.c +vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d69a7f3ae31e..d4b268641173 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -57,6 +57,10 @@ typedef struct VFIORegion { uint8_t nr; /* cache the region number for debug */ } VFIORegion; =20 +typedef struct VFIOMigration { + VFIORegion region; +} VFIOMigration; + typedef struct VFIOAddressSpace { AddressSpace *as; QLIST_HEAD(, VFIOContainer) containers; @@ -113,6 +117,8 @@ typedef struct VFIODevice { unsigned int num_irqs; unsigned int num_regions; unsigned int flags; + VFIOMigration *migration; + Error *migration_blocker; } VFIODevice; =20 struct VFIODeviceOps { @@ -204,4 +210,7 @@ int vfio_spapr_create_window(VFIOContainer *container, int vfio_spapr_remove_window(VFIOContainer *container, hwaddr offset_within_address_space); =20 +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp); +void vfio_migration_finalize(VFIODevice *vbasedev); + #endif /* HW_VFIO_VFIO_COMMON_H */ --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686796; cv=none; d=zohomail.com; s=zohoarc; b=a/lnpXgjD8mH01Dk1waXdGTDgVYN1JirYF2lU42CbwJmMtqkbHKeL1OmjOy/AxYv28/I8U2/9wrtNmxLIDhUigicN/UlpLvVWwgfe5B65mvivkji3s3EmndLLu5MBtj1pfHSIFATprdBA70BwI2yJGVSrShOtMAC7FG8TwBuvCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686796; h=Content-Type: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=K1C65JoEPytQXZwdQnOSF4f//Ku2lRx1zrDleule5Gc=; b=LdxY3yhtWjBonoHft4JU5EvWFVT311awOQvG+fuqN4nt9SCLwXLYnbUi6wd3iyF/5vR81jQ7tqCh1toafTVRX43boAWxl9Hps84rJ2/hAtQ5HaT3V3GVpVWqwWVUyYDfoAQ0w6o8Cuvle11t7hPVYV3g20IypqwCLZlskqxUbbw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686796820650.5003926198729; Sat, 20 Jun 2020 13:59:56 -0700 (PDT) Received: from localhost ([::1]:54916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkah-0004KR-JE for importer@patchew.org; Sat, 20 Jun 2020 16:59:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWL-0004Uv-IG for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:25 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:18952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWJ-0000IO-BI for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:25 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:53:53 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:22 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:16 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:08 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:55:22 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 05/17] vfio: Add VM state change handler to know state of VM Date: Sun, 21 Jun 2020 01:51:14 +0530 Message-ID: <1592684486-18511-6-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686433; bh=K1C65JoEPytQXZwdQnOSF4f//Ku2lRx1zrDleule5Gc=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=l6Q27vqbTBffrOHpYfCTJ1VHa2X6yGl5Wb75wpU4INkgFcqdIhuYc+Odr3oLKr33Q iDudc4exavlc3ILplsDxYUdL2dwXeU78l5/m12g5vpSZ7KaA4p6DuX+wq/3/HQc2PT psHVSq/IL73haV6fQY4HdSYZ9ScIfhDzPYnH1JCQY3TWyO4KRNXOY8TIde8fE2KyTN wfj7BOZVPQgtkfKCu1hXNFilKsWzYU9jp7jHiEvIKOIwWIfsHHAbrBctC8AxTSGtIV 9NC7BzPv8sr1gaRvM4i50BlGTroMgAkPPCxta9wgNh6V16ai5XtvYMvX7O+KttA+O1 OldhMcfDnk+fw== 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; Received-SPF: pass client-ip=216.228.121.143; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate24.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:43 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" VM state change handler gets called on change in VM's state. This is used t= o set VFIO device state to _RUNNING. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Dr. David Alan Gilbert --- hw/vfio/migration.c | 87 +++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 2 + include/hw/vfio/vfio-common.h | 4 ++ 3 files changed, 93 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 48ac385d80a7..fcecc0bb0874 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include =20 +#include "sysemu/runstate.h" #include "hw/vfio/vfio-common.h" #include "cpu.h" #include "migration/migration.h" @@ -74,6 +75,85 @@ err: return ret; } =20 +static int vfio_migration_set_state(VFIODevice *vbasedev, uint32_t mask, + uint32_t value) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint32_t device_state; + int ret; + + ret =3D pread(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + device_state)); + if (ret < 0) { + error_report("%s: Failed to read device state %d %s", + vbasedev->name, ret, strerror(errno)); + return ret; + } + + device_state =3D (device_state & mask) | value; + + if (!VFIO_DEVICE_STATE_VALID(device_state)) { + return -EINVAL; + } + + ret =3D pwrite(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration= _info, + device_state)); + if (ret < 0) { + error_report("%s: Failed to set device state %d %s", + vbasedev->name, ret, strerror(errno)); + + ret =3D pread(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + device_state)); + if (ret < 0) { + error_report("%s: On failure, failed to read device state %d %= s", + vbasedev->name, ret, strerror(errno)); + return ret; + } + + if (VFIO_DEVICE_STATE_IS_ERROR(device_state)) { + error_report("%s: Device is in error state 0x%x", + vbasedev->name, device_state); + return -EFAULT; + } + } + + vbasedev->device_state =3D device_state; + trace_vfio_migration_set_state(vbasedev->name, device_state); + return 0; +} + +static void vfio_vmstate_change(void *opaque, int running, RunState state) +{ + VFIODevice *vbasedev =3D opaque; + + if ((vbasedev->vm_running !=3D running)) { + int ret; + uint32_t value =3D 0, mask =3D 0; + + if (running) { + value =3D VFIO_DEVICE_STATE_RUNNING; + if (vbasedev->device_state & VFIO_DEVICE_STATE_RESUMING) { + mask =3D ~VFIO_DEVICE_STATE_RESUMING; + } + } else { + mask =3D ~VFIO_DEVICE_STATE_RUNNING; + } + + ret =3D vfio_migration_set_state(vbasedev, mask, value); + if (ret) { + error_report("%s: Failed to set device state 0x%x", + vbasedev->name, value & mask); + } + vbasedev->vm_running =3D running; + trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(st= ate), + value & mask); + } +} + static int vfio_migration_init(VFIODevice *vbasedev, struct vfio_region_info *info) { @@ -87,8 +167,11 @@ static int vfio_migration_init(VFIODevice *vbasedev, vbasedev->name); g_free(vbasedev->migration); vbasedev->migration =3D NULL; + return ret; } =20 + vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, + vbasedev); return ret; } =20 @@ -131,6 +214,10 @@ add_blocker: =20 void vfio_migration_finalize(VFIODevice *vbasedev) { + if (vbasedev->vm_state) { + qemu_del_vm_change_state_handler(vbasedev->vm_state); + } + if (vbasedev->migration_blocker) { migrate_del_blocker(vbasedev->migration_blocker); error_free(vbasedev->migration_blocker); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index fd034ac53684..14b0a86c0035 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -146,3 +146,5 @@ vfio_display_edid_write_error(void) "" =20 # migration.c vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" +vfio_migration_set_state(char *name, uint32_t state) " (%s) state %d" +vfio_vmstate_change(char *name, int running, const char *reason, uint32_t = dev_state) " (%s) running %d reason %s device state %d" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d4b268641173..3d18eb146b33 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -29,6 +29,7 @@ #ifdef CONFIG_LINUX #include #endif +#include "sysemu/sysemu.h" =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 @@ -119,6 +120,9 @@ typedef struct VFIODevice { unsigned int flags; VFIOMigration *migration; Error *migration_blocker; + VMChangeStateEntry *vm_state; + uint32_t device_state; + int vm_running; } VFIODevice; =20 struct VFIODeviceOps { --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686822; cv=none; d=zohomail.com; s=zohoarc; b=nu7hZQ1wPmhtnCXjM39oYrocuc7I4tGEUHDJrJoz9FL03ZMzs6wxt0DwUhXlfKsUrX9mtU+1KC8XCWC39RWYEn6a/8tZnpUj0UI/bwQXz2ptlc4ZFzeHN5gp1OhAz7F3Fxc5YSFc/wxtiCmMVop3aRr7n1eL8X2Rbt1iyW4rnOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686822; h=Content-Type: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=qu8o0x/bVhJn93/HxYrWJNXqh84qn3ie+3sErzCpLWU=; b=XHEez6q+oAFwpzqs8/KLKUpDu6p1kA0JXqhFZItzZ9G15dGS6f/Uw9I32ZZ6jyfWZyC90iAhQoZe00PyaoFpoG5Lt+sQ1eJ+IOzDw+VYJ5MPixxQ3BFu+pkGyT0doOkPI0X4+uoyoPhnBuJ8G8aAutYJqHcau4itKle6Po6i/0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686822298462.7163443880885; Sat, 20 Jun 2020 14:00:22 -0700 (PDT) Received: from localhost ([::1]:56680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkb6-00051i-VU for importer@patchew.org; Sat, 20 Jun 2020 17:00:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWW-0004sc-KU for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:36 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWU-0000Ie-Fs for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:36 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:49 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:33 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:24 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:16 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:55:33 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 06/17] vfio: Add migration state change notifier Date: Sun, 21 Jun 2020 01:51:15 +0530 Message-ID: <1592684486-18511-7-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686489; bh=qu8o0x/bVhJn93/HxYrWJNXqh84qn3ie+3sErzCpLWU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=GGD3yn0n6lZfucr4KclVNHSHUVFfZW1nnAMXtuIVOknTNkyit+woeiuhchL1iMEHk 2h1BprTxQh44P/Gp/BY6eIe5yvsZQSu+vJZUXCvg8w0EtoaHqrlUXWITqwdx86MSM7 CZ7ykJR1t89GgjzGwGW4kEJAk88PRNLfWzs8GFDYRTjlbz+SbjLhhp9e/4E4h5Jz6p LrSnuyge3kMh6OD3pAYTsiF/7G1uXVNrcpKTfqks9Vw31MbIwVFZQyf0uBvmrSN0FE I4FgU3IEBSvVsXZeolM+SAQyagVBwJA1wGRVk6qhmzSJIKd9liV4kPeh3Riah+oyfO TG4akA2AjKVAw== 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; Received-SPF: pass client-ip=216.228.121.64; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate25.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:55:03 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added migration state change notifier to get notification on migration state change. These states are translated to VFIO device state and conveyed to ve= ndor driver. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Dr. David Alan Gilbert --- hw/vfio/migration.c | 29 +++++++++++++++++++++++++++++ hw/vfio/trace-events | 5 +++-- include/hw/vfio/vfio-common.h | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index fcecc0bb0874..e30bd8768701 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -154,6 +154,28 @@ static void vfio_vmstate_change(void *opaque, int runn= ing, RunState state) } } =20 +static void vfio_migration_state_notifier(Notifier *notifier, void *data) +{ + MigrationState *s =3D data; + VFIODevice *vbasedev =3D container_of(notifier, VFIODevice, migration_= state); + int ret; + + trace_vfio_migration_state_notifier(vbasedev->name, + MigrationStatus_str(s->state)); + + switch (s->state) { + case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_FAILED: + ret =3D vfio_migration_set_state(vbasedev, + ~(VFIO_DEVICE_STATE_SAVING | VFIO_DEVICE_STATE_RESUM= ING), + VFIO_DEVICE_STATE_RUNNING); + if (ret) { + error_report("%s: Failed to set state RUNNING", vbasedev->name= ); + } + } +} + static int vfio_migration_init(VFIODevice *vbasedev, struct vfio_region_info *info) { @@ -172,6 +194,8 @@ static int vfio_migration_init(VFIODevice *vbasedev, =20 vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, vbasedev); + vbasedev->migration_state.notify =3D vfio_migration_state_notifier; + add_migration_state_change_notifier(&vbasedev->migration_state); return ret; } =20 @@ -214,6 +238,11 @@ add_blocker: =20 void vfio_migration_finalize(VFIODevice *vbasedev) { + + if (vbasedev->migration_state.notify) { + remove_migration_state_change_notifier(&vbasedev->migration_state); + } + if (vbasedev->vm_state) { qemu_del_vm_change_state_handler(vbasedev->vm_state); } diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 14b0a86c0035..bd3d47b005cb 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -146,5 +146,6 @@ vfio_display_edid_write_error(void) "" =20 # migration.c vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" -vfio_migration_set_state(char *name, uint32_t state) " (%s) state %d" -vfio_vmstate_change(char *name, int running, const char *reason, uint32_t = dev_state) " (%s) running %d reason %s device state %d" +vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" +vfio_vmstate_change(const char *name, int running, const char *reason, uin= t32_t dev_state) " (%s) running %d reason %s device state %d" +vfio_migration_state_notifier(const char *name, const char *state) " (%s) = state %s" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 3d18eb146b33..28f55f66d019 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -123,6 +123,7 @@ typedef struct VFIODevice { VMChangeStateEntry *vm_state; uint32_t device_state; int vm_running; + Notifier migration_state; } VFIODevice; =20 struct VFIODeviceOps { --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686629; cv=none; d=zohomail.com; s=zohoarc; b=dtIsuND9TsKrcEY/ou92Gk4oTDVLodYhnW4uj6aGWv9N4Bf5WZV1xYzgiraplfnQLlw5Cu41OToBYh75RLzR24NVve2NOc7yzTMMfcnBnILRmmRF81ukcUnC1HkJUQ0bP+raY809mquMW61HcuOfrWmRlPqxzVO7sycaJ1qIW0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686629; h=Content-Type: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=ssgwQ+dYeBquOog0ic4yDdS8jDHl63cRDlskKzoP750=; b=UGK55n+pdyxDNfMWmvJUhVnr1qgBPLuU8KT4uHXGeSI19z9TBMCH8Ds3ocIC1LHpkgcJEIi0sfVS/JwlrL8DfIKY2y4zMBdJZyvd9825x30RNidMFezgz/gx4aR5IuFP1rMfL/PFJNokbqSgxsDvl88rdC/j6RuyikYftTQpf34= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686629670801.7099381565961; Sat, 20 Jun 2020 13:57:09 -0700 (PDT) Received: from localhost ([::1]:43220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkY0-0006s5-Dc for importer@patchew.org; Sat, 20 Jun 2020 16:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWi-0005C1-IP for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:48 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:18969) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWe-0000J0-PR for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:47 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:13 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:42 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:32 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:24 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 20 Jun 2020 13:55:42 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 07/17] vfio: Register SaveVMHandlers for VFIO device Date: Sun, 21 Jun 2020 01:51:16 +0530 Message-ID: <1592684486-18511-8-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686453; bh=ssgwQ+dYeBquOog0ic4yDdS8jDHl63cRDlskKzoP750=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=UWojAbVKVZ2Hz7ctpgse8M267F+s9gHoystXkPkf7L5bnaftgn6bsyXiMVcrBjsov +oPigKzinZ+99Ji6ee5ykwq3tyTgPirJUYa30KH4PpKEeVYykZnkSBPbZqm1OApeIK MX2qOcOJ9J9ZHLcw7sCaNu0/HiJgMz0HWVPxk08asPVDJ/RGyb5FPcIlLtbdb2LcS3 J6PUO9j3Lzj7BS7A71rSR6ogUfFgabI6L5Syd6ARU/ybhUv6h33wEgaQ1LcnzsUBea wgfaN0bj3hKFBh8YSG2/ViUg1c39kqvJeBwEXfsJORi5i+zB1/6xBNQRzlzBlAya1/ vrw+UPXm0ycDA== 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; Received-SPF: pass client-ip=216.228.121.143; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate24.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:43 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define flags to be used as delimeter in migration file stream. Added .save_setup and .save_cleanup functions. Mapped & unmapped migration region from these functions at source during saving or pre-copy phase. Set VFIO device state depending on VM's state. During live migration, VM is running when .save_setup is called, _SAVING | _RUNNING state is set for VFIO device. During save-restore, VM is paused, _SAVING state is set for VFIO de= vice. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 2 ++ 2 files changed, 94 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index e30bd8768701..133bb5b1b3b2 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -8,12 +8,15 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "qemu/cutils.h" #include =20 #include "sysemu/runstate.h" #include "hw/vfio/vfio-common.h" #include "cpu.h" #include "migration/migration.h" +#include "migration/vmstate.h" #include "migration/qemu-file.h" #include "migration/register.h" #include "migration/blocker.h" @@ -24,6 +27,17 @@ #include "pci.h" #include "trace.h" =20 +/* + * Flags used as delimiter: + * 0xffffffff =3D> MSB 32-bit all 1s + * 0xef10 =3D> emulated (virtual) function IO + * 0x0000 =3D> 16-bits reserved for flags + */ +#define VFIO_MIG_FLAG_END_OF_STATE (0xffffffffef100001ULL) +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE (0xffffffffef100002ULL) +#define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL) +#define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) + static void vfio_migration_region_exit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; @@ -126,6 +140,65 @@ static int vfio_migration_set_state(VFIODevice *vbased= ev, uint32_t mask, return 0; } =20 +/* ---------------------------------------------------------------------- = */ + +static int vfio_save_setup(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + trace_vfio_save_setup(vbasedev->name); + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_SETUP_STATE); + + if (migration->region.mmaps) { + qemu_mutex_lock_iothread(); + ret =3D vfio_region_mmap(&migration->region); + qemu_mutex_unlock_iothread(); + if (ret) { + error_report("%s: Failed to mmap VFIO migration region %d: %s", + vbasedev->name, migration->region.nr, + strerror(-ret)); + return ret; + } + } + + ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_MASK, + VFIO_DEVICE_STATE_SAVING); + if (ret) { + error_report("%s: Failed to set state SAVING", vbasedev->name); + return ret; + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + return 0; +} + +static void vfio_save_cleanup(void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + + if (migration->region.mmaps) { + vfio_region_unmap(&migration->region); + } + trace_vfio_save_cleanup(vbasedev->name); +} + +static SaveVMHandlers savevm_vfio_handlers =3D { + .save_setup =3D vfio_save_setup, + .save_cleanup =3D vfio_save_cleanup, +}; + +/* ---------------------------------------------------------------------- = */ + static void vfio_vmstate_change(void *opaque, int running, RunState state) { VFIODevice *vbasedev =3D opaque; @@ -180,6 +253,7 @@ static int vfio_migration_init(VFIODevice *vbasedev, struct vfio_region_info *info) { int ret; + char id[256] =3D ""; =20 vbasedev->migration =3D g_new0(VFIOMigration, 1); =20 @@ -192,6 +266,24 @@ static int vfio_migration_init(VFIODevice *vbasedev, return ret; } =20 + if (vbasedev->ops->vfio_get_object) { + Object *obj =3D vbasedev->ops->vfio_get_object(vbasedev); + + if (obj) { + DeviceState *dev =3D DEVICE(obj); + char *oid =3D vmstate_if_get_id(VMSTATE_IF(dev)); + + if (oid) { + pstrcpy(id, sizeof(id), oid); + pstrcat(id, sizeof(id), "/"); + g_free(oid); + } + } + } + pstrcat(id, sizeof(id), "vfio"); + + register_savevm_live(id, VMSTATE_INSTANCE_ID_ANY, 1, &savevm_vfio_hand= lers, + vbasedev); vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, vbasedev); vbasedev->migration_state.notify =3D vfio_migration_state_notifier; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index bd3d47b005cb..86c18def016e 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -149,3 +149,5 @@ vfio_migration_probe(const char *name, uint32_t index) = " (%s) Region %d" vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, uin= t32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) = state %s" +vfio_save_setup(const char *name) " (%s)" +vfio_save_cleanup(const char *name) " (%s)" --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686712; cv=none; d=zohomail.com; s=zohoarc; b=oAEXUpcA2zTSkmGJJQKwVea2axdlwTmlbvKJNZCYLogVGD1/nvNtRHOPZQcxUfpA2kQiOoMqEGQWDHNLoefuFL2/0in2gq7Ii9DwsrAE+m8EyNaQdK3gLlbGZBznPqRB/aSNDo5UlgPx7NP7PCYo47SyhAzLh1OOKFmhfC+vI/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686712; h=Content-Type: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=q+YYjjeKkPAopPp0GYvi6uzwXT7+5KdXfMPmxQ3tjpw=; b=nhK2nWiQPd2ELnu97jjr8wrGkKptTUKCkeOmqSF1fnNdFcERtAJeHrk6p+x6TyhphgTijwWDemFie4nkXSU/ga6e6uGAnMIP8x1qfzOHTSHtWNu+bRhqlGln/5L8gWvRSNtPYg2cMx8VTdzBJEd4V8o7BTEgw5rIGrENyIsfaM0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686712973701.2043051023605; Sat, 20 Jun 2020 13:58:32 -0700 (PDT) Received: from localhost ([::1]:49660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkZL-0001xB-JO for importer@patchew.org; Sat, 20 Jun 2020 16:58:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWn-0005GZ-OY for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:53 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:18983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWj-0000NR-Py for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:55:52 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:19 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:48 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:41 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:33 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:55:48 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 08/17] vfio: Add save state functions to SaveVMHandlers Date: Sun, 21 Jun 2020 01:51:17 +0530 Message-ID: <1592684486-18511-9-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686459; bh=q+YYjjeKkPAopPp0GYvi6uzwXT7+5KdXfMPmxQ3tjpw=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=OYY5EZDEOCylAN3UHPrXNQ2PCf3NagxztyH3G6iBKbNQ3xT3yzAIJr3y86UUaH418 0EFPb1kb+WJD3oF7XHV/RPINoFqfmxcVMPfoo+ykTksQHfWuBmA5bkfMPL7agq+kqn +7Yl2NgyAitOoZkSLUngU3NPX3V7AEtLf8ZpTBt07RgJFGuLcUJHP0eNVnO19CpL8y 6ed2fb+NY8HpulbtCOzkC+irvM6p4kVqXeKJ2Sz5w697vP2+3SbJNyLc2dJ+LBXJkM giJxNnNJCvzqTirefK75BG7MHAmW+E2WOvxHRLoOfarNbj16XoVeFejSJkMvY5GmDd 7uNsNkucIbaeg== 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; Received-SPF: pass client-ip=216.228.121.143; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate24.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:43 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added .save_live_pending, .save_live_iterate and .save_live_complete_precopy functions. These functions handles pre-copy and stop-and-copy phase. In _SAVING|_RUNNING device state or pre-copy phase: - read pending_bytes. If pending_bytes > 0, go through below steps. - read data_offset - indicates kernel driver to write data to staging buffer. - read data_size - amount of data in bytes written by vendor driver in migration region. - read data_size bytes of data from data_offset in the migration region. - Write data packet to file stream as below: {VFIO_MIG_FLAG_DEV_DATA_STATE, data_size, actual data, VFIO_MIG_FLAG_END_OF_STATE } In _SAVING device state or stop-and-copy phase a. read config space of device and save to migration file stream. This doesn't need to be from vendor driver. Any other special config state from driver can be saved as data in following iteration. b. read pending_bytes. If pending_bytes > 0, go through below steps. c. read data_offset - indicates kernel driver to write data to staging buffer. d. read data_size - amount of data in bytes written by vendor driver in migration region. e. read data_size bytes of data from data_offset in the migration region. f. Write data packet as below: {VFIO_MIG_FLAG_DEV_DATA_STATE, data_size, actual data} g. iterate through steps b to f while (pending_bytes > 0) h. Write {VFIO_MIG_FLAG_END_OF_STATE} When data region is mapped, its user's responsibility to read data from data_offset of data_size before moving to next steps. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 283 ++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 6 + include/hw/vfio/vfio-common.h | 1 + 3 files changed, 290 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 133bb5b1b3b2..ef1150c1ff02 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -140,6 +140,168 @@ static int vfio_migration_set_state(VFIODevice *vbase= dev, uint32_t mask, return 0; } =20 +static void *get_data_section_size(VFIORegion *region, uint64_t data_offse= t, + uint64_t data_size, uint64_t *size) +{ + void *ptr =3D NULL; + int i; + + if (!region->mmaps) { + *size =3D data_size; + return ptr; + } + + /* check if data_offset in within sparse mmap areas */ + for (i =3D 0; i < region->nr_mmaps; i++) { + VFIOMmap *map =3D region->mmaps + i; + + if ((data_offset >=3D map->offset) && + (data_offset < map->offset + map->size)) { + ptr =3D map->mmap + data_offset - map->offset; + + if (data_offset + data_size <=3D map->offset + map->size) { + *size =3D data_size; + } else { + *size =3D map->offset + map->size - data_offset; + } + break; + } + } + + if (!ptr) { + uint64_t limit =3D 0; + + /* + * data_offset is not within sparse mmap areas, find size of non-m= apped + * area. Check through all list since region->mmaps list is not so= rted. + */ + for (i =3D 0; i < region->nr_mmaps; i++) { + VFIOMmap *map =3D region->mmaps + i; + + if ((data_offset < map->offset) && + (!limit || limit > map->offset)) { + limit =3D map->offset; + } + } + + *size =3D limit ? limit - data_offset : data_size; + } + return ptr; +} + +static int vfio_save_buffer(QEMUFile *f, VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint64_t data_offset =3D 0, data_size =3D 0, size; + int ret; + + ret =3D pread(vbasedev->fd, &data_offset, sizeof(data_offset), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + data_offset)); + if (ret !=3D sizeof(data_offset)) { + error_report("%s: Failed to get migration buffer data offset %d", + vbasedev->name, ret); + return -EINVAL; + } + + ret =3D pread(vbasedev->fd, &data_size, sizeof(data_size), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + data_size)); + if (ret !=3D sizeof(data_size)) { + error_report("%s: Failed to get migration buffer data size %d", + vbasedev->name, ret); + return -EINVAL; + } + + trace_vfio_save_buffer(vbasedev->name, data_offset, data_size, + migration->pending_bytes); + + qemu_put_be64(f, data_size); + size =3D data_size; + + while (size) { + void *buf =3D NULL; + bool buffer_mmaped; + uint64_t sec_size; + + buf =3D get_data_section_size(region, data_offset, size, &sec_size= ); + + buffer_mmaped =3D (buf !=3D NULL); + + if (!buffer_mmaped) { + buf =3D g_try_malloc(sec_size); + if (!buf) { + error_report("%s: Error allocating buffer ", __func__); + return -ENOMEM; + } + + ret =3D pread(vbasedev->fd, buf, sec_size, + region->fd_offset + data_offset); + if (ret !=3D sec_size) { + error_report("%s: Failed to get migration data %d", + vbasedev->name, ret); + g_free(buf); + return -EINVAL; + } + } + + qemu_put_buffer(f, buf, sec_size); + + if (!buffer_mmaped) { + g_free(buf); + } + size -=3D sec_size; + data_offset +=3D sec_size; + } + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + return data_size; +} + +static int vfio_update_pending(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint64_t pending_bytes =3D 0; + int ret; + + ret =3D pread(vbasedev->fd, &pending_bytes, sizeof(pending_bytes), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + pending_bytes)); + if ((ret < 0) || (ret !=3D sizeof(pending_bytes))) { + error_report("%s: Failed to get pending bytes %d", + vbasedev->name, ret); + migration->pending_bytes =3D 0; + return (ret < 0) ? ret : -EINVAL; + } + + migration->pending_bytes =3D pending_bytes; + trace_vfio_update_pending(vbasedev->name, pending_bytes); + return 0; +} + +static int vfio_save_device_config_state(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_CONFIG_STATE); + + if (vbasedev->ops && vbasedev->ops->vfio_save_config) { + vbasedev->ops->vfio_save_config(vbasedev, f); + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + trace_vfio_save_device_config_state(vbasedev->name); + + return qemu_file_get_error(f); +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -192,9 +354,130 @@ static void vfio_save_cleanup(void *opaque) trace_vfio_save_cleanup(vbasedev->name); } =20 +static void vfio_save_pending(QEMUFile *f, void *opaque, + uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return; + } + + *res_precopy_only +=3D migration->pending_bytes; + + trace_vfio_save_pending(vbasedev->name, *res_precopy_only, + *res_postcopy_only, *res_compatible); +} + +static int vfio_save_iterate(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret, data_size; + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE); + + if (migration->pending_bytes =3D=3D 0) { + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return ret; + } + + if (migration->pending_bytes =3D=3D 0) { + /* indicates data finished, goto complete phase */ + return 1; + } + } + + data_size =3D vfio_save_buffer(f, vbasedev); + + if (data_size < 0) { + error_report("%s: vfio_save_buffer failed %s", vbasedev->name, + strerror(errno)); + return data_size; + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + trace_vfio_save_iterate(vbasedev->name, data_size); + + return 0; +} + +static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + ret =3D vfio_migration_set_state(vbasedev, ~VFIO_DEVICE_STATE_RUNNING, + VFIO_DEVICE_STATE_SAVING); + if (ret) { + error_report("%s: Failed to set state STOP and SAVING", + vbasedev->name); + return ret; + } + + ret =3D vfio_save_device_config_state(f, opaque); + if (ret) { + return ret; + } + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return ret; + } + + while (migration->pending_bytes > 0) { + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE); + ret =3D vfio_save_buffer(f, vbasedev); + if (ret < 0) { + error_report("%s: Failed to save buffer", vbasedev->name); + return ret; + } else if (ret =3D=3D 0) { + break; + } + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return ret; + } + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + ret =3D vfio_migration_set_state(vbasedev, ~VFIO_DEVICE_STATE_SAVING, = 0); + if (ret) { + error_report("%s: Failed to set state STOPPED", vbasedev->name); + return ret; + } + + trace_vfio_save_complete_precopy(vbasedev->name); + return ret; +} + static SaveVMHandlers savevm_vfio_handlers =3D { .save_setup =3D vfio_save_setup, .save_cleanup =3D vfio_save_cleanup, + .save_live_pending =3D vfio_save_pending, + .save_live_iterate =3D vfio_save_iterate, + .save_live_complete_precopy =3D vfio_save_complete_precopy, }; =20 /* ---------------------------------------------------------------------- = */ diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 86c18def016e..9a1c5e17d97f 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -151,3 +151,9 @@ vfio_vmstate_change(const char *name, int running, cons= t char *reason, uint32_t vfio_migration_state_notifier(const char *name, const char *state) " (%s) = state %s" vfio_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" +vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_siz= e, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%= "PRIx64 +vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%= "PRIx64 +vfio_save_device_config_state(const char *name) " (%s)" +vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, u= int64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compati= ble 0x%"PRIx64 +vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" +vfio_save_complete_precopy(const char *name) " (%s)" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 28f55f66d019..c78033e4149d 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -60,6 +60,7 @@ typedef struct VFIORegion { =20 typedef struct VFIOMigration { VFIORegion region; + uint64_t pending_bytes; } VFIOMigration; =20 typedef struct VFIOAddressSpace { --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686759; cv=none; d=zohomail.com; s=zohoarc; b=gF49NR/Ny+za1zBHZTRbomxYyGduN5EIl8ynI3juueWOyEDV5XDPEk2cOaAHOM86pLPziP+e436/wmV8JY8yirG70hYSJ1TAuU3lFPpyIT4nPDuPf5DdJZxFb+yopo9jzZXjkxGNDeurLKub+7ivXKvHMF1BATn3p/XWS9MaogE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686759; h=Content-Type: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=Qf7CjFhDoLL2nWoM5CroFNrYN/RE4eOqmkcGW3azapU=; b=dA8sP3mt8egj2xYhXTOuPenaPl7Ya7DzBXt06n39ri/5wdXfE8VAWrekbDbqUZDxORMJ8QkPGzYhTnJ15meOQBhycbbUEy/ah+sOa9mpvxoGJP9ncO4cUuUUpHwtZd2lG7Voels0qYstxEDCYr6hf6HrlrRc3qD35xwOooD68CA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 15926867592308.825851447873447; Sat, 20 Jun 2020 13:59:19 -0700 (PDT) Received: from localhost ([::1]:51802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmka5-00033t-P0 for importer@patchew.org; Sat, 20 Jun 2020 16:59:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWv-0005cj-Tb for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:01 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkWt-0000P2-Mg for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:01 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:55:45 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:55:58 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:49 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:41 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 20 Jun 2020 13:55:58 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 09/17] vfio: Add load state functions to SaveVMHandlers Date: Sun, 21 Jun 2020 01:51:18 +0530 Message-ID: <1592684486-18511-10-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686545; bh=Qf7CjFhDoLL2nWoM5CroFNrYN/RE4eOqmkcGW3azapU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=X3g340cmbjzWWuDP2m77GZZPH/o0c0hekLcztSMdCnmdNzO2k9IK2TyPDB+kDJ8gi olxvYorA+bu8r8emURQafKfNQRbh/K3tRZ6BaW9C3LKA0Gz24A8h6ymNXueJ3F0W2P 1mTkMwqT9Px3iA1dvO9yxyRY68VsJiCWi2V57iR0/5coxpiuXuk0zA60b37N+0DkBe OyK6eHLTaHPziGG8MtI7D7UZVNb9m7EMVIbChLcSdiNDS2bCh4FTN9YZBp5gSUwqoD ob0L8zxumLc66qi05t1KpP2gEjW5DKc5vh1NM4yT9wVxDL4xfkZ0XmsbdxyT/Zmz98 rr/BOTgWeUl8g== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sequence during _RESUMING device state: While data for this device is available, repeat below steps: a. read data_offset from where user application should write data. b. write data of data_size to migration region from data_offset. c. write data_size which indicates vendor driver that data is written in staging buffer. For user, data is opaque. User should write data in the same order as received. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Dr. David Alan Gilbert --- hw/vfio/migration.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 3 + 2 files changed, 180 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index ef1150c1ff02..faacea5327cb 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -302,6 +302,33 @@ static int vfio_save_device_config_state(QEMUFile *f, = void *opaque) return qemu_file_get_error(f); } =20 +static int vfio_load_device_config_state(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + uint64_t data; + + if (vbasedev->ops && vbasedev->ops->vfio_load_config) { + int ret; + + ret =3D vbasedev->ops->vfio_load_config(vbasedev, f); + if (ret) { + error_report("%s: Failed to load device config space", + vbasedev->name); + return ret; + } + } + + data =3D qemu_get_be64(f); + if (data !=3D VFIO_MIG_FLAG_END_OF_STATE) { + error_report("%s: Failed loading device config space, " + "end flag incorrect 0x%"PRIx64, vbasedev->name, data); + return -EINVAL; + } + + trace_vfio_load_device_config_state(vbasedev->name); + return qemu_file_get_error(f); +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -472,12 +499,162 @@ static int vfio_save_complete_precopy(QEMUFile *f, v= oid *opaque) return ret; } =20 +static int vfio_load_setup(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret =3D 0; + + if (migration->region.mmaps) { + ret =3D vfio_region_mmap(&migration->region); + if (ret) { + error_report("%s: Failed to mmap VFIO migration region %d: %s", + vbasedev->name, migration->region.nr, + strerror(-ret)); + return ret; + } + } + + ret =3D vfio_migration_set_state(vbasedev, ~VFIO_DEVICE_STATE_MASK, + VFIO_DEVICE_STATE_RESUMING); + if (ret) { + error_report("%s: Failed to set state RESUMING", vbasedev->name); + } + return ret; +} + +static int vfio_load_cleanup(void *opaque) +{ + vfio_save_cleanup(opaque); + return 0; +} + +static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret =3D 0; + uint64_t data, data_size; + + data =3D qemu_get_be64(f); + while (data !=3D VFIO_MIG_FLAG_END_OF_STATE) { + + trace_vfio_load_state(vbasedev->name, data); + + switch (data) { + case VFIO_MIG_FLAG_DEV_CONFIG_STATE: + { + ret =3D vfio_load_device_config_state(f, opaque); + if (ret) { + return ret; + } + break; + } + case VFIO_MIG_FLAG_DEV_SETUP_STATE: + { + data =3D qemu_get_be64(f); + if (data =3D=3D VFIO_MIG_FLAG_END_OF_STATE) { + return ret; + } else { + error_report("%s: SETUP STATE: EOS not found 0x%"PRIx64, + vbasedev->name, data); + return -EINVAL; + } + break; + } + case VFIO_MIG_FLAG_DEV_DATA_STATE: + { + VFIORegion *region =3D &migration->region; + uint64_t data_offset =3D 0, size; + + data_size =3D size =3D qemu_get_be64(f); + if (data_size =3D=3D 0) { + break; + } + + ret =3D pread(vbasedev->fd, &data_offset, sizeof(data_offset), + region->fd_offset + + offsetof(struct vfio_device_migration_info, + data_offset)); + if (ret !=3D sizeof(data_offset)) { + error_report("%s:Failed to get migration buffer data offse= t %d", + vbasedev->name, ret); + return -EINVAL; + } + + trace_vfio_load_state_device_data(vbasedev->name, data_offset, + data_size); + + while (size) { + void *buf =3D NULL; + uint64_t sec_size; + bool buffer_mmaped; + + buf =3D get_data_section_size(region, data_offset, size, + &sec_size); + + buffer_mmaped =3D (buf !=3D NULL); + + if (!buffer_mmaped) { + buf =3D g_try_malloc(sec_size); + if (!buf) { + error_report("%s: Error allocating buffer ", __fun= c__); + return -ENOMEM; + } + } + + qemu_get_buffer(f, buf, sec_size); + + if (!buffer_mmaped) { + ret =3D pwrite(vbasedev->fd, buf, sec_size, + region->fd_offset + data_offset); + g_free(buf); + + if (ret !=3D sec_size) { + error_report("%s: Failed to set migration buffer %= d", + vbasedev->name, ret); + return -EINVAL; + } + } + size -=3D sec_size; + data_offset +=3D sec_size; + } + + ret =3D pwrite(vbasedev->fd, &data_size, sizeof(data_size), + region->fd_offset + + offsetof(struct vfio_device_migration_info, data_si= ze)); + if (ret !=3D sizeof(data_size)) { + error_report("%s: Failed to set migration buffer data size= %d", + vbasedev->name, ret); + return -EINVAL; + } + break; + } + + default: + error_report("%s: Unknown tag 0x%"PRIx64, vbasedev->name, data= ); + return -EINVAL; + } + + data =3D qemu_get_be64(f); + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + } + + return ret; +} + static SaveVMHandlers savevm_vfio_handlers =3D { .save_setup =3D vfio_save_setup, .save_cleanup =3D vfio_save_cleanup, .save_live_pending =3D vfio_save_pending, .save_live_iterate =3D vfio_save_iterate, .save_live_complete_precopy =3D vfio_save_complete_precopy, + .load_setup =3D vfio_load_setup, + .load_cleanup =3D vfio_load_cleanup, + .load_state =3D vfio_load_state, }; =20 /* ---------------------------------------------------------------------- = */ diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 9a1c5e17d97f..4a4bd3ba9a2a 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -157,3 +157,6 @@ vfio_save_device_config_state(const char *name) " (%s)" vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, u= int64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compati= ble 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" +vfio_load_device_config_state(const char *name) " (%s)" +vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 +vfio_load_state_device_data(const char *name, uint64_t data_offset, uint64= _t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686885; cv=none; d=zohomail.com; s=zohoarc; b=NsHifSlx5M5FrURJalmh6CNWz8BdpowP9Gx4mqTKPeagex9JyNCPG7iYSj6MN5UCZb+9TNKgMwGeCgKKKH2d4De13/9mHWv9uayyxyKjV8xoMItj4qXP1i8ogvYQkpDZ/ujZ6edfdjLBOJ+Gsn9+Gd8Y8X0Bn2spHGPSBoetXiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686885; h=Content-Type: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=lNqT20ne3SxmddsSgpUXew1AhQgIkvUAlxCSf7c7Hcs=; b=FIu2UTj86tFGQETmrprFm6N4QUSAOhsselp5wGi13oYmuNvxT9DaxzpqdbgvGOVHNWDT1EW3zCN9ubu1001dgugW9cK8tw+lNxUDMX8RByO35pEDGvgA9L++TD1EgRdALg325gEmJDL1+DuadQZZTIf66AjKgfH1Ld2qGA3nC80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686885086602.2066934166957; Sat, 20 Jun 2020 14:01:25 -0700 (PDT) Received: from localhost ([::1]:60328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkc7-0006sb-E7 for importer@patchew.org; Sat, 20 Jun 2020 17:01:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkX6-0005rA-9g for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:13 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkX2-0000Pp-Hm for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:11 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:55:54 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:07 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:55:57 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:49 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:07 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 10/17] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled Date: Sun, 21 Jun 2020 01:51:19 +0530 Message-ID: <1592684486-18511-11-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686554; bh=lNqT20ne3SxmddsSgpUXew1AhQgIkvUAlxCSf7c7Hcs=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=PKDDXdqIp6UgRFETptIt0xpYy76NZb2QMNqKGyrHxVemNWWll6ZPSnfk7LRDG0FUf I+QkLBoWU2pin37fO7sg3h4O6s+c+LXkPuE3PkqgxKpZ/Z0o+MOfe4AV5yb7AXG3cU 8G3RGFDSHsFfEDPGdEdyZH2QMr3YvfFGfCr9VfyWmC/B36VPnC19s7Vkkr6Sd15lJe SRL0uB4IU+EOUKDNSElXSspFNAFMSgBAeKCrjUtt7qFgFnb73a3RBVs4akcBeam1uF UGMxqOM/EWIuj++7BLK/ZcvbNsUDaDbnKHIGTijTOxHXyxquF4/gdkbl4FAplDoD2h Yt/uvHIahKoQA== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mr->ram_block is NULL when mr->is_iommu is true, then fr.dirty_log_mask wasn't set correctly due to which memory listener's log_sync doesn't get called. This patch returns log_mask with DIRTY_MEMORY_MIGRATION set when IOMMU is enabled. Signed-off-by: Kirti Wankhede --- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 2f15a4b250c8..95a47d2d9533 100644 --- a/memory.c +++ b/memory.c @@ -1788,7 +1788,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr) uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; - if (global_dirty_log && mr->ram_block) { + if (global_dirty_log && (mr->ram_block || memory_region_is_iommu(mr)))= { mask |=3D (1 << DIRTY_MEMORY_MIGRATION); } return mask; --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592687024; cv=none; d=zohomail.com; s=zohoarc; b=a2ZkwHvRUHpiB6IXkV4SPQ3l4y6zitlDBMr/V2RK6IrMIWmVW+uIGU8T1J9fKMFfWmG+903/w1FEUFZuw610gJi+O7wNWO/6RsCzK8eYdp8spiSAQ4z+9jgcE7IZhtx0/dFAVyXPS8D+neQe4fiA4A9EfIHPCvmmGIsBusxrPfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592687024; h=Content-Type: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=aKZUgPnC6agty/TggaOBTbqItryyZyuaUmorDKodvOQ=; b=iNdDghJSQqKejRMdjatETns10z43Ee/aWiW3pd9wttp320ycX6Sr//dBk7/PQSb+qh1RE2b+pAh/qsshP07yXLozvH2G76Js9usMomTQhnHliJCJDp6UMsSZA0O83HqWHMzjdVfCbGbdy+JrAJ8RHKFmVi548eNRxevsvichHMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592687024093695.9714574712223; Sat, 20 Jun 2020 14:03:44 -0700 (PDT) Received: from localhost ([::1]:40542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkeM-0002pZ-5D for importer@patchew.org; Sat, 20 Jun 2020 17:03:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXG-00064D-7c for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:22 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:19000) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXD-0000Rq-PQ for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:21 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:54:49 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:18 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:05 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:55:57 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 20 Jun 2020 13:56:18 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 11/17] vfio: Get migration capability flags for container Date: Sun, 21 Jun 2020 01:51:20 +0530 Message-ID: <1592684486-18511-12-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686489; bh=aKZUgPnC6agty/TggaOBTbqItryyZyuaUmorDKodvOQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=CgIuFMoB30DuUrOaulsFZljPpbJvFjejPUPWjJLFvKHkkiIFVUMyaXz+d5fN0K9dT FCJCPO2U1ORkHCnaqJvkOFFeHLRDPtFSYomrHUPKyoldhneGTcUvHNaZ9I58QCzch7 2J9+AJy5q72es/kDT2VgLTm/tnAf2mqkenBelQdyj7gJ6+Mb94bvl699yCWj/jEGMd zoj8ViGIFWOuAWw5m1utdyOuJKffzhb2kO+5688HhI95VypyjbGur3ppUj9OL/8Rkh 9qBU0xg4AmBghel1D8vhSr7rTPVgGEjv8cgZ/rhEhEQb8W1Q2cKu174J+lswGXPgQR ScznLOSBCQaZg== 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; Received-SPF: pass client-ip=216.228.121.143; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate24.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:43 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, Eric Auger , changpeng.liu@intel.com, eskultet@redhat.com, Shameer Kolothum , Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added helper functions to get IOMMU info capability chain. Added function to get migration capability information from that capability chain for IOMMU container. Similar change was proposed earlier: https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg03759.html Signed-off-by: Kirti Wankhede Cc: Shameer Kolothum Cc: Eric Auger --- hw/vfio/common.c | 91 +++++++++++++++++++++++++++++++++++++++= ---- include/hw/vfio/vfio-common.h | 3 ++ 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 90e9a854d82c..e0d3d4585a65 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1229,6 +1229,75 @@ static int vfio_init_container(VFIOContainer *contai= ner, int group_fd, return 0; } =20 +static int vfio_get_iommu_info(VFIOContainer *container, + struct vfio_iommu_type1_info **info) +{ + + size_t argsz =3D sizeof(struct vfio_iommu_type1_info); + + *info =3D g_new0(struct vfio_iommu_type1_info, 1); +again: + (*info)->argsz =3D argsz; + + if (ioctl(container->fd, VFIO_IOMMU_GET_INFO, *info)) { + g_free(*info); + *info =3D NULL; + return -errno; + } + + if (((*info)->argsz > argsz)) { + argsz =3D (*info)->argsz; + *info =3D g_realloc(*info, argsz); + goto again; + } + + return 0; +} + +static struct vfio_info_cap_header * +vfio_get_iommu_info_cap(struct vfio_iommu_type1_info *info, uint16_t id) +{ + struct vfio_info_cap_header *hdr; + void *ptr =3D info; + + if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) { + return NULL; + } + + for (hdr =3D ptr + info->cap_offset; hdr !=3D ptr; hdr =3D ptr + hdr->= next) { + if (hdr->id =3D=3D id) { + return hdr; + } + } + + return NULL; +} + +static void vfio_get_iommu_info_migration(VFIOContainer *container, + struct vfio_iommu_type1_info *inf= o) +{ + struct vfio_info_cap_header *hdr; + struct vfio_iommu_type1_info_cap_migration *cap_mig; + + hdr =3D vfio_get_iommu_info_cap(info, VFIO_IOMMU_TYPE1_INFO_CAP_MIGRAT= ION); + if (!hdr) { + return; + } + + cap_mig =3D container_of(hdr, struct vfio_iommu_type1_info_cap_migrati= on, + header); + + container->dirty_pages_supported =3D true; + container->max_dirty_bitmap_size =3D cap_mig->max_dirty_bitmap_size; + container->dirty_pgsizes =3D cap_mig->pgsize_bitmap; + + /* + * cpu_physical_memory_set_dirty_lebitmap() expects pages in bitmap of + * TARGET_PAGE_SIZE to mark those dirty. + */ + assert(container->dirty_pgsizes & TARGET_PAGE_SIZE); +} + static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, Error **errp) { @@ -1293,6 +1362,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, container->space =3D space; container->fd =3D fd; container->error =3D NULL; + container->dirty_pages_supported =3D false; QLIST_INIT(&container->giommu_list); QLIST_INIT(&container->hostwin_list); =20 @@ -1305,7 +1375,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, case VFIO_TYPE1v2_IOMMU: case VFIO_TYPE1_IOMMU: { - struct vfio_iommu_type1_info info; + struct vfio_iommu_type1_info *info; =20 /* * FIXME: This assumes that a Type1 IOMMU can map any 64-bit @@ -1314,15 +1384,20 @@ static int vfio_connect_container(VFIOGroup *group,= AddressSpace *as, * existing Type1 IOMMUs generally support any IOVA we're * going to actually try in practice. */ - info.argsz =3D sizeof(info); - ret =3D ioctl(fd, VFIO_IOMMU_GET_INFO, &info); - /* Ignore errors */ - if (ret || !(info.flags & VFIO_IOMMU_INFO_PGSIZES)) { + ret =3D vfio_get_iommu_info(container, &info); + if (ret) { + goto free_container_exit; + } + + if (!(info->flags & VFIO_IOMMU_INFO_PGSIZES)) { /* Assume 4k IOVA page size */ - info.iova_pgsizes =3D 4096; + info->iova_pgsizes =3D 4096; } - vfio_host_win_add(container, 0, (hwaddr)-1, info.iova_pgsizes); - container->pgsizes =3D info.iova_pgsizes; + vfio_host_win_add(container, 0, (hwaddr)-1, info->iova_pgsizes); + container->pgsizes =3D info->iova_pgsizes; + + vfio_get_iommu_info_migration(container, info); + g_free(info); break; } case VFIO_SPAPR_TCE_v2_IOMMU: diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index c78033e4149d..5a57a78ec517 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -79,6 +79,9 @@ typedef struct VFIOContainer { unsigned iommu_type; Error *error; bool initialized; + bool dirty_pages_supported; + uint64_t dirty_pgsizes; + uint64_t max_dirty_bitmap_size; unsigned long pgsizes; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686846; cv=none; d=zohomail.com; s=zohoarc; b=PnF/DHNrP1zQG3QOjQGHrHHa1KZ9cIgj0CbAVQ3oQpJ2KT9Inr+DK+BHfMaYMP2+w76Tl90iQxU9kUYgyyIaAqA9pd25F9gDXxSwXNzmmf+k4Kads/GyhvSzgASFjiIC7UEvZqY8h/BqSGU6uRT/XGmPsydwlUzGr307j1lulOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686846; h=Content-Type: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=d4GtgRebZrD+j0T32Py4C4tR/eRSo8dzeIagsSuR6cU=; b=dY1qQSobMqhpXoHuguiauj/wPJFxUx89qhsqK5RrAZ80ezlIqisohk0vjZqx9b51GUicXNbgt8urxAFOHPrEbq9NlHuPWaEAth+N3Nsa+5Rousr3IKFB6AMOubkS+JnClWP8odjC353sP8JKNZXeG3bWd7YqGOhN7iXum3G3OoU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686846406623.7637312074994; Sat, 20 Jun 2020 14:00:46 -0700 (PDT) Received: from localhost ([::1]:58154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkbV-0005fu-51 for importer@patchew.org; Sat, 20 Jun 2020 17:00:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXK-0006Ee-Iq for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:26 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:19783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXI-0000SB-Jo for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:26 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:55:39 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:23 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:13 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:05 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:23 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 12/17] vfio: Add function to start and stop dirty pages tracking Date: Sun, 21 Jun 2020 01:51:21 +0530 Message-ID: <1592684486-18511-13-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686539; bh=d4GtgRebZrD+j0T32Py4C4tR/eRSo8dzeIagsSuR6cU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=cIHH1839z43c++N4/pbKAzQYwJZNHMO25LmYdiVRPGYtqQ/yXeHpQUXh8NhDwwKHN FIipwoNaMSLTZM9JG6lCQiuluR3VWW3JOTk2chpByTcwRtheSVmfgtlGumbNPiK1V+ X+s3ORRLGvEhiDauoSfy8y95yrVBLm4IXKSxC5G2+R3/7qebndPjT++vT4pZRoa4cO 2Qb3+UN8+pOV68RzCLnt8e55OJ1/YrfEk+RGB4Ggyavtxf8cUph9NQHE8T9lsPwwbW gBogSNJL8ixsX6MzP5t58Ak+ihS1VnaKCkAygfYGHMSWY9J3zZXipLZchcEGiNzv+7 kNbU68aR94nKw== 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; Received-SPF: pass client-ip=216.228.121.64; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate25.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:55:03 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Call VFIO_IOMMU_DIRTY_PAGES ioctl to start and stop dirty pages tracking for VFIO devices. Signed-off-by: Kirti Wankhede Reviewed-by: Dr. David Alan Gilbert --- hw/vfio/migration.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index faacea5327cb..e0fbb3a01855 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -11,6 +11,7 @@ #include "qemu/main-loop.h" #include "qemu/cutils.h" #include +#include =20 #include "sysemu/runstate.h" #include "hw/vfio/vfio-common.h" @@ -329,6 +330,32 @@ static int vfio_load_device_config_state(QEMUFile *f, = void *opaque) return qemu_file_get_error(f); } =20 +static int vfio_start_dirty_page_tracking(VFIODevice *vbasedev, bool start) +{ + int ret; + VFIOContainer *container =3D vbasedev->group->container; + struct vfio_iommu_type1_dirty_bitmap dirty =3D { + .argsz =3D sizeof(dirty), + }; + + if (start) { + if (vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) { + dirty.flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_START; + } else { + return -EINVAL; + } + } else { + dirty.flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty); + if (ret) { + error_report("Failed to set dirty tracking flag 0x%x errno: %d", + dirty.flags, errno); + } + return ret; +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -360,6 +387,11 @@ static int vfio_save_setup(QEMUFile *f, void *opaque) return ret; } =20 + ret =3D vfio_start_dirty_page_tracking(vbasedev, true); + if (ret) { + return ret; + } + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); =20 ret =3D qemu_file_get_error(f); @@ -375,6 +407,8 @@ static void vfio_save_cleanup(void *opaque) VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; =20 + vfio_start_dirty_page_tracking(vbasedev, false); + if (migration->region.mmaps) { vfio_region_unmap(&migration->region); } @@ -706,6 +740,8 @@ static void vfio_migration_state_notifier(Notifier *not= ifier, void *data) if (ret) { error_report("%s: Failed to set state RUNNING", vbasedev->name= ); } + + vfio_start_dirty_page_tracking(vbasedev, false); } } =20 --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592687169; cv=none; d=zohomail.com; s=zohoarc; b=TMdWSpZQ5hFX9gjSef2g1A/m1bzDW6ztBv/y+gtOxb+4+U3ISr6Xfn3uYd+OKmyHbpRClkEuBYEb30ggFAs6n3Zx6IuorRs3vrFrVU96EuRr1/cN6KAa5MBLWrvOYThVuvPPTl67cHAdgOTw0aHjf4IPoNR4wvPrJ/EnItjqaVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592687169; h=Content-Type: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=azm+HEg8eFiI6GAZx/d7Ht6MPVKq1vZpEvScHis2BBU=; b=Mf09+H3tUxCe+HGROODHgWiszFO+4pSi50BCEZlX8ivhfAVncOJCuh5N9xkXHOOEpAmhdipXYzu0D+qRaqL+jihjhqZm16ptDCINUpeWYlZ6/5+90T4zl11oHx1Pk0+EpG43dIlSzUgg4iMjaWKhknDx6WP6G9MdgoVNL2dqymQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592687169273621.5471519661545; Sat, 20 Jun 2020 14:06:09 -0700 (PDT) Received: from localhost ([::1]:48954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkgh-0007Qe-R2 for importer@patchew.org; Sat, 20 Jun 2020 17:06:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXO-0006OP-KD for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:30 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXM-0000SS-94 for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:30 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:56:14 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:26 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:21 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:13 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:26 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 13/17] vfio: create mapped iova list when vIOMMU is enabled Date: Sun, 21 Jun 2020 01:51:22 +0530 Message-ID: <1592684486-18511-14-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686574; bh=azm+HEg8eFiI6GAZx/d7Ht6MPVKq1vZpEvScHis2BBU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=CSAmbb5VyjkUYUl2YEmLdzYnnjRVzs3Tiv6sikoYmCe0+m0cEG1xcewLqkdmqQIgn WJ7Wc+SJvqO2HarasEy9AsIvEELsohUhwjIIyr3LUuDVw3tjo3nbU2tNuH49z57v+M bP0PKRwolkyxg2QE4LDzSffLIEB02/lgbDMQTMM3bA5dJeGplFv0Gg+G8+v/cF0T95 V3JyYfKB4LnQj7doy1HCmIgM2o/b4mQp0ioa9Z1aefpNooqRhCF5E0rhakWligNURB G0I8yRMR5iXDjFHYDyr4cwwCX7s1KPItNolvdo4j9AdvcsalUIYrSsSA80mX0D/kSD yMmL/G405bqKw== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create mapped iova list when vIOMMU is enabled. For each mapped iova save translated address. Add node to list on MAP and remove node from list on UNMAP. This list is used to track dirty pages during migration. Signed-off-by: Kirti Wankhede --- hw/vfio/common.c | 58 ++++++++++++++++++++++++++++++++++++++-= ---- include/hw/vfio/vfio-common.h | 8 ++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e0d3d4585a65..6921a78e9ba5 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -408,8 +408,8 @@ static bool vfio_listener_skipped_section(MemoryRegionS= ection *section) } =20 /* Called with rcu_read_lock held. */ -static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr, - bool *read_only) +static bool vfio_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, + ram_addr_t *ram_addr, bool *read_only) { MemoryRegion *mr; hwaddr xlat; @@ -440,8 +440,17 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void = **vaddr, return false; } =20 - *vaddr =3D memory_region_get_ram_ptr(mr) + xlat; - *read_only =3D !writable || mr->readonly; + if (vaddr) { + *vaddr =3D memory_region_get_ram_ptr(mr) + xlat; + } + + if (ram_addr) { + *ram_addr =3D memory_region_get_ram_addr(mr) + xlat; + } + + if (read_only) { + *read_only =3D !writable || mr->readonly; + } =20 return true; } @@ -451,7 +460,6 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) VFIOGuestIOMMU *giommu =3D container_of(n, VFIOGuestIOMMU, n); VFIOContainer *container =3D giommu->container; hwaddr iova =3D iotlb->iova + giommu->iommu_offset; - bool read_only; void *vaddr; int ret; =20 @@ -467,7 +475,10 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IO= MMUTLBEntry *iotlb) rcu_read_lock(); =20 if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { - if (!vfio_get_vaddr(iotlb, &vaddr, &read_only)) { + ram_addr_t ram_addr; + bool read_only; + + if (!vfio_get_xlat_addr(iotlb, &vaddr, &ram_addr, &read_only)) { goto out; } /* @@ -485,8 +496,28 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IO= MMUTLBEntry *iotlb) "0x%"HWADDR_PRIx", %p) =3D %d (%m)", container, iova, iotlb->addr_mask + 1, vaddr, ret); + } else { + VFIOIovaRange *iova_range; + + iova_range =3D g_malloc0(sizeof(*iova_range)); + iova_range->iova =3D iova; + iova_range->size =3D iotlb->addr_mask + 1; + iova_range->ram_addr =3D ram_addr; + + QLIST_INSERT_HEAD(&giommu->iova_list, iova_range, next); } } else { + VFIOIovaRange *iova_range, *tmp; + + QLIST_FOREACH_SAFE(iova_range, &giommu->iova_list, next, tmp) { + if (iova_range->iova >=3D iova && + iova_range->iova + iova_range->size <=3D iova + + iotlb->addr_mask + = 1) { + QLIST_REMOVE(iova_range, next); + g_free(iova_range); + } + } + ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " @@ -643,6 +674,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, g_free(giommu); goto fail; } + QLIST_INIT(&giommu->iova_list); QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next); memory_region_iommu_replay(giommu->iommu, &giommu->n); =20 @@ -741,6 +773,13 @@ static void vfio_listener_region_del(MemoryListener *l= istener, QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { if (MEMORY_REGION(giommu->iommu) =3D=3D section->mr && giommu->n.start =3D=3D section->offset_within_region) { + VFIOIovaRange *iova_range, *tmp; + + QLIST_FOREACH_SAFE(iova_range, &giommu->iova_list, next, t= mp) { + QLIST_REMOVE(iova_range, next); + g_free(iova_range); + } + memory_region_unregister_iommu_notifier(section->mr, &giommu->n); QLIST_REMOVE(giommu, giommu_next); @@ -1538,6 +1577,13 @@ static void vfio_disconnect_container(VFIOGroup *gro= up) QLIST_REMOVE(container, next); =20 QLIST_FOREACH_SAFE(giommu, &container->giommu_list, giommu_next, t= mp) { + VFIOIovaRange *iova_range, *itmp; + + QLIST_FOREACH_SAFE(iova_range, &giommu->iova_list, next, itmp)= { + QLIST_REMOVE(iova_range, next); + g_free(iova_range); + } + memory_region_unregister_iommu_notifier( MEMORY_REGION(giommu->iommu), &giommu->n); QLIST_REMOVE(giommu, giommu_next); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 5a57a78ec517..56b75e4a8bc4 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -89,11 +89,19 @@ typedef struct VFIOContainer { QLIST_ENTRY(VFIOContainer) next; } VFIOContainer; =20 +typedef struct VFIOIovaRange { + hwaddr iova; + size_t size; + ram_addr_t ram_addr; + QLIST_ENTRY(VFIOIovaRange) next; +} VFIOIovaRange; + typedef struct VFIOGuestIOMMU { VFIOContainer *container; IOMMUMemoryRegion *iommu; hwaddr iommu_offset; IOMMUNotifier n; + QLIST_HEAD(, VFIOIovaRange) iova_list; QLIST_ENTRY(VFIOGuestIOMMU) giommu_next; } VFIOGuestIOMMU; =20 --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686988; cv=none; d=zohomail.com; s=zohoarc; b=IkFjwWh1T9S5Uz/o6WTeZY8QhtGIcCjWvsRv6s8RY5Ma3fZ49PMHbM4/vhN1NjOLbrYors2qnDECSkzPBTy1Hs26324SRzq1Pp3rKAynuo6TMZ2iFKFdJipSLQCgaERRWWdgh9wiNUdqBLZiz0Syb4GlFhOl9APV7UJldFteeoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686988; h=Content-Type: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=N/jUjXWsWdLZD+8jlrwaf5har468h4ELMmhLfVIXQHA=; b=eTQtU/x8yhEuGXN0Nqq9SJ/Dm5STNYi7N17qmQhCdHGl3mUS0bmEi2wnka+ZYnZ9pJ3UzKdObsWNRnGVYPwoqBOeTWWcaRmo3LF0/usX48tU66qtYLF2XueF6eSMWHegYGABa0GN5ppVI+si1RHXAXduxMOAbzxHVxvXOptoboo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 159268698809616.314284512041013; Sat, 20 Jun 2020 14:03:08 -0700 (PDT) Received: from localhost ([::1]:38532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkdm-0001VC-IB for importer@patchew.org; Sat, 20 Jun 2020 17:03:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXc-0006vo-6Z for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:44 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1181) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXW-0000WA-9Q for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:43 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:56:24 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:37 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:29 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:21 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Sat, 20 Jun 2020 13:56:37 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 14/17] vfio: Add vfio_listener_log_sync to mark dirty pages Date: Sun, 21 Jun 2020 01:51:23 +0530 Message-ID: <1592684486-18511-15-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686584; bh=N/jUjXWsWdLZD+8jlrwaf5har468h4ELMmhLfVIXQHA=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=H+otU3hVNTld1i8AXX90WSU0hTPgJknx+7GqSuMcChXGCeAnkIzoGOGeCWw/jv2zB 04IeTCBrFiHayXlC68IS+AthVbktOQtCxJyNl388HAJ8kdVHuOqufoO9I6zC3Z7Mwv mGXVLtfHpX1ZgtOV+WviPN9MJtAJ3rd0Xj8KohDFuNszb1xH7p/uRLrHvZMm8BkfrX N/1KLrvUvTf1u/pCnAlKxZwkjvpuTPRtLykc8es4fox2q5jUctv6c43Phs92f4AgEM LD0Hs5sdYVP4VjKDEfldKZ1hEgn4RJa/cAPqCfiyXeDCThLB7GFND5ExvTOOdKnnvZ Q9JxtPmmluArw== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vfio_listener_log_sync gets list of dirty pages from container using VFIO_IOMMU_GET_DIRTY_BITMAP ioctl and mark those pages dirty when all devices are stopped and saving state. Return early for the RAM block section of mapped MMIO region. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/common.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 1 + 2 files changed, 131 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 6921a78e9ba5..0518cf228ed5 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -29,6 +29,7 @@ #include "hw/vfio/vfio.h" #include "exec/address-spaces.h" #include "exec/memory.h" +#include "exec/ram_addr.h" #include "hw/hw.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" @@ -38,6 +39,7 @@ #include "sysemu/reset.h" #include "trace.h" #include "qapi/error.h" +#include "migration/migration.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -288,6 +290,28 @@ const MemoryRegionOps vfio_region_ops =3D { }; =20 /* + * Device state interfaces + */ + +static bool vfio_devices_are_stopped_and_saving(void) +{ + VFIOGroup *group; + VFIODevice *vbasedev; + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if ((vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) && + !(vbasedev->device_state & VFIO_DEVICE_STATE_RUNNING)) { + continue; + } else { + return false; + } + } + } + return true; +} + +/* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ static int vfio_dma_unmap(VFIOContainer *container, @@ -852,9 +876,115 @@ static void vfio_listener_region_del(MemoryListener *= listener, } } =20 +static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova, + uint64_t size, ram_addr_t ram_addr) +{ + struct vfio_iommu_type1_dirty_bitmap *dbitmap; + struct vfio_iommu_type1_dirty_bitmap_get *range; + uint64_t pages; + int ret; + + dbitmap =3D g_malloc0(sizeof(*dbitmap) + sizeof(*range)); + + dbitmap->argsz =3D sizeof(*dbitmap) + sizeof(*range); + dbitmap->flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP; + range =3D (struct vfio_iommu_type1_dirty_bitmap_get *)&dbitmap->data; + range->iova =3D iova; + range->size =3D size; + + /* + * cpu_physical_memory_set_dirty_lebitmap() expects pages in bitmap of + * TARGET_PAGE_SIZE to mark those dirty. Hence set bitmap's pgsize to + * TARGET_PAGE_SIZE. + */ + range->bitmap.pgsize =3D TARGET_PAGE_SIZE; + + pages =3D TARGET_PAGE_ALIGN(range->size) >> TARGET_PAGE_BITS; + range->bitmap.size =3D ROUND_UP(pages, sizeof(__u64) * BITS_PER_BYTE) / + BITS_PER_BYTE; + range->bitmap.data =3D g_try_malloc0(range->bitmap.size); + if (!range->bitmap.data) { + ret =3D -ENOMEM; + goto err_out; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap); + if (ret) { + error_report("Failed to get dirty bitmap for iova: 0x%llx " + "size: 0x%llx err: %d", + range->iova, range->size, errno); + goto err_out; + } + + cpu_physical_memory_set_dirty_lebitmap((uint64_t *)range->bitmap.data, + ram_addr, pages); + + trace_vfio_get_dirty_bitmap(container->fd, range->iova, range->size, + range->bitmap.size, ram_addr); +err_out: + g_free(range->bitmap.data); + g_free(dbitmap); + + return ret; +} + +static int vfio_sync_dirty_bitmap(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); + VFIOGuestIOMMU *giommu =3D NULL; + ram_addr_t ram_addr; + uint64_t iova, size; + int ret =3D 0; + + if (memory_region_is_iommu(section->mr)) { + + QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { + if (MEMORY_REGION(giommu->iommu) =3D=3D section->mr && + giommu->n.start =3D=3D section->offset_within_region) { + VFIOIovaRange *iova_range; + + QLIST_FOREACH(iova_range, &giommu->iova_list, next) { + ret =3D vfio_get_dirty_bitmap(container, iova_range->i= ova, + iova_range->size, iova_range->ram_= addr); + if (ret) { + break; + } + } + break; + } + } + + } else { + iova =3D TARGET_PAGE_ALIGN(section->offset_within_address_space); + size =3D int128_get64(section->size); + + ram_addr =3D memory_region_get_ram_addr(section->mr) + + section->offset_within_region + iova - + TARGET_PAGE_ALIGN(section->offset_within_address_space); + + ret =3D vfio_get_dirty_bitmap(container, iova, size, ram_addr); + } + + return ret; +} + +static void vfio_listerner_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + if (vfio_listener_skipped_section(section)) { + return; + } + + if (vfio_devices_are_stopped_and_saving()) { + vfio_sync_dirty_bitmap(listener, section); + } +} + static const MemoryListener vfio_memory_listener =3D { .region_add =3D vfio_listener_region_add, .region_del =3D vfio_listener_region_del, + .log_sync =3D vfio_listerner_log_sync, }; =20 static void vfio_listener_release(VFIOContainer *container) diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 4a4bd3ba9a2a..c61ae4f3ead8 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -160,3 +160,4 @@ vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_load_state_device_data(const char *name, uint64_t data_offset, uint64= _t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitma= p_size, uint64_t start) "container fd=3D%d, iova=3D0x%"PRIx64" size=3D 0x%"= PRIx64" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64 --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592687319; cv=none; d=zohomail.com; s=zohoarc; b=YzqCKwdZlJ3tiCQ4JzSNF9sUQMDherd84Z7t0YC512rF5dCeHjhinafyMMh+WirxuJNT+LZcFE/lqGDc8F+AmgNkNEwODEWVHCLd+UbbgOsjv3pM1zVYIQ4PS26ohTWDIzlo8vMggqRAtbNSK+iICeIoi7UoG13rqZJ4nNQyv/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592687319; h=Content-Type: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=7MOtC0a1G3F+JPPeNTGaDgzeI+ej4DZNVmcUZDoxzKg=; b=e65Nq6zwhIlaixrapZCXJ3d1tNYVhtTfWLB6vfAK1e1iz2t6LCw6XzK+wvyjasmYavI443Ddp8O7DjudU9VghCvxKVKedbHTUmwFbD7iXFp13FsJHyXWsMyh1er/SF7mzRfHOmZSsQA8qhlyYSKsfxev4SpJin1Cj5jqKwocGpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592687319067600.3456923412716; Sat, 20 Jun 2020 14:08:39 -0700 (PDT) Received: from localhost ([::1]:57768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkj7-0003ee-Ku for importer@patchew.org; Sat, 20 Jun 2020 17:08:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51898) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXf-00072t-7k for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:47 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1197) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXc-0000Yf-TV for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:46 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:56:30 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:43 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:36 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:29 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:43 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 15/17] vfio: Add ioctl to get dirty pages bitmap during dma unmap. Date: Sun, 21 Jun 2020 01:51:24 +0530 Message-ID: <1592684486-18511-16-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686590; bh=7MOtC0a1G3F+JPPeNTGaDgzeI+ej4DZNVmcUZDoxzKg=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=MkzxCayj0XTgBcBWnOeKlYOfEcTssG0sLheAv+nwbtq1XvNbq6SHbhy3x6GVbf8BQ 3QeHLvQDKtdEi1mAc16dP9qGhVQ1Q7AgwNPKv0I4ZeYyRJAMHLI7DYSJJMAl33sJay ttT8aVYjvcMDXvJl9oh0YXRxkkjMoK3oNXOwKfAbvjKb4K1xT4tCsj2TcmVrqN7iSP l5NV0VijDklnWUJE8QjPykEa2fpVo1jxz/8G8qlRjme+dLWC1iNIE/QswRzo2tAn7y LvR4YpzBoABuOVLRD+7qSwzJEv5HLcZ5Rte8gu9aTcXFXWbVuY98skPifwBG2lWUxp LhSSg2wcUTizQ== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With vIOMMU, IO virtual address range can get unmapped while in pre-copy phase of migration. In that case, unmap ioctl should return pages pinned in that range and QEMU should find its correcponding guest physical addresses and report those dirty. Suggested-by: Alex Williamson Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/common.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0518cf228ed5..a06b8f2f66e2 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -311,11 +311,83 @@ static bool vfio_devices_are_stopped_and_saving(void) return true; } =20 +static bool vfio_devices_are_running_and_saving(void) +{ + VFIOGroup *group; + VFIODevice *vbasedev; + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if ((vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) && + (vbasedev->device_state & VFIO_DEVICE_STATE_RUNNING)) { + continue; + } else { + return false; + } + } + } + return true; +} + +static int vfio_dma_unmap_bitmap(VFIOContainer *container, + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) +{ + struct vfio_iommu_type1_dma_unmap *unmap; + struct vfio_bitmap *bitmap; + uint64_t pages =3D TARGET_PAGE_ALIGN(size) >> TARGET_PAGE_BITS; + int ret; + + unmap =3D g_malloc0(sizeof(*unmap) + sizeof(*bitmap)); + + unmap->argsz =3D sizeof(*unmap) + sizeof(*bitmap); + unmap->iova =3D iova; + unmap->size =3D size; + unmap->flags |=3D VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP; + bitmap =3D (struct vfio_bitmap *)&unmap->data; + + /* + * cpu_physical_memory_set_dirty_lebitmap() expects pages in bitmap of + * TARGET_PAGE_SIZE to mark those dirty. Hence set bitmap_pgsize to + * TARGET_PAGE_SIZE. + */ + + bitmap->pgsize =3D TARGET_PAGE_SIZE; + bitmap->size =3D ROUND_UP(pages, sizeof(__u64) * BITS_PER_BYTE) / + BITS_PER_BYTE; + + if (bitmap->size > container->max_dirty_bitmap_size) { + error_report("UNMAP: Size of bitmap too big 0x%llx", bitmap->size); + ret =3D -E2BIG; + goto unmap_exit; + } + + bitmap->data =3D g_try_malloc0(bitmap->size); + if (!bitmap->data) { + ret =3D -ENOMEM; + goto unmap_exit; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, unmap); + if (!ret) { + cpu_physical_memory_set_dirty_lebitmap((uint64_t *)bitmap->data, + iotlb->translated_addr, pages); + } else { + error_report("VFIO_UNMAP_DMA with DIRTY_BITMAP : %m"); + } + + g_free(bitmap->data); +unmap_exit: + g_free(unmap); + return ret; +} + /* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ static int vfio_dma_unmap(VFIOContainer *container, - hwaddr iova, ram_addr_t size) + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) { struct vfio_iommu_type1_dma_unmap unmap =3D { .argsz =3D sizeof(unmap), @@ -324,6 +396,11 @@ static int vfio_dma_unmap(VFIOContainer *container, .size =3D size, }; =20 + if (iotlb && container->dirty_pages_supported && + vfio_devices_are_running_and_saving()) { + return vfio_dma_unmap_bitmap(container, iova, size, iotlb); + } + while (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { /* * The type1 backend has an off-by-one bug in the kernel (71a7d3d7= 8e3c @@ -371,7 +448,7 @@ static int vfio_dma_map(VFIOContainer *container, hwadd= r iova, * the VGA ROM space. */ if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) =3D=3D 0 || - (errno =3D=3D EBUSY && vfio_dma_unmap(container, iova, size) =3D= =3D 0 && + (errno =3D=3D EBUSY && vfio_dma_unmap(container, iova, size, NULL)= =3D=3D 0 && ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) =3D=3D 0)) { return 0; } @@ -542,7 +619,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) } } =20 - ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1); + ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1, iotl= b); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") =3D %d (%m)", @@ -853,7 +930,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, } =20 if (try_unmap) { - ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize)); + ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize), NULL= ); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") =3D %d (%m)", --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592687134; cv=none; d=zohomail.com; s=zohoarc; b=NfDnmG2lmyjQlCHe39tgLt4744S6skpuL5FzNvtXvkA4LEC9FyF7ln5nRP4RLaMwCd6aWWqjEfWgm/cyZXnix9luu0+zbdPzhmEiluTmKbOVDnSNMbyfLZD+5NfxNHMO0oCjFaKfCmmprWYzlOQF9ReJMBzfPkkY+3yUDwh1B6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592687134; h=Content-Type: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=4mBVs2u4Z55g8cokYzZt9bDlmCVwrsx11CQpSDb4qpY=; b=QheWtfSyLX7ZRkXx9tYcyh7ah4/V1CqikKImKkcgbgktgCzr4q79Fu289bHiQZUbSGj8edvA4BJQDC9+aggyTg4NXNrHiZBnoFiALm0V8nUfq5ePgd1szkSmZhhgLCN4vI5IMkrFisbDh8A5h44W2Qvf+MRJze+uRR23CP5/yio= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592687134803253.31782326295138; Sat, 20 Jun 2020 14:05:34 -0700 (PDT) Received: from localhost ([::1]:46764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkg9-0005yB-Hq for importer@patchew.org; Sat, 20 Jun 2020 17:05:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXo-0007If-K1 for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:56 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1202) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXm-0000b8-MB for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:56:56 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:56:40 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:53 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:44 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:37 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:53 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 16/17] vfio: Make vfio-pci device migration capable Date: Sun, 21 Jun 2020 01:51:25 +0530 Message-ID: <1592684486-18511-17-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686600; bh=4mBVs2u4Z55g8cokYzZt9bDlmCVwrsx11CQpSDb4qpY=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=PfrpkyMCFG94AO8Yfl8LEntBC2dZlrnmZS+wJ/APqAqPfyxXQ70eCJcuOYSyCxO8r U5FmsTqx5aBwLRf8Dr5muq6C5sm4dDf8Qf1duPT0BnFXqXFX5m3c0Xu0KFw5WPk3rP H3ZseMnAf9HZVY0oAe2t840gQ07uy0cPeeW05E28qkatygLENNuSaPA3LkqKGytAoy 0/+HP97U9If2TbXYPvuajyP4wPQDMTj1SbvcWQRAPncXJlbA+HK1d2u0mLy02Ixw68 /FMGMQtiG3Bs6AU7dtW2lJkjR9ncA9K89CY++KMEh/buS5nd4IO1yml6NZzs4N/7dn e+filzxBZjk7A== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If device is not failover primary device call vfio_migration_probe() and vfio_migration_finalize() functions for vfio-pci device to enable migration for vfio PCI device which support migration. Removed vfio_pci_vmstate structure. Removed migration blocker from VFIO PCI device specific structure and use migration blocker from generic structure of VFIO device. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Dr. David Alan Gilbert --- hw/vfio/pci.c | 32 +++++++++++--------------------- hw/vfio/pci.h | 1 - 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5ba340aee1d4..9dc2868993fb 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2841,22 +2841,11 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) return; } =20 - if (!pdev->failover_pair_id) { - error_setg(&vdev->migration_blocker, - "VFIO device doesn't support migration"); - ret =3D migrate_add_blocker(vdev->migration_blocker, &err); - if (ret) { - error_propagate(errp, err); - error_free(vdev->migration_blocker); - vdev->migration_blocker =3D NULL; - return; - } - } - vdev->vbasedev.name =3D g_path_get_basename(vdev->vbasedev.sysfsdev); vdev->vbasedev.ops =3D &vfio_pci_ops; vdev->vbasedev.type =3D VFIO_DEVICE_TYPE_PCI; vdev->vbasedev.dev =3D DEVICE(vdev); + vdev->vbasedev.device_state =3D 0; =20 tmp =3D g_strdup_printf("%s/iommu_group", vdev->vbasedev.sysfsdev); len =3D readlink(tmp, group_path, sizeof(group_path)); @@ -3120,6 +3109,14 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) } } =20 + if (!pdev->failover_pair_id) { + ret =3D vfio_migration_probe(&vdev->vbasedev, errp); + if (ret) { + error_report("%s: Failed to setup for migration", + vdev->vbasedev.name); + } + } + vfio_register_err_notifier(vdev); vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); @@ -3134,11 +3131,6 @@ out_teardown: vfio_bars_exit(vdev); error: error_prepend(errp, VFIO_MSG_PREFIX, vdev->vbasedev.name); - if (vdev->migration_blocker) { - migrate_del_blocker(vdev->migration_blocker); - error_free(vdev->migration_blocker); - vdev->migration_blocker =3D NULL; - } } =20 static void vfio_instance_finalize(Object *obj) @@ -3150,10 +3142,7 @@ static void vfio_instance_finalize(Object *obj) vfio_bars_finalize(vdev); g_free(vdev->emulated_config_bits); g_free(vdev->rom); - if (vdev->migration_blocker) { - migrate_del_blocker(vdev->migration_blocker); - error_free(vdev->migration_blocker); - } + /* * XXX Leaking igd_opregion is not an oversight, we can't remove the * fw_cfg entry therefore leaking this allocation seems like the safest @@ -3181,6 +3170,7 @@ static void vfio_exitfn(PCIDevice *pdev) } vfio_teardown_msi(vdev); vfio_bars_exit(vdev); + vfio_migration_finalize(&vdev->vbasedev); } =20 static void vfio_pci_reset(DeviceState *dev) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 0da7a20a7ec2..b148c937ef72 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -168,7 +168,6 @@ typedef struct VFIOPCIDevice { bool no_vfio_ioeventfd; bool enable_ramfb; VFIODisplay *dpy; - Error *migration_blocker; Notifier irqchip_change_notifier; } VFIOPCIDevice; =20 --=20 2.7.0 From nobody Thu Jun 13 12:38:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1592686964; cv=none; d=zohomail.com; s=zohoarc; b=CuO06my6JW/uiMlKD5VBl19yvisSNC4CTdmvRvd0LQY0HWoNrqTdchGBfQXMgbkCYC7adtLKpPzWTLDCqXU3/rHSFe9smJBTkBR7+ghhZWMgDWC0lTqTYpESgD5/QgtA715TdLuAS7JrPcM5oPwoTTP2qqpEguzcQ70j7xDy7QU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592686964; h=Content-Type: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=ZgbpubgazlEdcwYSFUCPqwnBN7S6ohc3gEMlRJXIsxc=; b=L/QMhLQyLwqJsqv4GCmNqc3RHqscIzKy0O/uRwYTL3Ptde0ecUMNSs57PLpkKrOlrO/jlUd9DcNDro2543VvziX0R2lYT+ENlxfEtVcFfqwl0DbVq0POdxc0BKACL4b+3PZ6Zg3Y+6TyUZTYrEerGa8jbgen+/olgABqM2B7X6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1592686964007592.5750842341976; Sat, 20 Jun 2020 14:02:44 -0700 (PDT) Received: from localhost ([::1]:37046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmkdO-0000m7-NH for importer@patchew.org; Sat, 20 Jun 2020 17:02:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXt-0007N5-Qx for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:57:01 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:1216) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmkXr-0000bL-M8 for qemu-devel@nongnu.org; Sat, 20 Jun 2020 16:57:01 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Sat, 20 Jun 2020 13:56:45 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Sat, 20 Jun 2020 13:56:58 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Sat, 20 Jun 2020 20:56:52 +0000 Received: from kwankhede-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Sat, 20 Jun 2020 20:56:45 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Sat, 20 Jun 2020 13:56:58 -0700 From: Kirti Wankhede To: , Subject: [PATCH QEMU v25 17/17] qapi: Add VFIO devices migration stats in Migration stats Date: Sun, 21 Jun 2020 01:51:26 +0530 Message-ID: <1592684486-18511-18-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> References: <1592684486-18511-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1592686605; bh=ZgbpubgazlEdcwYSFUCPqwnBN7S6ohc3gEMlRJXIsxc=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=LDU+ZD/qv8f4owutKpzCEmU4jX0twqTBg6nP38h9prN4eQDjJCD477OmtfQ242rSS QE9jhXz4Aiq5iA9rUvabavmrbm2w6gn83ch3THkkaMO36JRatwu+ABjKerxRboby5C 4paXyGQv26OuSXA+yQGnRoHv1fyfJL/Y8U0dOs0RLXOefIYKXAWHePtKE5S6ELGyKK HyrS2FF4A4VFXOC1XwXgghOcCKYysz5BDsgo85mu8oZkuQ/3njiUzjTJvB9N0Mi6FL a/Jgn092jCylo6zL2qvTQL+T6Dj7NG61mG6hc9rG5E2Ij02b2yoFfMCK4V8zaZCFAs 49f31Svi38Hfw== 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; Received-SPF: pass client-ip=216.228.121.65; envelope-from=kwankhede@nvidia.com; helo=hqnvemgate26.nvidia.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/20 16:54:48 X-ACL-Warn: Detected OS = Windows 7 or 8 [fuzzy] X-Spam_score_int: -80 X-Spam_score: -8.1 X-Spam_bar: -------- X-Spam_report: (-8.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: cohuck@redhat.com, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org, peterx@redhat.com, Kirti Wankhede , eauger@redhat.com, yi.l.liu@intel.com, quintela@redhat.com, ziye.yang@intel.com, armbru@redhat.com, mlevitsk@redhat.com, pasic@linux.ibm.com, felipe@nutanix.com, zhi.a.wang@intel.com, kevin.tian@intel.com, yan.y.zhao@intel.com, dgilbert@redhat.com, changpeng.liu@intel.com, eskultet@redhat.com, Ken.Xue@amd.com, jonathan.davies@nutanix.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added amount of bytes transferred to the target VM by all VFIO devices Signed-off-by: Kirti Wankhede --- hw/vfio/common.c | 20 ++++++++++++++++++++ hw/vfio/migration.c | 11 ++++++++++- include/qemu/vfio-helpers.h | 3 +++ migration/migration.c | 14 ++++++++++++++ monitor/hmp-cmds.c | 6 ++++++ qapi/migration.json | 17 +++++++++++++++++ 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index a06b8f2f66e2..ff0a4072107f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -40,6 +40,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/migration.h" +#include "qemu/vfio-helpers.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -293,6 +294,25 @@ const MemoryRegionOps vfio_region_ops =3D { * Device state interfaces */ =20 +bool vfio_mig_active(void) +{ + VFIOGroup *group; + VFIODevice *vbasedev; + + if (QLIST_EMPTY(&vfio_group_list)) { + return false; + } + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if (vbasedev->migration_blocker) { + return false; + } + } + } + return true; +} + static bool vfio_devices_are_stopped_and_saving(void) { VFIOGroup *group; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index e0fbb3a01855..09eec9cafdd5 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -27,7 +27,7 @@ #include "exec/ram_addr.h" #include "pci.h" #include "trace.h" - +#include "qemu/vfio-helpers.h" /* * Flags used as delimiter: * 0xffffffff =3D> MSB 32-bit all 1s @@ -39,6 +39,8 @@ #define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL) #define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) =20 +static int64_t bytes_transferred; + static void vfio_migration_region_exit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; @@ -261,6 +263,7 @@ static int vfio_save_buffer(QEMUFile *f, VFIODevice *vb= asedev) return ret; } =20 + bytes_transferred +=3D data_size; return data_size; } =20 @@ -742,6 +745,7 @@ static void vfio_migration_state_notifier(Notifier *not= ifier, void *data) } =20 vfio_start_dirty_page_tracking(vbasedev, false); + bytes_transferred =3D 0; } } =20 @@ -789,6 +793,11 @@ static int vfio_migration_init(VFIODevice *vbasedev, =20 /* ---------------------------------------------------------------------- = */ =20 +int64_t vfio_mig_bytes_transferred(void) +{ + return bytes_transferred; +} + int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) { struct vfio_region_info *info; diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h index 1f057c2b9e40..26a7df0767b1 100644 --- a/include/qemu/vfio-helpers.h +++ b/include/qemu/vfio-helpers.h @@ -29,4 +29,7 @@ void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index,= void *bar, int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e, int irq_type, Error **errp); =20 +bool vfio_mig_active(void); +int64_t vfio_mig_bytes_transferred(void); + #endif diff --git a/migration/migration.c b/migration/migration.c index 481a590f7222..8b010a002c3d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -54,6 +54,7 @@ #include "net/announce.h" #include "qemu/queue.h" #include "multifd.h" +#include "qemu/vfio-helpers.h" =20 #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttli= ng */ =20 @@ -970,6 +971,17 @@ static void populate_disk_info(MigrationInfo *info) } } =20 +static void populate_vfio_info(MigrationInfo *info) +{ +#ifdef CONFIG_LINUX + if (vfio_mig_active()) { + info->has_vfio =3D true; + info->vfio =3D g_malloc0(sizeof(*info->vfio)); + info->vfio->transferred =3D vfio_mig_bytes_transferred(); + } +#endif +} + static void fill_source_migration_info(MigrationInfo *info) { MigrationState *s =3D migrate_get_current(); @@ -995,6 +1007,7 @@ static void fill_source_migration_info(MigrationInfo *= info) populate_time_info(info, s); populate_ram_info(info, s); populate_disk_info(info); + populate_vfio_info(info); break; case MIGRATION_STATUS_COLO: info->has_status =3D true; @@ -1003,6 +1016,7 @@ static void fill_source_migration_info(MigrationInfo = *info) case MIGRATION_STATUS_COMPLETED: populate_time_info(info, s); populate_ram_info(info, s); + populate_vfio_info(info); break; case MIGRATION_STATUS_FAILED: info->has_status =3D true; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 2b0b58a336e6..29bb4d2d949c 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -355,6 +355,12 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) } monitor_printf(mon, "]\n"); } + + if (info->has_vfio) { + monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n= ", + info->vfio->transferred >> 10); + } + qapi_free_MigrationInfo(info); } =20 diff --git a/qapi/migration.json b/qapi/migration.json index d5000558c6c9..952864b05455 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -146,6 +146,18 @@ 'active', 'postcopy-active', 'postcopy-paused', 'postcopy-recover', 'completed', 'failed', 'colo', 'pre-switchover', 'device', 'wait-unplug' ] } +## +# @VfioStats: +# +# Detailed VFIO devices migration statistics +# +# @transferred: amount of bytes transferred to the target VM by VFIO devic= es +# +# Since: 5.1 +# +## +{ 'struct': 'VfioStats', + 'data': {'transferred': 'int' } } =20 ## # @MigrationInfo: @@ -207,11 +219,16 @@ # # @socket-address: Only used for tcp, to know what the real port is (Since= 4.0) # +# @vfio: @VfioStats containing detailed VFIO devices migration statistics, +# only returned if VFIO device is present, migration is supported b= y all +# VFIO devices and status is 'active' or 'completed' (since 5.1) +# # Since: 0.14.0 ## { 'struct': 'MigrationInfo', 'data': {'*status': 'MigrationStatus', '*ram': 'MigrationStats', '*disk': 'MigrationStats', + '*vfio': 'VfioStats', '*xbzrle-cache': 'XBZRLECacheStats', '*total-time': 'int', '*expected-downtime': 'int', --=20 2.7.0