From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsdOh-0006op-1m for qemu-devel@nongnu.org; Fri, 28 Jun 2013 14:27:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsdOf-0000Xz-0j for qemu-devel@nongnu.org; Fri, 28 Jun 2013 14:27:50 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:34139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsdOe-0000Xb-QL for qemu-devel@nongnu.org; Fri, 28 Jun 2013 14:27:48 -0400 Received: by mail-ee0-f45.google.com with SMTP id c1so1195309eek.4 for ; Fri, 28 Jun 2013 11:27:48 -0700 (PDT) Received: from playground.lan (net-37-116-217-184.cust.dsl.vodafone.it. [37.116.217.184]) by mx.google.com with ESMTPSA id o5sm12035344eef.5.2013.06.28.11.27.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Jun 2013 11:27:47 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 28 Jun 2013 20:26:45 +0200 Message-Id: <1372444009-11544-27-git-send-email-pbonzini@redhat.com> In-Reply-To: <1372444009-11544-1-git-send-email-pbonzini@redhat.com> References: <1372444009-11544-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 26/30] exec: remove cur_map List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org cur_map is not used anymore; instead, each AddressSpaceDispatch has its own nodes/sections pair. The priorities of the MemoryListeners, and in the future RCU, guarantee that the nodes/sections are not freed while they are still in use. (In fact, next_map itself is not needed except to free the data on the next update). To avoid incorrect use, replace cur_map with a temporary copy that is only valid while the topology is being updated. If you use it, the name prev_map makes it clear that you're doing something weird. Signed-off-by: Paolo Bonzini --- exec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exec.c b/exec.c index 581f0c4..7f87e16 100644 --- a/exec.c +++ b/exec.c @@ -128,7 +128,7 @@ typedef struct PhysPageMap { MemoryRegionSection *sections; } PhysPageMap; -static PhysPageMap cur_map; +static PhysPageMap *prev_map; static PhysPageMap next_map; #define PHYS_MAP_NODE_NIL (((uint16_t)~0) >> 1) @@ -804,7 +804,7 @@ static void phys_section_destroy(MemoryRegion *mr) } } -static void phys_sections_clear(PhysPageMap *map) +static void phys_sections_free(PhysPageMap *map) { while (map->sections_nb > 0) { MemoryRegionSection *section = &map->sections[--map->sections_nb]; @@ -812,6 +812,7 @@ static void phys_sections_clear(PhysPageMap *map) } g_free(map->sections); g_free(map->nodes); + g_free(map); } static void register_subpage(AddressSpaceDispatch *d, MemoryRegionSection *section) @@ -1745,6 +1746,9 @@ static void core_begin(MemoryListener *listener) { uint16_t n; + prev_map = g_new(PhysPageMap, 1); + *prev_map = next_map; + memset(&next_map, 0, sizeof(next_map)); n = dummy_section(&io_mem_unassigned); assert(n == PHYS_SECTION_UNASSIGNED); @@ -1761,9 +1765,7 @@ static void core_begin(MemoryListener *listener) */ static void core_commit(MemoryListener *listener) { - PhysPageMap info = cur_map; - cur_map = next_map; - phys_sections_clear(&info); + phys_sections_free(prev_map); } static void tcg_commit(MemoryListener *listener) -- 1.8.1.4