From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S61Dm-00043o-Mb for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:55:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S61Dk-00023v-EO for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:55:06 -0500 Received: from cantor2.suse.de ([195.135.220.15]:39145 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S61Dk-0001zp-4t for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:55:04 -0500 Message-ID: <4F5A19C4.3040406@suse.de> Date: Fri, 09 Mar 2012 15:55:00 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1331303600-30715-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1331303600-30715-1-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] cpu-all.h: Don't accidentally sign extend in g2h() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Riku Voipio , qemu-devel@nongnu.org, patches@linaro.org, Alexander Graf Am 09.03.2012 15:33, schrieb Peter Maydell: > Cast the argument of the g2h() macro to a target_ulong so that > it isn't accidentally sign-extended if it is a signed 32 bit > type and long is a 64 bit type. In particular, this fixes a > bug where it would return the wrong value for 32 bit guests > on 64 bit hosts when passed in one of the arg* values from > do_syscall() [which are all abi_long and thus signed types]. > This could result in spurious failure of mlock(), among others. >=20 > Signed-off-by: Peter Maydell > --- > This should be committed before Alex's patch to make mmap allocate > downwards (http://patchwork.ozlabs.org/patch/144476/) because that > hugely increases the chances that g2h will get passed a pointer > that has the high bit set. >=20 > cpu-all.h | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) >=20 > diff --git a/cpu-all.h b/cpu-all.h > index 80e6d42..a174532 100644 > --- a/cpu-all.h > +++ b/cpu-all.h > @@ -197,7 +197,7 @@ extern unsigned long reserved_va; > #endif > =20 > /* All direct uses of g2h and h2g need to go away for usermode softmmu= . */ > -#define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) > +#define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + GUEST_BASE= )) So *only* for a 32-bit guest does this cast from signed int to unsigned int and then to unsigned long, avoiding the sign extension on 64-bit host. For 64-bit guests it remains as broken as before. Commit message could be clearer. Reviewed-by: Andreas F=E4rber Note that unsigned long would be wrong for Win64 (where we don't currently have any user emulation using this macro). uintptr_t would be cleaner. Andreas > =20 > #if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS > #define h2g_valid(x) 1 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg