From nobody Tue Apr 30 04:21:08 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 1505729966794375.6867575867891; Mon, 18 Sep 2017 03:19:26 -0700 (PDT) Received: from localhost ([::1]:35591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt9B-0006ya-WD for importer@patchew.org; Mon, 18 Sep 2017 06:19:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7E-0005i5-TM for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7A-0004DP-IP for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:24 -0400 Received: from ozlabs.ru ([107.173.13.209]:35230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7A-0004Bn-CE for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:20 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 3DB083A6002B; Mon, 18 Sep 2017 06:18:33 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:16:57 +1000 Message-Id: <20170918101709.30421-2-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 01/13] memory: Postpone flatview and dispatch tree building till all devices are added 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" Most devices use at least one address space and every time a new address space is added, flat views and dispatch trees are rebuild for all address spaces. This is not a problem for a relatively small amount of devices but even 50 virtio-pci devices use more than 8GB of RAM. What happens that on every flatview/dispatch rebuild, new arrays are allocated and old ones release but the release is done via RCU so until an entire machine is build, they are not released. This wraps devices creation into memory_region_transaction_begin/commit to massively reduce amount of flat view/dispatch tree (re)allocations. Signed-off-by: Alexey Kardashevskiy --- Changes: v2: * wrapped qemu_run_machine_init_done_notifiers() as well --- vl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vl.c b/vl.c index 9e62e92aea..e4f2ece590 100644 --- a/vl.c +++ b/vl.c @@ -4741,12 +4741,16 @@ int main(int argc, char **argv, char **envp) igd_gfx_passthru(); =20 /* init generic devices */ + memory_region_transaction_begin(); + rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, NULL)) { exit(1); } =20 + memory_region_transaction_commit(); + cpu_synchronize_all_post_init(); =20 rom_reset_order_override(); @@ -4829,8 +4833,13 @@ int main(int argc, char **argv, char **envp) /* TODO: once all bus devices are qdevified, this should be done * when bus is created by qdev.c */ qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); + + memory_region_transaction_begin(); + qemu_run_machine_init_done_notifiers(); =20 + memory_region_transaction_commit(); + if (rom_check_and_register_reset() !=3D 0) { error_report("rom check and register reset failed"); exit(1); --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730620906386.70683484666074; Mon, 18 Sep 2017 03:30:20 -0700 (PDT) Received: from localhost ([::1]:35655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttJk-0007br-9r for importer@patchew.org; Mon, 18 Sep 2017 06:30:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7i-00065z-My for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7e-0004MI-Ff for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:54 -0400 Received: from ozlabs.ru ([107.173.13.209]:35328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7e-0004M9-98 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:50 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 81ACB3A6004B; Mon, 18 Sep 2017 06:18:34 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:16:58 +1000 Message-Id: <20170918101709.30421-3-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 02/13] exec: Explicitely export target AS from address_space_translate_internal 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 is not so mechanical change in order to move to shared FlatViews so make it a separate patch. The first argument of address_space_do_translate() will become a FlatView, however since address_space_get_iotlb_entry() still wants AS, hence this change. Signed-off-by: Alexey Kardashevskiy --- exec.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index d20c34ca83..bd94248390 100644 --- a/exec.c +++ b/exec.c @@ -477,7 +477,8 @@ static MemoryRegionSection address_space_do_translate(A= ddressSpace *as, hwaddr *xlat, hwaddr *plen, bool is_write, - bool is_mmio) + bool is_mmio, + AddressSpace **targe= t_as) { IOMMUTLBEntry iotlb; MemoryRegionSection *section; @@ -504,6 +505,7 @@ static MemoryRegionSection address_space_do_translate(A= ddressSpace *as, } =20 as =3D iotlb.target_as; + *target_as =3D iotlb.target_as; } =20 *xlat =3D addr; @@ -526,7 +528,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpac= e *as, hwaddr addr, =20 /* This can never be MMIO. */ section =3D address_space_do_translate(as, addr, &xlat, &plen, - is_write, false); + is_write, false, &as); =20 /* Illegal translation */ if (section.mr =3D=3D &io_mem_unassigned) { @@ -549,7 +551,7 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpac= e *as, hwaddr addr, plen -=3D 1; =20 return (IOMMUTLBEntry) { - .target_as =3D section.address_space, + .target_as =3D as, .iova =3D addr & ~plen, .translated_addr =3D xlat & ~plen, .addr_mask =3D plen, @@ -570,7 +572,8 @@ MemoryRegion *address_space_translate(AddressSpace *as,= hwaddr addr, MemoryRegionSection section; =20 /* This can be MMIO, so setup MMIO bit. */ - section =3D address_space_do_translate(as, addr, xlat, plen, is_write,= true); + section =3D address_space_do_translate(as, addr, xlat, plen, is_write,= true, + &as); mr =3D section.mr; =20 if (xen_enabled() && memory_access_is_direct(mr, is_write)) { --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505729969408767.2301320389191; Mon, 18 Sep 2017 03:19:29 -0700 (PDT) Received: from localhost ([::1]:35593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt9E-00070X-Ho for importer@patchew.org; Mon, 18 Sep 2017 06:19:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7I-0005kD-CW for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7D-0004E6-WA for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:28 -0400 Received: from ozlabs.ru ([107.173.13.209]:35246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7D-0004DX-Nd for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:23 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id C51FC3A60021; Mon, 18 Sep 2017 06:18:35 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:16:59 +1000 Message-Id: <20170918101709.30421-4-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 03/13] memory: Open code FlatView rendering 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" We are going to share FlatView's between AddressSpace's and per-AS memory listeners won't suite the purpose anymore so open code the dispatch tree rendering. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * inlined & simplified address_space_update_flatview --- include/exec/memory-internal.h | 6 ++++-- include/exec/memory.h | 1 - exec.c | 27 +++------------------------ memory.c | 13 ++++++++++--- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index fb467acdba..9abde2f11c 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -22,8 +22,6 @@ #ifndef CONFIG_USER_ONLY typedef struct AddressSpaceDispatch AddressSpaceDispatch; =20 -void address_space_init_dispatch(AddressSpace *as); -void address_space_unregister(AddressSpace *as); void address_space_destroy_dispatch(AddressSpace *as); =20 extern const MemoryRegionOps unassigned_mem_ops; @@ -31,5 +29,9 @@ extern const MemoryRegionOps unassigned_mem_ops; bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, unsigned size, bool is_write); =20 +void mem_add(AddressSpace *as, MemoryRegionSection *section); +void mem_begin(AddressSpace *as); +void mem_commit(AddressSpace *as); + #endif #endif diff --git a/include/exec/memory.h b/include/exec/memory.h index 1dcd3122d7..9581f7a7db 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -318,7 +318,6 @@ struct AddressSpace { struct MemoryRegionIoeventfd *ioeventfds; struct AddressSpaceDispatch *dispatch; struct AddressSpaceDispatch *next_dispatch; - MemoryListener dispatch_listener; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; }; diff --git a/exec.c b/exec.c index bd94248390..3ed3718dea 100644 --- a/exec.c +++ b/exec.c @@ -1348,9 +1348,8 @@ static void register_multipage(AddressSpaceDispatch *= d, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_in= dex); } =20 -static void mem_add(MemoryListener *listener, MemoryRegionSection *section) +void mem_add(AddressSpace *as, MemoryRegionSection *section) { - AddressSpace *as =3D container_of(listener, AddressSpace, dispatch_lis= tener); AddressSpaceDispatch *d =3D as->next_dispatch; MemoryRegionSection now =3D *section, remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); @@ -2674,9 +2673,8 @@ static void io_mem_init(void) NULL, UINT64_MAX); } =20 -static void mem_begin(MemoryListener *listener) +void mem_begin(AddressSpace *as) { - AddressSpace *as =3D container_of(listener, AddressSpace, dispatch_lis= tener); AddressSpaceDispatch *d =3D g_new0(AddressSpaceDispatch, 1); uint16_t n; =20 @@ -2700,9 +2698,8 @@ static void address_space_dispatch_free(AddressSpaceD= ispatch *d) g_free(d); } =20 -static void mem_commit(MemoryListener *listener) +void mem_commit(AddressSpace *as) { - AddressSpace *as =3D container_of(listener, AddressSpace, dispatch_lis= tener); AddressSpaceDispatch *cur =3D as->dispatch; AddressSpaceDispatch *next =3D as->next_dispatch; =20 @@ -2732,24 +2729,6 @@ static void tcg_commit(MemoryListener *listener) tlb_flush(cpuas->cpu); } =20 -void address_space_init_dispatch(AddressSpace *as) -{ - as->dispatch =3D NULL; - as->dispatch_listener =3D (MemoryListener) { - .begin =3D mem_begin, - .commit =3D mem_commit, - .region_add =3D mem_add, - .region_nop =3D mem_add, - .priority =3D 0, - }; - memory_listener_register(&as->dispatch_listener, as); -} - -void address_space_unregister(AddressSpace *as) -{ - memory_listener_unregister(&as->dispatch_listener); -} - void address_space_destroy_dispatch(AddressSpace *as) { AddressSpaceDispatch *d =3D as->dispatch; diff --git a/memory.c b/memory.c index c0adc35410..5671757011 100644 --- a/memory.c +++ b/memory.c @@ -879,11 +879,19 @@ static void address_space_update_topology_pass(Addres= sSpace *as, } } =20 - 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); + int i; + + mem_begin(as); + for (i =3D 0; i < new_view->nr; i++) { + MemoryRegionSection mrs =3D + section_from_flat_range(&new_view->ranges[i], as); + mem_add(as, &mrs); + } + mem_commit(as); =20 address_space_update_topology_pass(as, old_view, new_view, false); address_space_update_topology_pass(as, old_view, new_view, true); @@ -2621,7 +2629,7 @@ void address_space_init(AddressSpace *as, MemoryRegio= n *root, const char *name) QTAILQ_INIT(&as->listeners); QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link); as->name =3D g_strdup(name ? name : "anonymous"); - address_space_init_dispatch(as); + as->dispatch =3D NULL; memory_region_update_pending |=3D root->enabled; memory_region_transaction_commit(); } @@ -2672,7 +2680,6 @@ void address_space_destroy(AddressSpace *as) as->root =3D NULL; memory_region_transaction_commit(); QTAILQ_REMOVE(&address_spaces, as, address_spaces_link); - address_space_unregister(as); =20 /* At this point, as->dispatch and as->current_map are dummy * entries that the guest should never use. Wait for the old --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 150573012493061.15052469083105; Mon, 18 Sep 2017 03:22:04 -0700 (PDT) Received: from localhost ([::1]:35606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttBk-0000qO-2p for importer@patchew.org; Mon, 18 Sep 2017 06:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7I-0005kL-To for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7E-0004EH-I0 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:28 -0400 Received: from ozlabs.ru ([107.173.13.209]:35254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7E-0004Dh-CI for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:24 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 161973A60050; Mon, 18 Sep 2017 06:18:36 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:00 +1000 Message-Id: <20170918101709.30421-5-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 04/13] memory: Move FlatView allocation to a helper 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 moves a FlatView allocation and initialization to a helper. While we are nere, replace g_new with g_new0 to not to bother if we add new fields in the future. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * s/flatview_alloc/flatview_new/ --- memory.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/memory.c b/memory.c index 5671757011..d3bf0da703 100644 --- a/memory.c +++ b/memory.c @@ -258,12 +258,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *= b) && a->readonly =3D=3D b->readonly; } =20 -static void flatview_init(FlatView *view) +static FlatView *flatview_new(void) { + FlatView *view; + + view =3D g_new0(FlatView, 1); view->ref =3D 1; - view->ranges =3D NULL; - view->nr =3D 0; - view->nr_allocated =3D 0; + + return view; } =20 /* Insert a range into a given position. Caller is responsible for mainta= ining @@ -706,8 +708,7 @@ static FlatView *generate_memory_topology(MemoryRegion = *mr) { FlatView *view; =20 - view =3D g_new(FlatView, 1); - flatview_init(view); + view =3D flatview_new(); =20 if (mr) { render_memory_region(view, mr, int128_zero(), @@ -2622,8 +2623,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 g_new(FlatView, 1); - flatview_init(as->current_map); + as->current_map =3D flatview_new(); as->ioeventfd_nb =3D 0; as->ioeventfds =3D NULL; QTAILQ_INIT(&as->listeners); --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730686192103.34903546462647; Mon, 18 Sep 2017 03:31:26 -0700 (PDT) Received: from localhost ([::1]:35660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttKn-0008Gm-FO for importer@patchew.org; Mon, 18 Sep 2017 06:31:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7j-00066q-Ki for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7i-0004NU-6W for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:55 -0400 Received: from ozlabs.ru ([107.173.13.209]:35346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7h-0004NB-Q3 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:54 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 30F333A60051; Mon, 18 Sep 2017 06:18:38 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:01 +1000 Message-Id: <20170918101709.30421-6-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 05/13] memory: Move AddressSpaceDispatch from AddressSpace to 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" As we are going to share FlatView's between AddressSpace's, and AddressSpaceDispatch is a structure to perform quick lookup in FlatView, this moves ASD to FlatView. After previosly open coded ASD rendering, we can also remove as->next_dispatch as the new FlatView pointer is stored on a stack and set to an AS atomically. flatview_destroy() is executed under RCU instead of address_space_dispatch_free() now. This makes mem_begin/mem_commit to work with ASD and mem_add with FV as later on mem_add will be taking FV as an argument anyway. Signed-off-by: Alexey Kardashevskiy --- include/exec/memory-internal.h | 12 +++++++----- include/exec/memory.h | 2 -- exec.c | 41 +++++++++++---------------------------= --- memory.c | 29 +++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 9abde2f11c..6e08eda256 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -22,16 +22,18 @@ #ifndef CONFIG_USER_ONLY typedef struct AddressSpaceDispatch AddressSpaceDispatch; =20 -void address_space_destroy_dispatch(AddressSpace *as); - extern const MemoryRegionOps unassigned_mem_ops; =20 bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, unsigned size, bool is_write); =20 -void mem_add(AddressSpace *as, MemoryRegionSection *section); -void mem_begin(AddressSpace *as); -void mem_commit(AddressSpace *as); +void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section); +AddressSpaceDispatch *mem_begin(AddressSpace *as); +void mem_commit(AddressSpaceDispatch *d); + +AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as); +AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv); +void address_space_dispatch_free(AddressSpaceDispatch *d); =20 #endif #endif diff --git a/include/exec/memory.h b/include/exec/memory.h index 9581f7a7db..2346f8b863 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -316,8 +316,6 @@ struct AddressSpace { =20 int ioeventfd_nb; struct MemoryRegionIoeventfd *ioeventfds; - struct AddressSpaceDispatch *dispatch; - struct AddressSpaceDispatch *next_dispatch; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; }; diff --git a/exec.c b/exec.c index 3ed3718dea..6b0211bafc 100644 --- a/exec.c +++ b/exec.c @@ -188,8 +188,6 @@ typedef struct PhysPageMap { } PhysPageMap; =20 struct AddressSpaceDispatch { - struct rcu_head rcu; - MemoryRegionSection *mru_section; /* This is a multi-level map on the physical address space. * The bottom level has pointers to MemoryRegionSections. @@ -486,7 +484,7 @@ static MemoryRegionSection address_space_do_translate(A= ddressSpace *as, IOMMUMemoryRegionClass *imrc; =20 for (;;) { - AddressSpaceDispatch *d =3D atomic_rcu_read(&as->dispatch); + AddressSpaceDispatch *d =3D address_space_to_dispatch(as); section =3D address_space_translate_internal(d, addr, &addr, plen,= is_mmio); =20 iommu_mr =3D memory_region_get_iommu(section->mr); @@ -1223,7 +1221,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, } else { AddressSpaceDispatch *d; =20 - d =3D atomic_rcu_read(§ion->address_space->dispatch); + d =3D address_space_to_dispatch(section->address_space); iotlb =3D section - d->map.sections; iotlb +=3D xlat; } @@ -1348,9 +1346,9 @@ static void register_multipage(AddressSpaceDispatch *= d, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_in= dex); } =20 -void mem_add(AddressSpace *as, MemoryRegionSection *section) +void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) { - AddressSpaceDispatch *d =3D as->next_dispatch; + AddressSpaceDispatch *d =3D flatview_to_dispatch(fv); MemoryRegionSection now =3D *section, remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); =20 @@ -2673,7 +2671,7 @@ static void io_mem_init(void) NULL, UINT64_MAX); } =20 -void mem_begin(AddressSpace *as) +AddressSpaceDispatch *mem_begin(AddressSpace *as) { AddressSpaceDispatch *d =3D g_new0(AddressSpaceDispatch, 1); uint16_t n; @@ -2689,26 +2687,19 @@ void mem_begin(AddressSpace *as) =20 d->phys_map =3D (PhysPageEntry) { .ptr =3D PHYS_MAP_NODE_NIL, .skip = =3D 1 }; d->as =3D as; - as->next_dispatch =3D d; + + return d; } =20 -static void address_space_dispatch_free(AddressSpaceDispatch *d) +void address_space_dispatch_free(AddressSpaceDispatch *d) { phys_sections_free(&d->map); g_free(d); } =20 -void mem_commit(AddressSpace *as) +void mem_commit(AddressSpaceDispatch *d) { - AddressSpaceDispatch *cur =3D as->dispatch; - AddressSpaceDispatch *next =3D as->next_dispatch; - - phys_page_compact_all(next, next->map.nodes_nb); - - atomic_rcu_set(&as->dispatch, next); - if (cur) { - call_rcu(cur, address_space_dispatch_free, rcu); - } + phys_page_compact_all(d, d->map.nodes_nb); } =20 static void tcg_commit(MemoryListener *listener) @@ -2724,21 +2715,11 @@ static void tcg_commit(MemoryListener *listener) * We reload the dispatch pointer now because cpu_reloading_memory_map= () * may have split the RCU critical section. */ - d =3D atomic_rcu_read(&cpuas->as->dispatch); + d =3D address_space_to_dispatch(cpuas->as); atomic_rcu_set(&cpuas->memory_dispatch, d); tlb_flush(cpuas->cpu); } =20 -void address_space_destroy_dispatch(AddressSpace *as) -{ - AddressSpaceDispatch *d =3D as->dispatch; - - atomic_rcu_set(&as->dispatch, NULL); - if (d) { - call_rcu(d, address_space_dispatch_free, rcu); - } -} - static void memory_map_init(void) { system_memory =3D g_malloc(sizeof(*system_memory)); diff --git a/memory.c b/memory.c index d3bf0da703..7d28aec5e3 100644 --- a/memory.c +++ b/memory.c @@ -229,6 +229,7 @@ struct FlatView { FlatRange *ranges; unsigned nr; unsigned nr_allocated; + struct AddressSpaceDispatch *dispatch; }; =20 typedef struct AddressSpaceOps AddressSpaceOps; @@ -289,6 +290,9 @@ static void flatview_destroy(FlatView *view) { int i; =20 + if (view->dispatch) { + address_space_dispatch_free(view->dispatch); + } for (i =3D 0; i < view->nr; i++) { memory_region_unref(view->ranges[i].mr); } @@ -304,10 +308,25 @@ static void flatview_ref(FlatView *view) static void flatview_unref(FlatView *view) { if (atomic_fetch_dec(&view->ref) =3D=3D 1) { - flatview_destroy(view); + call_rcu(view, flatview_destroy, rcu); } } =20 +static FlatView *address_space_to_flatview(AddressSpace *as) +{ + return atomic_rcu_read(&as->current_map); +} + +AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv) +{ + return fv->dispatch; +} + +AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as) +{ + return flatview_to_dispatch(address_space_to_flatview(as)); +} + static bool can_merge(FlatRange *r1, FlatRange *r2) { return int128_eq(addrrange_end(r1->addr), r2->addr.start) @@ -886,13 +905,13 @@ static void address_space_update_topology(AddressSpac= e *as) FlatView *new_view =3D generate_memory_topology(as->root); int i; =20 - mem_begin(as); + new_view->dispatch =3D mem_begin(as); for (i =3D 0; i < new_view->nr; i++) { MemoryRegionSection mrs =3D section_from_flat_range(&new_view->ranges[i], as); - mem_add(as, &mrs); + mem_add(as, new_view, &mrs); } - mem_commit(as); + mem_commit(new_view->dispatch); =20 address_space_update_topology_pass(as, old_view, new_view, false); address_space_update_topology_pass(as, old_view, new_view, true); @@ -2629,7 +2648,6 @@ void address_space_init(AddressSpace *as, MemoryRegio= n *root, const char *name) QTAILQ_INIT(&as->listeners); QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link); as->name =3D g_strdup(name ? name : "anonymous"); - as->dispatch =3D NULL; memory_region_update_pending |=3D root->enabled; memory_region_transaction_commit(); } @@ -2638,7 +2656,6 @@ static void do_address_space_destroy(AddressSpace *as) { bool do_free =3D as->malloced; =20 - address_space_destroy_dispatch(as); assert(QTAILQ_EMPTY(&as->listeners)); =20 flatview_unref(as->current_map); --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505729968910942.6859963744629; Mon, 18 Sep 2017 03:19:28 -0700 (PDT) Received: from localhost ([::1]:35592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt9E-00070B-0b for importer@patchew.org; Mon, 18 Sep 2017 06:19:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7J-0005kR-4l for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7E-0004ER-V2 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:29 -0400 Received: from ozlabs.ru ([107.173.13.209]:35246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7E-0004DX-OG for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:24 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 73F5C3A60054; Mon, 18 Sep 2017 06:18:39 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:02 +1000 Message-Id: <20170918101709.30421-7-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 06/13] memory: Remove AddressSpace pointer from AddressSpaceDispatch 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" AS in ASD is only used to pass AS from mem_begin() to register_subpage() to store it in MemoryRegionSection, we can do this directly now. Signed-off-by: Alexey Kardashevskiy --- exec.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index 6b0211bafc..3212c5e70d 100644 --- a/exec.c +++ b/exec.c @@ -194,7 +194,6 @@ struct AddressSpaceDispatch { */ PhysPageEntry phys_map; PhysPageMap map; - AddressSpace *as; }; =20 #define SUBPAGE_IDX(addr) ((addr) & ~TARGET_PAGE_MASK) @@ -1304,7 +1303,8 @@ static void phys_sections_free(PhysPageMap *map) g_free(map->nodes); } =20 -static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection = *section) +static void register_subpage(AddressSpace *as, AddressSpaceDispatch *d, + MemoryRegionSection *section) { subpage_t *subpage; hwaddr base =3D section->offset_within_address_space @@ -1319,8 +1319,8 @@ static void register_subpage(AddressSpaceDispatch *d,= MemoryRegionSection *secti assert(existing->mr->subpage || existing->mr =3D=3D &io_mem_unassigned= ); =20 if (!(existing->mr->subpage)) { - subpage =3D subpage_init(d->as, base); - subsection.address_space =3D d->as; + subpage =3D subpage_init(as, base); + subsection.address_space =3D as; subsection.mr =3D &subpage->iomem; phys_page_set(d, base >> TARGET_PAGE_BITS, 1, phys_section_add(&d->map, &subsection)); @@ -1357,7 +1357,7 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRe= gionSection *section) - now.offset_within_address_space; =20 now.size =3D int128_min(int128_make64(left), now.size); - register_subpage(d, &now); + register_subpage(as, d, &now); } else { now.size =3D int128_zero(); } @@ -1367,10 +1367,10 @@ void mem_add(AddressSpace *as, FlatView *fv, Memory= RegionSection *section) remain.offset_within_region +=3D int128_get64(now.size); now =3D remain; if (int128_lt(remain.size, page_size)) { - register_subpage(d, &now); + register_subpage(as, d, &now); } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK)= { now.size =3D page_size; - register_subpage(d, &now); + register_subpage(as, d, &now); } else { now.size =3D int128_and(now.size, int128_neg(page_size)); register_multipage(d, &now); @@ -2686,7 +2686,6 @@ AddressSpaceDispatch *mem_begin(AddressSpace *as) assert(n =3D=3D PHYS_SECTION_WATCH); =20 d->phys_map =3D (PhysPageEntry) { .ptr =3D PHYS_MAP_NODE_NIL, .skip = =3D 1 }; - d->as =3D as; =20 return d; } --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730134661968.5155297655812; Mon, 18 Sep 2017 03:22:14 -0700 (PDT) Received: from localhost ([::1]:35608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttBt-00019n-Mi for importer@patchew.org; Mon, 18 Sep 2017 06:22:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7K-0005l2-36 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7G-0004FE-Aq 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 1dtt7F-0004Dh-Uh for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:26 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 8C6AF3A60050; Mon, 18 Sep 2017 06:18:40 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:03 +1000 Message-Id: <20170918101709.30421-8-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 07/13] memory: Switch memory from using AddressSpace to 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" FlatView's will be shared between AddressSpace's and subpage_t and MemoryRegionSection cannot store AS anymore, hence this change. In particular, for: typedef struct subpage_t { MemoryRegion iomem; - AddressSpace *as; + FlatView *fv; hwaddr base; uint16_t sub_section[]; } subpage_t; struct MemoryRegionSection { MemoryRegion *mr; - AddressSpace *address_space; + FlatView *fv; hwaddr offset_within_region; Int128 size; hwaddr offset_within_address_space; bool readonly; }; Signed-off-by: Alexey Kardashevskiy --- include/exec/memory-internal.h | 2 +- include/exec/memory.h | 51 ++++++++---- exec.c | 180 ++++++++++++++++++++++++-------------= ---- hw/intc/openpic_kvm.c | 2 +- memory.c | 28 ++++--- 5 files changed, 157 insertions(+), 106 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 6e08eda256..1cf8ad9869 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -27,7 +27,7 @@ extern const MemoryRegionOps unassigned_mem_ops; bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, unsigned size, bool is_write); =20 -void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section); +void mem_add(FlatView *fv, MemoryRegionSection *section); AddressSpaceDispatch *mem_begin(AddressSpace *as); void mem_commit(AddressSpaceDispatch *d); =20 diff --git a/include/exec/memory.h b/include/exec/memory.h index 2346f8b863..7816e5d655 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -48,6 +48,7 @@ =20 typedef struct MemoryRegionOps MemoryRegionOps; typedef struct MemoryRegionMmio MemoryRegionMmio; +typedef struct FlatView FlatView; =20 struct MemoryRegionMmio { CPUReadMemoryFunc *read[3]; @@ -320,6 +321,8 @@ struct AddressSpace { QTAILQ_ENTRY(AddressSpace) address_spaces_link; }; =20 +FlatView *address_space_to_flatview(AddressSpace *as); + /** * MemoryRegionSection: describes a fragment of a #MemoryRegion * @@ -333,7 +336,7 @@ struct AddressSpace { */ struct MemoryRegionSection { MemoryRegion *mr; - AddressSpace *address_space; + FlatView *fv; hwaddr offset_within_region; Int128 size; hwaddr offset_within_address_space; @@ -1842,9 +1845,17 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressS= pace *as, hwaddr addr, * @len: pointer to length * @is_write: indicates the transfer direction */ -MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, - hwaddr *xlat, hwaddr *len, - bool is_write); +MemoryRegion *flatview_translate(FlatView *fv, + hwaddr addr, hwaddr *xlat, + hwaddr *len, bool is_write); + +static inline MemoryRegion *address_space_translate(AddressSpace *as, + hwaddr addr, hwaddr *x= lat, + hwaddr *len, bool is_w= rite) +{ + return flatview_translate(address_space_to_flatview(as), + addr, xlat, len, is_write); +} =20 /* address_space_access_valid: check for validity of accessing an address * space range @@ -1895,12 +1906,13 @@ void address_space_unmap(AddressSpace *as, void *bu= ffer, hwaddr len, =20 =20 /* Internal functions, part of the implementation of address_space_read. = */ -MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, - MemTxAttrs attrs, uint8_t *buf, - int len, hwaddr addr1, hwaddr l, - MemoryRegion *mr); -MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, - MemTxAttrs attrs, uint8_t *buf, int le= n); +MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, + int len, hwaddr addr1, hwaddr l, + MemoryRegion *mr); + +MemTxResult flatview_read_full(FlatView *fv, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, int len); void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); =20 static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) @@ -1927,8 +1939,8 @@ static inline bool memory_access_is_direct(MemoryRegi= on *mr, bool is_write) * @buf: buffer with the data transferred */ static inline __attribute__((__always_inline__)) -MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs a= ttrs, - uint8_t *buf, int len) +MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs, + uint8_t *buf, int len) { MemTxResult result =3D MEMTX_OK; hwaddr l, addr1; @@ -1939,22 +1951,29 @@ MemTxResult address_space_read(AddressSpace *as, hw= addr addr, MemTxAttrs attrs, if (len) { rcu_read_lock(); l =3D len; - mr =3D address_space_translate(as, addr, &addr1, &l, false); + mr =3D flatview_translate(fv, addr, &addr1, &l, false); if (len =3D=3D l && memory_access_is_direct(mr, false)) { ptr =3D qemu_map_ram_ptr(mr->ram_block, addr1); memcpy(buf, ptr, len); } else { - result =3D address_space_read_continue(as, addr, attrs, bu= f, len, - addr1, l, mr); + result =3D flatview_read_continue(fv, addr, attrs, buf, le= n, + addr1, l, mr); } rcu_read_unlock(); } } else { - result =3D address_space_read_full(as, addr, attrs, buf, len); + result =3D flatview_read_full(fv, addr, attrs, buf, len); } return result; } =20 +static inline MemTxResult address_space_read(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, uint8_t *bu= f, + int len) +{ + return flatview_read(address_space_to_flatview(as), addr, attrs, buf, = len); +} + /** * address_space_read_cached: read from a cached RAM region * diff --git a/exec.c b/exec.c index 3212c5e70d..b561098df3 100644 --- a/exec.c +++ b/exec.c @@ -199,7 +199,7 @@ struct AddressSpaceDispatch { #define SUBPAGE_IDX(addr) ((addr) & ~TARGET_PAGE_MASK) typedef struct subpage_t { MemoryRegion iomem; - AddressSpace *as; + FlatView *fv; hwaddr base; uint16_t sub_section[]; } subpage_t; @@ -469,13 +469,13 @@ address_space_translate_internal(AddressSpaceDispatch= *d, hwaddr addr, hwaddr *x } =20 /* Called from RCU critical section */ -static MemoryRegionSection address_space_do_translate(AddressSpace *as, - hwaddr addr, - hwaddr *xlat, - hwaddr *plen, - bool is_write, - bool is_mmio, - AddressSpace **targe= t_as) +static MemoryRegionSection flatview_do_translate(FlatView *fv, + hwaddr addr, + hwaddr *xlat, + hwaddr *plen, + bool is_write, + bool is_mmio, + AddressSpace **target_as) { IOMMUTLBEntry iotlb; MemoryRegionSection *section; @@ -483,8 +483,9 @@ static MemoryRegionSection address_space_do_translate(A= ddressSpace *as, IOMMUMemoryRegionClass *imrc; =20 for (;;) { - AddressSpaceDispatch *d =3D address_space_to_dispatch(as); - section =3D address_space_translate_internal(d, addr, &addr, plen,= is_mmio); + section =3D address_space_translate_internal( + flatview_to_dispatch(fv), addr, &addr, + plen, is_mmio); =20 iommu_mr =3D memory_region_get_iommu(section->mr); if (!iommu_mr) { @@ -501,7 +502,7 @@ static MemoryRegionSection address_space_do_translate(A= ddressSpace *as, goto translate_fail; } =20 - as =3D iotlb.target_as; + fv =3D address_space_to_flatview(iotlb.target_as); *target_as =3D iotlb.target_as; } =20 @@ -524,8 +525,8 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpac= e *as, hwaddr addr, plen =3D (hwaddr)-1; =20 /* This can never be MMIO. */ - section =3D address_space_do_translate(as, addr, &xlat, &plen, - is_write, false, &as); + section =3D flatview_do_translate(address_space_to_flatview(as), addr, + &xlat, &plen, is_write, false, &as); =20 /* Illegal translation */ if (section.mr =3D=3D &io_mem_unassigned) { @@ -561,16 +562,15 @@ iotlb_fail: } =20 /* Called from RCU critical section */ -MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, - hwaddr *xlat, hwaddr *plen, - bool is_write) +MemoryRegion *flatview_translate(FlatView *fv, hwaddr addr, hwaddr *xlat, + hwaddr *plen, bool is_write) { MemoryRegion *mr; MemoryRegionSection section; + AddressSpace *as =3D NULL; =20 /* This can be MMIO, so setup MMIO bit. */ - section =3D address_space_do_translate(as, addr, xlat, plen, is_write,= true, - &as); + section =3D flatview_do_translate(fv, addr, xlat, plen, is_write, true= , &as); mr =3D section.mr; =20 if (xen_enabled() && memory_access_is_direct(mr, is_write)) { @@ -1220,7 +1220,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, } else { AddressSpaceDispatch *d; =20 - d =3D address_space_to_dispatch(section->address_space); + d =3D flatview_to_dispatch(section->fv); iotlb =3D section - d->map.sections; iotlb +=3D xlat; } @@ -1246,7 +1246,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, =20 static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, uint16_t section); -static subpage_t *subpage_init(AddressSpace *as, hwaddr base); +static subpage_t *subpage_init(FlatView *fv, hwaddr base); =20 static void *(*phys_mem_alloc)(size_t size, uint64_t *align) =3D qemu_anon_ram_alloc; @@ -1303,7 +1303,7 @@ static void phys_sections_free(PhysPageMap *map) g_free(map->nodes); } =20 -static void register_subpage(AddressSpace *as, AddressSpaceDispatch *d, +static void register_subpage(FlatView *fv, AddressSpaceDispatch *d, MemoryRegionSection *section) { subpage_t *subpage; @@ -1319,8 +1319,8 @@ static void register_subpage(AddressSpace *as, Addres= sSpaceDispatch *d, assert(existing->mr->subpage || existing->mr =3D=3D &io_mem_unassigned= ); =20 if (!(existing->mr->subpage)) { - subpage =3D subpage_init(as, base); - subsection.address_space =3D as; + subpage =3D subpage_init(fv, base); + subsection.fv =3D fv; subsection.mr =3D &subpage->iomem; phys_page_set(d, base >> TARGET_PAGE_BITS, 1, phys_section_add(&d->map, &subsection)); @@ -1346,7 +1346,7 @@ static void register_multipage(AddressSpaceDispatch *= d, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_in= dex); } =20 -void mem_add(AddressSpace *as, FlatView *fv, MemoryRegionSection *section) +void mem_add(FlatView *fv, MemoryRegionSection *section) { AddressSpaceDispatch *d =3D flatview_to_dispatch(fv); MemoryRegionSection now =3D *section, remain =3D *section; @@ -1357,7 +1357,7 @@ void mem_add(AddressSpace *as, FlatView *fv, MemoryRe= gionSection *section) - now.offset_within_address_space; =20 now.size =3D int128_min(int128_make64(left), now.size); - register_subpage(as, d, &now); + register_subpage(fv, d, &now); } else { now.size =3D int128_zero(); } @@ -1367,10 +1367,10 @@ void mem_add(AddressSpace *as, FlatView *fv, Memory= RegionSection *section) remain.offset_within_region +=3D int128_get64(now.size); now =3D remain; if (int128_lt(remain.size, page_size)) { - register_subpage(as, d, &now); + register_subpage(fv, d, &now); } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK)= { now.size =3D page_size; - register_subpage(as, d, &now); + register_subpage(fv, d, &now); } else { now.size =3D int128_and(now.size, int128_neg(page_size)); register_multipage(d, &now); @@ -2501,6 +2501,11 @@ static const MemoryRegionOps watch_mem_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 +static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs at= trs, + const uint8_t *buf, int len); +static bool flatview_access_valid(FlatView *fv, hwaddr addr, int len, + bool is_write); + static MemTxResult subpage_read(void *opaque, hwaddr addr, uint64_t *data, unsigned len, MemTxAttrs attrs) { @@ -2512,8 +2517,7 @@ static MemTxResult subpage_read(void *opaque, hwaddr = addr, uint64_t *data, printf("%s: subpage %p len %u addr " TARGET_FMT_plx "\n", __func__, subpage, len, addr); #endif - res =3D address_space_read(subpage->as, addr + subpage->base, - attrs, buf, len); + res =3D flatview_read(subpage->fv, addr + subpage->base, attrs, buf, l= en); if (res) { return res; } @@ -2562,8 +2566,7 @@ static MemTxResult subpage_write(void *opaque, hwaddr= addr, default: abort(); } - return address_space_write(subpage->as, addr + subpage->base, - attrs, buf, len); + return flatview_write(subpage->fv, addr + subpage->base, attrs, buf, l= en); } =20 static bool subpage_accepts(void *opaque, hwaddr addr, @@ -2575,8 +2578,8 @@ static bool subpage_accepts(void *opaque, hwaddr addr, __func__, subpage, is_write ? 'w' : 'r', len, addr); #endif =20 - return address_space_access_valid(subpage->as, addr + subpage->base, - len, is_write); + return flatview_access_valid(subpage->fv, addr + subpage->base, + len, is_write); } =20 static const MemoryRegionOps subpage_ops =3D { @@ -2610,12 +2613,12 @@ static int subpage_register (subpage_t *mmio, uint3= 2_t start, uint32_t end, return 0; } =20 -static subpage_t *subpage_init(AddressSpace *as, hwaddr base) +static subpage_t *subpage_init(FlatView *fv, hwaddr base) { subpage_t *mmio; =20 mmio =3D g_malloc0(sizeof(subpage_t) + TARGET_PAGE_SIZE * sizeof(uint1= 6_t)); - mmio->as =3D as; + mmio->fv =3D fv; mmio->base =3D base; memory_region_init_io(&mmio->iomem, NULL, &subpage_ops, mmio, NULL, TARGET_PAGE_SIZE); @@ -2629,12 +2632,11 @@ static subpage_t *subpage_init(AddressSpace *as, hw= addr base) return mmio; } =20 -static uint16_t dummy_section(PhysPageMap *map, AddressSpace *as, - MemoryRegion *mr) +static uint16_t dummy_section(PhysPageMap *map, FlatView *fv, MemoryRegion= *mr) { - assert(as); + assert(fv); MemoryRegionSection section =3D { - .address_space =3D as, + .fv =3D fv, .mr =3D mr, .offset_within_address_space =3D 0, .offset_within_region =3D 0, @@ -2673,16 +2675,17 @@ static void io_mem_init(void) =20 AddressSpaceDispatch *mem_begin(AddressSpace *as) { + FlatView *fv =3D address_space_to_flatview(as); AddressSpaceDispatch *d =3D g_new0(AddressSpaceDispatch, 1); uint16_t n; =20 - n =3D dummy_section(&d->map, as, &io_mem_unassigned); + n =3D dummy_section(&d->map, fv, &io_mem_unassigned); assert(n =3D=3D PHYS_SECTION_UNASSIGNED); - n =3D dummy_section(&d->map, as, &io_mem_notdirty); + n =3D dummy_section(&d->map, fv, &io_mem_notdirty); assert(n =3D=3D PHYS_SECTION_NOTDIRTY); - n =3D dummy_section(&d->map, as, &io_mem_rom); + n =3D dummy_section(&d->map, fv, &io_mem_rom); assert(n =3D=3D PHYS_SECTION_ROM); - n =3D dummy_section(&d->map, as, &io_mem_watch); + n =3D dummy_section(&d->map, fv, &io_mem_watch); assert(n =3D=3D PHYS_SECTION_WATCH); =20 d->phys_map =3D (PhysPageEntry) { .ptr =3D PHYS_MAP_NODE_NIL, .skip = =3D 1 }; @@ -2862,11 +2865,11 @@ static bool prepare_mmio_access(MemoryRegion *mr) } =20 /* Called within RCU critical section. */ -static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr a= ddr, - MemTxAttrs attrs, - const uint8_t *buf, - int len, hwaddr addr1, - hwaddr l, MemoryRegion *mr) +static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, + MemTxAttrs attrs, + const uint8_t *buf, + int len, hwaddr addr1, + hwaddr l, MemoryRegion *mr) { uint8_t *ptr; uint64_t val; @@ -2928,14 +2931,14 @@ static MemTxResult address_space_write_continue(Add= ressSpace *as, hwaddr addr, } =20 l =3D len; - mr =3D address_space_translate(as, addr, &addr1, &l, true); + mr =3D flatview_translate(fv, addr, &addr1, &l, true); } =20 return result; } =20 -MemTxResult address_space_write(AddressSpace *as, hwaddr addr, MemTxAttrs = attrs, - const uint8_t *buf, int len) +static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs at= trs, + const uint8_t *buf, int len) { hwaddr l; hwaddr addr1; @@ -2945,20 +2948,27 @@ MemTxResult address_space_write(AddressSpace *as, h= waddr addr, MemTxAttrs attrs, if (len > 0) { rcu_read_lock(); l =3D len; - mr =3D address_space_translate(as, addr, &addr1, &l, true); - result =3D address_space_write_continue(as, addr, attrs, buf, len, - addr1, l, mr); + mr =3D flatview_translate(fv, addr, &addr1, &l, true); + result =3D flatview_write_continue(fv, addr, attrs, buf, len, + addr1, l, mr); rcu_read_unlock(); } =20 return result; } =20 +MemTxResult address_space_write(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, + const uint8_t *buf, int len) +{ + return flatview_write(address_space_to_flatview(as), addr, attrs, buf,= len); +} + /* Called within RCU critical section. */ -MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, - MemTxAttrs attrs, uint8_t *buf, - int len, hwaddr addr1, hwaddr l, - MemoryRegion *mr) +MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, + int len, hwaddr addr1, hwaddr l, + MemoryRegion *mr) { uint8_t *ptr; uint64_t val; @@ -3018,14 +3028,14 @@ MemTxResult address_space_read_continue(AddressSpac= e *as, hwaddr addr, } =20 l =3D len; - mr =3D address_space_translate(as, addr, &addr1, &l, false); + mr =3D flatview_translate(fv, addr, &addr1, &l, false); } =20 return result; } =20 -MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, - MemTxAttrs attrs, uint8_t *buf, int le= n) +MemTxResult flatview_read_full(FlatView *fv, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, int len) { hwaddr l; hwaddr addr1; @@ -3035,25 +3045,33 @@ MemTxResult address_space_read_full(AddressSpace *a= s, hwaddr addr, if (len > 0) { rcu_read_lock(); l =3D len; - mr =3D address_space_translate(as, addr, &addr1, &l, false); - result =3D address_space_read_continue(as, addr, attrs, buf, len, - addr1, l, mr); + mr =3D flatview_translate(fv, addr, &addr1, &l, false); + result =3D flatview_read_continue(fv, addr, attrs, buf, len, + addr1, l, mr); rcu_read_unlock(); } =20 return result; } =20 -MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, MemTxAttrs att= rs, - uint8_t *buf, int len, bool is_write) +static MemTxResult flatview_rw(FlatView *fv, hwaddr addr, MemTxAttrs attrs, + uint8_t *buf, int len, bool is_write) { if (is_write) { - return address_space_write(as, addr, attrs, (uint8_t *)buf, len); + return flatview_write(fv, addr, attrs, (uint8_t *)buf, len); } else { - return address_space_read(as, addr, attrs, (uint8_t *)buf, len); + return flatview_read(fv, addr, attrs, (uint8_t *)buf, len); } } =20 +MemTxResult address_space_rw(AddressSpace *as, hwaddr addr, + MemTxAttrs attrs, uint8_t *buf, + int len, bool is_write) +{ + return flatview_rw(address_space_to_flatview(as), + addr, attrs, buf, len, is_write); +} + void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, int len, int is_write) { @@ -3211,7 +3229,8 @@ static void cpu_notify_map_clients(void) qemu_mutex_unlock(&map_client_list_lock); } =20 -bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bo= ol is_write) +static bool flatview_access_valid(FlatView *fv, hwaddr addr, int len, + bool is_write) { MemoryRegion *mr; hwaddr l, xlat; @@ -3219,7 +3238,7 @@ bool address_space_access_valid(AddressSpace *as, hwa= ddr addr, int len, bool is_ rcu_read_lock(); while (len > 0) { l =3D len; - mr =3D address_space_translate(as, addr, &xlat, &l, is_write); + mr =3D flatview_translate(fv, addr, &xlat, &l, is_write); if (!memory_access_is_direct(mr, is_write)) { l =3D memory_access_size(mr, l, addr); if (!memory_region_access_valid(mr, xlat, l, is_write)) { @@ -3235,8 +3254,16 @@ bool address_space_access_valid(AddressSpace *as, hw= addr addr, int len, bool is_ return true; } =20 +bool address_space_access_valid(AddressSpace *as, hwaddr addr, + int len, bool is_write) +{ + return flatview_access_valid(address_space_to_flatview(as), + addr, len, is_write); +} + static hwaddr -address_space_extend_translation(AddressSpace *as, hwaddr addr, hwaddr tar= get_len, +flatview_extend_translation(FlatView *fv, hwaddr addr, + hwaddr target_len, MemoryRegion *mr, hwaddr base, hwaddr len, bool is_write) { @@ -3253,7 +3280,8 @@ address_space_extend_translation(AddressSpace *as, hw= addr addr, hwaddr target_le } =20 len =3D target_len; - this_mr =3D address_space_translate(as, addr, &xlat, &len, is_writ= e); + this_mr =3D flatview_translate(fv, addr, &xlat, + &len, is_write); if (this_mr !=3D mr || xlat !=3D base + done) { return done; } @@ -3276,6 +3304,7 @@ void *address_space_map(AddressSpace *as, hwaddr l, xlat; MemoryRegion *mr; void *ptr; + FlatView *fv =3D address_space_to_flatview(as); =20 if (len =3D=3D 0) { return NULL; @@ -3283,7 +3312,7 @@ void *address_space_map(AddressSpace *as, =20 l =3D len; rcu_read_lock(); - mr =3D address_space_translate(as, addr, &xlat, &l, is_write); + mr =3D flatview_translate(fv, addr, &xlat, &l, is_write); =20 if (!memory_access_is_direct(mr, is_write)) { if (atomic_xchg(&bounce.in_use, true)) { @@ -3299,7 +3328,7 @@ void *address_space_map(AddressSpace *as, memory_region_ref(mr); bounce.mr =3D mr; if (!is_write) { - address_space_read(as, addr, MEMTXATTRS_UNSPECIFIED, + flatview_read(fv, addr, MEMTXATTRS_UNSPECIFIED, bounce.buffer, l); } =20 @@ -3310,7 +3339,8 @@ void *address_space_map(AddressSpace *as, =20 =20 memory_region_ref(mr); - *plen =3D address_space_extend_translation(as, addr, len, mr, xlat, l,= is_write); + *plen =3D flatview_extend_translation(fv, addr, len, mr, xlat, + l, is_write); ptr =3D qemu_ram_ptr_length(mr->ram_block, xlat, plen, true); rcu_read_unlock(); =20 diff --git a/hw/intc/openpic_kvm.c b/hw/intc/openpic_kvm.c index 0518e017c4..fa83420254 100644 --- a/hw/intc/openpic_kvm.c +++ b/hw/intc/openpic_kvm.c @@ -124,7 +124,7 @@ static void kvm_openpic_region_add(MemoryListener *list= ener, uint64_t reg_base; int ret; =20 - if (section->address_space !=3D &address_space_memory) { + if (section->fv !=3D address_space_to_flatview(&address_space_memory))= { abort(); } =20 diff --git a/memory.c b/memory.c index 7d28aec5e3..d208106032 100644 --- a/memory.c +++ b/memory.c @@ -154,7 +154,8 @@ enum ListenerDirection { Forward, Reverse }; /* No need to ref/unref .mr, the FlatRange keeps it alive. */ #define MEMORY_LISTENER_UPDATE_REGION(fr, as, dir, callback, _args...) \ do { \ - MemoryRegionSection mrs =3D section_from_flat_range(fr, as); \ + MemoryRegionSection mrs =3D section_from_flat_range(fr, \ + address_space_to_flatview(as)); \ MEMORY_LISTENER_CALL(as, callback, dir, &mrs, ##_args); \ } while(0) =20 @@ -238,11 +239,11 @@ typedef struct AddressSpaceOps AddressSpaceOps; for (var =3D (view)->ranges; var < (view)->ranges + (view)->nr; ++var) =20 static inline MemoryRegionSection -section_from_flat_range(FlatRange *fr, AddressSpace *as) +section_from_flat_range(FlatRange *fr, FlatView *fv) { return (MemoryRegionSection) { .mr =3D fr->mr, - .address_space =3D as, + .fv =3D fv, .offset_within_region =3D fr->offset_in_region, .size =3D fr->addr.size, .offset_within_address_space =3D int128_get64(fr->addr.start), @@ -312,7 +313,7 @@ static void flatview_unref(FlatView *view) } } =20 -static FlatView *address_space_to_flatview(AddressSpace *as) +FlatView *address_space_to_flatview(AddressSpace *as) { return atomic_rcu_read(&as->current_map); } @@ -760,7 +761,7 @@ static void address_space_add_del_ioeventfds(AddressSpa= ce *as, fds_new[inew]))) { fd =3D &fds_old[iold]; section =3D (MemoryRegionSection) { - .address_space =3D as, + .fv =3D address_space_to_flatview(as), .offset_within_address_space =3D int128_get64(fd->addr.sta= rt), .size =3D fd->addr.size, }; @@ -773,7 +774,7 @@ static void address_space_add_del_ioeventfds(AddressSpa= ce *as, fds_old[iold]))) { fd =3D &fds_new[inew]; section =3D (MemoryRegionSection) { - .address_space =3D as, + .fv =3D address_space_to_flatview(as), .offset_within_address_space =3D int128_get64(fd->addr.sta= rt), .size =3D fd->addr.size, }; @@ -908,8 +909,8 @@ static void address_space_update_topology(AddressSpace = *as) new_view->dispatch =3D mem_begin(as); for (i =3D 0; i < new_view->nr; i++) { MemoryRegionSection mrs =3D - section_from_flat_range(&new_view->ranges[i], as); - mem_add(as, new_view, &mrs); + section_from_flat_range(&new_view->ranges[i], new_view); + mem_add(new_view, &mrs); } mem_commit(new_view->dispatch); =20 @@ -1863,7 +1864,7 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr) view =3D address_space_get_flatview(as); FOR_EACH_FLAT_RANGE(fr, view) { if (fr->mr =3D=3D mr) { - MemoryRegionSection mrs =3D section_from_flat_range(fr, as= ); + MemoryRegionSection mrs =3D section_from_flat_range(fr, vi= ew); listener->log_sync(listener, &mrs); } } @@ -1966,7 +1967,7 @@ static void memory_region_update_coalesced_range_as(M= emoryRegion *mr, AddressSpa FOR_EACH_FLAT_RANGE(fr, view) { if (fr->mr =3D=3D mr) { section =3D (MemoryRegionSection) { - .address_space =3D as, + .fv =3D view, .offset_within_address_space =3D int128_get64(fr->addr.sta= rt), .size =3D fr->addr.size, }; @@ -2328,7 +2329,7 @@ static MemoryRegionSection memory_region_find_rcu(Mem= oryRegion *mr, } =20 ret.mr =3D fr->mr; - ret.address_space =3D as; + ret.fv =3D view; range =3D addrrange_intersection(range, fr->addr); ret.offset_within_region =3D fr->offset_in_region; ret.offset_within_region +=3D int128_get64(int128_sub(range.start, @@ -2377,7 +2378,8 @@ void memory_global_dirty_log_sync(void) view =3D address_space_get_flatview(as); FOR_EACH_FLAT_RANGE(fr, view) { if (fr->dirty_log_mask) { - MemoryRegionSection mrs =3D section_from_flat_range(fr, as= ); + MemoryRegionSection mrs =3D section_from_flat_range(fr, vi= ew); + listener->log_sync(listener, &mrs); } } @@ -2462,7 +2464,7 @@ static void listener_add_address_space(MemoryListener= *listener, FOR_EACH_FLAT_RANGE(fr, view) { MemoryRegionSection section =3D { .mr =3D fr->mr, - .address_space =3D as, + .fv =3D view, .offset_within_region =3D fr->offset_in_region, .size =3D fr->addr.size, .offset_within_address_space =3D int128_get64(fr->addr.start), --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730171404943.9406085084262; Mon, 18 Sep 2017 03:22:51 -0700 (PDT) Received: from localhost ([::1]:35609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttCU-0001iD-3J for importer@patchew.org; Mon, 18 Sep 2017 06:22:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7K-0005l4-3K 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 1dtt7H-0004FX-87 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 1dtt7H-0004Dh-1e for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:27 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id D05373A60054; Mon, 18 Sep 2017 06:18:41 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:04 +1000 Message-Id: <20170918101709.30421-9-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 08/13] memory: Cleanup after switching to 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" We store AddressSpaceDispatch* in FlatView anyway so there is no need to carry it from mem_add() to register_subpage/register_multipage. Signed-off-by: Alexey Kardashevskiy --- exec.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exec.c b/exec.c index b561098df3..3e02b82c05 100644 --- a/exec.c +++ b/exec.c @@ -1303,9 +1303,9 @@ static void phys_sections_free(PhysPageMap *map) g_free(map->nodes); } =20 -static void register_subpage(FlatView *fv, AddressSpaceDispatch *d, - MemoryRegionSection *section) +static void register_subpage(FlatView *fv, MemoryRegionSection *section) { + AddressSpaceDispatch *d =3D flatview_to_dispatch(fv); subpage_t *subpage; hwaddr base =3D section->offset_within_address_space & TARGET_PAGE_MASK; @@ -1334,9 +1334,10 @@ static void register_subpage(FlatView *fv, AddressSp= aceDispatch *d, } =20 =20 -static void register_multipage(AddressSpaceDispatch *d, +static void register_multipage(FlatView *fv, MemoryRegionSection *section) { + AddressSpaceDispatch *d =3D flatview_to_dispatch(fv); hwaddr start_addr =3D section->offset_within_address_space; uint16_t section_index =3D phys_section_add(&d->map, section); uint64_t num_pages =3D int128_get64(int128_rshift(section->size, @@ -1348,7 +1349,6 @@ static void register_multipage(AddressSpaceDispatch *= d, =20 void mem_add(FlatView *fv, MemoryRegionSection *section) { - AddressSpaceDispatch *d =3D flatview_to_dispatch(fv); MemoryRegionSection now =3D *section, remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); =20 @@ -1357,7 +1357,7 @@ void mem_add(FlatView *fv, MemoryRegionSection *secti= on) - now.offset_within_address_space; =20 now.size =3D int128_min(int128_make64(left), now.size); - register_subpage(fv, d, &now); + register_subpage(fv, &now); } else { now.size =3D int128_zero(); } @@ -1367,13 +1367,13 @@ void mem_add(FlatView *fv, MemoryRegionSection *sec= tion) remain.offset_within_region +=3D int128_get64(now.size); now =3D remain; if (int128_lt(remain.size, page_size)) { - register_subpage(fv, d, &now); + register_subpage(fv, &now); } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK)= { now.size =3D page_size; - register_subpage(fv, d, &now); + register_subpage(fv, &now); } else { now.size =3D int128_and(now.size, int128_neg(page_size)); - register_multipage(d, &now); + register_multipage(fv, &now); } } } --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730435768891.3097622761223; Mon, 18 Sep 2017 03:27:15 -0700 (PDT) Received: from localhost ([::1]:35638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttGl-0005Yu-0e for importer@patchew.org; Mon, 18 Sep 2017 06:27:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7K-0005l1-35 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 1dtt7I-0004Ft-DR 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 1dtt7I-0004Dh-51 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:28 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id E97043A60055; Mon, 18 Sep 2017 06:18:42 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:05 +1000 Message-Id: <20170918101709.30421-10-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 09/13] memory: Rename mem_begin/mem_commit/mem_add helpers 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 renames some helper to reflect better what they do. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * s/flatview_mem_add/flatview_add_to_dispatch/ * s/phys_page_compact_all/address_space_dispatch_compact/ * s/address_space_dispatch_alloc/address_space_dispatch_new/ --- include/exec/memory-internal.h | 6 +++--- exec.c | 12 +++--------- memory.c | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 1cf8ad9869..d4a35c6e96 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -27,9 +27,9 @@ extern const MemoryRegionOps unassigned_mem_ops; bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr, unsigned size, bool is_write); =20 -void mem_add(FlatView *fv, MemoryRegionSection *section); -AddressSpaceDispatch *mem_begin(AddressSpace *as); -void mem_commit(AddressSpaceDispatch *d); +void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section); +AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv); +void address_space_dispatch_compact(AddressSpaceDispatch *d); =20 AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as); AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv); diff --git a/exec.c b/exec.c index 3e02b82c05..b1f29d35d8 100644 --- a/exec.c +++ b/exec.c @@ -359,7 +359,7 @@ static void phys_page_compact(PhysPageEntry *lp, Node *= nodes) } } =20 -static void phys_page_compact_all(AddressSpaceDispatch *d, int nodes_nb) +void address_space_dispatch_compact(AddressSpaceDispatch *d) { if (d->phys_map.skip) { phys_page_compact(&d->phys_map, d->map.nodes); @@ -1347,7 +1347,7 @@ static void register_multipage(FlatView *fv, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_in= dex); } =20 -void mem_add(FlatView *fv, MemoryRegionSection *section) +void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) { MemoryRegionSection now =3D *section, remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); @@ -2673,9 +2673,8 @@ static void io_mem_init(void) NULL, UINT64_MAX); } =20 -AddressSpaceDispatch *mem_begin(AddressSpace *as) +AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv) { - FlatView *fv =3D address_space_to_flatview(as); AddressSpaceDispatch *d =3D g_new0(AddressSpaceDispatch, 1); uint16_t n; =20 @@ -2699,11 +2698,6 @@ void address_space_dispatch_free(AddressSpaceDispatc= h *d) g_free(d); } =20 -void mem_commit(AddressSpaceDispatch *d) -{ - phys_page_compact_all(d, d->map.nodes_nb); -} - static void tcg_commit(MemoryListener *listener) { CPUAddressSpace *cpuas; diff --git a/memory.c b/memory.c index d208106032..e046f7bc2f 100644 --- a/memory.c +++ b/memory.c @@ -906,13 +906,13 @@ static void address_space_update_topology(AddressSpac= e *as) FlatView *new_view =3D generate_memory_topology(as->root); int i; =20 - new_view->dispatch =3D mem_begin(as); + new_view->dispatch =3D address_space_dispatch_new(new_view); for (i =3D 0; i < new_view->nr; i++) { MemoryRegionSection mrs =3D section_from_flat_range(&new_view->ranges[i], new_view); - mem_add(new_view, &mrs); + flatview_add_to_dispatch(new_view, &mrs); } - mem_commit(new_view->dispatch); + address_space_dispatch_compact(new_view->dispatch); =20 address_space_update_topology_pass(as, old_view, new_view, false); address_space_update_topology_pass(as, old_view, new_view, true); --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 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 From nobody Tue Apr 30 04:21:08 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 1505730267575916.7975275855747; Mon, 18 Sep 2017 03:24:27 -0700 (PDT) Received: from localhost ([::1]:35616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttE2-00033W-SB for importer@patchew.org; Mon, 18 Sep 2017 06:24:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7L-0005ly-SK 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 1dtt7K-0004HC-KL for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:31 -0400 Received: from ozlabs.ru ([107.173.13.209]:35254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7K-0004Dh-CV for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:30 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 2A3C93A60055; Mon, 18 Sep 2017 06:18:44 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:07 +1000 Message-Id: <20170918101709.30421-12-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 11/13] memory: Share FlatView's and dispatch trees between address spaces 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 allows sharing flat views between address spaces when the same root memory region is used when creating a new address space. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * got rid of global and per-AS lists of FlatView objects --- I could also make all empty FlatViews (view->nr=3D=3D0 but they are still enabled) resolve to an empty FlatView but not sure it is worth it as in real life all devices and therefore FlatViews are expected not to be empty. --- memory.c | 92 ++++++++++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/memory.c b/memory.c index e18ef53cc2..6fca8bf932 100644 --- a/memory.c +++ b/memory.c @@ -917,36 +917,66 @@ static void address_space_update_topology_pass(Addres= sSpace *as, } } =20 -static void address_space_update_topology(AddressSpace *as) +static gboolean flatview_unref_g_hash(gpointer key, gpointer value, + gpointer user_data) +{ + flatview_unref((FlatView *) value); + return true; +} + +static void flatview_update_topology(void) { - FlatView *old_view =3D address_space_get_flatview(as); - MemoryRegion *physmr =3D memory_region_unalias_entire(old_view->root); - FlatView *new_view =3D generate_memory_topology(physmr); int i; + AddressSpace *as; + FlatView *old_view, *new_view; + GHashTable *views =3D g_hash_table_new(g_direct_hash, g_direct_equal); + MemoryRegion *physmr; + gpointer key; =20 - new_view->dispatch =3D address_space_dispatch_new(new_view); - for (i =3D 0; i < new_view->nr; i++) { - MemoryRegionSection mrs =3D - section_from_flat_range(&new_view->ranges[i], new_view); - flatview_add_to_dispatch(new_view, &mrs); + /* Render unique FVs */ + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + old_view =3D as->current_map; + physmr =3D memory_region_unalias_entire(old_view->root); + + key =3D !physmr->enabled ? 0 : physmr; + new_view =3D (FlatView *) g_hash_table_lookup(views, key); + if (new_view) { + continue; + } + + new_view =3D generate_memory_topology(physmr); + + new_view->dispatch =3D address_space_dispatch_new(new_view); + for (i =3D 0; i < new_view->nr; i++) { + MemoryRegionSection mrs =3D + section_from_flat_range(&new_view->ranges[i], new_view); + flatview_add_to_dispatch(new_view, &mrs); + } + address_space_dispatch_compact(new_view->dispatch); + + g_hash_table_insert(views, key, new_view); + } + + /* Replace FVs in ASes */ + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + old_view =3D as->current_map; + physmr =3D memory_region_unalias_entire(old_view->root); + + key =3D !physmr->enabled ? 0 : physmr; + new_view =3D (FlatView *) g_hash_table_lookup(views, key); + assert(new_view); + + address_space_update_topology_pass(as, old_view, new_view, false); + address_space_update_topology_pass(as, old_view, new_view, true); + + flatview_ref(new_view); + atomic_rcu_set(&as->current_map, new_view); + flatview_unref(old_view); } - 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); - - /* Writes are protected by the BQL. */ - atomic_rcu_set(&as->current_map, new_view); - call_rcu(old_view, flatview_unref, rcu); - - /* Note that all the old MemoryRegions are still alive up to this - * point. This relieves most MemoryListeners from the need to - * ref/unref the MemoryRegions they get---unless they use them - * outside the iothread mutex, in which case precise reference - * counting is necessary. - */ - flatview_unref(old_view); - - address_space_update_ioeventfds(as); + + /* Unref FVs from temporary table */ + g_hash_table_foreach_remove(views, flatview_unref_g_hash, 0); + g_hash_table_unref(views); } =20 void memory_region_transaction_begin(void) @@ -966,9 +996,10 @@ void memory_region_transaction_commit(void) if (!memory_region_transaction_depth) { if (memory_region_update_pending) { MEMORY_LISTENER_CALL_GLOBAL(begin, Forward); + flatview_update_topology(); =20 QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - address_space_update_topology(as); + address_space_update_ioeventfds(as); } memory_region_update_pending =3D false; MEMORY_LISTENER_CALL_GLOBAL(commit, Forward); @@ -2690,13 +2721,6 @@ AddressSpace *address_space_init_shareable(MemoryReg= ion *root, const char *name) { AddressSpace *as; =20 - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - if (root =3D=3D as->root && as->malloced) { - as->ref_count++; - return as; - } - } - as =3D g_malloc0(sizeof *as); address_space_init(as, root, name); as->malloced =3D true; --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730555185995.5563362892115; Mon, 18 Sep 2017 03:29:15 -0700 (PDT) Received: from localhost ([::1]:35648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttIg-000708-Dq for importer@patchew.org; Mon, 18 Sep 2017 06:29:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7Q-0005qA-Br for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7L-0004HT-Ni for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:36 -0400 Received: from ozlabs.ru ([107.173.13.209]:35254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7L-0004Dh-GB for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:31 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 485683A60054; Mon, 18 Sep 2017 06:18:46 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:08 +1000 Message-Id: <20170918101709.30421-13-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 12/13] memory: Get rid of address_space_init_shareable 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" Since FlatViews are shared now and ASes not, this gets rid of address_space_init_shareable(). Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * now removes @malloced and @ref_count, used to be in the previos patch --- include/exec/memory.h | 19 ------------------- include/hw/arm/armv7m.h | 2 +- cpus.c | 5 +++-- hw/arm/armv7m.c | 9 ++++----- memory.c | 22 +--------------------- target/arm/cpu.c | 16 ++++++++-------- target/i386/cpu.c | 5 +++-- 7 files changed, 20 insertions(+), 58 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 7816e5d655..d73430b543 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -309,8 +309,6 @@ struct AddressSpace { struct rcu_head rcu; char *name; MemoryRegion *root; - int ref_count; - bool malloced; =20 /* Accessed via RCU. */ struct FlatView *current_map; @@ -1585,23 +1583,6 @@ MemTxResult memory_region_dispatch_write(MemoryRegio= n *mr, void address_space_init(AddressSpace *as, MemoryRegion *root, const char *= name); =20 /** - * address_space_init_shareable: return an address space for a memory regi= on, - * creating it if it does not already exist - * - * @root: a #MemoryRegion that routes addresses for the address space - * @name: an address space name. The name is only used for debugging - * output. - * - * This function will return a pointer to an existing AddressSpace - * which was initialized with the specified MemoryRegion, or it will - * create and initialize one if it does not already exist. The ASes - * are reference-counted, so the memory will be freed automatically - * when the AddressSpace is destroyed via address_space_destroy. - */ -AddressSpace *address_space_init_shareable(MemoryRegion *root, - const char *name); - -/** * address_space_destroy: destroy an address space * * Releases all resources associated with an address space. After an addr= ess space diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h index 10eb058027..008000fe11 100644 --- a/include/hw/arm/armv7m.h +++ b/include/hw/arm/armv7m.h @@ -21,7 +21,7 @@ typedef struct { SysBusDevice parent_obj; /*< public >*/ =20 - AddressSpace *source_as; + AddressSpace source_as; MemoryRegion iomem; uint32_t base; MemoryRegion *source_memory; diff --git a/cpus.c b/cpus.c index 9bed61eefc..c9a624003a 100644 --- a/cpus.c +++ b/cpus.c @@ -1764,8 +1764,9 @@ void qemu_init_vcpu(CPUState *cpu) /* If the target cpu hasn't set up any address spaces itself, * give it the default one. */ - AddressSpace *as =3D address_space_init_shareable(cpu->memory, - "cpu-memory"); + AddressSpace *as =3D g_new0(AddressSpace, 1); + + address_space_init(as, cpu->memory, "cpu-memory"); cpu->num_ases =3D 1; cpu_address_space_init(cpu, as, 0); } diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c index b64a409b40..4900339646 100644 --- a/hw/arm/armv7m.c +++ b/hw/arm/armv7m.c @@ -41,7 +41,7 @@ static MemTxResult bitband_read(void *opaque, hwaddr offs= et, =20 /* Find address in underlying memory and round down to multiple of siz= e */ addr =3D bitband_addr(s, offset) & (-size); - res =3D address_space_read(s->source_as, addr, attrs, buf, size); + res =3D address_space_read(&s->source_as, addr, attrs, buf, size); if (res) { return res; } @@ -66,7 +66,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr off= set, uint64_t value, =20 /* Find address in underlying memory and round down to multiple of siz= e */ addr =3D bitband_addr(s, offset) & (-size); - res =3D address_space_read(s->source_as, addr, attrs, buf, size); + res =3D address_space_read(&s->source_as, addr, attrs, buf, size); if (res) { return res; } @@ -79,7 +79,7 @@ static MemTxResult bitband_write(void *opaque, hwaddr off= set, uint64_t value, } else { buf[bitpos >> 3] &=3D ~bit; } - return address_space_write(s->source_as, addr, attrs, buf, size); + return address_space_write(&s->source_as, addr, attrs, buf, size); } =20 static const MemoryRegionOps bitband_ops =3D { @@ -111,8 +111,7 @@ static void bitband_realize(DeviceState *dev, Error **e= rrp) return; } =20 - s->source_as =3D address_space_init_shareable(s->source_memory, - "bitband-source"); + address_space_init(&s->source_as, s->source_memory, "bitband-source"); } =20 /* Board init. */ diff --git a/memory.c b/memory.c index 6fca8bf932..c12507d26d 100644 --- a/memory.c +++ b/memory.c @@ -2689,9 +2689,7 @@ void address_space_init(AddressSpace *as, MemoryRegio= n *root, const char *name) { memory_region_ref(root); memory_region_transaction_begin(); - as->ref_count =3D 1; as->root =3D root; - as->malloced =3D false; as->current_map =3D flatview_new(root); as->ioeventfd_nb =3D 0; as->ioeventfds =3D NULL; @@ -2704,37 +2702,19 @@ void address_space_init(AddressSpace *as, MemoryReg= ion *root, const char *name) =20 static void do_address_space_destroy(AddressSpace *as) { - bool do_free =3D as->malloced; - assert(QTAILQ_EMPTY(&as->listeners)); =20 flatview_unref(as->current_map); g_free(as->name); g_free(as->ioeventfds); memory_region_unref(as->root); - if (do_free) { - g_free(as); - } -} - -AddressSpace *address_space_init_shareable(MemoryRegion *root, const char = *name) -{ - AddressSpace *as; - - as =3D g_malloc0(sizeof *as); - address_space_init(as, root, name); - as->malloced =3D true; - return as; + g_free(as); } =20 void address_space_destroy(AddressSpace *as) { MemoryRegion *root =3D as->root; =20 - as->ref_count--; - if (as->ref_count) { - return; - } /* Flush out anything from MemoryListeners listening in on this */ memory_region_transaction_begin(); as->root =3D NULL; diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 412e94c7ad..bba24f4590 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -684,6 +684,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error *= *errp) CPUARMState *env =3D &cpu->env; int pagebits; Error *local_err =3D NULL; +#ifndef CONFIG_USER_ONLY + AddressSpace *as; +#endif =20 cpu_exec_realizefn(cs, &local_err); if (local_err !=3D NULL) { @@ -874,24 +877,21 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) =20 #ifndef CONFIG_USER_ONLY if (cpu->has_el3 || arm_feature(env, ARM_FEATURE_M_SECURITY)) { - AddressSpace *as; + as =3D g_new0(AddressSpace, 1); =20 cs->num_ases =3D 2; =20 if (!cpu->secure_memory) { cpu->secure_memory =3D cs->memory; } - as =3D address_space_init_shareable(cpu->secure_memory, - "cpu-secure-memory"); + address_space_init(as, cpu->secure_memory, "cpu-secure-memory"); cpu_address_space_init(cs, as, ARMASIdx_S); } else { cs->num_ases =3D 1; } - - cpu_address_space_init(cs, - address_space_init_shareable(cs->memory, - "cpu-memory"), - ARMASIdx_NS); + as =3D g_new0(AddressSpace, 1); + address_space_init(as, cs->memory, "cpu-memory"); + cpu_address_space_init(cs, as, ARMASIdx_NS); #endif =20 qemu_init_vcpu(cs); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 69676e13e1..11178300ee 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3741,10 +3741,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) =20 #ifndef CONFIG_USER_ONLY if (tcg_enabled()) { - AddressSpace *as_normal =3D address_space_init_shareable(cs->memor= y, - "cpu-memory= "); + AddressSpace *as_normal =3D g_new0(AddressSpace, 1); AddressSpace *as_smm =3D g_new(AddressSpace, 1); =20 + address_space_init(as_normal, cs->memory, "cpu-memory"); + cpu->cpu_as_mem =3D g_new(MemoryRegion, 1); cpu->cpu_as_root =3D g_new(MemoryRegion, 1); =20 --=20 2.11.0 From nobody Tue Apr 30 04:21:08 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 1505730278674661.5244035354949; Mon, 18 Sep 2017 03:24:38 -0700 (PDT) Received: from localhost ([::1]:35617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dttED-0003B4-Pp for importer@patchew.org; Mon, 18 Sep 2017 06:24:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7P-0005pV-Mm for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtt7N-0004Hz-2F for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:35 -0400 Received: from ozlabs.ru ([107.173.13.209]:35254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtt7M-0004Dh-PJ for qemu-devel@nongnu.org; Mon, 18 Sep 2017 06:17:32 -0400 Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 64CCE3A60055; Mon, 18 Sep 2017 06:18:47 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 20:17:09 +1000 Message-Id: <20170918101709.30421-14-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 13/13] memory: Add flat views to HMP "info mtree" 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 adds a new switch to "info mtree" to print dispatch tree internals. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * reimplemented as there is no more global FlatView list --- Example: aik@fstn1-p1:~$ echo "info mtree -f -d" | nc localhost 30000 QEMU 2.10.50 monitor - type 'help' for more information (qemu) info mtree -f -d FlatView #0 AS "nec-usb-xhci", root: bus master container Root memory region: bus master container 0000000000000000-000000003fffffff (prio 0, i/o): tce-iommu-80000000 0000040000000000-000004000000ffff (prio 0, i/o): msi Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000003fffffff tce-iommu-80000000 [iommu] #5 @0000040000000000..000004000000ffff msi Nodes (9 bits per level, 6 levels) ptr=3D[2] skip=3D3 [0] 0 skip=3D2 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D1 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D0 ptr=3D#4 1..7 skip=3D1 ptr=3DNIL 8 skip=3D3 ptr=3D[6] 9..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D0 ptr=3D#4 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D2 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D1 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [6] 0..15 skip=3D0 ptr=3D#5 16..511 skip=3D0 ptr=3D#0 FlatView #1 AS "vfio-pci", root: bus master container Root memory region: bus master container 0000000000000000-000000003fffffff (prio 0, i/o): tce-iommu-80000000 0000040000000000-000004000000ffff (prio 0, i/o): msi Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000003fffffff tce-iommu-80000000 [iommu] #5 @0000040000000000..000004000000ffff msi Nodes (9 bits per level, 6 levels) ptr=3D[2] skip=3D3 [0] 0 skip=3D2 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D1 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D0 ptr=3D#4 1..7 skip=3D1 ptr=3DNIL 8 skip=3D3 ptr=3D[6] 9..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D0 ptr=3D#4 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D2 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D1 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [6] 0..15 skip=3D0 ptr=3D#5 16..511 skip=3D0 ptr=3D#0 FlatView #2 AS "pci@800000020000000", root: pci@800000020000000.iommu-root Root memory region: pci@800000020000000.iommu-root 0000000000000000-000000003fffffff (prio 0, i/o): tce-iommu-80000000 0000040000000000-000004000000ffff (prio 0, i/o): msi Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000003fffffff tce-iommu-80000000 [iommu] #5 @0000040000000000..000004000000ffff msi Nodes (9 bits per level, 6 levels) ptr=3D[2] skip=3D3 [0] 0 skip=3D2 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D1 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D0 ptr=3D#4 1..7 skip=3D1 ptr=3DNIL 8 skip=3D3 ptr=3D[6] 9..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D0 ptr=3D#4 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D2 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D1 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [6] 0..15 skip=3D0 ptr=3D#5 16..511 skip=3D0 ptr=3D#0 FlatView #3 AS "memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system AS "cpu-memory", root: system Root memory region: system 0000000000000000-000000007fffffff (prio 0, ram): ppc_spapr.ram 0000200000000020-000020000000003f (prio 1, i/o): virtio-pci 0000200080000000-000020008000003f (prio 0, i/o): capabilities 0000200080000040-000020008000043f (prio 0, i/o): operational 0000200080000440-000020008000044f (prio 0, i/o): usb3 port #1 0000200080000450-000020008000045f (prio 0, i/o): usb3 port #2 0000200080000460-000020008000046f (prio 0, i/o): usb3 port #3 0000200080000470-000020008000047f (prio 0, i/o): usb3 port #4 0000200080000480-000020008000048f (prio 0, i/o): usb2 port #1 0000200080000490-000020008000049f (prio 0, i/o): usb2 port #2 00002000800004a0-00002000800004af (prio 0, i/o): usb2 port #3 00002000800004b0-00002000800004bf (prio 0, i/o): usb2 port #4 0000200080001000-000020008000121f (prio 0, i/o): runtime 0000200080002000-000020008000281f (prio 0, i/o): doorbell 0000200080003000-00002000800030ff (prio 0, i/o): msix-table 0000200080003800-0000200080003807 (prio 0, i/o): msix-pba 0000200080010000-000020008001ffff (prio 0, ramd): 0021:09:00.0 BAR 0 mmap= s[0] 0000200080020000-000020008002007f (prio 0, i/o): msix-table 0000200080020080-0000200080021fff (prio 1, i/o): 0021:09:00.0 BAR 2 @0000= 000000000080 0000200080030000-000020008003002f (prio 0, i/o): msix-table 0000200080030800-0000200080030807 (prio 0, i/o): msix-pba 0000210000000000-0000210000000fff (prio 0, i/o): virtio-pci-common 0000210000001000-0000210000001fff (prio 0, i/o): virtio-pci-isr 0000210000002000-0000210000002fff (prio 0, i/o): virtio-pci-device 0000210000003000-0000210000003fff (prio 0, i/o): virtio-pci-notify Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000007fffffff ppc_spapr.ram [MRU] #5 @0000200000000000..0000200000000fff (noname) #6 @0000200000000020..000020000000003f virtio-pci #7 @0000200080000000..0000200080000fff (noname) #8 @0000200080000000..000020008000003f capabilities #9 @0000200080000040..000020008000043f operational #10 @0000200080000440..000020008000044f usb3 port #1 #11 @0000200080000450..000020008000045f usb3 port #2 #12 @0000200080000460..000020008000046f usb3 port #3 #13 @0000200080000470..000020008000047f usb3 port #4 #14 @0000200080000480..000020008000048f usb2 port #1 #15 @0000200080000490..000020008000049f usb2 port #2 #16 @00002000800004a0..00002000800004af usb2 port #3 #17 @00002000800004b0..00002000800004bf usb2 port #4 #18 @0000200080001000..0000200080001fff (noname) #19 @0000200080001000..000020008000121f runtime #20 @0000200080002000..0000200080002fff (noname) #21 @0000200080002000..000020008000281f doorbell #22 @0000200080003000..0000200080003fff (noname) #23 @0000200080003000..00002000800030ff msix-table #24 @0000200080003800..0000200080003807 msix-pba #25 @0000200080010000..000020008001ffff 0021:09:00.0 BAR 0 mmaps[0] #26 @0000200080020000..0000200080020fff (noname) #27 @0000200080020000..000020008002007f msix-table #28 @0000200080020080..000020008002207f 0021:09:00.0 BAR 2 #29 @0000200080021000..0000200080022fff 0021:09:00.0 BAR 2 #30 @0000200080030000..0000200080030fff (noname) #31 @0000200080030000..000020008003002f msix-table #32 @0000200080030800..0000200080030807 msix-pba #33 @0000210000000000..0000210000000fff virtio-pci-common #34 @0000210000001000..0000210000001fff virtio-pci-isr #35 @0000210000002000..0000210000002fff virtio-pci-device #36 @0000210000003000..0000210000003fff virtio-pci-notify Nodes (9 bits per level, 6 levels) ptr=3D[2] skip=3D3 [0] 0 skip=3D2 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D1 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D1 ptr=3D[3] 1..63 skip=3D1 ptr=3DNIL 64 skip=3D1 ptr=3D[4] 65 skip=3D1 ptr=3DNIL 66 skip=3D3 ptr=3D[11] 67..511 skip=3D1 ptr=3DNIL [3] 0..1 skip=3D0 ptr=3D#4 2..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D2 ptr=3D[6] 1 skip=3D1 ptr=3DNIL 2 skip=3D2 ptr=3D[8] 3..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D1 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [6] 0 skip=3D0 ptr=3D#5 1..511 skip=3D0 ptr=3D#0 [7] 0 skip=3D1 ptr=3D[8] 1..511 skip=3D1 ptr=3DNIL [8] 0 skip=3D0 ptr=3D#7 1 skip=3D0 ptr=3D#18 2 skip=3D0 ptr=3D#20 3 skip=3D0 ptr=3D#22 4..15 skip=3D0 ptr=3D#0 16..31 skip=3D0 ptr=3D#25 32 skip=3D0 ptr=3D#26 33 skip=3D0 ptr=3D#29 34..47 skip=3D0 ptr=3D#0 48 skip=3D0 ptr=3D#30 49..511 skip=3D0 ptr=3D#0 [9] 0 skip=3D2 ptr=3D[11] 1..511 skip=3D1 ptr=3DNIL [10] 0 skip=3D1 ptr=3D[11] 1..511 skip=3D1 ptr=3DNIL [11] 0 skip=3D0 ptr=3D#33 1 skip=3D0 ptr=3D#34 2 skip=3D0 ptr=3D#35 3 skip=3D0 ptr=3D#36 4..511 skip=3D0 ptr=3D#0 FlatView #4 AS "virtio-net-pci", root: bus master container Root memory region: bus master container 0000000000000000-000000003fffffff (prio 0, i/o): tce-iommu-80000000 0000040000000000-000004000000ffff (prio 0, i/o): msi Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000003fffffff tce-iommu-80000000 [iommu] #5 @0000040000000000..000004000000ffff msi Nodes (9 bits per level, 6 levels) ptr=3D[2] skip=3D3 [0] 0 skip=3D2 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D1 ptr=3D[2] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D0 ptr=3D#4 1..7 skip=3D1 ptr=3DNIL 8 skip=3D3 ptr=3D[6] 9..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D0 ptr=3D#4 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D2 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D1 ptr=3D[6] 1..511 skip=3D1 ptr=3DNIL [6] 0..15 skip=3D0 ptr=3D#5 16..511 skip=3D0 ptr=3D#0 FlatView #5 AS "I/O", root: io Root memory region: io 0000000000000000-000000000000ffff (prio 0, i/o): io Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000000000000000..000000000000ffff io [ROOT] Nodes (9 bits per level, 6 levels) ptr=3D[5] skip=3D6 [0] 0 skip=3D5 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D4 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [2] 0 skip=3D3 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D2 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D1 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [5] 0..15 skip=3D0 ptr=3D#4 16..511 skip=3D0 ptr=3D#0 FlatView #6 AS "virtio-pci-cfg-as", root: virtio-pci-cfg, alias virtio-pci Root memory region: virtio-pci 0000210000000000-0000210000000fff (prio 0, i/o): virtio-pci-common 0000210000001000-0000210000001fff (prio 0, i/o): virtio-pci-isr 0000210000002000-0000210000002fff (prio 0, i/o): virtio-pci-device 0000210000003000-0000210000003fff (prio 0, i/o): virtio-pci-notify Dispatch Physical sections #0 @0000000000000000..ffffffffffffffff (noname) [unassigned] #1 @0000000000000000..ffffffffffffffff (noname) [not dirty] #2 @0000000000000000..ffffffffffffffff (noname) [ROM] #3 @0000000000000000..ffffffffffffffff (noname) [watch] #4 @0000210000000000..0000210000000fff virtio-pci-common #5 @0000210000001000..0000210000001fff virtio-pci-isr #6 @0000210000002000..0000210000002fff virtio-pci-device #7 @0000210000003000..0000210000003fff virtio-pci-notify Nodes (9 bits per level, 6 levels) ptr=3D[5] skip=3D6 [0] 0 skip=3D5 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [1] 0 skip=3D4 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [2] 0..65 skip=3D1 ptr=3DNIL 66 skip=3D3 ptr=3D[5] 67..511 skip=3D1 ptr=3DNIL [3] 0 skip=3D2 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [4] 0 skip=3D1 ptr=3D[5] 1..511 skip=3D1 ptr=3DNIL [5] 0 skip=3D0 ptr=3D#4 1 skip=3D0 ptr=3D#5 2 skip=3D0 ptr=3D#6 3 skip=3D0 ptr=3D#7 4..511 skip=3D0 ptr=3D#0 --- include/exec/memory-internal.h | 4 ++ include/exec/memory.h | 3 +- exec.c | 84 +++++++++++++++++++++++++++++++++++++++ memory.c | 90 +++++++++++++++++++++++++++++++++++++-= ---- monitor.c | 3 +- hmp-commands-info.hx | 7 ++-- 6 files changed, 176 insertions(+), 15 deletions(-) diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index d4a35c6e96..647e9bd5c4 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -35,5 +35,9 @@ AddressSpaceDispatch *address_space_to_dispatch(AddressSp= ace *as); AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv); void address_space_dispatch_free(AddressSpaceDispatch *d); =20 +void mtree_print_dispatch(fprintf_function mon, void *f, + struct AddressSpaceDispatch *d, + MemoryRegion *root); + #endif #endif diff --git a/include/exec/memory.h b/include/exec/memory.h index d73430b543..402824c6f2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1513,7 +1513,8 @@ void memory_global_dirty_log_start(void); */ void memory_global_dirty_log_stop(void); =20 -void mtree_info(fprintf_function mon_printf, void *f, bool flatview); +void mtree_info(fprintf_function mon_printf, void *f, bool flatview, + bool dispatch_tree); =20 /** * memory_region_request_mmio_ptr: request a pointer to an mmio diff --git a/exec.c b/exec.c index b1f29d35d8..3110e38565 100644 --- a/exec.c +++ b/exec.c @@ -3617,3 +3617,87 @@ void page_size_init(void) } qemu_host_page_mask =3D -(intptr_t)qemu_host_page_size; } + +#if !defined(CONFIG_USER_ONLY) + +static void mtree_print_phys_entries(fprintf_function mon, void *f, + int start, int end, int skip, int ptr) +{ + if (start =3D=3D end - 1) { + mon(f, "\t%3d ", start); + } else { + mon(f, "\t%3d..%-3d ", start, end - 1); + } + mon(f, " skip=3D%d ", skip); + if (ptr =3D=3D PHYS_MAP_NODE_NIL) { + mon(f, " ptr=3DNIL"); + } else if (!skip) { + mon(f, " ptr=3D#%d", ptr); + } else { + mon(f, " ptr=3D[%d]", ptr); + } + mon(f, "\n"); +} + +#define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \ + int128_sub((size), int128_one())) : 0) + +void mtree_print_dispatch(fprintf_function mon, void *f, + AddressSpaceDispatch *d, MemoryRegion *root) +{ + int i; + + mon(f, " Dispatch\n"); + mon(f, " Physical sections\n"); + + for (i =3D 0; i < d->map.sections_nb; ++i) { + MemoryRegionSection *s =3D d->map.sections + i; + const char *names[] =3D { " [unassigned]", " [not dirty]", + " [ROM]", " [watch]" }; + + mon(f, " #%d @" TARGET_FMT_plx ".." TARGET_FMT_plx " %s%s%s%s= %s", + i, + s->offset_within_address_space, + s->offset_within_address_space + MR_SIZE(s->mr->size), + s->mr->name ? s->mr->name : "(noname)", + i < ARRAY_SIZE(names) ? names[i] : "", + s->mr =3D=3D root ? " [ROOT]" : "", + s =3D=3D d->mru_section ? " [MRU]" : "", + s->mr->is_iommu ? " [iommu]" : ""); + + if (s->mr->alias) { + mon(f, " alias=3D%s", s->mr->alias->name ? + s->mr->alias->name : "noname"); + } + mon(f, "\n"); + } + + mon(f, " Nodes (%d bits per level, %d levels) ptr=3D[%d] skip=3D%d\= n", + P_L2_BITS, P_L2_LEVELS, d->phys_map.ptr, d->phys_map.skip); + for (i =3D 0; i < d->map.nodes_nb; ++i) { + int j, jprev; + PhysPageEntry prev; + Node *n =3D d->map.nodes + i; + + mon(f, " [%d]\n", i); + + for (j =3D 0, jprev =3D 0, prev =3D *n[0]; j < ARRAY_SIZE(*n); ++j= ) { + PhysPageEntry *pe =3D *n + j; + + if (pe->ptr =3D=3D prev.ptr && pe->skip =3D=3D prev.skip) { + continue; + } + + mtree_print_phys_entries(mon, f, jprev, j, prev.skip, prev.ptr= ); + + jprev =3D j; + prev =3D *pe; + } + + if (jprev !=3D ARRAY_SIZE(*n)) { + mtree_print_phys_entries(mon, f, jprev, j, prev.skip, prev.ptr= ); + } + } +} + +#endif diff --git a/memory.c b/memory.c index c12507d26d..be08cb3915 100644 --- a/memory.c +++ b/memory.c @@ -2854,18 +2854,44 @@ static void mtree_print_mr(fprintf_function mon_pri= ntf, void *f, } } =20 -static void mtree_print_flatview(fprintf_function p, void *f, - AddressSpace *as) +struct FlatViewInfo { + fprintf_function mon_printf; + void *f; + int counter; + bool dispatch_tree; +}; + +static void mtree_print_flatview(gpointer key, gpointer value, + gpointer user_data) { - FlatView *view =3D address_space_get_flatview(as); + FlatView *view =3D key; + GArray *fv_address_spaces =3D value; + struct FlatViewInfo *fvi =3D user_data; + fprintf_function p =3D fvi->mon_printf; + void *f =3D fvi->f; FlatRange *range =3D &view->ranges[0]; MemoryRegion *mr; int n =3D view->nr; + int i; + AddressSpace *as; + + p(f, "FlatView #%d\n", fvi->counter); + ++fvi->counter; + + for (i =3D 0; i < fv_address_spaces->len; ++i) { + as =3D g_array_index(fv_address_spaces, AddressSpace*, i); + p(f, " AS \"%s\", root: %s", as->name, memory_region_name(as->root= )); + if (as->root->alias) { + p(f, ", alias %s", memory_region_name(as->root->alias)); + } + p(f, "\n"); + } + + p(f, " Root memory region: %s\n", memory_region_name(view->root)); =20 if (n <=3D 0) { - p(f, MTREE_INDENT "No rendered FlatView for " - "address space '%s'\n", as->name); - flatview_unref(view); + p(f, MTREE_INDENT "No rendered FlatView, root MR is %s\n\n", + view->root->enabled ? "enabled" : "disabled"); return; } =20 @@ -2892,21 +2918,65 @@ static void mtree_print_flatview(fprintf_function p= , void *f, range++; } =20 +#if !defined(CONFIG_USER_ONLY) + if (fvi->dispatch_tree) { + mtree_print_dispatch(p, f, view->dispatch, view->root); + } +#endif + + p(f, "\n"); +} + +static gboolean mtree_info_flatview_free(gpointer key, gpointer value, + gpointer user_data) +{ + FlatView *view =3D key; + GArray *fv_address_spaces =3D value; + + g_array_unref(fv_address_spaces); flatview_unref(view); + + return true; } =20 -void mtree_info(fprintf_function mon_printf, void *f, bool flatview) +void mtree_info(fprintf_function mon_printf, void *f, bool flatview, + bool dispatch_tree) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; =20 if (flatview) { + FlatView *view; + struct FlatViewInfo fvi =3D { + .mon_printf =3D mon_printf, + .f =3D f, + .counter =3D 0, + .dispatch_tree =3D dispatch_tree + }; + GArray *fv_address_spaces; + GHashTable *views =3D g_hash_table_new(g_direct_hash, g_direct_equ= al); + + /* Gather all FVs in one table */ QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - mon_printf(f, "address-space (flat view): %s\n", as->name); - mtree_print_flatview(mon_printf, f, as); - mon_printf(f, "\n"); + view =3D address_space_get_flatview(as); + + fv_address_spaces =3D g_hash_table_lookup(views, view); + if (!fv_address_spaces) { + fv_address_spaces =3D g_array_new(false, false, sizeof(as)= ); + g_hash_table_insert(views, view, fv_address_spaces); + } + + g_array_append_val(fv_address_spaces, as); } + + /* Print */ + g_hash_table_foreach(views, mtree_print_flatview, &fvi); + + /* Free */ + g_hash_table_foreach_remove(views, mtree_info_flatview_free, 0); + g_hash_table_unref(views); + return; } =20 diff --git a/monitor.c b/monitor.c index 058045b3cb..f4856b9268 100644 --- a/monitor.c +++ b/monitor.c @@ -1703,8 +1703,9 @@ static void hmp_boot_set(Monitor *mon, const QDict *q= dict) static void hmp_info_mtree(Monitor *mon, const QDict *qdict) { bool flatview =3D qdict_get_try_bool(qdict, "flatview", false); + bool dispatch_tree =3D qdict_get_try_bool(qdict, "dispatch_tree", fals= e); =20 - mtree_info((fprintf_function)monitor_printf, mon, flatview); + mtree_info((fprintf_function)monitor_printf, mon, flatview, dispatch_t= ree); } =20 static void hmp_info_numa(Monitor *mon, const QDict *qdict) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 1c6772597d..4f1ece93e5 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -250,9 +250,10 @@ ETEXI =20 { .name =3D "mtree", - .args_type =3D "flatview:-f", - .params =3D "[-f]", - .help =3D "show memory tree (-f: dump flat view for address = spaces)", + .args_type =3D "flatview:-f,dispatch_tree:-d", + .params =3D "[-f][-d]", + .help =3D "show memory tree (-f: dump flat view for address = spaces;" + "-d: dump dispatch tree, valid with -f only)", .cmd =3D hmp_info_mtree, }, =20 --=20 2.11.0