From nobody Fri May 3 05:26:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490637595940500.26796056761816; Mon, 27 Mar 2017 10:59:55 -0700 (PDT) Received: from localhost ([::1]:48325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYvq-0001fp-0j for importer@patchew.org; Mon, 27 Mar 2017 13:59:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csYv8-0001M0-SP for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csYv7-00050O-L9 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:59:10 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48939) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1csYv7-0004wz-Du for qemu-devel@nongnu.org; Mon, 27 Mar 2017 13:59:09 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1csYv3-0000ac-2r; Mon, 27 Mar 2017 18:59:05 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 18:59:04 +0100 Message-Id: <1490637544-15650-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-2.9] tests/virtio-9p-test: Don't call le*_to_cpus on fields of packed struct 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: Greg Kurz , "Aneesh Kumar K.V" , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For a packed struct like 'P9Hdr' the fields within it may not be aligned as much as the natural alignment for their types. This means it is not valid to pass the address of such a field to a function like le32_to_cpus() which operate on uint32_t* and assume alignment. Doing this results in a SIGBUS on hosts like SPARC which have strict alignment requirements. Use ldl_le_p() instead, which is specified to correctly handle unaligned pointers. Signed-off-by: Peter Maydell Reviewed-by: Greg Kurz --- Sadly gcc doesn't warn about this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D51628 clang supposedly was fixed to do so: https://bugs.llvm.org//show_bug.cgi?id=3D22821 but I think that commit was reverted without the bug being reopened; at least my clang doesn't have that warning flag. --- tests/virtio-9p-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index 43a1ad8..ad33d96 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -256,8 +256,8 @@ static void v9fs_req_recv(P9Req *req, uint8_t id) qvirtio_wait_queue_isr(v9p->dev, v9p->vq, 1000 * 1000); =20 v9fs_memread(req, &hdr, 7); - le32_to_cpus(&hdr.size); - le16_to_cpus(&hdr.tag); + hdr.size =3D ldl_le_p(&hdr.size); + hdr.tag =3D lduw_le_p(&hdr.tag); if (hdr.size >=3D 7) { break; } --=20 2.7.4