[v2,0/3] nptl: Fix robust mutex support detection and defer robust list initialization

Message ID 20260505190809.3898686-1-adhemerval.zanella@linaro.org (mailing list archive)
Headers
Series nptl: Fix robust mutex support detection and defer robust list initialization |

Message

Adhemerval Zanella Netto May 5, 2026, 7:06 p.m. UTC
  qemu-user does not implement the set_robust_list syscall for any
architecture [1].  On architectures without __ASSUME_SET_ROBUST_LIST
(e.g. riscv64), glibc probes the syscall at startup and correctly
propagates the failure: pthread_mutex_init returns ENOTSUP for
process-shared robust mutexes.  On architectures with
__ASSUME_SET_ROBUST_LIST (e.g. x86_64, aarch64), the runtime probe is
skipped entirely, so the missing syscall goes undetected and
pthread_mutex_init silently returns success (BZ 33225).

The fix removes __ASSUME_SET_ROBUST_LIST and always probes for
set_robust_list availability at runtime.  As an additional improvement,
the probe is moved out of process/thread startup and deferred to the
first actual robust mutex operation (pthread_mutex_init for
process-shared+robust, or the first lock of any robust mutex).  This
avoids the syscall altogether for programs that never use robust mutexes.

[1] https://gitlab.com/qemu-project/qemu/-/issues/3044
Reported-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

Adhemerval Zanella (3):
  support: Add support_process_shared_robust_mutex
  nptl: Do not always assume set_robust_list availability (BZ 33225)
  nptl: Only initialize robust list at mutex usage

 nptl/Makefile                                 |  2 +
 nptl/Versions                                 |  1 -
 nptl/allocatestack.c                          |  9 +-
 nptl/descr.h                                  | 31 +++++++
 nptl/nptl_robust_setup.c                      | 38 ++++++++
 nptl/pthread_create.c                         | 12 ---
 nptl/pthread_mutex_init.c                     |  5 +-
 nptl/pthread_mutex_lock.c                     |  2 +
 nptl/pthread_mutex_timedlock.c                |  2 +
 nptl/pthread_mutex_trylock.c                  |  2 +
 nptl/tst-mutexpi10.c                          |  4 +-
 nptl/tst-robust-fork.c                        | 21 +++++
 nptl/tst-robust-pshared.c                     | 89 +++++++++++++++++++
 support/Makefile                              |  1 +
 support/support_mutex_robust.c                | 34 +++++++
 support/xthread.h                             |  3 +
 sysdeps/nptl/_Fork.c                          | 24 ++---
 sysdeps/nptl/dl-tls_init_tp.c                 | 23 +----
 sysdeps/nptl/pthreadP.h                       |  8 +-
 sysdeps/pthread/tst-robust7.c                 |  1 -
 sysdeps/pthread/tst-robust8.c                 |  6 ++
 sysdeps/pthread/tst-robust9.c                 |  1 -
 sysdeps/unix/sysv/linux/arm/kernel-features.h |  7 --
 .../unix/sysv/linux/hppa/kernel-features.h    |  3 -
 sysdeps/unix/sysv/linux/kernel-features.h     |  5 --
 .../unix/sysv/linux/m68k/kernel-features.h    |  5 --
 .../unix/sysv/linux/mips/kernel-features.h    |  6 --
 .../unix/sysv/linux/riscv/kernel-features.h   |  5 --
 .../unix/sysv/linux/sparc/kernel-features.h   |  6 --
 29 files changed, 251 insertions(+), 105 deletions(-)
 create mode 100644 nptl/nptl_robust_setup.c
 create mode 100644 nptl/tst-robust-pshared.c
 create mode 100644 support/support_mutex_robust.c