From mboxrd@z Thu Jan 1 00:00:00 1970 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 Date: Fri, 13 Feb 2015 05:54:43 +0000 Message-Id: <1423806885-9548-11-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1423806885-9548-1-git-send-email-peter.maydell@linaro.org> References: <1423806885-9548-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 10/12] target-arm: A64: Fix handling of rotate in logic_imm_decode_wmask List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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; -- 1.9.1