From nobody Mon Feb 9 16:19:26 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 1505921802470432.7633484663887; Wed, 20 Sep 2017 08:36:42 -0700 (PDT) Received: from localhost ([::1]:48932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duh3I-0004av-Jl for importer@patchew.org; Wed, 20 Sep 2017 11:36:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufmG-0003O3-M2 for qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:15:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufmE-000584-2Z for qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:15:00 -0400 Received: from ozlabs.ru ([107.173.13.209]:59750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufmD-00057Q-Ks for qemu-devel@nongnu.org; Wed, 20 Sep 2017 10:14:57 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 558F63A6005C; Wed, 20 Sep 2017 07:48:12 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Wed, 20 Sep 2017 21:46:32 +1000 Message-Id: <20170920114637.42004-14-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170920114637.42004-1-aik@ozlabs.ru> References: <20170920114637.42004-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 v4 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 1083fe9130..aa8a49539d 100644 --- a/memory.c +++ b/memory.c @@ -963,22 +963,37 @@ static void flatviews_reset(void) =20 static void flatview_set_to_address_space(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 @@ -986,7 +1001,9 @@ static void flatview_set_to_address_space(AddressSpace= *as) * 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) @@ -2704,7 +2721,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