From: Scott Mitchell <scott.k.mitch1@gmail.com>
To: dev@dpdk.org
Cc: mb@smartsharesystems.com, david.marchand@redhat.com,
thomas@monjalon.net, stephen@networkplumber.org,
Scott Mitchell <scott.k.mitch1@gmail.com>,
Cyril Chemparathy <cchemparathy@ezchip.com>,
stable@dpdk.org
Subject: [PATCH v21] eal: add may_alias to unaligned typedefs
Date: Wed, 2 Dec 2026 09:30:51 -0800 [thread overview]
Message-ID: <20261202173051.59927-1-scott.k.mitch1@gmail.com> (raw)
In-Reply-To: <20261201201801.23189-1-scott.k.mitch1@gmail.com>
The unaligned_uint{16,32,64}_t types may be 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 __rte_may_alias to the non-MSVC typedefs as a leading attribute,
so the existing __rte_aligned(1) declarations are unchanged, and move
its definition above them. MSVC keeps __unaligned and has no type-based
alias analysis to disable.
Fixes: 7621d6a8d0bd ("eal: add and use unaligned integer types")
Cc: Cyril Chemparathy <cchemparathy@ezchip.com>
Cc: stable@dpdk.org
Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
---
v21:
* Commit message says "may be used to". (Morten)
* Use __rte_may_alias, with its definition moved above __rte_aligned(),
instead of spelling out the attribute. (Morten)
* Keep it as a leading attribute so the __rte_aligned(1) typedef lines
are unchanged. v19 changed those lines, which checkpatch flags in
check_aligned_attributes:
https://patches.dpdk.org/project/dpdk/patch/20260202044841.90945-2-scott.k.mitch1@gmail.com/
The leading form takes effect with gcc 11 and clang 21 and 23.
lib/eal/include/rte_common.h | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index fed373f412..b25db73862 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -132,4 +132,13 @@ extern "C" {
#endif
+/**
+ * Macro to mark a type that is not subject to type-based aliasing rules
+ */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_may_alias
+#else
+#define __rte_may_alias __attribute__((__may_alias__))
+#endif
+
/**
* Force type alignment
@@ -152,4 +161,5 @@ extern "C" {
/**
* Integer types with no alignment requirement.
+ * They may alias other types, e.g. to read a header written field by field.
*/
#ifdef RTE_TOOLCHAIN_MSVC
@@ -158,6 +168,9 @@ typedef __unaligned uint32_t unaligned_uint32_t;
typedef __unaligned uint16_t unaligned_uint16_t;
#else
+__rte_may_alias
typedef uint64_t unaligned_uint64_t __rte_aligned(1);
+__rte_may_alias
typedef uint32_t unaligned_uint32_t __rte_aligned(1);
+__rte_may_alias
typedef uint16_t unaligned_uint16_t __rte_aligned(1);
#endif
@@ -178,13 +191,4 @@ typedef uint16_t unaligned_uint16_t __rte_aligned(1);
#endif
-/**
- * Macro to mark a type that is not subject to type-based aliasing rules
- */
-#ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_may_alias
-#else
-#define __rte_may_alias __attribute__((__may_alias__))
-#endif
-
/******* Macro to mark functions and fields scheduled for removal *****/
#ifdef RTE_TOOLCHAIN_MSVC
--
2.54.0 (Apple Git-157)
prev parent reply other threads:[~2026-12-02 17:32 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-12 12:04 [PATCH v14 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-12 12:04 ` [PATCH v14 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-12 13:28 ` Morten Brørup
2026-01-12 15:00 ` Scott Mitchell
2026-01-12 12:04 ` [PATCH v14 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-17 21:21 ` [PATCH v15 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-17 21:21 ` [PATCH v15 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-20 15:23 ` Morten Brørup
2026-01-23 14:34 ` Scott Mitchell
2026-01-17 21:21 ` [PATCH v15 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-17 22:08 ` [PATCH v15 0/2] net: optimize __rte_raw_cksum Stephen Hemminger
2026-01-20 12:45 ` Morten Brørup
2026-01-23 15:43 ` Scott Mitchell
2026-01-23 16:02 ` [PATCH v16 " scott.k.mitch1
2026-01-23 16:02 ` [PATCH v16 1/2] eal: add __rte_may_alias to unaligned typedefs scott.k.mitch1
2026-01-23 16:02 ` [PATCH v16 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-28 11:05 ` David Marchand
2026-01-28 17:39 ` Scott Mitchell
2026-01-24 8:23 ` [PATCH v16 0/2] net: optimize __rte_raw_cksum Morten Brørup
2026-01-28 18:05 ` [PATCH v17 " scott.k.mitch1
2026-01-28 18:05 ` [PATCH v17 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-01-28 18:05 ` [PATCH v17 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-28 19:41 ` [PATCH v18 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-01-28 19:41 ` [PATCH v18 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-01-29 8:28 ` Morten Brørup
2026-02-02 4:31 ` Scott Mitchell
2026-01-28 19:41 ` [PATCH v18 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-01-29 8:31 ` Morten Brørup
2026-02-02 4:48 ` [PATCH v19 0/2] net: optimize __rte_raw_cksum scott.k.mitch1
2026-02-02 4:48 ` [PATCH v19 1/2] eal: add __rte_may_alias and __rte_aligned to unaligned typedefs scott.k.mitch1
2026-02-03 8:18 ` Morten Brørup
2026-02-16 14:29 ` David Marchand
2026-02-16 15:00 ` Morten Brørup
2026-02-02 4:48 ` [PATCH v19 2/2] net: __rte_raw_cksum pointers enable compiler optimizations scott.k.mitch1
2026-02-03 8:19 ` Morten Brørup
2026-02-06 14:54 ` [PATCH v19 0/2] net: optimize __rte_raw_cksum David Marchand
2026-02-07 1:29 ` Scott Mitchell
2026-02-10 11:53 ` Thomas Monjalon
2026-02-16 14:04 ` David Marchand
2026-12-01 20:18 ` [PATCH v20] eal: add may_alias to unaligned typedefs Scott Mitchell
2026-12-02 7:39 ` Morten Brørup
2026-12-02 17:28 ` Scott Mitchell
2026-12-02 17:30 ` Scott Mitchell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202173051.59927-1-scott.k.mitch1@gmail.com \
--to=scott.k.mitch1@gmail.com \
--cc=cchemparathy@ezchip.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox