From nobody Tue Feb 10 15:29:14 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 1505730306524440.8333214283191; Mon, 18 Sep 2017 03:25:06 -0700 (PDT) Received: from localhost ([::1]:35618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttEf-0003Yj-Pe for importer@patchew.org; Mon, 18 Sep 2017 06:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7K-0005lV-GH for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7J-0004GS-DZ for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:30 -0400 Received: from ozlabs.ru ([107.173.13.209]:35254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7J-0004Dh-8e for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:29 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 0E2833A60054; Mon, 18 Sep 2017 06:18:43 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:06 +1000 Message-Id: <20170918101709.30421-11-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170918101709.30421-1-aik@ozlabs.ru> References: <20170918101709.30421-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 v3 10/13] memory: Store physical root MR in FlatView 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" Address spaces get to keep a root MR (alias or not) but FlatView stores the actual MR as this is going to be used later on to decide whether to share a particular FlatView or not. Signed-off-by: Alexey Kardashevskiy --- memory.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/memory.c b/memory.c index e046f7bc2f..e18ef53cc2 100644 --- a/memory.c +++ b/memory.c @@ -231,6 +231,7 @@ struct FlatView { unsigned nr; unsigned nr_allocated; struct AddressSpaceDispatch *dispatch; + MemoryRegion *root; }; =20 typedef struct AddressSpaceOps AddressSpaceOps; @@ -260,12 +261,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *= b) && a->readonly =3D=3D b->readonly; } =20 -static FlatView *flatview_new(void) +static FlatView *flatview_new(MemoryRegion *mr_root) { FlatView *view; =20 view =3D g_new0(FlatView, 1); view->ref =3D 1; + view->root =3D mr_root; + memory_region_ref(mr_root); =20 return view; } @@ -298,6 +301,7 @@ static void flatview_destroy(FlatView *view) memory_region_unref(view->ranges[i].mr); } g_free(view->ranges); + memory_region_unref(view->root); g_free(view); } =20 @@ -723,12 +727,25 @@ static void render_memory_region(FlatView *view, } } =20 +static MemoryRegion *memory_region_unalias_entire(MemoryRegion *mr) +{ + while (mr->alias && !mr->alias_offset && + int128_ge(mr->size, mr->alias->size)) { + /* The alias is included in its entirety. Use it as + * the "real" root, so that we can share more FlatViews. + */ + mr =3D mr->alias; + } + + return mr; +} + /* Render a memory topology into a list of disjoint absolute ranges. */ static FlatView *generate_memory_topology(MemoryRegion *mr) { FlatView *view; =20 - view =3D flatview_new(); + view =3D flatview_new(mr); =20 if (mr) { render_memory_region(view, mr, int128_zero(), @@ -903,7 +920,8 @@ static void address_space_update_topology_pass(AddressS= pace *as, static void address_space_update_topology(AddressSpace *as) { FlatView *old_view =3D address_space_get_flatview(as); - FlatView *new_view =3D generate_memory_topology(as->root); + MemoryRegion *physmr =3D memory_region_unalias_entire(old_view->root); + FlatView *new_view =3D generate_memory_topology(physmr); int i; =20 new_view->dispatch =3D address_space_dispatch_new(new_view); @@ -913,7 +931,6 @@ static void address_space_update_topology(AddressSpace = *as) flatview_add_to_dispatch(new_view, &mrs); } address_space_dispatch_compact(new_view->dispatch); - address_space_update_topology_pass(as, old_view, new_view, false); address_space_update_topology_pass(as, old_view, new_view, true); =20 @@ -2644,7 +2661,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(); + as->current_map =3D flatview_new(root); as->ioeventfd_nb =3D 0; as->ioeventfds =3D NULL; QTAILQ_INIT(&as->listeners); --=20 2.11.0