From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 666B2C04AB5 for ; Mon, 3 Jun 2019 18:42:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 344312709D for ; Mon, 3 Jun 2019 18:42:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 344312709D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([127.0.0.1]:39404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXruz-00060o-CH for qemu-devel@archiver.kernel.org; Mon, 03 Jun 2019 14:42:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXrtB-0004YP-63 for qemu-devel@nongnu.org; Mon, 03 Jun 2019 14:40:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hXrt9-0004dR-Nq for qemu-devel@nongnu.org; Mon, 03 Jun 2019 14:40:57 -0400 Received: from indium.canonical.com ([91.189.90.7]:38322) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hXrt9-0004bj-Gy for qemu-devel@nongnu.org; Mon, 03 Jun 2019 14:40:55 -0400 Received: from loganberry.canonical.com ([91.189.90.37]) by indium.canonical.com with esmtp (Exim 4.86_2 #2 (Debian)) id 1hXrt7-0000c4-Bh for ; Mon, 03 Jun 2019 18:40:53 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 445B22E80CB for ; Mon, 3 Jun 2019 18:40:53 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Date: Mon, 03 Jun 2019 18:29:11 -0000 From: "Laszlo Ersek \(Red Hat\)" To: qemu-devel@nongnu.org X-Launchpad-Notification-Type: bug X-Launchpad-Bug: product=qemu; status=New; importance=Undecided; assignee=None; X-Launchpad-Bug-Tags: arm testcase X-Launchpad-Bug-Information-Type: Public X-Launchpad-Bug-Private: no X-Launchpad-Bug-Security-Vulnerability: no X-Launchpad-Bug-Commenters: ajbennee andrew-randrianasulu lersek X-Launchpad-Bug-Reporter: Laszlo Ersek (Red Hat) (lersek) X-Launchpad-Bug-Modifier: Laszlo Ersek (Red Hat) (lersek) References: <155912118291.12579.8926874795813611531.malonedeb@soybean.canonical.com> <20190603150120.29255-1-alex.bennee@linaro.org> Message-Id: <5f684c68-d2cd-90f7-3892-1c6245728042@redhat.com> X-Launchpad-Message-Rationale: Subscriber (QEMU) @qemu-devel-ml X-Launchpad-Message-For: qemu-devel-ml Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="18968"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 30032e40571463437dd18332ec8b9aeaf4354f73 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 91.189.90.7 Subject: [Qemu-devel] [Bug 1830872] Re: [RFC PATCH] cputlb: use uint64_t for interim values for unaligned load X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Bug 1830872 <1830872@bugs.launchpad.net> Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" (+Igor) On 06/03/19 17:01, Alex Benn=C3=A9e wrote: > When running on 32 bit TCG backends a wide unaligned load ends up > truncating data before returning to the guest. We specifically have > the return type as uint64_t to avoid any premature truncation so we > should use the same for the interim types. > = > Hopefully fixes #1830872 > = > Signed-off-by: Alex Benn=C3=A9e > --- > accel/tcg/cputlb.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > = > diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c > index cdcc3771020..b796ab1cbea 100644 > --- a/accel/tcg/cputlb.c > +++ b/accel/tcg/cputlb.c > @@ -1303,7 +1303,7 @@ load_helper(CPUArchState *env, target_ulong addr, T= CGMemOpIdx oi, > && unlikely((addr & ~TARGET_PAGE_MASK) + size - 1 > >=3D TARGET_PAGE_SIZE)) { > target_ulong addr1, addr2; > - tcg_target_ulong r1, r2; > + uint64_t r1, r2; > unsigned shift; > do_unaligned_access: > addr1 =3D addr & ~(size - 1); > = Applied on top of commit ad88e4252f09c2956b99c90de39e95bab2e8e7af: Tested-by: Laszlo Ersek Thanks! Laszlo -- = You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. https://bugs.launchpad.net/bugs/1830872 Title: AARCH64 to ARMv7 mistranslation in TCG Status in QEMU: New Bug description: The following guest code: https://github.com/tianocore/edk2/blob/3604174718e2afc950c3cc64c64ba5165c= 8692bd/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/CopyMem.S implements, in hand-optimized aarch64 assembly, the CopyMem() edk2 (EFI Development Kit II) library function. (CopyMem() basically has memmove() semantics, to provide a standard C analog here.) The relevant functions are InternalMemCopyMem() and __memcpy(). When TCG translates this aarch64 code to x86_64, everything works fine. When TCG translates this aarch64 code to ARMv7, the destination area of the translated CopyMem() function becomes corrupted -- it differs from the intended source contents. Namely, in every 4096 byte block, the 8-byte word at offset 4032 (0xFC0) is zeroed out in the destination, instead of receiving the intended source value. I'm attaching two hexdumps of the same destination area: - "good.txt" is a hexdump of the destination area when CopyMem() was translated to x86_64, - "bad.txt" is a hexdump of the destination area when CopyMem() was translated to ARMv7. In order to assist with the analysis of this issue, I disassembled the aarch64 binary with "objdump". Please find the listing in "DxeCore.objdump", attached. The InternalMemCopyMem() function starts at hex offset 2b2ec. The __memcpy() function starts at hex offset 2b180. And, I ran the guest on the ARMv7 host with "-d in_asm,op,op_opt,op_ind,out_asm". Please find the log in "tcg.in_asm.op.op_opt.op_ind.out_asm.log", attached. The TBs that correspond to (parts of) the InternalMemCopyMem() and __memcpy() functions are scattered over the TCG log file, but the offset between the "nice" disassembly from "DxeCore.objdump", and the in-RAM TBs in the TCG log, can be determined from the fact that there is a single prfm instruction in the entire binary. The instruction's offset is 0x2b180 in "DxeCore.objdump" -- at the beginning of the __memcpy() function --, and its RAM address is 0x472d2180 in the TCG log. Thus the difference (=3D the load address of DxeCore.efi) is 0x472a7000. QEMU was built at commit a4f667b67149 ("Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20190521-3' into staging", 2019-05-21). The reproducer command line is (on an ARMv7 host): qemu-system-aarch64 \ -display none \ -machine virt,accel=3Dtcg \ -nodefaults \ -nographic \ -drive if=3Dpflash,format=3Draw,file=3D$prefix/share/qemu/edk2-aarch6= 4-code.fd,readonly \ -drive if=3Dpflash,format=3Draw,file=3D$prefix/share/qemu/edk2-arm-va= rs.fd,snapshot=3Don \ -cpu cortex-a57 \ -chardev stdio,signal=3Doff,mux=3Don,id=3Dchar0 \ -mon chardev=3Dchar0,mode=3Dreadline \ -serial chardev:char0 The apparent symptom is an assertion failure *in the guest*, such as > ASSERT [DxeCore] > /home/lacos/src/upstream/qemu/roms/edk2/MdePkg/Library/BaseLib/String.c= (1090): > Length < _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength but that is only a (distant) consequence of the CopyMem() mistranslation, and resultant destination area corruption. Originally reported in the following two mailing list messages: - http://mid.mail-archive.com/9d2e260c-c491-03d2-9b8b-b57b72083f77@redhat= .com - http://mid.mail-archive.com/f1cec8c0-1a9b-f5bb-f951-ea0ba9d276ee@redhat= .com To manage notifications about this bug go to: https://bugs.launchpad.net/qemu/+bug/1830872/+subscriptions From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9763C04AB5 for ; Mon, 3 Jun 2019 18:43:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9426E2709F for ; Mon, 3 Jun 2019 18:43:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9426E2709F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([127.0.0.1]:39406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXrvN-0006Mk-NE for qemu-devel@archiver.kernel.org; Mon, 03 Jun 2019 14:43:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXrr8-0002fN-Qw for qemu-devel@nongnu.org; Mon, 03 Jun 2019 14:38:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hXri0-0002Mi-Ra for qemu-devel@nongnu.org; Mon, 03 Jun 2019 14:29:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hXrhy-0002Gn-Of; Mon, 03 Jun 2019 14:29:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3172C30C0DDB; Mon, 3 Jun 2019 18:29:21 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-13.rdu2.redhat.com [10.10.121.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4168D2E16F; Mon, 3 Jun 2019 18:29:17 +0000 (UTC) To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , qemu-devel@nongnu.org References: <20190603150120.29255-1-alex.bennee@linaro.org> From: Laszlo Ersek Message-ID: <5f684c68-d2cd-90f7-3892-1c6245728042@redhat.com> Date: Mon, 3 Jun 2019 20:29:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190603150120.29255-1-alex.bennee@linaro.org> Content-Type: text/plain; charset="UTF-8" Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 03 Jun 2019 18:29:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [RFC PATCH] cputlb: use uint64_t for interim values for unaligned load X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 1830872@bugs.launchpad.net, qemu-arm@nongnu.org, Paolo Bonzini , Igor Mammedov , randrianasulu@gmail.com, Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Message-ID: <20190603182911.WXljjtLe-cUK0xc7e0t1M3QEkIbKGqryppdHNYfRo3I@z> (+Igor) On 06/03/19 17:01, Alex Benn=C3=A9e wrote: > When running on 32 bit TCG backends a wide unaligned load ends up > truncating data before returning to the guest. We specifically have > the return type as uint64_t to avoid any premature truncation so we > should use the same for the interim types. >=20 > Hopefully fixes #1830872 >=20 > Signed-off-by: Alex Benn=C3=A9e > --- > accel/tcg/cputlb.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c > index cdcc3771020..b796ab1cbea 100644 > --- a/accel/tcg/cputlb.c > +++ b/accel/tcg/cputlb.c > @@ -1303,7 +1303,7 @@ load_helper(CPUArchState *env, target_ulong addr,= TCGMemOpIdx oi, > && unlikely((addr & ~TARGET_PAGE_MASK) + size - 1 > >=3D TARGET_PAGE_SIZE)) { > target_ulong addr1, addr2; > - tcg_target_ulong r1, r2; > + uint64_t r1, r2; > unsigned shift; > do_unaligned_access: > addr1 =3D addr & ~(size - 1); >=20 Applied on top of commit ad88e4252f09c2956b99c90de39e95bab2e8e7af: Tested-by: Laszlo Ersek Thanks! Laszlo