Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/futex: Fix futex_wait() for 32bit ARM

On 32bit ARM systems gcc-12 will use 32bit timestamps while gcc-13 and later
will use 64bit timestamps. The problem is that SYS_futex will continue
pointing at the 32bit system call. This makes the futex_wait test fail like
this:

waiter failed errno 110
not ok 1 futex_wake private returned: 0 Success
waiter failed errno 110
not ok 2 futex_wake shared (page anon) returned: 0 Success
waiter failed errno 110
not ok 3 futex_wake shared (file backed) returned: 0 Success

Instead of compiling differently depending on the gcc version, use the
-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 options to ensure that 64bit timestamps
are used. Then use ifdefs to make SYS_futex point to the 64bit system call.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: André Almeida <andrealmeid@igalia.com>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Link: https://lore.kernel.org/20250827130011.677600-6-bigeasy@linutronix.de

authored by

Dan Carpenter and committed by
Borislav Petkov (AMD)
237bfb76 5fdb877b

+12 -1
+1 -1
tools/testing/selftests/futex/functional/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 INCLUDES := -I../include -I../../ $(KHDR_INCLUDES) 3 - CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread $(INCLUDES) $(KHDR_INCLUDES) 3 + CFLAGS := $(CFLAGS) -g -O2 -Wall -pthread -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $(INCLUDES) $(KHDR_INCLUDES) 4 4 LDLIBS := -lpthread -lrt -lnuma 5 5 6 6 LOCAL_HDRS := \
+11
tools/testing/selftests/futex/include/futextest.h
··· 58 58 #define SYS_futex SYS_futex_time64 59 59 #endif 60 60 61 + /* 62 + * On 32bit systems if we use "-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" or if 63 + * we are using a newer compiler then the size of the timestamps will be 64bit, 64 + * however, the SYS_futex will still point to the 32bit futex system call. 65 + */ 66 + #if __SIZEOF_POINTER__ == 4 && defined(SYS_futex_time64) && \ 67 + defined(_TIME_BITS) && _TIME_BITS == 64 68 + # undef SYS_futex 69 + # define SYS_futex SYS_futex_time64 70 + #endif 71 + 61 72 /** 62 73 * futex() - SYS_futex syscall wrapper 63 74 * @uaddr: address of first futex