From patchwork Fri Feb 13 05:54:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 44657 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2264621527 for ; Fri, 13 Feb 2015 05:56:07 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf9353271lbi.0 for ; Thu, 12 Feb 2015 21:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=66ZiJT2xW+TZvJyNFgOzAM0k8llXx2OoILTKcvzhEIw=; b=EZPYG/PZrd2CiNSq8HFq0TDpQSBUbOiCttgJE0f4k0UFWIP1ghaqlmcy2YQ8DRu1pt FhTld/1w9C59233ZcLTl+/7VQ3x0FDKATWNFtH6hTzRT38+mYKU+ZipDI7Wn4jZR5HEU T3eSFiL/2mi46cfDE4VaqPEB76KW9YNtqHai7hsZ/GAYIV3Ie1bOMINZbs+AKxDKCl26 v8BQB+VkmTZ8qkW320m1igXKt/isRuF8iEc0AWzVbATqgMswoxf02UlpGdr1cqXWYlBR O4GFd/U/5pIOGSriO+ufkRZM8TEJAUsLYLpSoD7FbLsyzg8qUtQw1ZP7aCYv/Q0nRlHm tEaA== X-Gm-Message-State: ALoCoQntnuyo5uZIkObY4tqFNvxeZJ3zICl0QimNr70I4Dci8oCMS/EyRvAHBxgMyg+147ST+lmS X-Received: by 10.180.89.194 with SMTP id bq2mr996771wib.4.1423806966007; Thu, 12 Feb 2015 21:56:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.194 with SMTP id a2ls284606lak.108.gmail; Thu, 12 Feb 2015 21:56:05 -0800 (PST) X-Received: by 10.112.198.161 with SMTP id jd1mr6223680lbc.93.1423806965724; Thu, 12 Feb 2015 21:56:05 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id lv3si792277lac.167.2015.02.12.21.56.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Feb 2015 21:56:05 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id z12so13637809lbi.11 for ; Thu, 12 Feb 2015 21:56:05 -0800 (PST) X-Received: by 10.112.114.230 with SMTP id jj6mr6293201lbb.112.1423806965311; Thu, 12 Feb 2015 21:56:05 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp867730lbj; Thu, 12 Feb 2015 21:56:04 -0800 (PST) X-Received: by 10.236.209.65 with SMTP id r41mr6910740yho.152.1423806963282; Thu, 12 Feb 2015 21:56:03 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b13si1616042qac.129.2015.02.12.21.56.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 12 Feb 2015 21:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:53532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM9EQ-0004AI-HN for patch@linaro.org; Fri, 13 Feb 2015 00:56:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM9DL-0002ot-Ca for qemu-devel@nongnu.org; Fri, 13 Feb 2015 00:54:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YM9DK-0007Ej-0Q for qemu-devel@nongnu.org; Fri, 13 Feb 2015 00:54:55 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:54985) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YM9DJ-0007E4-QW for qemu-devel@nongnu.org; Fri, 13 Feb 2015 00:54:53 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1YM9DC-0002VG-Fl for qemu-devel@nongnu.org; Fri, 13 Feb 2015 05:54:46 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 13 Feb 2015 05:54:43 +0000 Message-Id: <1423806885-9548-11-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1423806885-9548-1-git-send-email-peter.maydell@linaro.org> References: <1423806885-9548-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 10/12] target-arm: A64: Fix handling of rotate in logic_imm_decode_wmask X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The code in logic_imm_decode_wmask attempts to rotate a mask value within the bottom 'e' bits of the value with mask = (mask >> r) | (mask << (e - r)); This has two issues: * if the element size is 64 then a rotate by zero results in a shift left by 64, which is undefined behaviour * if the element size is smaller than 64 then this will leave junk in the value at bit 'e' and above, which is not valid input to bitfield_replicate(). As it happens, the bits at bit 'e' to '2e - r' are exactly the ones which bitfield_replicate is going to copy in there, so this isn't a "wrong code generated" bug, but it's confusing and if we ever put an assert in bitfield_replicate it would fire on valid guest code. Fix the former by not doing anything if r is zero, and the latter by masking with bitmask64(e). Signed-off-by: Peter Maydell Message-id: 1423233250-15853-3-git-send-email-peter.maydell@linaro.org --- target-arm/translate-a64.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index d3801c5..94b3bf4 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -2820,7 +2820,10 @@ static bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn, * by r within the element (which is e bits wide)... */ mask = bitmask64(s + 1); - mask = (mask >> r) | (mask << (e - r)); + if (r) { + mask = (mask >> r) | (mask << (e - r)); + mask &= bitmask64(e); + } /* ...then replicate the element over the whole 64 bit value */ mask = bitfield_replicate(mask, e); *result = mask;