From patchwork Tue Jun 3 02:10:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 355142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1F90614009F for ; Tue, 3 Jun 2014 12:14:33 +1000 (EST) Received: from localhost ([::1]:50046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WreFD-0000kh-0d for incoming@patchwork.ozlabs.org; Mon, 02 Jun 2014 22:14:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WreEh-0008RP-NN for qemu-devel@nongnu.org; Mon, 02 Jun 2014 22:14:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WreEZ-00074z-SV for qemu-devel@nongnu.org; Mon, 02 Jun 2014 22:13:59 -0400 Received: from mail-qa0-f42.google.com ([209.85.216.42]:56921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WreEZ-00074t-NM for qemu-devel@nongnu.org; Mon, 02 Jun 2014 22:13:51 -0400 Received: by mail-qa0-f42.google.com with SMTP id j5so4015123qaq.29 for ; Mon, 02 Jun 2014 19:13:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=20e+VAEUg7agqX/OTHTE6bVmr1KKeohkNYLcPn7MMl8=; b=CVc2lmxiUpLcczTmXdu5IGcqUl+rCf7LZFwaNHCL3JmseFl4oUhjmpKNPkf+J9rQbM 8ZNYN0bggATvpqzkJKiU2bVkVkpeLy4pVdbb2Kv3/YrapHb9e1QJkor7qRrkFKkKtQy/ aa54Zwf9Yx8ZfjVAj/LAwaNS0kad7z8RKFzwOSvz4QsTuOLfLNCTouskgBotOAeKWbq2 +mP25ilPC1PWvTSfTYbnZh1ON1/1GEmTmyEFpIaY6vTnFgkSZMZP3PzF+ljLQcX/ryzW wlZ98kxDkaUMnEljSAYZ5JMvTQjhMSsyGv9Bh/FC4OIi2IyxRJ28srstKlcNZPOPBCmU d++A== X-Gm-Message-State: ALoCoQlrnOXr+I+jj77MbvYDaoAQb0boSs669PbbATM/+uNWRj3fkc4OIviJJSSWLanCYZfJXNw+ X-Received: by 10.224.29.76 with SMTP id p12mr57555489qac.18.1401761631501; Mon, 02 Jun 2014 19:13:51 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPSA id il9sm24347680qab.22.2014.06.02.19.13.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 02 Jun 2014 19:13:51 -0700 (PDT) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Mon, 2 Jun 2014 19:10:25 -0700 Message-Id: <254c2b9197eb5178a12b10c5e5391e2023084f53.1401760826.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.216.42 Cc: pbonzini@redhat.com, edgari@xilinx.com, afaerber@suse.de, peter.maydell@linaro.org Subject: [Qemu-devel] [RFC PATCH v1 07/11] memory.c: Add address_space_init_shareable() 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 This will either create a new AS or return a pointer to an already existing equivalent one. Both name and root mr must match. The motivation is to reuse address spaces as much as possible. Its going to be quite common that bus masters out in device land have pointers to the same memory region for their mastering yet each will need to create its own address space. Let the memory API implement sharing for them. Signed-off-by: Peter Crosthwaite --- I know this leaks memory. I'll fix that post RFC. I think we need AS ref counters to do it properly if anyone has any input on how that should be done. We could change the equivalency test only match mr to support device specific naming of these shared ASes. The singleton AS can ultimately only have one name however. So perhaps some strcatting each time a new sharer is added to the share. That or first-in-best-dressed. include/exec/memory.h | 2 ++ memory.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 117c0d3..ae902b3 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -945,6 +945,8 @@ void mtree_info(fprintf_function mon_printf, void *f); */ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name); +AddressSpace *address_space_init_shareable(MemoryRegion *root, + const char *name); /** * address_space_destroy: destroy an address space diff --git a/memory.c b/memory.c index 6f5e0e5..33dde7b 100644 --- a/memory.c +++ b/memory.c @@ -1953,6 +1953,30 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name) memory_region_transaction_commit(); } +AddressSpace *address_space_init_shareable(MemoryRegion *root, const char *name) +{ + AddressSpace *as; + + if (!root) { + return NULL; + } + + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + if (root == as->root && !strcmp(name ? name : "anonymous", as->name)) { + return as; + } + } + + /* FIMXE: this leaks */ + as = g_malloc0(sizeof *as); + address_space_init(as, root, name); + return as; +} + +/* FIXME: patch this to be a ref decrementer, and when the AS runs out of + * refs do garbage collection + */ + void address_space_destroy(AddressSpace *as) { /* Flush out anything from MemoryListeners listening in on this */