From nobody Mon Feb 9 22:59:48 2026 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