selftests/rseq: Uplift rseq selftests for compatibility with glibc-2.35

glibc-2.35 (upcoming release date 2022-02-01) exposes the rseq per-thread
data in the TCB, accessible at an offset from the thread pointer, rather
than through an actual Thread-Local Storage (TLS) variable, as the
Linux kernel selftests initially expected.

The __rseq_abi TLS and glibc-2.35's ABI for per-thread data cannot
actively coexist in a process, because the kernel supports only a single
rseq registration per thread.

Here is the scheme introduced to ensure selftests can work both with an
older glibc and with glibc-2.35+:

- librseq exposes its own "rseq_offset, rseq_size, rseq_flags" ABI.

- librseq queries for glibc rseq ABI (__rseq_offset, __rseq_size,
  __rseq_flags) using dlsym() in a librseq library constructor. If those
  are found, copy their values into rseq_offset, rseq_size, and
  rseq_flags.

- Else, if those glibc symbols are not found, handle rseq registration
  from librseq and use its own IE-model TLS to implement the rseq ABI
  per-thread storage.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220124171253.22072-8-mathieu.desnoyers@efficios.com
This commit is contained in:
Mathieu Desnoyers
2022-01-24 12:12:45 -05:00
committed by Peter Zijlstra
parent 886ddfba93
commit 233e667e1a
3 changed files with 93 additions and 93 deletions

View File

@@ -43,12 +43,19 @@
#define RSEQ_INJECT_FAILED
#endif
extern __thread struct rseq_abi __rseq_abi;
extern int __rseq_handled;
#include "rseq-thread-pointer.h"
/* Offset from the thread pointer to the rseq area. */
extern int rseq_offset;
/* Size of the registered rseq area. 0 if the registration was
unsuccessful. */
extern unsigned int rseq_size;
/* Flags used during rseq registration. */
extern unsigned int rseq_flags;
static inline struct rseq_abi *rseq_get_abi(void)
{
return &__rseq_abi;
return (struct rseq_abi *) ((uintptr_t) rseq_thread_pointer() + rseq_offset);
}
#define rseq_likely(x) __builtin_expect(!!(x), 1)