From nobody Wed May 1 22:41:32 2024 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 1516601081840233.86233913969238; Sun, 21 Jan 2018 22:04:41 -0800 (PST) Received: from localhost ([::1]:48322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVDj-0001EA-Cf for importer@patchew.org; Mon, 22 Jan 2018 01:04:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVCA-0000MR-6P for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edVC9-0004Vj-7g for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1edVC9-0004VS-0d for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:01 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E1E4C057FA7; Mon, 22 Jan 2018 06:03:00 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 856C26018A; Mon, 22 Jan 2018 06:02:56 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 14:02:41 +0800 Message-Id: <20180122060244.29368-2-peterx@redhat.com> In-Reply-To: <20180122060244.29368-1-peterx@redhat.com> References: <20180122060244.29368-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 22 Jan 2018 06:03:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/4] vhost: add traces for memory listeners 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: Peter Maydell , "Michael S . Tsirkin" , Alexey Kardashevskiy , peterx@redhat.com, Alex Williamson , Paolo Bonzini , David Gibson 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" Trace these operations on two memory listeners. It helps to verify the new memory listener fix, and good to keep them there. Signed-off-by: Peter Xu Acked-by: Michael S. Tsirkin Reviewed-by: Paolo Bonzini --- hw/virtio/trace-events | 6 ++++++ hw/virtio/vhost.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 775461ae98..2b8f81eb25 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -25,3 +25,9 @@ virtio_balloon_handle_output(const char *name, uint64_t g= pa) "section name: %s g virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages:= %d actual: %d" virtio_balloon_set_config(uint32_t actual, uint32_t oldactual) "actual: %d= oldactual: %d" virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon tar= get: 0x%"PRIx64" num_pages: %d" + +# hw/virtio/vhost.c +vhost_region_add(void *p, const char *mr) "dev %p mr %s" +vhost_region_del(void *p, const char *mr) "dev %p mr %s" +vhost_iommu_region_add(void *p, const char *mr) "dev %p mr %s" +vhost_iommu_region_del(void *p, const char *mr) "dev %p mr %s" diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index e4290ce93d..19a7a3cb37 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -27,6 +27,7 @@ #include "hw/virtio/virtio-access.h" #include "migration/blocker.h" #include "sysemu/dma.h" +#include "trace.h" =20 /* enabled until disconnected backend stabilizes */ #define _VHOST_DEBUG 1 @@ -687,6 +688,7 @@ static void vhost_region_add(MemoryListener *listener, return; } =20 + trace_vhost_region_add(dev, section->mr->name ?: NULL); ++dev->n_mem_sections; dev->mem_sections =3D g_renew(MemoryRegionSection, dev->mem_sections, dev->n_mem_sections); @@ -706,6 +708,7 @@ static void vhost_region_del(MemoryListener *listener, return; } =20 + trace_vhost_region_del(dev, section->mr->name ?: NULL); vhost_set_memory(listener, section, false); memory_region_unref(section->mr); for (i =3D 0; i < dev->n_mem_sections; ++i) { @@ -743,6 +746,8 @@ static void vhost_iommu_region_add(MemoryListener *list= ener, return; } =20 + trace_vhost_iommu_region_add(dev, section->mr->name ?: NULL); + iommu =3D g_malloc0(sizeof(*iommu)); end =3D int128_add(int128_make64(section->offset_within_region), section->size); @@ -771,6 +776,8 @@ static void vhost_iommu_region_del(MemoryListener *list= ener, return; } =20 + trace_vhost_iommu_region_del(dev, section->mr->name ?: NULL); + QLIST_FOREACH(iommu, &dev->iommu_list, iommu_next) { if (iommu->mr =3D=3D section->mr && iommu->n.start =3D=3D section->offset_within_region) { --=20 2.14.3 From nobody Wed May 1 22:41:32 2024 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 1516601202930237.05287743847998; Sun, 21 Jan 2018 22:06:42 -0800 (PST) Received: from localhost ([::1]:48393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVFi-0002rV-8Q for importer@patchew.org; Mon, 22 Jan 2018 01:06:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVCJ-0000TB-Ub for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edVCG-0004Xq-1m for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1edVCF-0004Xl-SP for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:07 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7F408762F; Mon, 22 Jan 2018 06:03:06 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B3356444D; Mon, 22 Jan 2018 06:03:00 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 14:02:42 +0800 Message-Id: <20180122060244.29368-3-peterx@redhat.com> In-Reply-To: <20180122060244.29368-1-peterx@redhat.com> References: <20180122060244.29368-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 22 Jan 2018 06:03:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/4] arm: postpone device listener unregister 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: Peter Maydell , "Michael S . Tsirkin" , Alexey Kardashevskiy , peterx@redhat.com, Alex Williamson , Paolo Bonzini , David Gibson 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" It's a preparation for follow-up patch to call region_del() in memory_listener_unregister(), otherwise all device addr attached with kvm_devices_head will be reset before calling kvm_arm_set_device_addr. Signed-off-by: Peter Xu Reviewed-by: Paolo Bonzini --- target/arm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 211a7bf7be..1219d0062b 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -266,7 +266,6 @@ static void kvm_arm_machine_init_done(Notifier *notifie= r, void *data) { KVMDevice *kd, *tkd; =20 - memory_listener_unregister(&devlistener); QSLIST_FOREACH_SAFE(kd, &kvm_devices_head, entries, tkd) { if (kd->kda.addr !=3D -1) { kvm_arm_set_device_addr(kd); @@ -274,6 +273,7 @@ static void kvm_arm_machine_init_done(Notifier *notifie= r, void *data) memory_region_unref(kd->mr); g_free(kd); } + memory_listener_unregister(&devlistener); } =20 static Notifier notify =3D { --=20 2.14.3 From nobody Wed May 1 22:41:32 2024 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 1516601104694445.92352663483996; Sun, 21 Jan 2018 22:05:04 -0800 (PST) Received: from localhost ([::1]:48328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVE7-0001X1-VX for importer@patchew.org; Mon, 22 Jan 2018 01:05:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVCU-0000aJ-Ef for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edVCQ-0004aP-Hi for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39182) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1edVCQ-0004aE-C1 for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FB8972FE9; Mon, 22 Jan 2018 06:03:17 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 619FE6018A; Mon, 22 Jan 2018 06:03:07 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 14:02:43 +0800 Message-Id: <20180122060244.29368-4-peterx@redhat.com> In-Reply-To: <20180122060244.29368-1-peterx@redhat.com> References: <20180122060244.29368-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 22 Jan 2018 06:03:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/4] vfio: listener unregister before unset container 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: Peter Maydell , "Michael S . Tsirkin" , Alexey Kardashevskiy , peterx@redhat.com, Alex Williamson , Paolo Bonzini , David Gibson 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" After next patch, listener unregister will need the container to be alive. Let's move this unregister phase to be before unset container, since that operation will free the backend container in kernel, otherwise we'll get these after next patch: qemu-system-x86_64: VFIO_UNMAP_DMA: -22 qemu-system-x86_64: vfio_dma_unmap(0x559bf53a4590, 0x0, 0xa0000) =3D -22 (I= nvalid argument) Signed-off-by: Peter Xu Acked-by: Alex Williamson Reviewed-by: Paolo Bonzini --- hw/vfio/common.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b77be3a8b3..76cf28d462 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1161,19 +1161,27 @@ static void vfio_disconnect_container(VFIOGroup *gr= oup) { VFIOContainer *container =3D group->container; =20 + QLIST_REMOVE(group, container_next); + group->container =3D NULL; + + /* + * Explicitly release the listener first before unset container, + * since unset may destroy the backend container if it's the last + * group. + */ + if (QLIST_EMPTY(&container->group_list)) { + vfio_listener_release(container); + } + if (ioctl(group->fd, VFIO_GROUP_UNSET_CONTAINER, &container->fd)) { error_report("vfio: error disconnecting group %d from container", group->groupid); } =20 - QLIST_REMOVE(group, container_next); - group->container =3D NULL; - if (QLIST_EMPTY(&container->group_list)) { VFIOAddressSpace *space =3D container->space; VFIOGuestIOMMU *giommu, *tmp; =20 - vfio_listener_release(container); QLIST_REMOVE(container, next); =20 QLIST_FOREACH_SAFE(giommu, &container->giommu_list, giommu_next, t= mp) { --=20 2.14.3 From nobody Wed May 1 22:41:32 2024 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 1516601226916963.7441733034335; Sun, 21 Jan 2018 22:07:06 -0800 (PST) Received: from localhost ([::1]:48400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVG6-00036J-81 for importer@patchew.org; Mon, 22 Jan 2018 01:07:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edVCV-0000bQ-Ou for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edVCU-0004c4-Lg for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1edVCU-0004bf-DF for qemu-devel@nongnu.org; Mon, 22 Jan 2018 01:03:22 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8626C72FE9; Mon, 22 Jan 2018 06:03:21 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-131.nay.redhat.com [10.66.14.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 168446018A; Mon, 22 Jan 2018 06:03:17 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 14:02:44 +0800 Message-Id: <20180122060244.29368-5-peterx@redhat.com> In-Reply-To: <20180122060244.29368-1-peterx@redhat.com> References: <20180122060244.29368-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 22 Jan 2018 06:03:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/4] memory: do explicit cleanup when remove listeners 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: Peter Maydell , "Michael S . Tsirkin" , Alexey Kardashevskiy , peterx@redhat.com, Alex Williamson , Paolo Bonzini , David Gibson 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" When unregister memory listeners, we should call, e.g., region_del() (and possibly other undo operations) on every existing memory region sections there, otherwise we may leak resources that are held during the region_add(). This patch undo the stuff for the listeners, which emulates the case when the address space is set from current to an empty state. I found this problem when debugging a refcount leak issue that leads to a device unplug event lost (please see the "Bug:" line below). In that case, the leakage of resource is the PCI BAR memory region refcount. And since memory regions are not keeping their own refcount but onto their owners, so the vfio-pci device's (who is the owner of the PCI BAR memory regions) refcount is leaked, and event missing. We had encountered similar issues before and fixed in other way (ee4c112846, "vhost: Release memory references on cleanup"). This patch can be seen as a more high-level fix of similar problems that are caused by the resource leaks from memory listeners. So now we can remove the explicit unref of memory regions since that'll be done altogether during unregistering of listeners now. Bug: https://bugzilla.redhat.com/show_bug.cgi?id=3D1531393 Signed-off-by: Peter Xu Reviewed-by: Paolo Bonzini --- hw/virtio/vhost.c | 4 ---- memory.c | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 19a7a3cb37..54480ffd85 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1368,10 +1368,6 @@ void vhost_dev_cleanup(struct vhost_dev *hdev) if (hdev->mem) { /* those are only safe after successful init */ memory_listener_unregister(&hdev->memory_listener); - for (i =3D 0; i < hdev->n_mem_sections; ++i) { - MemoryRegionSection *section =3D &hdev->mem_sections[i]; - memory_region_unref(section->mr); - } QLIST_REMOVE(hdev, entry); } if (hdev->migration_blocker) { diff --git a/memory.c b/memory.c index 4b41fb837b..9ad98b701b 100644 --- a/memory.c +++ b/memory.c @@ -2609,6 +2609,32 @@ static void listener_add_address_space(MemoryListene= r *listener, flatview_unref(view); } =20 +static void listener_del_address_space(MemoryListener *listener, + AddressSpace *as) +{ + FlatView *view; + FlatRange *fr; + + if (listener->begin) { + listener->begin(listener); + } + view =3D address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + MemoryRegionSection section =3D section_from_flat_range(fr, view); + + if (fr->dirty_log_mask && listener->log_stop) { + listener->log_stop(listener, §ion, fr->dirty_log_mask, 0); + } + if (listener->region_del) { + listener->region_del(listener, §ion); + } + } + if (listener->commit) { + listener->commit(listener); + } + flatview_unref(view); +} + void memory_listener_register(MemoryListener *listener, AddressSpace *as) { MemoryListener *other =3D NULL; @@ -2649,6 +2675,7 @@ void memory_listener_unregister(MemoryListener *liste= ner) return; } =20 + listener_del_address_space(listener, listener->address_space); QTAILQ_REMOVE(&memory_listeners, listener, link); QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as); listener->address_space =3D NULL; --=20 2.14.3