From patchwork Thu Jun 20 14:18:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18030 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f197.google.com (mail-ye0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 19F3F2393D for ; Thu, 20 Jun 2013 14:18:09 +0000 (UTC) Received: by mail-ye0-f197.google.com with SMTP id q4sf7558415yen.4 for ; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=KBpbMMQGqStFl737NeOnNLMedA5BTyDUrEaRcUIVQZE=; b=g9Q9dB23Ar+ZDd4fGGLItfjqtlq6XT/5ypGgcjpXipdeEGpWk54+jmtOyZYSmgfU+w nLVlL0Ms0bb+C5VWJzsh1jU3mL/qxWGgnYJTp7RpG8UZy98vJOhJYebNF5XODTEotEdW hzKgDuKdlPnNmAvMlYhiiSoTrDRyE65stYRk2FQNdc+tY/p4fKYSKVyLYa8e821rSCWv memk2aGaGp5Eeo1uJd8dCugJ9eXolQOE22Rf2MFkULS5zaU0EHBq686vtl+Kk4Neppma ggTRKsBDtfsoXKXoshsImSxdmoTaIm3RquvWgExhqVn+GzGOWBu2uHf8IgR3iZ4YS97/ YW2w== X-Received: by 10.236.139.3 with SMTP id b3mr4457223yhj.3.1371737888694; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.26.100 with SMTP id k4ls751139qeg.37.gmail; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) X-Received: by 10.58.31.106 with SMTP id z10mr3173507veh.61.1371737888535; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id t8si167207vcz.28.2013.06.20.07.18.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 07:18:08 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hr11so4743960vcb.20 for ; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) X-Received: by 10.220.67.10 with SMTP id p10mr2823885vci.85.1371737888428; Thu, 20 Jun 2013 07:18:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp23200veb; Thu, 20 Jun 2013 07:18:07 -0700 (PDT) X-Received: by 10.194.84.205 with SMTP id b13mr5726140wjz.92.1371737886938; Thu, 20 Jun 2013 07:18:06 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id pv1si193932wjc.151.2013.06.20.07.18.06 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 20 Jun 2013 07:18:06 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Upfga-0006m9-63; Thu, 20 Jun 2013 15:18:04 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Paolo Bonzini Subject: [PATCH] exec.c: address_space_translate: handle access to addr 0 of 2^64 sized region Date: Thu, 20 Jun 2013 15:18:04 +0100 Message-Id: <1371737884-26020-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQlcR95Cbb+Z3NB2ZbsCmh62scdekWnhRw0qtj0a+L8GLkpsidJC2wn6wUQK0kPtaQZOGVL8 X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The memory API allows a MemoryRegion's size to be 2^64, as a special case (otherwise the size always fits in a 64 bit integer). This meant that attempts to access address zero in a 2^64 sized region would assert in address_space_translate(): #3 0x00007ffff3e4d192 in __GI___assert_fail#(assertion=0x555555a43f32 "!a.hi", file=0x555555a43ef0 "include/qemu/int128.h", line=18, function=0x555555a4439f "int128_get64") at assert.c:103 #4 0x0000555555877642 in int128_get64 (a=...) at include/qemu/int128.h:18 #5 0x00005555558782f2 in address_space_translate (as=0x55555668d140, /addr=0, xlat=0x7fffafac9918, plen=0x7fffafac9920, is_write=false) at exec.c:221 Fix this by doing the 'min' operation in 128 bit arithmetic rather than 64 bit arithmetic (we know the result of the 'min' definitely fits in 64 bits because one of the inputs did). Signed-off-by: Peter Maydell --- The other possible approach here would be: if (!diff.hi) { *plen = MIN(int128_get64(diff), *plen); } (since if diff.hi is nonzero we know plen is smaller) but it seems slightly cleaner not to "look inside" the Int128. exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 5b8b40d..eb200d0 100644 --- a/exec.c +++ b/exec.c @@ -218,7 +218,7 @@ MemoryRegionSection *address_space_translate(AddressSpace *as, hwaddr addr, *xlat = addr + section->offset_within_region; diff = int128_sub(section->mr->size, int128_make64(addr)); - *plen = MIN(int128_get64(diff), *plen); + *plen = int128_get64(int128_min(diff, int128_make64(*plen))); return section; } #endif