From patchwork Tue Oct 9 16:32:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 190378 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6A5A52C0199 for ; Wed, 10 Oct 2012 04:12:02 +1100 (EST) Received: from localhost ([::1]:49000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLcmm-0007lR-IY for incoming@patchwork.ozlabs.org; Tue, 09 Oct 2012 12:36:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLclz-0006mg-Nc for qemu-devel@nongnu.org; Tue, 09 Oct 2012 12:35:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLcla-0000HF-Ax for qemu-devel@nongnu.org; Tue, 09 Oct 2012 12:35:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56899) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLcla-0000Gm-2K for qemu-devel@nongnu.org; Tue, 09 Oct 2012 12:34:46 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q99GYhsS030798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 9 Oct 2012 12:34:43 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q99GWrqO008429; Tue, 9 Oct 2012 12:34:39 -0400 From: Avi Kivity To: qemu-devel@nongnu.org, Anthony Liguori , liu ping fan , "Michael S. Tsirkin" , Paolo Bonzini , Blue Swirl Date: Tue, 9 Oct 2012 18:32:46 +0200 Message-Id: <1349800368-15228-22-git-send-email-avi@redhat.com> In-Reply-To: <1349800368-15228-1-git-send-email-avi@redhat.com> References: <1349800368-15228-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 21/23] memory: add address_space_destroy() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Since address spaces can be created dynamically by device hotplug, they can also be destroyed dynamically. Signed-off-by: Avi Kivity --- exec.c | 10 ++++++++++ memory-internal.h | 1 + memory.c | 18 ++++++++++++++++-- memory.h | 12 ++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index ffd60c4..4bc79fb 100644 --- a/exec.c +++ b/exec.c @@ -3242,6 +3242,16 @@ void address_space_init_dispatch(AddressSpace *as) memory_listener_register(&d->listener, as); } +void address_space_destroy_dispatch(AddressSpace *as) +{ + AddressSpaceDispatch *d = as->dispatch; + + memory_listener_unregister(&d->listener); + destroy_l2_mapping(&d->phys_map, P_L2_LEVELS - 1); + g_free(d); + as->dispatch = NULL; +} + static void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); diff --git a/memory-internal.h b/memory-internal.h index a9d914e..7923ced 100644 --- a/memory-internal.h +++ b/memory-internal.h @@ -40,6 +40,7 @@ struct AddressSpaceDispatch { }; void address_space_init_dispatch(AddressSpace *as); +void address_space_destroy_dispatch(AddressSpace *as); ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr); diff --git a/memory.c b/memory.c index 13be848..2f68d67 100644 --- a/memory.c +++ b/memory.c @@ -564,8 +564,10 @@ static FlatView generate_memory_topology(MemoryRegion *mr) flatview_init(&view); - render_memory_region(&view, mr, int128_zero(), - addrrange_make(int128_zero(), int128_2_64()), false); + if (mr) { + render_memory_region(&view, mr, int128_zero(), + addrrange_make(int128_zero(), int128_2_64()), false); + } flatview_simplify(&view); return view; @@ -1542,6 +1544,18 @@ void address_space_init(AddressSpace *as, MemoryRegion *root) address_space_init_dispatch(as); } +void address_space_destroy(AddressSpace *as) +{ + /* Flush out anything from MemoryListeners listening in on this */ + memory_region_transaction_begin(); + as->root = NULL; + memory_region_transaction_commit(); + QTAILQ_REMOVE(&address_spaces, as, address_spaces_link); + address_space_destroy_dispatch(as); + flatview_destroy(as->current_map); + g_free(as->current_map); +} + uint64_t io_mem_read(MemoryRegion *mr, target_phys_addr_t addr, unsigned size) { return memory_region_dispatch_read(mr, addr, size); diff --git a/memory.h b/memory.h index d36c2ba..79393f1 100644 --- a/memory.h +++ b/memory.h @@ -804,6 +804,18 @@ void mtree_info(fprintf_function mon_printf, void *f); */ void address_space_init(AddressSpace *as, MemoryRegion *root); + +/** + * address_space_destroy: destroy an address space + * + * Releases all resources associated with an address space. After an address space + * is destroyed, its root memory region (given by address_space_init()) may be destroyed + * as well. + * + * @as: address space to be destroyed + */ +void address_space_destroy(AddressSpace *as); + /** * address_space_rw: read from or write to an address space. *