[PATCH v15 0/8] Add rseq extensible ABI support
Michael Jeanson
mjeanson@efficios.com
Tue Jan 7 22:35:04 GMT 2025
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 v14:
- Add TLS_TP_OFFSET to the extra TLS block offset calculation
- Style nits
Changes since v13:
- Ensure that the VOLATILE variants of the RSEQ_ accessors static
asserts on 64bit types on 32bit architectures
- Move rtld_hidden_proto rseq symbols to a separate patch
Changes since v12:
- Set _rseq_size to 0 on registration failure
- Split RSEQ_SET/GETMEM from THREAD_SET/GETMEM
- Rename rseq_get_area() to RSEQ_SELF()
- Add rtld_hidden_proto to __rseq_size and __rseq_offset
- Add comment and variable array member to 'struct rseq_area'
- Style nits
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 (8):
nptl: Add rseq auxvals
Add generic 'extra TLS'
Add Linux 'extra TLS'
nptl: add rtld_hidden_proto to __rseq_size and __rseq_offset
nptl: Introduce <rseq-access.h> for RSEQ_* accessors
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 | 63 ++++++++++--
elf/dl-tls.c | 62 ++++++++++++
nptl/descr.h | 22 +----
nptl/pthread_create.c | 2 +-
sysdeps/generic/dl-extra_tls.h | 45 +++++++++
sysdeps/i386/nptl/rseq-access.h | 98 +++++++++++++++++++
sysdeps/nptl/dl-tls_init_tp.c | 23 ++---
sysdeps/nptl/rseq-access.h | 58 +++++++++++
sysdeps/unix/sysv/linux/Makefile | 10 ++
sysdeps/unix/sysv/linux/dl-extra_tls.h | 70 +++++++++++++
sysdeps/unix/sysv/linux/dl-parse_auxv.h | 7 ++
sysdeps/unix/sysv/linux/dl-rseq-symbols.S | 27 +++--
sysdeps/unix/sysv/linux/rseq-internal.h | 95 ++++++++++++++----
sysdeps/unix/sysv/linux/sched_getcpu.c | 3 +-
sysdeps/unix/sysv/linux/sys/rseq.h | 11 +++
.../unix/sysv/linux/tst-rseq-disable-static.c | 1 +
sysdeps/unix/sysv/linux/tst-rseq-disable.c | 65 ++++++++++--
.../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 | 85 +++++++++++++---
sysdeps/unix/sysv/linux/tst-rseq.h | 3 +-
sysdeps/x86_64/nptl/rseq-access.h | 79 +++++++++++++++
22 files changed, 734 insertions(+), 97 deletions(-)
create mode 100644 sysdeps/generic/dl-extra_tls.h
create mode 100644 sysdeps/i386/nptl/rseq-access.h
create mode 100644 sysdeps/nptl/rseq-access.h
create mode 100644 sysdeps/unix/sysv/linux/dl-extra_tls.h
create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-disable-static.c
create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-nptl-static.c
create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-static.c
create mode 100644 sysdeps/x86_64/nptl/rseq-access.h
--
2.39.5
More information about the Libc-alpha
mailing list