From patchwork Tue Feb 19 08:52:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 10819493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1398B139A for ; Tue, 19 Feb 2019 08:54:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AF828B18 for ; Tue, 19 Feb 2019 08:54:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB57328D29; Tue, 19 Feb 2019 08:54:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6514F28B18 for ; Tue, 19 Feb 2019 08:54:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:44379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gw1AN-0004AN-Lr for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Feb 2019 03:54:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gw192-0002tU-US for qemu-devel@nongnu.org; Tue, 19 Feb 2019 03:52:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gw190-0001B8-VM for qemu-devel@nongnu.org; Tue, 19 Feb 2019 03:52:52 -0500 Received: from mga02.intel.com ([134.134.136.20]:25125) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gw18z-00019y-01 for qemu-devel@nongnu.org; Tue, 19 Feb 2019 03:52:50 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 00:52:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,387,1544515200"; d="scan'208";a="123524385" Received: from joy-desktop.sh.intel.com ([10.239.13.17]) by fmsmga007.fm.intel.com with ESMTP; 19 Feb 2019 00:52:42 -0800 From: Yan Zhao To: alex.williamson@redhat.com, qemu-devel@nongnu.org Date: Tue, 19 Feb 2019 16:52:41 +0800 Message-Id: <1550566361-3697-1-git-send-email-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550566254-3545-1-git-send-email-yan.y.zhao@intel.com> References: <1550566254-3545-1-git-send-email-yan.y.zhao@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [PATCH 3/5] vfio/migration: tracking of dirty page in system memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cjia@nvidia.com, kvm@vger.kernel.org, aik@ozlabs.ru, Zhengxiao.zx@Alibaba-inc.com, shuangtai.tst@alibaba-inc.com, kwankhede@nvidia.com, eauger@redhat.com, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, arei.gonglei@huawei.com, felipe@nutanix.com, Ken.Xue@amd.com, kevin.tian@intel.com, Yan Zhao , dgilbert@redhat.com, intel-gvt-dev@lists.freedesktop.org, changpeng.liu@intel.com, cohuck@redhat.com, zhi.a.wang@intel.com, jonathan.davies@nutanix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP register the log_sync interface to hook into ram's live migration callbacks. ram_save_pending |->migration_bitmap_sync |->memory_global_dirty_log_sync |->memory_region_sync_dirty_bitmap |->listener->log_sync(listener, &mrs); So, the dirty page produced by vfio device in system memory will be save/load by ram's live migration code iteratively. Bitmap of device's dirty page in system memory is retrieved from Dirty Bitmap Region Signed-off-by: Yan Zhao Signed-off-by: Yulei Zhang --- hw/vfio/common.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7c185e5a..719e750 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -27,6 +27,7 @@ #include "hw/vfio/vfio-common.h" #include "hw/vfio/vfio.h" +#include "hw/vfio/pci.h" #include "exec/address-spaces.h" #include "exec/memory.h" #include "hw/hw.h" @@ -698,9 +699,34 @@ static void vfio_listener_region_del(MemoryListener *listener, } } +static void vfio_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container = container_of(listener, VFIOContainer, listener); + VFIOGroup *group = QLIST_FIRST(&container->group_list); + VFIODevice *vbasedev; + VFIOPCIDevice *vdev; + + ram_addr_t size = int128_get64(section->size); + uint64_t page_nr = size >> TARGET_PAGE_BITS; + uint64_t start_addr = section->offset_within_address_space; + + QLIST_FOREACH(vbasedev, &group->device_list, next) { + vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev); + if (!vdev->migration || + !vfio_device_data_cap_system_memory(vdev) || + !(vdev->migration->device_state & VFIO_DEVICE_STATE_LOGGING)) { + continue; + } + + vfio_set_dirty_page_bitmap(vdev, start_addr, page_nr); + } +} + static const MemoryListener vfio_memory_listener = { .region_add = vfio_listener_region_add, .region_del = vfio_listener_region_del, + .log_sync = vfio_log_sync, }; static void vfio_listener_release(VFIOContainer *container)