From patchwork Tue Oct 5 20:13:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 66857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1686BB70D6 for ; Wed, 6 Oct 2010 07:16:19 +1100 (EST) Received: from localhost ([127.0.0.1]:43117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3Dvs-0002iT-72 for incoming@patchwork.ozlabs.org; Tue, 05 Oct 2010 16:16:16 -0400 Received: from [140.186.70.92] (port=53297 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P3DuV-0002Kn-Mf for qemu-devel@nongnu.org; Tue, 05 Oct 2010 16:14:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3DuU-0003xZ-GN for qemu-devel@nongnu.org; Tue, 05 Oct 2010 16:14:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3DuU-0003xL-9c for qemu-devel@nongnu.org; Tue, 05 Oct 2010 16:14:50 -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.13.8/8.13.8) with ESMTP id o95KEeWJ019623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Oct 2010 16:14:41 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o95KEdre025858; Tue, 5 Oct 2010 16:14:40 -0400 Received: from amt.cnet (vpn-10-75.rdu.redhat.com [10.11.10.75]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o95KEb6w013882; Tue, 5 Oct 2010 16:14:38 -0400 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 3C9BE68A06E; Tue, 5 Oct 2010 17:13:23 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id o95KDJoW006061; Tue, 5 Oct 2010 17:13:19 -0300 Date: Tue, 5 Oct 2010 17:13:19 -0300 From: Marcelo Tosatti To: Anthony Liguori Message-ID: <20101005201319.GA5686@amt.cnet> References: <20101004185447.891324545@redhat.com> <20101004185714.983252370@redhat.com> <4CAB20AA.7040801@codemonkey.ws> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4CAB20AA.7040801@codemonkey.ws> User-Agent: Mutt/1.5.20 (2009-08-17) 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. Cc: Dean Nelson , qemu-devel@nongnu.org, kvm@vger.kernel.org, Huang Ying Subject: [Qemu-devel] Re: [patch uq/master 5/8] Export qemu_ram_addr_from_host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Tue, Oct 05, 2010 at 07:57:14AM -0500, Anthony Liguori wrote: > On 10/04/2010 01:54 PM, Marcelo Tosatti wrote: > >To be used by next patches. > > > >Signed-off-by: Marcelo Tosatti > > > >Index: qemu/cpu-common.h > >=================================================================== > >--- qemu.orig/cpu-common.h > >+++ qemu/cpu-common.h > >@@ -47,6 +47,7 @@ void qemu_ram_free(ram_addr_t addr); > > /* This should only be used for ram local to a device. */ > > void *qemu_get_ram_ptr(ram_addr_t addr); > > /* This should not be used by devices. */ > >+int do_qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr); > > This is not a great name for a function. A better way to do this > would be to make the existing qemu_ram_addr_from_host() -> > qemu_ram_addr_from_host_nofail(). It should fail for all callers in tree now, where address from qemu_get_ram_ptr() is saved somewhere. MCE handler is an exception to that. Are you OK with this: Index: qemu/cpu-common.h =================================================================== --- qemu.orig/cpu-common.h +++ qemu/cpu-common.h @@ -47,6 +47,7 @@ void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); /* This should not be used by devices. */ +int qemu_ram_addr_from_host_nofail(void *ptr, ram_addr_t *ram_addr); ram_addr_t qemu_ram_addr_from_host(void *ptr); int cpu_register_io_memory(CPUReadMemoryFunc * const *mem_read, Index: qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -2938,23 +2938,31 @@ void *qemu_get_ram_ptr(ram_addr_t addr) return NULL; } -/* Some of the softmmu routines need to translate from a host pointer - (typically a TLB entry) back to a ram offset. */ -ram_addr_t qemu_ram_addr_from_host(void *ptr) +int qemu_ram_addr_from_host_nofail(void *ptr, ram_addr_t *ram_addr) { RAMBlock *block; uint8_t *host = ptr; QLIST_FOREACH(block, &ram_list.blocks, next) { if (host - block->host < block->length) { - return block->offset + (host - block->host); + *ram_addr = block->offset + (host - block->host); + return 0; } } + return -1; +} - fprintf(stderr, "Bad ram pointer %p\n", ptr); - abort(); +/* Some of the softmmu routines need to translate from a host pointer + (typically a TLB entry) back to a ram offset. */ +ram_addr_t qemu_ram_addr_from_host(void *ptr) +{ + ram_addr_t ram_addr; - return 0; + if (qemu_ram_addr_from_host_nofail(ptr, &ram_addr)) { + fprintf(stderr, "Bad ram pointer %p\n", ptr); + abort(); + } + return ram_addr; } static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr)