From patchwork Thu Jul 4 15:13:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 256927 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BEF3B2C0091 for ; Fri, 5 Jul 2013 01:25:36 +1000 (EST) Received: from localhost ([::1]:38795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulPa-0006Zl-I2 for incoming@patchwork.ozlabs.org; Thu, 04 Jul 2013 11:25:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulFh-0001JQ-9B for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:15:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UulFf-0005Oc-DS for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:15:21 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:33270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulFf-0005OR-44 for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:15:19 -0400 Received: by mail-wi0-f175.google.com with SMTP id m6so6429120wiv.2 for ; Thu, 04 Jul 2013 08:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=Colc3B3A2TD0iul7aYrYfyqVhi6okBLZBWCqryYq2i4=; b=w4qrNLXuYrPzbc49v1gWenNIAjAeMXzYRxTLlMGSMKDW6y68/ZhiVz5ugIdYNP/Ror sPI06ekiO1WlJ++vhT6JJk7KFwa8f+T6TbygphhtbpKweYsVug2Wfy95EGourio+s6wr U7cBzgoll4SiC5WSFl00zTpPSpgUSa/a/Eh1y4owvlgEtaDy/5KMEuP3dak0mOR8opMn J5bOSxg2g6klHeQyLR5p+uGSvdNkEvWZYk3qxVz73TiADdHAWJrk3AoGdmsq5kJF+zoH RrOvwABd7DIliq3UOzt6zpOPgmM2VCx1Jc5wOIjgxdUNnit6REtJqNI1ZpKW+6qP53Yn IscQ== X-Received: by 10.180.187.235 with SMTP id fv11mr3551056wic.65.1372950918479; Thu, 04 Jul 2013 08:15:18 -0700 (PDT) Received: from playground.station (net-37-117-148-210.cust.dsl.vodafone.it. [37.117.148.210]) by mx.google.com with ESMTPSA id d8sm4212546wiz.0.2013.07.04.08.15.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Jul 2013 08:15:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 4 Jul 2013 17:13:23 +0200 Message-Id: <1372950842-32422-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> References: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22f Subject: [Qemu-devel] [PATCH 27/66] memory: return MemoryRegion from qemu_ram_addr_from_host 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 It will be needed in the next patch. Reviewed-by: Jan Kiszka Signed-off-by: Paolo Bonzini --- cputlb.c | 2 +- exec.c | 37 ++++++++++++++++++++++--------------- include/exec/cpu-common.h | 2 +- target-i386/kvm.c | 4 ++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cputlb.c b/cputlb.c index be24080..828007c 100644 --- a/cputlb.c +++ b/cputlb.c @@ -162,7 +162,7 @@ static inline ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr) { ram_addr_t ram_addr; - if (qemu_ram_addr_from_host(ptr, &ram_addr)) { + if (qemu_ram_addr_from_host(ptr, &ram_addr) == NULL) { fprintf(stderr, "Bad ram pointer %p\n", ptr); abort(); } diff --git a/exec.c b/exec.c index 55c0750..307efea 100644 --- a/exec.c +++ b/exec.c @@ -1288,15 +1288,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) } #endif /* !_WIN32 */ -/* Return a host pointer to ram allocated with qemu_ram_alloc. - With the exception of the softmmu code in this file, this should - only be used for local memory (e.g. video ram) that the device owns, - and knows it isn't going to access beyond the end of the block. - - It should not be used for general purpose DMA. - Use cpu_physical_memory_map/cpu_physical_memory_rw instead. - */ -void *qemu_get_ram_ptr(ram_addr_t addr) +static RAMBlock *qemu_get_ram_block(ram_addr_t addr) { RAMBlock *block; @@ -1316,6 +1308,21 @@ void *qemu_get_ram_ptr(ram_addr_t addr) found: ram_list.mru_block = block; + return block; +} + +/* Return a host pointer to ram allocated with qemu_ram_alloc. + With the exception of the softmmu code in this file, this should + only be used for local memory (e.g. video ram) that the device owns, + and knows it isn't going to access beyond the end of the block. + + It should not be used for general purpose DMA. + Use cpu_physical_memory_map/cpu_physical_memory_rw instead. + */ +void *qemu_get_ram_ptr(ram_addr_t addr) +{ + RAMBlock *block = qemu_get_ram_block(addr); + if (xen_enabled()) { /* We need to check if the requested address is in the RAM * because we don't want to map the entire memory in QEMU. @@ -1392,14 +1399,14 @@ static void *qemu_ram_ptr_length(ram_addr_t addr, ram_addr_t *size) /* Some of the softmmu routines need to translate from a host pointer (typically a TLB entry) back to a ram offset. */ -int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) +MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) { RAMBlock *block; uint8_t *host = ptr; if (xen_enabled()) { *ram_addr = xen_ram_addr_from_mapcache(ptr); - return 0; + return qemu_get_ram_block(*ram_addr)->mr; } block = ram_list.mru_block; @@ -1417,11 +1424,11 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) } } - return -1; + return NULL; found: *ram_addr = block->offset + (host - block->host); - return 0; + return block->mr; } static void notdirty_mem_write(void *opaque, hwaddr ram_addr, @@ -2111,8 +2118,8 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, if (buffer != bounce.buffer) { if (is_write) { ram_addr_t addr1; - int rc = qemu_ram_addr_from_host(buffer, &addr1); - assert(rc == 0); + MemoryRegion *mr = qemu_ram_addr_from_host(buffer, &addr1); + assert(mr != NULL); while (access_len) { unsigned l; l = TARGET_PAGE_SIZE; diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 7abb70f..e4996e1 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -52,7 +52,7 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr); void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); /* This should not be used by devices. */ -int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); +MemoryRegion *qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev); void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf, diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 39f4fbb..4b557b3 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -318,7 +318,7 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) if ((env->mcg_cap & MCG_SER_P) && addr && (code == BUS_MCEERR_AR || code == BUS_MCEERR_AO)) { - if (qemu_ram_addr_from_host(addr, &ram_addr) || + if (qemu_ram_addr_from_host(addr, &ram_addr) == NULL || !kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instead of guest system!\n"); @@ -350,7 +350,7 @@ int kvm_arch_on_sigbus(int code, void *addr) hwaddr paddr; /* Hope we are lucky for AO MCE */ - if (qemu_ram_addr_from_host(addr, &ram_addr) || + if (qemu_ram_addr_from_host(addr, &ram_addr) == NULL || !kvm_physical_memory_addr_from_host(CPU(first_cpu)->kvm_state, addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by "