From patchwork Mon Jun 27 17:26:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 102256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3FCA4B6F68 for ; Tue, 28 Jun 2011 04:31:48 +1000 (EST) Received: from localhost ([::1]:44210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbGb3-0003gw-3J for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2011 14:31:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:34467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbFVP-0003Ec-F1 for qemu-devel@nongnu.org; Mon, 27 Jun 2011 13:21:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QbFVN-0001Cv-Iy for qemu-devel@nongnu.org; Mon, 27 Jun 2011 13:21:51 -0400 Received: from smtp.citrix.com ([66.165.176.89]:63340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbFVN-0001Cp-8E for qemu-devel@nongnu.org; Mon, 27 Jun 2011 13:21:49 -0400 X-IronPort-AV: E=Sophos;i="4.65,433,1304308800"; d="scan'208";a="14815227" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 27 Jun 2011 13:21:48 -0400 Received: from smtp01.ad.xensource.com (10.219.128.104) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.137.0; Mon, 27 Jun 2011 13:21:47 -0400 Received: from localhost.localdomain (kaball.uk.xensource.com [10.80.2.59]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id p5RHLbsI009736; Mon, 27 Jun 2011 10:21:39 -0700 From: To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2011 18:26:06 +0100 Message-ID: <1309195566-29207-1-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, agraf@suse.de, Stefano Stabellini Subject: [Qemu-devel] [PATCH v2] qemu_ram_ptr_length: take ram_addr_t as arguments 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 From: Stefano Stabellini qemu_ram_ptr_length should take ram_addr_t as argument rather than target_phys_addr_t because is doing comparisons with RAMBlock addresses. cpu_physical_memory_map should create a ram_addr_t address to pass to qemu_ram_ptr_length from PhysPageDesc phys_offset. Remove code after abort() in qemu_ram_ptr_length. Changes in v2: - handle 0 size in qemu_ram_ptr_length; - rename addr1 to raddr; - initialize raddr to ULONG_MAX. Signed-off-by: Stefano Stabellini Reviewed-by: Peter Maydell --- cpu-common.h | 2 +- exec.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index b027e43..e4fcded 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -65,7 +65,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr); void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); -void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size); +void *qemu_ram_ptr_length(ram_addr_t addr, ram_addr_t *size); /* Same but slower, to use for migration, where the order of * RAMBlocks must not change. */ void *qemu_safe_ram_ptr(ram_addr_t addr); diff --git a/exec.c b/exec.c index 7f14332..7d7c2b2 100644 --- a/exec.c +++ b/exec.c @@ -3135,8 +3135,11 @@ void *qemu_safe_ram_ptr(ram_addr_t addr) /* Return a host pointer to guest's ram. Similar to qemu_get_ram_ptr * but takes a size argument */ -void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size) +void *qemu_ram_ptr_length(ram_addr_t addr, ram_addr_t *size) { + if (*size == 0) { + return NULL; + } if (xen_mapcache_enabled()) return qemu_map_cache(addr, *size, 1); else { @@ -3152,9 +3155,6 @@ void *qemu_ram_ptr_length(target_phys_addr_t addr, target_phys_addr_t *size) fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr); abort(); - - *size = 0; - return NULL; } } @@ -4020,7 +4020,9 @@ void *cpu_physical_memory_map(target_phys_addr_t addr, target_phys_addr_t page; unsigned long pd; PhysPageDesc *p; - target_phys_addr_t addr1 = addr; + ram_addr_t raddr = ULONG_MAX; + ram_addr_t rlen; + void *ret; while (len > 0) { page = addr & TARGET_PAGE_MASK; @@ -4048,13 +4050,18 @@ void *cpu_physical_memory_map(target_phys_addr_t addr, *plen = l; return bounce.buffer; } + if (!todo) { + raddr = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK); + } len -= l; addr += l; todo += l; } - *plen = todo; - return qemu_ram_ptr_length(addr1, plen); + rlen = todo; + ret = qemu_ram_ptr_length(raddr, &rlen); + *plen = rlen; + return ret; } /* Unmaps a memory region previously mapped by cpu_physical_memory_map().