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

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Nov 11 12:08:57 GMT 2026



On 10/11/26 11:51, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> When __ASSUME_TIME64_SYSCALLS is set, __NR_futex_time64 is always
> available, so use that in place of __NR_futex for 32-bit architectures
> regardless of __TIMESIZE.
> 
> Remove the slightly ambiguous lll_futex_timed_wait() macro that
> could take either a timespec or __timespec64 argument depending

Agreed, futex_wait was its only user and always passed NULL.

> on the architecture. This was harmless since the only caller
> always passes a NULL timeout. All users that do care about the
> timeout were already calling helpers from futex-internal.c
> which handles this correctly.
> 
> This is required for running on __TIMESIZE==32 architectures on
> kernels built with CONFIG_COMPAT_32BIT_TIME.

s/CONFIG_COMPAT_32BIT_TIME/CONFIG_COMPAT_32BIT_TIME=n/ (or "without").

> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  sysdeps/nptl/futex-internal.h     |  6 +-----
>  sysdeps/nptl/lowlevellock-futex.h | 15 +++++++++++----
>  2 files changed, 12 insertions(+), 9 deletions(-)

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. Moving
it to lowlevellock-futex.h works, and I think it is what you want anyway
(see below). 

> 
> 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).
  
  - 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.

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

> diff --git a/sysdeps/nptl/lowlevellock-futex.h b/sysdeps/nptl/lowlevellock-futex.h
> index 640861350101..711723b0b0ad 100644
> --- a/sysdeps/nptl/lowlevellock-futex.h
> +++ b/sysdeps/nptl/lowlevellock-futex.h
> @@ -53,6 +53,15 @@
>  # define __lll_private_flag(fl, private) \
>    (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
>  
> +#if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_futex_time64)
> +# define lll_futex_syscall(nargs, futexp, op, ...)                      \
> +  ({                                                                    \
> +    long int __ret = INTERNAL_SYSCALL (futex_time64, nargs, futexp, op,	\
> +				       __VA_ARGS__);                    \
> +    (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
> +     ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0);                     	\
> +  })
> +#else
>  # define lll_futex_syscall(nargs, futexp, op, ...)                      \
>    ({                                                                    \
>      long int __ret = INTERNAL_SYSCALL (futex, nargs, futexp, op, 	\
> @@ -60,6 +69,7 @@
>      (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret))         	\
>       ? -INTERNAL_SYSCALL_ERRNO (__ret) : 0);                     	\
>    })
> +#endif
>  
>  /* For most of these macros, the return value is never really used.
>     Nevertheless, the protocol is that each one returns a negated errno
> @@ -70,12 +80,9 @@
>  
>  /* Wait while *FUTEXP == VAL for an lll_futex_wake call on FUTEXP.  */
>  # define lll_futex_wait(futexp, val, private) \
> -  lll_futex_timed_wait (futexp, val, NULL, private)
> -
> -# define lll_futex_timed_wait(futexp, val, timeout, private)     \
>    lll_futex_syscall (4, futexp,                                 \
>  		     __lll_private_flag (FUTEX_WAIT, private),  \
> -		     val, timeout)
> +		     val, NULL)
>  
>  /* Verify whether the supplied clockid is supported by
>     lll_futex_clock_wait_bitset.  */



More information about the Libc-alpha mailing list