From nobody Fri Dec 19 07:15:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621508978; cv=none; d=zohomail.com; s=zohoarc; b=nxGC1RbHXITZd/n7QixgyVlnNNQkbBxJwRBDG1eVkImCjmTwJnlh8pCbUSC9xb6IUrVAgJSJr9bGqqIwMEukWDn/m9O3OhnyR+DSoSoZUxhafHHg9FA2AC2gKwK873eD0JuRgu5ICjXajCqM3eAQyzTdfck76Bn4vDNCeISJ9gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621508978; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=ea27qBr8mLKRvK7jpH5vS86i1xdbhzBt7Zk5gV8i1rNnFSG44cgdXX4SP6KCXcuDzkp1kJcIfqaiCkg6HyOtByLr6OD6H/GGZBVjk9HJ3UpQSOGF9ItjhvyC2CIGY722MZ920svoU438B4Y6WgnGu4uuvUJvawQ8TB1U0N7ka7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1621508978321184.99203207211735; Thu, 20 May 2021 04:09:38 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-XGktsYa_MEySmUcsCFanXA-1; Thu, 20 May 2021 07:09:35 -0400 Received: by mail-wm1-f70.google.com with SMTP id 12-20020a1c010c0000b0290176491efde9so2188408wmb.4 for ; Thu, 20 May 2021 04:09:35 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id c6sm2750046wru.50.2021.05.20.04.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:09:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621508977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=Ads1KW9jf9UgrIJmirUn3zN7HPJfZ5ueJX7QxY6xv6GAxf4+6ZUCM+On44IQMEJsteOeco TplGyI/JF8kn8EFRxlGQfSnAIowyYSHsrfLSV+7ZDUYaPGF7WgZfx9dV7bZ9VgkcxWwwr1 HVhd1CP/v6Lt/kXk2rQH7c5q1SwAlUE= X-MC-Unique: XGktsYa_MEySmUcsCFanXA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BIUKBelUrGAg7JFPfqNH9aSjg1FuXfUME+/SSVTybmA=; b=BiSBVOdF/3m35cLBv0PuKfE51eqcpYA5w8eMbi0D/5FblICsN4AsEbhai/u5g6ZeOw /yHQYG5kTsylMXIikBoyMbOlvbYTVlZuLtuHf32NcFmmp9a44drPxQqTAaXIOnaFiOVt w0ej9zQG71cTBUNsOYlcOaA34cA15n9wG2JG+yJ9kDKlkrMdh+DI/bxuLkv58NFZ848u xSc9tC9HI86tvQzHOFGikULLYP8Utxpz9XD01b2DfAtQLfAYtu2PvkYISrsgE0WiLD9q X7+eTm5xweQcU3KB2A2VIhU5NGsEkNoWWHA7+v4YL+6m2NdtaKl91aSO0bBgWgFBJzLD LJkA== X-Gm-Message-State: AOAM533A7CKSmbzkpiwxqWy/mB5mmRDU4ST+/C3pYaSeQpyGJiUpsOcu FIcz+2/jwAuS77ePG6dIcd+p7Zc8+QcEP4fMj0bwxvPeggyEcQfclJGxlE7zfnDrBPVmS9MA/8K 9O8WYbEHKvUH4ig== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr3673001wrv.372.1621508974668; Thu, 20 May 2021 04:09:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEUAwnlIZe3JtCq7uoFHBWXQoJs3UxNmzzOa9mrg8Z+HtdwTbQUbXUK7S5h4KZbQr5i0Yq5A== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr3672987wrv.372.1621508974526; Thu, 20 May 2021 04:09:34 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 03/12] exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addresses Date: Thu, 20 May 2021 13:09:10 +0200 Message-Id: <20210520110919.2483190-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) All address_space internal handlers have the /* warning: addr must be aligned */ comment, so we don't expect any caller to pass unaligned addresses. Now than we added the MemTxAttrs.aligned attribute, callers might want to pass unaligned addresses. In case they do, be ready and return MEMTX_UNALIGNED_ERROR. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- memory_ldst.c.inc | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/memory_ldst.c.inc b/memory_ldst.c.inc index 84b868f2946..efeb545479e 100644 --- a/memory_ldst.c.inc +++ b/memory_ldst.c.inc @@ -32,6 +32,13 @@ static inline uint32_t glue(address_space_ldl_internal, = SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint32_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 4 || !memory_access_is_direct(mr, false)) { @@ -101,6 +108,13 @@ static inline uint64_t glue(address_space_ldq_internal= , SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint64_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 8 || !memory_access_is_direct(mr, false)) { @@ -205,6 +219,13 @@ static inline uint16_t glue(address_space_lduw_interna= l, SUFFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return (uint16_t)-1; /* XXX */ + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, false, attrs); if (l < 2 || !memory_access_is_direct(mr, false)) { @@ -275,6 +296,13 @@ void glue(address_space_stl_notdirty, SUFFIX)(ARG1_DEC= L, uint8_t dirty_log_mask; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 4 || !memory_access_is_direct(mr, true)) { @@ -312,6 +340,13 @@ static inline void glue(address_space_stl_internal, SU= FFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint32_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 4 || !memory_access_is_direct(mr, true)) { @@ -408,6 +443,13 @@ static inline void glue(address_space_stw_internal, SU= FFIX)(ARG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint16_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 2 || !memory_access_is_direct(mr, true)) { @@ -472,6 +514,13 @@ static void glue(address_space_stq_internal, SUFFIX)(A= RG1_DECL, MemTxResult r; bool release_lock =3D false; =20 + if (unlikely(!QEMU_IS_ALIGNED(addr, sizeof(uint64_t)))) { + if (result) { + *result =3D MEMTX_UNALIGNED_ERROR; + } + return; + } + RCU_READ_LOCK(); mr =3D TRANSLATE(addr, &addr1, &l, true, attrs); if (l < 8 || !memory_access_is_direct(mr, true)) { --=20 2.26.3