[PATCH v22] eal: add may_alias to unaligned typedefs
Scott Mitchell
scott.k.mitch1 at gmail.com
Thu Dec 3 17:27:48 CET 2026
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 next to __rte_aligned(1) in the non-MSVC typedefs,
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 at ezchip.com>
Cc: stable at dpdk.org
Signed-off-by: Scott Mitchell <scott.k.mitch1 at gmail.com>
Reviewed-by: Morten Brørup <mb at smartsharesystems.com>
---
v22:
* Place __rte_may_alias next to __rte_aligned(1) in the typedefs, and
update the commit message to match. (Morten)
* checkpatch's check_aligned_attributes warns on these lines because
__rte_aligned is used outside a struct/union; this is expected.
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 | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index fed373f412..c386c42789 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -131,6 +131,15 @@ extern "C" {
#define __rte_ptr_arith_add_zero
#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
*
@@ -151,15 +160,16 @@ 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
typedef __unaligned uint64_t unaligned_uint64_t;
typedef __unaligned uint32_t unaligned_uint32_t;
typedef __unaligned uint16_t unaligned_uint16_t;
#else
-typedef uint64_t unaligned_uint64_t __rte_aligned(1);
-typedef uint32_t unaligned_uint32_t __rte_aligned(1);
-typedef uint16_t unaligned_uint16_t __rte_aligned(1);
+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) __rte_may_alias;
#endif
/**
@@ -177,15 +187,6 @@ typedef uint16_t unaligned_uint16_t __rte_aligned(1);
#define __rte_packed_end __attribute__((__packed__))
#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
#define __rte_deprecated
--
2.54.0 (Apple Git-157)
More information about the stable
mailing list