From patchwork Thu Apr 17 17:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvise Rigo X-Patchwork-Id: 339988 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 00C631400B8 for ; Fri, 18 Apr 2014 03:31:13 +1000 (EST) Received: from localhost ([::1]:33991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Waq9W-0007Us-Ja for incoming@patchwork.ozlabs.org; Thu, 17 Apr 2014 13:31:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Waq8e-0006MI-9L for qemu-devel@nongnu.org; Thu, 17 Apr 2014 13:30:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Waq8Y-000557-7B for qemu-devel@nongnu.org; Thu, 17 Apr 2014 13:30:16 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:56679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Waq8X-00054l-St for qemu-devel@nongnu.org; Thu, 17 Apr 2014 13:30:10 -0400 Received: by mail-wi0-f181.google.com with SMTP id hm4so1162850wib.2 for ; Thu, 17 Apr 2014 10:30:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6GjyWkyKD3PO6O21gLGSXkhDRVAraJStCKX//1aBRNY=; b=R4ExTKvfnlhIB20TOAqdYtGARuFR0H3OMf/7KxXR0uM4U+yMqSk+VIVu6E5DW7g1v8 B3dqZb+1eSSJxf+WXZKYrBgFRQ5VuS9rGceyA+PhaaaBjhC+pGlg24v+AEfzCrDtylZV oQCGNgq1UdM87VYMp0lvhIwQmMQFWBfSROAPPdDoqQ1S/6QkpINf2Z7DcphD+tGHLG+P ZVT+SzkqKe5RfIRCa6pB4pZuG0/Q+4nByEToGMTTlLTSemxyy1L3UjzIs9JPTJke8ptC z6ZmQtnbOvJRZWanmD4Eau8vPWOqeNW8UgjqmrCOVH/Ycf8lzNssrhUE8zxUUuG4R8iK Ql6g== X-Gm-Message-State: ALoCoQmk2tmY5GP66GYi0G7zK73z89naWl1MoGdwqSUBvVnvSWFW32ysYRatDZAixvl125ccZOO8 X-Received: by 10.194.189.201 with SMTP id gk9mr13141028wjc.13.1397755808816; Thu, 17 Apr 2014 10:30:08 -0700 (PDT) Received: from localhost.localdomain (AGrenoble-651-1-481-123.w90-42.abo.wanadoo.fr. [90.42.177.123]) by mx.google.com with ESMTPSA id gz1sm5996833wib.14.2014.04.17.10.30.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Apr 2014 10:30:07 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, a.motakis@virtualopensystems.com, eric.auger@st.com, kim.phillips@linaro.org Date: Thu, 17 Apr 2014 19:29:32 +0200 Message-Id: <1397755775-23833-2-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1397755775-23833-1-git-send-email-a.rigo@virtualopensystems.com> References: <1397755775-23833-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.181 Cc: Peter Maydell , Laszlo Ersek , Juan Quintela , Jan Kiszka , "Michael S. Tsirkin" , Alvise Rigo , Luiz Capitulino , Jens Freimann , Anthony Liguori , Paolo Bonzini , tech@virtualopensystems.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Subject: [Qemu-devel] [RFC 1/4] Allocate non-RAM MemoryRegion from user pointer 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 The method memory_region_init_ptr() allows the allocation of non-RAM memory from a user-provided pointer. The function is useful in VFIO, where a pointer to the memory regions of the device is provided by the user. A new flag inside MemoryRegion tells if the memory has been allocated through a user pointer, allowing to not call the IOMMU callbacks for these regions, but rather to access the memory directly. Signed-off-by: Alvise Rigo --- exec.c | 2 +- include/exec/memory.h | 16 ++++++++++++++++ memory.c | 14 ++++++++++++++ memory_mapping.c | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 91513c6..ed91823 100644 --- a/exec.c +++ b/exec.c @@ -341,7 +341,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { - if (memory_region_is_ram(mr)) { + if (memory_region_is_ram(mr) || mr->alloc_from_ptr) { return !(is_write && mr->readonly); } if (memory_region_is_romd(mr)) { diff --git a/include/exec/memory.h b/include/exec/memory.h index c084db2..1f2745d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -149,6 +149,7 @@ struct MemoryRegion { bool rom_device; bool warning_printed; /* For reservations */ bool flush_coalesced_mmio; + bool alloc_from_ptr; MemoryRegion *alias; hwaddr alias_offset; int priority; @@ -327,6 +328,21 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, const char *name, uint64_t size, void *ptr); +/** + * memory_region_init_ram_ptr: As before, but for non-RAM memory. + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @ptr: memory to be mapped; must contain at least @size bytes. + */ +void memory_region_init_ptr(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + void *ptr); + /** * memory_region_init_alias: Initialize a memory region that aliases all or a diff --git a/memory.c b/memory.c index 3f1df23..fbb48bf 100644 --- a/memory.c +++ b/memory.c @@ -1030,6 +1030,20 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram_from_ptr; mr->ram_addr = qemu_ram_alloc_from_ptr(size, ptr, mr); + mr->alloc_from_ptr = true; +} + +void memory_region_init_ptr(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + void *ptr) +{ + memory_region_init(mr, owner, name, size); + mr->terminates = true; + mr->destructor = memory_region_destructor_ram_from_ptr; + mr->ram_addr = qemu_ram_alloc_from_ptr(size, ptr, mr); + mr->alloc_from_ptr = true; } void memory_region_init_alias(MemoryRegion *mr, diff --git a/memory_mapping.c b/memory_mapping.c index 87a6ed5..6e3d334 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -203,7 +203,7 @@ static void guest_phys_blocks_region_add(MemoryListener *listener, GuestPhysBlock *predecessor; /* we only care about RAM */ - if (!memory_region_is_ram(section->mr)) { + if (!memory_region_is_ram(section->mr) && !section->mr->alloc_from_ptr) { return; }