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: 10819487 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 DAA3B13B5 for ; Tue, 19 Feb 2019 08:52:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B1F2B9A3 for ; Tue, 19 Feb 2019 08:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCC452BC05; Tue, 19 Feb 2019 08:52:48 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DA32B9A3 for ; Tue, 19 Feb 2019 08:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbfBSIwr (ORCPT ); Tue, 19 Feb 2019 03:52:47 -0500 Received: from mga18.intel.com ([134.134.136.126]:41202 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727249AbfBSIwr (ORCPT ); Tue, 19 Feb 2019 03:52:47 -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 orsmga106.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 Cc: intel-gvt-dev@lists.freedesktop.org, Zhengxiao.zx@Alibaba-inc.com, yi.l.liu@intel.com, eskultet@redhat.com, ziye.yang@intel.com, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com, kwankhede@nvidia.com, kevin.tian@intel.com, cjia@nvidia.com, arei.gonglei@huawei.com, kvm@vger.kernel.org, Yan Zhao Subject: [PATCH 3/5] vfio/migration: tracking of dirty page in system memory 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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)