From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 893C3606A32F for ; Tue, 1 Dec 2026 20:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=xAgAyXR1 Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4EF25402D9; Tue, 1 Dec 2026 21:19:23 +0100 (CET) Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) by mails.dpdk.org (Postfix) with ESMTPS id 37D45402BD for ; Tue, 1 Dec 2026 21:19:22 +0100 (CET) Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-1b5adf7eacdso973054c88.1 for ; Tue, 01 Dec 2026 12:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796156360; x=1796761160; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xhyzLe1mZ8+IrnCD20raP+ItwZVCDA3LA927vk9u5II=; b=xAgAyXR1Nzht7ul32+H/Qa7QHxJ1++JL11F2xC4naWh1QR2Xxvp70uNB6bF+nvm1Pj EpYUdh4hg6WxdXNe9zi4WC7Xgj+NFsND/YKdLdkvl1FzAYvbsfdVzU+xz+luz39/zwbE UuVGI5y8/Pf51gGAlEWc1JbPNbXapco6pqDwYN1dORTILSMoJp7BYG1hnxkMJeEej7Wy BZnXOEMR4lK09xKXMmlXHqjWXKxBkqyjLV7A6Rnpcq5Lr/F64dLFsZyvaU3+e+danIh8 7s5J8wrQ5Ia+4AWqMj/lhHJOx7+NDre1AAsqxodpNZ+enS/29VWFU6LF7kSOtGaWtoiX 4n7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796156360; x=1796761160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xhyzLe1mZ8+IrnCD20raP+ItwZVCDA3LA927vk9u5II=; b=iR1Vek5/SSsruIrScPq/MlyDCQYjbk1FCkWFlnqzNXCxdfPEeIUCt1fKsihHz9Jrj7 4H0Kz71Fbmfh/smELFBRqv5X9tUcfQpU7SPeQUB19NQV/SeY38XUZwiWFrpDa9e/MoJA FUlYG+LBzDw4CfrSoUCAnq9TQ9bMeM7MtMYCxlZ62biV+J2BtDJC0wSblqGl2F7YrXo6 AtNqKNlXxyZxau3C8U2XNu8uqtsZxRgVeP8dVvE+QWxfv0HKo6WbtZkrT3e98eng/cK3 f65pSXQ7O7MgxvDwPyO+ikwazKuWAPgDtzPr+O1NalbSPQ+NhIXFl34YdPtp0Pu7ffgv cbeQ== X-Gm-Message-State: APuU4Z+ROar6dLl+oSs09etubX4nuTa7CzmKi1pk45mGjXNmF9/AaCrY S9bvh9uQvyF6ws/gIHuIAPpnvJa3Vrb9jq6LET4H5edz4cYqIsFGB30C/yaJTw== X-Gm-Gg: AZFdTZdsRZSrLXl8WKXn1tGV5o55lb1sRvrZ6nKYF1L4DCZQCBLzNReW0xoDkpEPmlA vngl5jOTLJ4rOVghaXu4hJBJtw2BUywUdybTCFWmbXZZ6OdRXqfTl8jfWJUdib8n1kJzwXXFVM7 Gk81QB1QZfdpvdv7LqacLIDS1m6/GHJ6GmzQrcgpdDvHgg/ZKIM2anmwpzyPaYZYnsgunT1DNb+ FiP7WBKi9q1bisO7mq7gkleA4KqHrSAv+3P6xF9WGob5VcRt+RUWKERssMWGk2YUg6ce7Ctv20a wFL0OqBDLl/iBm0J3T5HDxEkhte1C7AA8t365Kd47hZORDh04PtD5HNJAy8H03eCCQHHz6hkd6x rJrdDXimAEQfg3bu+uhnhSyo4zsaIwzpVMuVnh+rLc1mILAN0cjDIgIP2ZEy4KNuy2YT9pdFiu/ Plqv3kWndd8oaog/eCahtOe8T/Mx1Qemxl/giYEKoAWgxVO2rLfAeJjj86M8E+TKb1xMS03wRl4 m5p6cxSRNLOs7s8L4DyPH5WdMdjzOSeSrpEnTnqMM0/MEb9BK5SbTJJZy91kuTPGCo6ity4WSRU FQKZy6JV3WJ2/8IwEobSaYpqGlwYyuxpjnmE5ubv1Rz+9kXmOQn822zKg+Q4YkBqHSkvgYo6McO wyCTfJFSJ6sbfqpnMu+M= X-Received: by 2002:a05:7022:ec17:b0:166:862b:9bcc with SMTP id a92af1059eb24-1b55689ad7amr48221648c88.18.1796156360187; Tue, 01 Dec 2026 12:19:20 -0800 (PST) Received: from mr41p01nt-relayp02.apple.com ([17.199.97.123]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm108085440c88.5.2026.12.01.12.19.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 12:19:19 -0800 (PST) From: Scott Mitchell To: dev@dpdk.org Cc: Thomas Monjalon , David Marchand , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , Scott Mitchell , Cyril Chemparathy , stable@dpdk.org Subject: [PATCH v20] eal: add may_alias to unaligned typedefs Date: Tue, 1 Dec 2026 12:18:01 -0800 Message-ID: <20261201201801.23189-1-scott.k.mitch1@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260202044841.90945-1-scott.k.mitch1@gmail.com> References: <20260202044841.90945-1-scott.k.mitch1@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The unaligned_uint{16,32,64}_t types are used to read memory that was written through other types, e.g. checksumming a packet header that was just filled in field by field. Without may_alias, type-based alias analysis may assume those reads do not alias the preceding stores and move them ahead of the stores. clang 22 does this to a raw checksum loop reading through unaligned_uint16_t, producing TCP checksums over stale header bytes. Add may_alias to the non-MSVC typedefs, as a leading attribute so the existing __rte_aligned(1) declarations are unchanged. The attribute is spelled out because __rte_may_alias is defined later in rte_common.h. MSVC keeps __unaligned and has no type-based alias analysis to disable. Fixes: 7621d6a8d0bd ("eal: add and use unaligned integer types") Cc: Cyril Chemparathy Cc: stable@dpdk.org Signed-off-by: Scott Mitchell --- v20: - rebase on "eal: make unaligned types really unaligned", which already made the types __rte_aligned(1); only may_alias is added now - add may_alias as a leading attribute so the existing __rte_aligned(1) declarations are unchanged (no __rte_aligned outside struct/union) - drop "net: __rte_raw_cksum pointers enable compiler optimizations": "eal: improve pointer add/sub/align macros" already lets compilers vectorize __rte_raw_cksum - drop the test_hash_functions change, fixed upstream by "test/hash: fix jhash 32-bit key type" --- lib/eal/include/rte_common.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index fed373f412..026eeab02e 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -151,14 +151,21 @@ extern "C" { /** * Integer types with no alignment requirement. + * + * may_alias - Prevents strict-aliasing optimization bugs where + * compilers may incorrectly elide memory operations + * when casting between pointer types. */ #ifdef RTE_TOOLCHAIN_MSVC typedef __unaligned uint64_t unaligned_uint64_t; typedef __unaligned uint32_t unaligned_uint32_t; typedef __unaligned uint16_t unaligned_uint16_t; #else +__attribute__((__may_alias__)) typedef uint64_t unaligned_uint64_t __rte_aligned(1); +__attribute__((__may_alias__)) typedef uint32_t unaligned_uint32_t __rte_aligned(1); +__attribute__((__may_alias__)) typedef uint16_t unaligned_uint16_t __rte_aligned(1); #endif -- 2.54.0 (Apple Git-157)