From: Cynthia Huang cynthia@andestech.com
[ Upstream commit 04850819c65c8242072818655d4341e70ae998b5 ]
The kernel does not provide sys_futex() on 32-bit architectures that do not support 32-bit time representations, such as riscv32.
As a result, glibc cannot define SYS_futex, causing compilation failures in tests that rely on this syscall. Define SYS_futex as SYS_futex_time64 in such cases to ensure successful compilation and compatibility.
Signed-off-by: Cynthia Huang cynthia@andestech.com Signed-off-by: Ben Zong-You Xie ben717@andestech.com Signed-off-by: Thomas Gleixner tglx@linutronix.de Reviewed-by: Muhammad Usama Anjum usama.anjum@collabora.com Link: https://lore.kernel.org/all/20250710103630.3156130-1-ben717@andestech.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the following reasons:
1. **Fixes a real compilation failure bug**: The commit addresses a build failure in kernel selftests on 32-bit architectures with 64-bit time_t, specifically riscv32. This prevents the futex selftests from compiling on these architectures, which is a functional bug that affects testing infrastructure.
2. **Simple and contained fix**: The change is minimal - it only adds a conditional preprocessor definition that maps `SYS_futex` to `SYS_futex_time64` when the former is not defined but the latter is. The fix is: ```c #if !defined(SYS_futex) && defined(SYS_futex_time64) #define SYS_futex SYS_futex_time64 #endif ```
3. **No risk of regression**: The change is guarded by preprocessor conditionals that only activate when `SYS_futex` is not defined AND `SYS_futex_time64` is defined. This means it has zero impact on architectures where `SYS_futex` is already defined, ensuring no regressions on existing systems.
4. **Affects kernel testing infrastructure**: While this is in the selftests directory and not core kernel code, having working selftests is critical for kernel stability and quality assurance. The futex selftests are important for validating futex functionality across different architectures.
5. **Addresses Y2038 compatibility**: This fix is part of the broader Y2038 compatibility effort where 32-bit architectures are transitioning to 64-bit time_t. As more 32-bit architectures adopt 64-bit time_t, this fix becomes increasingly important.
6. **Clear problem and solution**: The commit message clearly explains the issue (glibc cannot define SYS_futex on certain architectures) and provides a clean solution that maintains compatibility.
The fix follows stable kernel rules by being a minimal change that fixes an important bug without introducing new features or architectural changes. It's confined to the testing infrastructure and has clear boundaries with no side effects beyond enabling compilation of the futex selftests on affected architectures.
tools/testing/selftests/futex/include/futextest.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/testing/selftests/futex/include/futextest.h index ddbcfc9b7bac..7a5fd1d5355e 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -47,6 +47,17 @@ typedef volatile u_int32_t futex_t; FUTEX_PRIVATE_FLAG) #endif
+/* + * SYS_futex is expected from system C library, in glibc some 32-bit + * architectures (e.g. RV32) are using 64-bit time_t, therefore it doesn't have + * SYS_futex defined but just SYS_futex_time64. Define SYS_futex as + * SYS_futex_time64 in this situation to ensure the compilation and the + * compatibility. + */ +#if !defined(SYS_futex) && defined(SYS_futex_time64) +#define SYS_futex SYS_futex_time64 +#endif + /** * futex() - SYS_futex syscall wrapper * @uaddr: address of first futex