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[] = {