Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Wake Liu <wakel@google.com>, Jakub Kicinski <kuba@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	nathan@kernel.org, netdev@vger.kernel.org, llvm@lists.linux.dev
Subject: [PATCH AUTOSEL 6.17-5.4] selftests/net: Replace non-standard __WORDSIZE with sizeof(long) * 8
Date: Sat, 25 Oct 2025 11:54:50 -0400	[thread overview]
Message-ID: <20251025160905.3857885-59-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>

From: Wake Liu <wakel@google.com>

[ Upstream commit c36748e8733ef9c5f4cd1d7c4327994e5b88b8df ]

The `__WORDSIZE` macro, defined in the non-standard `<bits/wordsize.h>`
header, is a GNU extension and not universally available with all
toolchains, such as Clang when used with musl libc.

This can lead to build failures in environments where this header is
missing.

The intention of the code is to determine the bit width of a C `long`.
Replace the non-portable `__WORDSIZE` with the standard and portable
`sizeof(long) * 8` expression to achieve the same result.

This change also removes the inclusion of the now-unused
`<bits/wordsize.h>` header.

Signed-off-by: Wake Liu <wakel@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

YES

- What it fixes
  - Fixes selftest build failures on toolchains without GNU
    `<bits/wordsize.h>` (e.g., Clang with musl). The current code
    directly includes a GNU-internal header and uses a GNU extension
    macro.
  - Evidence: direct inclusion at
    `tools/testing/selftests/net/psock_tpacket.c:36` and use of
    `__WORDSIZE` at `tools/testing/selftests/net/psock_tpacket.c:788`.

- Change details
  - Removes non-standard header include: `#include <bits/wordsize.h>`
    (tools/testing/selftests/net/psock_tpacket.c:36).
  - Replaces non-portable `__WORDSIZE` with the portable and standard-
    compliant `sizeof(long) * 8` inside `test_user_bit_width()`
    (tools/testing/selftests/net/psock_tpacket.c:788 → now returns
    `sizeof(long) * 8`).
  - No other functional changes; all behavior, interfaces, and test
    logic remain intact.

- Behavioral impact
  - The intent of `test_user_bit_width()` is to report the userspace
    “word” width as used by the test to decide whether to skip
    TPACKET_V1 when user/kernel bit widths differ (see its use in
    `test_tpacket()` adjacent to
    tools/testing/selftests/net/psock_tpacket.c:811).
  - On Linux ABIs, `__WORDSIZE` effectively matches the bit width of
    `long`. Using `sizeof(long) * 8` is semantically equivalent across
    LP64 and ILP32, including x86_64 ILP32 (x32), where it returns 32
    and properly triggers the intended skip path when comparing to the
    kernel’s 64-bit width parsed from `/proc/kallsyms`.
  - Therefore, no functional change to test behavior, only improved
    portability.

- Scope and risk
  - Selftests-only change (single file), no kernel code touched.
  - Very small and contained: removal of one include and a one-line
    return expression change.
  - No architectural changes; no side effects beyond enabling builds on
    non-glibc toolchains.
  - Aligns with existing tools-side practice:
    `tools/include/linux/bitops.h` already falls back to a portable
    definition of `__WORDSIZE` via `__SIZEOF_LONG__ * 8`, reinforcing
    that using the C type width is the right approach.

- Stable backport criteria
  - Addresses a real user-facing bug: selftests fail to build on
    legitimate toolchains (Clang + musl).
  - Minimal risk and fully contained to a test; no runtime kernel
    impact.
  - Not a new feature; purely a portability/build fix.
  - Touches a non-critical subtree (selftests), commonly accepted for
    stable when it fixes build or test breakages.

Conclusion: This is a low-risk, portability/build fix for selftests with
no kernel runtime impact and should be backported to stable.

 tools/testing/selftests/net/psock_tpacket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/psock_tpacket.c b/tools/testing/selftests/net/psock_tpacket.c
index 221270cee3eaa..0dd909e325d93 100644
--- a/tools/testing/selftests/net/psock_tpacket.c
+++ b/tools/testing/selftests/net/psock_tpacket.c
@@ -33,7 +33,6 @@
 #include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <bits/wordsize.h>
 #include <net/ethernet.h>
 #include <netinet/ip.h>
 #include <arpa/inet.h>
@@ -785,7 +784,7 @@ static int test_kernel_bit_width(void)
 
 static int test_user_bit_width(void)
 {
-	return __WORDSIZE;
+	return sizeof(long) * 8;
 }
 
 static const char *tpacket_str[] = {
-- 
2.51.0


       reply	other threads:[~2025-10-25 16:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:54 ` Sasha Levin [this message]
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] sparc: Replace __ASSEMBLY__ with __ASSEMBLER__ in uapi headers Sasha Levin
2025-10-27  8:09   ` Andreas Larsson
2025-11-04 14:14     ` Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.4] sparc/module: Add R_SPARC_UA64 relocation handling Sasha Levin

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=20251025160905.3857885-59-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=wakel@google.com \
    /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