From nobody Tue Feb 10 05:27:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501482624693715.7833054597528; Sun, 30 Jul 2017 23:30:24 -0700 (PDT) Received: from localhost ([::1]:57682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dc4DT-0008Un-8t for importer@patchew.org; Mon, 31 Jul 2017 02:30:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dc49i-0005zy-TT for qemu-devel@nongnu.org; Mon, 31 Jul 2017 02:26:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dc49h-0007a4-PV for qemu-devel@nongnu.org; Mon, 31 Jul 2017 02:26:18 -0400 Received: from mga05.intel.com ([192.55.52.43]:6607) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dc49h-0007Ui-HX for qemu-devel@nongnu.org; Mon, 31 Jul 2017 02:26:17 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 30 Jul 2017 23:26:17 -0700 Received: from yzhang13-kvm.sh.intel.com ([10.239.36.121]) by fmsmga005.fm.intel.com with ESMTP; 30 Jul 2017 23:26:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,440,1496127600"; d="scan'208";a="133271168" From: Yulei Zhang To: qemu-devel@nongnu.org Date: Tue, 9 May 2017 15:58:47 +0800 Message-Id: <1494316727-15518-5-git-send-email-yulei.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494316727-15518-1-git-send-email-yulei.zhang@intel.com> References: <1494316727-15518-1-git-send-email-yulei.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [RFC V2 4/4] vifo: introduce new VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, joonas.lahtinen@linux.intel.com, zhenyuw@linux.intel.com, Yulei Zhang , alex.williamson@redhat.com, xiao.zheng@intel.com, zhi.a.wang@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" New VFIO ioctl VFIO_IOMMU_GET_DIRTY_BITMAP is used to fetch the bitmap of pinned memory in iommu container, we need copy those memory to the target during the migration as they are dirtied by mdev devices. Signed-off-by: Yulei Zhang --- hw/vfio/common.c | 32 ++++++++++++++++++++++++++++++++ linux-headers/linux/vfio.h | 14 ++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f3ba9b9..54d43d5 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -35,6 +35,7 @@ #include "sysemu/kvm.h" #include "trace.h" #include "qapi/error.h" +#include "exec/ram_addr.h" =20 struct vfio_group_head vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -603,9 +604,40 @@ static void vfio_listener_region_del(MemoryListener *l= istener, } } =20 +static void vfio_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); + VFIOGroup *group =3D QLIST_FIRST(&container->group_list); + VFIODevice *vbasedev; + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if (vbasedev->device_state =3D=3D VFIO_DEVICE_START) + return; + } + + struct vfio_iommu_get_dirty_bitmap *d; + ram_addr_t size =3D int128_get64(section->size); + unsigned long page_nr =3D size >> TARGET_PAGE_BITS; + unsigned long bitmap_size =3D (BITS_TO_LONGS(page_nr) + 1) * sizeof(un= signed long); + d =3D g_malloc0(sizeof(*d) + bitmap_size); + d->start_addr =3D section->offset_within_address_space; + d->page_nr =3D page_nr; + + if (ioctl(container->fd, VFIO_IOMMU_GET_DIRTY_BITMAP, d)) { + error_report("vfio: Failed to fetch dirty pages for migration\n"); + goto exit; + } + + cpu_physical_memory_set_dirty_lebitmap((unsigned long*)&d->dirty_bitma= p, d->start_addr, d->page_nr); + +exit: + g_free(d); +} + 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_log_sync, }; =20 static void vfio_listener_release(VFIOContainer *container) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index dbbe7e1..cf3d163 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -553,6 +553,20 @@ struct vfio_iommu_type1_dma_unmap { #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) =20 +/** + * VFIO_IOMMU_GET_DIRTY_BITMAP - _IOW(VFIO_TYPE, VFIO_BASE + 17, + * struct vfio_iommu_get_dirty_bitmap) + * + * Return: 0 on success, -errno on failure. + */ +struct vfio_iommu_get_dirty_bitmap{ + __u64 start_addr; + __u64 page_nr; + __u8 dirty_bitmap[]; +}; + +#define VFIO_IOMMU_GET_DIRTY_BITMAP _IO(VFIO_TYPE, VFIO_BASE + 17) + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ =20 /* --=20 2.7.4