[RFC PATCH 1/4] nptl: use futex_time64 for lll_futex_syscall() if possible

Arnd Bergmann arnd@arndb.de
Wed Nov 11 12:56:55 GMT 2026


On Wed, Nov 11, 2026, at 13:08, Adhemerval Zanella Netto wrote:

>
> This diffstat seems wrong, futex-internal.h is listed as
> 1 insertion and 5 deletions, but only a single-line change is posted.
>
> I guess it is the
>
>   #ifndef __NR_futex_time64
>   # define __NR_futex_time64 __NR_futex
>   #endif
>
> block at line 72.  Removing it on its own would break every 64-bit ABI,
> because nptl/futex-internal.c uses futex_time64 unconditionally.

Yes, that's what I get for editing the patches manually. I removed
that change from my git tree when I noticed it would break 64-bit
systems but did not recreate the text when I did the same change
in the local patch file.

> Moving it to lowlevellock-futex.h works, and I think it is what you
> want anyway (see below). 

I had thought about that but not actually done it because redirecting
syscall numbers with incompatible ABIs does seem fragile, even though
I understand this one is probably safe and there are other users in
glibc doing the same thing.

>> diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
>> index 502f89476a24..8934a5ee7932 100644
>> --- a/sysdeps/nptl/futex-internal.h
>> +++ b/sysdeps/nptl/futex-internal.h
>> @@ -123,7 +119,7 @@ futex_fatal_error (void)
>>  static __always_inline int
>>  futex_wait (unsigned int *futex_word, unsigned int expected, int private)
>>  {
>> -  int err = lll_futex_timed_wait (futex_word, expected, NULL, private);
>> +  int err = lll_futex_wait (futex_word, expected, private);
>>    switch (err)
>>      {
>>      case 0:
>
> This misses the two other places in nptl that call the time32 futex
> directly with no timeout:
>
>   - lll_futex_wait_cancel, a few lines below in this same header, used by
>     the GLIBC_2.0 __old_sem_wait compat symbol (i386 and the other ABIs
>     that have it). With the time32 futex gone, it returns -1/ENOSYS
>     instead of blocking, and it is silent regression (and unfortunately we
>     don't have a testcase for it).

This one should be covered by my change to lll_futex_syscall()

>   - nptl/pthread_mutex_trylock.c, the FUTEX_TRYLOCK_PI call on the robust
>     PI owner-died path. On ENOSYS the code continues as if the kernel had
>     finished the owner death, it clears FUTEX_OWNER_DIED and returns
>     EOWNERDEAD. I am almost sure it is wrong.

This one I did miss.

> Instead of two copies of lll_futex_syscall, I would pick the syscall
> number once, use the existing fallback idiom, and use it everywhere.

Fair enough.

On a related note, if both glibc and musl end up defining the
__NR_...time64 macros this way for 64-bit architectures, I wonder
if we should just do the same thing in the kernel and use the time64
names as the canonical names for the macros. There are several
ways to do this, and each of them risks breaking something, but
it does seem appealing to have the definitions in the kernel do
something along the lines of:

// in the generated asm/unistd.h file from the kernel, drop __NR_futex
// in favor of explicit __NR_futex_time32/__NR_futex_time64 to match
// the internal implementation

#if __WORDSIZE==32
#define __NR_futex_time32 98
#define __NR_futex_time64 422
#define __NR_gettimeofday_time32 169
...
#else
#define __NR_futex_time64 98
#define __NR_gettimeofday_time64 169
...
#endif

// in a new architecture-independent header included from there
#if __WORDSIZE==64 || (defined(__x86_64__) && defined(__ILP32__))
# define __NR_futex __NR_futex_time64
# define __NR_gettimeofday __NR_gettimeofday_time64
...
#elif !defined(__USE_TIME_BITS64)
# define __NR_futex __NR_futex_time32
# define __NR_gettimeofday __NR_gettimeofday_time32
...
#else
// leave the old macros undefined when building with __USE_TIME_BITS64
#endif

This would forcibly break any source code that attempts to
call the time32 syscalls by their traditional name in a source
file built with -D_TIME_BITS=64, which would otherwise be a bug
that may go unnoticed for a long time.

     Arnd


More information about the Libc-alpha mailing list