From: "Morten Brørup" <mb@smartsharesystems.com>
To: <scott.k.mitch1@gmail.com>, <dev@dpdk.org>, <stephen@networkplumber.org>
Cc: "Scott" <scott_mitchell@apple.com>
Subject: RE: [PATCH v12 2/3] eal: add workaround for UBSAN alignment false positive
Date: Sat, 10 Jan 2026 16:02:01 +0100 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F65647@smartserver.smartshare.dk> (raw)
In-Reply-To: <20260110015651.26201-3-scott.k.mitch1@gmail.com>
> From: Scott <scott_mitchell@apple.com>
>
> The optimized __rte_raw_cksum() uses unaligned_uint16_t pointer access
> which triggers UBSAN alignment warnings even though the access is safe
> due to the unaligned type definition.
>
> Add __rte_no_ubsan_alignment attribute to suppress these false positive
> warnings while preserving other UBSAN checks.
I think root cause of the false positive warnings is a faulty type definition of unaligned_uint16_t in rte_common.h [1].
For architectures with strict alignment requirements, the type is correctly defined as:
typedef uint16_t unaligned_uint16_t __rte_aligned(1);
But for architectures with relaxed alignment requirements, the type definition is incomplete:
typedef uint16_t unaligned_uint16_t;
When UBSAN runs with the latter definition (which doesn't remove the type's alignment requirement), UBSAN is correctly warning about the misalignment.
Either UBSAN should run with the first definition (i.e. with __rte_aligned(1)), or the type definitions with __rte_aligned(1) should be used for all architectures.
[1]: https://elixir.bootlin.com/dpdk/v25.11/source/lib/eal/include/rte_common.h#L124
Stephen, WDYT?
>
> Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
> ---
> lib/eal/include/rte_common.h | 9 +++++++++
> lib/net/rte_cksum.h | 1 +
> 2 files changed, 10 insertions(+)
>
> diff --git a/lib/eal/include/rte_common.h
> b/lib/eal/include/rte_common.h
> index 9e7d84f929..00d428e295 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -546,6 +546,15 @@ static void
> __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
> #define __rte_no_asan
> #endif
>
> +/**
> + * Disable UndefinedBehaviorSanitizer alignment check on some code
> + */
> +#if defined(RTE_CC_CLANG) || defined(RTE_CC_GCC)
> +#define __rte_no_ubsan_alignment
> __attribute__((no_sanitize("alignment")))
> +#else
> +#define __rte_no_ubsan_alignment
> +#endif
> +
> /*********** Macros for pointer arithmetic ********/
>
> /**
> diff --git a/lib/net/rte_cksum.h b/lib/net/rte_cksum.h
> index 8dbe1179e8..9a7fda563d 100644
> --- a/lib/net/rte_cksum.h
> +++ b/lib/net/rte_cksum.h
> @@ -39,6 +39,7 @@ extern "C" {
> * @return
> * sum += Sum of all words in the buffer.
> */
> +__rte_no_ubsan_alignment
> static inline uint32_t
> __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
> {
> --
> 2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-01-10 15:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-10 1:56 [PATCH v12 0/3] net: optimize raw checksum computation scott.k.mitch1
2026-01-10 1:56 ` [PATCH v12 1/3] net: optimize __rte_raw_cksum and add tests scott.k.mitch1
2026-01-10 2:28 ` Scott Mitchell
2026-01-10 14:47 ` Morten Brørup
2026-01-10 1:56 ` [PATCH v12 2/3] eal: add workaround for UBSAN alignment false positive scott.k.mitch1
2026-01-10 15:02 ` Morten Brørup [this message]
2026-01-10 1:56 ` [PATCH v12 3/3] eal/net: add workaround for GCC optimization bug scott.k.mitch1
2026-01-10 15:29 ` Morten Brørup
2026-01-11 6:21 ` Scott Mitchell
2026-01-10 16:59 ` [PATCH v12 0/3] net: optimize raw checksum computation Stephen Hemminger
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=98CBD80474FA8B44BF855DF32C47DC35F65647@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=dev@dpdk.org \
--cc=scott.k.mitch1@gmail.com \
--cc=scott_mitchell@apple.com \
--cc=stephen@networkplumber.org \
/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;
as well as URLs for NNTP newsgroup(s).