Skip to content

Commit d620024

Browse files
author
Peter Zijlstra
committed
rseq: Allow registering RSEQ with slice extension
Since glibc cares about the number of syscalls required to initialize a new thread, allow initializing rseq with slice extension on. This avoids having to do another prctl(). Requested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260121143207.814193010@infradead.org
1 parent 830969e commit d620024

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

include/uapi/linux/rseq.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ enum rseq_cpu_id_state {
1919
};
2020

2121
enum rseq_flags {
22-
RSEQ_FLAG_UNREGISTER = (1 << 0),
22+
RSEQ_FLAG_UNREGISTER = (1 << 0),
23+
RSEQ_FLAG_SLICE_EXT_DEFAULT_ON = (1 << 1),
2324
};
2425

2526
enum rseq_cs_flags_bit {

kernel/rseq.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, int, flags, u32
424424
return 0;
425425
}
426426

427-
if (unlikely(flags))
427+
if (unlikely(flags & ~(RSEQ_FLAG_SLICE_EXT_DEFAULT_ON)))
428428
return -EINVAL;
429429

430430
if (current->rseq.usrptr) {
@@ -459,8 +459,12 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, int, flags, u32
459459
if (!access_ok(rseq, rseq_len))
460460
return -EFAULT;
461461

462-
if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSION))
462+
if (IS_ENABLED(CONFIG_RSEQ_SLICE_EXTENSION)) {
463463
rseqfl |= RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE;
464+
if (rseq_slice_extension_enabled() &&
465+
(flags & RSEQ_FLAG_SLICE_EXT_DEFAULT_ON))
466+
rseqfl |= RSEQ_CS_FLAG_SLICE_EXT_ENABLED;
467+
}
464468

465469
scoped_user_write_access(rseq, efault) {
466470
/*
@@ -488,6 +492,10 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, int, flags, u32
488492
current->rseq.len = rseq_len;
489493
current->rseq.sig = sig;
490494

495+
#ifdef CONFIG_RSEQ_SLICE_EXTENSION
496+
current->rseq.slice.state.enabled = !!(rseqfl & RSEQ_CS_FLAG_SLICE_EXT_ENABLED);
497+
#endif
498+
491499
/*
492500
* If rseq was previously inactive, and has just been
493501
* registered, ensure the cpu_id_start and cpu_id fields

0 commit comments

Comments
 (0)