mbox series

[v12,00/17] Add rseq extensible ABI support

Message ID 20240801-rseq-abi-v11-split-v12-0-0e87479dddc0@efficios.com
Headers show
Series Add rseq extensible ABI support | expand

Message

Michael Jeanson Aug. 5, 2024, 8:48 p.m. UTC
Introduced in Linux v6.3 the rseq extensible ABI [1] will allow adding
rseq features past the initial 32 bytes of the original ABI.

While the rseq features in the latest kernel still fit within the
original ABI size, there are currently only 4 bytes left. It would thus
be a good time to add support for the extensible ABI so that when new
features are added, they are immediately available to GNU libc users.

We use the ELF auxiliary vector to query the kernel for the size and
alignment of the rseq area, if this fails we default to the original
fixed size and alignment of '32' which the kernel will accept as a
compatibility mode with the original ABI.

This makes the size of the rseq area variable and thus requires to
relocate it out of 'struct pthread'. We chose to move it after (in block
allocation order) the last TLS block inside the static TLS block
allocation. It required a fairly small modification to the TLS block
allocator and did not interfere with the main executable TLS block which
must always be the first block relative to the thread pointer.

[1] https://lore.kernel.org/all/20221122203932.231377-4-mathieu.desnoyers@efficios.com/


Cc: Florian Weimer <fweimer@redhat.com>
Cc: Carlos O'Donell <carlos@redhat.com>
Cc: DJ Delorie <dj@redhat.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
Changes since v11:
- Removed _dl_rseq_feature_size, use __rseq_size instead
- Replace GLRO(dl_rseq_align) with a hidden global variable _rseq_align
- __rseq_size is now set directly in _dl_parse_auxv, set it to 0 when
  the main thread registration fails or is disabled by tunable
Changes since v10:
- Split the patchset in smaller patches
- Rebased on 'Make __rseq_size useful for feature detection'
- Remove 'rseq' from the generic TLS code, add 'extra TLS'
- Add thread_pointer.h for all Linux architectures
- Fix build on the Hurd
Changes since v8:
- Fix copyright year in sysdeps/generic/dl-rseq.h
- Clarify the the tcb math comments
- Add a comment to clarify what enforces the aligment requirements of a
  pointer calculated from the rseq_offset
- Remove nonsensical test in tst-rseq-disable
- Add comments to clarify why the rseq size is 0 when registration fails
  or is disabled
- Add comments to explain why whe allocate and rseq area block even when
  the registration is disabled by tunable
- Rename 'rseq_size' -> 'rseq_alloc_size' and 'dl_tls_rseq_size' ->
  'dl_tls_rseq_alloc_size' to clarify the distinction between the
  allocated rseq size and the size reported to application code in
  '__rseq_size'
Changes since v6:
- Fix tst-rseq for feature size over 32 bytes
- Rebased on 'nptl: fix potential merge of __rseq_* relro symbols'
Changes since v5:
- Fix TLS_DTV_AT_TP rseq offset with statically linked executables
Changes since RFC v4:
- Move dynamic linker defines to a header file
- Fix alignment when tls block align is smaller than rseq align with
  statically linked executables
- Add statically linked rseq tests
- Revert: Set __rseq_size even when the registration fails
- Use minimum size when rseq is disabled by tunable
Changes since RFC v3:
- Fix RSEQ_SETMEM for rseq disabled
- Replace sys/auxv.h usage with dl-parse_auxv.h
- Fix offset for TLS_TCB_AT_TP with statically linked executables
- Zero the rseq area before registration
Changes since RFC v2:
- Set __rseq_size even when the registration fails
- Adjust rseq tests to the new ABI
- Added support for statically linked executables
Changes since RFC v1:
- Insert the rseq area after the last TLS block
- Add proper support for TLS_TCB_AT_TP variant

---
Michael Jeanson (17):
      nptl: Add rseq auxvals
      Add generic 'extra TLS'
      Add Linux 'extra TLS'
      nptl: Add <thread_pointer.h> for RISC-V
      nptl: Add <thread_pointer.h> for LoongArch
      nptl: Add <thread_pointer.h> for sparc
      nptl: Add <thread_pointer.h> for m68k
      nptl: Add <thread_pointer.h> for or1k
      nptl: Add <thread_pointer.h> for nios2
      nptl: Add <thread_pointer.h> for microblaze
      nptl: Add <thread_pointer.h> for hppa
      nptl: Add <thread_pointer.h> for csky
      nptl: add RSEQ_SIG for RISC-V
      nptl: Introduce RSEQ_GETMEM_VOLATILE and RSEQ_SETMEM
      nptl: Move the rseq area to the 'extra TLS' block
      nptl: Remove the rseq area from 'struct pthread'
      Linux: Update internal copy of '<sys/rseq.h>'

 csu/libc-tls.c                                    | 59 ++++++++++++++---
 elf/dl-tls.c                                      | 59 +++++++++++++++++
 nptl/descr.h                                      | 20 +-----
 nptl/pthread_create.c                             |  2 +-
 sysdeps/csky/nptl/thread_pointer.h                | 30 +++++++++
 sysdeps/generic/dl-extra_tls.h                    | 45 +++++++++++++
 sysdeps/hppa/nptl/thread_pointer.h                | 30 +++++++++
 sysdeps/i386/nptl/tcb-access.h                    | 61 +++++++++++++++++
 sysdeps/loongarch/nptl/thread_pointer.h           | 34 ++++++++++
 sysdeps/m68k/nptl/thread_pointer.h                | 30 +++++++++
 sysdeps/microblaze/nptl/thread_pointer.h          | 30 +++++++++
 sysdeps/nios2/nptl/thread_pointer.h               | 30 +++++++++
 sysdeps/nptl/dl-tls_init_tp.c                     | 22 +++---
 sysdeps/nptl/tcb-access.h                         |  5 ++
 sysdeps/or1k/nptl/thread_pointer.h                | 30 +++++++++
 sysdeps/riscv/nptl/thread_pointer.h               | 34 ++++++++++
 sysdeps/sparc/nptl/thread_pointer.h               | 30 +++++++++
 sysdeps/unix/sysv/linux/Makefile                  | 10 +++
 sysdeps/unix/sysv/linux/dl-extra_tls.h            | 76 +++++++++++++++++++++
 sysdeps/unix/sysv/linux/dl-parse_auxv.h           |  5 ++
 sysdeps/unix/sysv/linux/riscv/bits/rseq.h         | 44 ++++++++++++
 sysdeps/unix/sysv/linux/rseq-internal.h           | 81 ++++++++++++++++++++---
 sysdeps/unix/sysv/linux/sched_getcpu.c            |  3 +-
 sysdeps/unix/sysv/linux/sys/rseq.h                | 11 +++
 sysdeps/unix/sysv/linux/tst-rseq-disable-static.c |  1 +
 sysdeps/unix/sysv/linux/tst-rseq-disable.c        | 60 ++++++++++++++---
 sysdeps/unix/sysv/linux/tst-rseq-nptl-static.c    |  1 +
 sysdeps/unix/sysv/linux/tst-rseq-static.c         |  1 +
 sysdeps/unix/sysv/linux/tst-rseq.c                | 81 ++++++++++++++++++-----
 sysdeps/unix/sysv/linux/tst-rseq.h                |  7 +-
 sysdeps/x86_64/nptl/tcb-access.h                  | 61 +++++++++++++++++
 31 files changed, 919 insertions(+), 74 deletions(-)
---
base-commit: 060c2618c804aee86f3b787c851c2760c0391a68
change-id: 20240801-rseq-abi-v11-split-ae0d0f1d39e3