From patchwork Fri Mar 9 14:33:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 7191 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A65FB23E67 for ; Fri, 9 Mar 2012 14:33:26 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 644F7A187D2 for ; Fri, 9 Mar 2012 14:33:26 +0000 (UTC) Received: by iage36 with SMTP id e36so3033780iag.11 for ; Fri, 09 Mar 2012 06:33:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=XFJIAY8DFn6pLfozsVYxr12k247wMmhoL0ewM8Qh36A=; b=Xn9NPwpkX2YLbwGECfVK3Rm6L2y3Jq5YUV/RHD5j5rAXnVYA3eg9CrOoodrZRKSiF/ GKeHvZpHQCffUyz4+Up/QS5rmT1AN4NBxJBy3nzB+nApUyt/qCgNW+ohlCXQYz7gA5Lt CeXXcBwP92U+yjKqCcq8DEJvipJWKOxylamMmi4ibb3n5Y5SHckoXNW5H8GE+82FT1Ag /G/io++EKRgLQltMIx98dHpSZr3oGdT/7LL0Q0IubdbKuFI6QVT6KwmTdH8qIIyqoyf7 i9rkuUgHTaumgxXglV0v/DqamSKVcM/stUE8EJ4HCb+nMPN5WZDg5YQi3fsn01OYIGJq i/8A== Received: by 10.50.184.228 with SMTP id ex4mr2582893igc.50.1331303605859; Fri, 09 Mar 2012 06:33:25 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.53.18 with SMTP id k18csp32839ibg; Fri, 9 Mar 2012 06:33:24 -0800 (PST) Received: by 10.180.24.166 with SMTP id v6mr5351405wif.10.1331303604152; Fri, 09 Mar 2012 06:33:24 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id fa5si3306323wib.22.2012.03.09.06.33.23 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 09 Mar 2012 06:33:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1S60si-0007zq-Q7; Fri, 09 Mar 2012 14:33:20 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Riku Voipio , Alexander Graf Subject: [PATCH] cpu-all.h: Don't accidentally sign extend in g2h() Date: Fri, 9 Mar 2012 14:33:20 +0000 Message-Id: <1331303600-30715-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQkJsivWigE4irIQIP0cr3P+YssVzN1X3OquslBvPba/XsTh34XGVI5CHwgNIfdj38G2QIGG 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 Reviewed-by: Andreas Färber --- 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