From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7H2V-0007Eo-D0 for qemu-devel@nongnu.org; Mon, 12 Mar 2012 22:00:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7H2T-0002eH-57 for qemu-devel@nongnu.org; Mon, 12 Mar 2012 22:00:38 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:47889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7H2T-0002cM-0R for qemu-devel@nongnu.org; Mon, 12 Mar 2012 22:00:37 -0400 Received: by mail-yw0-f45.google.com with SMTP id o21so48024yho.4 for ; Mon, 12 Mar 2012 19:00:36 -0700 (PDT) Message-ID: <4F5EAA41.9030109@codemonkey.ws> Date: Mon, 12 Mar 2012 21:00:33 -0500 From: Anthony Liguori 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-1; format=flowed Content-Transfer-Encoding: 7bit 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 On 03/09/2012 08:33 AM, Peter Maydell wrote: > 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. > > Signed-off-by: Peter Maydell > --- Applied. Thanks. Regards, Anthony Liguori > 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. > > cpu-all.h | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > 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 > > /* 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)) > > #if HOST_LONG_BITS<= TARGET_VIRT_ADDR_SPACE_BITS > #define h2g_valid(x) 1