From nobody Mon Nov 3 20:15:02 2025 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 1505984178940275.2605376998839; Thu, 21 Sep 2017 01:56:18 -0700 (PDT) Received: from localhost ([::1]:52442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxHN-0000My-Vw for importer@patchew.org; Thu, 21 Sep 2017 04:56:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxCs-00056z-AN for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duxCp-0001Jd-Tc for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:37 -0400 Received: from ozlabs.ru ([107.173.13.209]:54112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duxCp-0001CA-NQ for qemu-devel@nongnu.org; Thu, 21 Sep 2017 04:51:35 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 965D13A60051; Thu, 21 Sep 2017 04:52:51 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 18:51:05 +1000 Message-Id: <20170921085110.25598-14-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170921085110.25598-1-aik@ozlabs.ru> References: <20170921085110.25598-1-aik@ozlabs.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 107.173.13.209 Subject: [Qemu-devel] [PATCH qemu v5 13/18] memory: Do not allocate FlatView in address_space_init 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: Alexey Kardashevskiy , Paolo Bonzini 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" This creates a new AS object without any FlatView as memory_region_transaction_commit() may want to reuse the empty FV. Signed-off-by: Alexey Kardashevskiy --- I do not really want to add view!=3DNULL into flatview_ref()/flatview_unref() as this is quite special case when view=3D=3DNULL. --- memory.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/memory.c b/memory.c index 56b3dd47ab..c623575dac 100644 --- a/memory.c +++ b/memory.c @@ -962,22 +962,37 @@ static void flatviews_reset(void) =20 static void address_space_set_flatview(AddressSpace *as) { - FlatView *old_view =3D address_space_get_flatview(as); + FlatView *old_view =3D address_space_to_flatview(as); MemoryRegion *physmr =3D memory_region_get_flatview_root(as->root); FlatView *new_view =3D g_hash_table_lookup(flat_views, physmr); =20 assert(new_view); =20 + if (old_view =3D=3D new_view) { + return; + } + + if (old_view) { + flatview_ref(old_view); + } + flatview_ref(new_view); =20 if (!QTAILQ_EMPTY(&as->listeners)) { - address_space_update_topology_pass(as, old_view, new_view, false); - address_space_update_topology_pass(as, old_view, new_view, true); + FlatView tmpview =3D { 0 }, *old_view2 =3D old_view; + + if (!old_view2) { + old_view2 =3D &tmpview; + } + address_space_update_topology_pass(as, old_view2, new_view, false); + address_space_update_topology_pass(as, old_view2, new_view, true); } =20 /* Writes are protected by the BQL. */ atomic_rcu_set(&as->current_map, new_view); - flatview_unref(old_view); + if (old_view) { + flatview_unref(old_view); + } =20 /* Note that all the old MemoryRegions are still alive up to this * point. This relieves most MemoryListeners from the need to @@ -985,7 +1000,9 @@ static void address_space_set_flatview(AddressSpace *a= s) * outside the iothread mutex, in which case precise reference * counting is necessary. */ - flatview_unref(old_view); + if (old_view) { + flatview_unref(old_view); + } } =20 void memory_region_transaction_begin(void) @@ -2703,7 +2720,7 @@ void address_space_init(AddressSpace *as, MemoryRegio= n *root, const char *name) as->ref_count =3D 1; as->root =3D root; as->malloced =3D false; - as->current_map =3D flatview_new(root); + as->current_map =3D NULL; as->ioeventfd_nb =3D 0; as->ioeventfds =3D NULL; QTAILQ_INIT(&as->listeners); --=20 2.11.0