Skip to content

Commit d82991a

Browse files
committed
Merge branch 'core-rseq-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull restartable sequence support from Thomas Gleixner: "The restartable sequences syscall (finally): After a lot of back and forth discussion and massive delays caused by the speculative distraction of maintainers, the core set of restartable sequences has finally reached a consensus. It comes with the basic non disputed core implementation along with support for arm, powerpc and x86 and a full set of selftests It was exposed to linux-next earlier this week, so it does not fully comply with the merge window requirements, but there is really no point to drag it out for yet another cycle" * 'core-rseq-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: rseq/selftests: Provide Makefile, scripts, gitignore rseq/selftests: Provide parametrized tests rseq/selftests: Provide basic percpu ops test rseq/selftests: Provide basic test rseq/selftests: Provide rseq library selftests/lib.mk: Introduce OVERRIDE_TARGETS powerpc: Wire up restartable sequences system call powerpc: Add syscall detection for restartable sequences powerpc: Add support for restartable sequences x86: Wire up restartable sequence system call x86: Add support for restartable sequences arm: Wire up restartable sequences system call arm: Add syscall detection for restartable sequences arm: Add restartable sequences support rseq: Introduce restartable sequences system call uapi/headers: Provide types_32_64.h
2 parents f4e5b30 + ccba8b6 commit d82991a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5491
-8
lines changed

MAINTAINERS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12134,6 +12134,18 @@ F: include/dt-bindings/reset/
1213412134
F: include/linux/reset.h
1213512135
F: include/linux/reset-controller.h
1213612136

12137+
RESTARTABLE SEQUENCES SUPPORT
12138+
M: Mathieu Desnoyers <[email protected]>
12139+
M: Peter Zijlstra <[email protected]>
12140+
M: "Paul E. McKenney" <[email protected]>
12141+
M: Boqun Feng <[email protected]>
12142+
12143+
S: Supported
12144+
F: kernel/rseq.c
12145+
F: include/uapi/linux/rseq.h
12146+
F: include/trace/events/rseq.h
12147+
F: tools/testing/selftests/rseq/
12148+
1213712149
RFKILL
1213812150
M: Johannes Berg <[email protected]>
1213912151

arch/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ config HAVE_REGS_AND_STACK_ACCESS_API
272272
declared in asm/ptrace.h
273273
For example the kprobes-based event tracer needs this API.
274274

275+
config HAVE_RSEQ
276+
bool
277+
depends on HAVE_REGS_AND_STACK_ACCESS_API
278+
help
279+
This symbol should be selected by an architecture if it
280+
supports an implementation of restartable sequences.
281+
275282
config HAVE_CLK
276283
bool
277284
help

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ config ARM
9191
select HAVE_PERF_USER_STACK_DUMP
9292
select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
9393
select HAVE_REGS_AND_STACK_ACCESS_API
94+
select HAVE_RSEQ
9495
select HAVE_SYSCALL_TRACEPOINTS
9596
select HAVE_UID16
9697
select HAVE_VIRT_CPU_ACCOUNTING_GEN

arch/arm/kernel/entry-common.S

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ saved_pc .req lr
3939

4040
.section .entry.text,"ax",%progbits
4141
.align 5
42-
#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING))
42+
#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \
43+
IS_ENABLED(CONFIG_DEBUG_RSEQ))
4344
/*
4445
* This is the fast syscall return path. We do as little as possible here,
4546
* such as avoiding writing r0 to the stack. We only use this path if we
46-
* have tracing and context tracking disabled - the overheads from those
47-
* features make this path too inefficient.
47+
* have tracing, context tracking and rseq debug disabled - the overheads
48+
* from those features make this path too inefficient.
4849
*/
4950
ret_fast_syscall:
5051
UNWIND(.fnstart )
@@ -71,14 +72,20 @@ fast_work_pending:
7172
/* fall through to work_pending */
7273
#else
7374
/*
74-
* The "replacement" ret_fast_syscall for when tracing or context tracking
75-
* is enabled. As we will need to call out to some C functions, we save
76-
* r0 first to avoid needing to save registers around each C function call.
75+
* The "replacement" ret_fast_syscall for when tracing, context tracking,
76+
* or rseq debug is enabled. As we will need to call out to some C functions,
77+
* we save r0 first to avoid needing to save registers around each C function
78+
* call.
7779
*/
7880
ret_fast_syscall:
7981
UNWIND(.fnstart )
8082
UNWIND(.cantunwind )
8183
str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
84+
#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
85+
/* do_rseq_syscall needs interrupts enabled. */
86+
mov r0, sp @ 'regs'
87+
bl do_rseq_syscall
88+
#endif
8289
disable_irq_notrace @ disable interrupts
8390
ldr r2, [tsk, #TI_ADDR_LIMIT]
8491
cmp r2, #TASK_SIZE
@@ -113,6 +120,12 @@ ENDPROC(ret_fast_syscall)
113120
*/
114121
ENTRY(ret_to_user)
115122
ret_slow_syscall:
123+
#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
124+
/* do_rseq_syscall needs interrupts enabled. */
125+
enable_irq_notrace @ enable interrupts
126+
mov r0, sp @ 'regs'
127+
bl do_rseq_syscall
128+
#endif
116129
disable_irq_notrace @ disable interrupts
117130
ENTRY(ret_to_user_from_irq)
118131
ldr r2, [tsk, #TI_ADDR_LIMIT]

arch/arm/kernel/signal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
540540
sigset_t *oldset = sigmask_to_save();
541541
int ret;
542542

543+
/*
544+
* Increment event counter and perform fixup for the pre-signal
545+
* frame.
546+
*/
547+
rseq_signal_deliver(regs);
548+
543549
/*
544550
* Set up the stack frame
545551
*/
@@ -660,6 +666,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
660666
} else {
661667
clear_thread_flag(TIF_NOTIFY_RESUME);
662668
tracehook_notify_resume(regs);
669+
rseq_handle_notify_resume(regs);
663670
}
664671
}
665672
local_irq_disable();
@@ -703,3 +710,10 @@ asmlinkage void addr_limit_check_failed(void)
703710
{
704711
addr_limit_user_check();
705712
}
713+
714+
#ifdef CONFIG_DEBUG_RSEQ
715+
asmlinkage void do_rseq_syscall(struct pt_regs *regs)
716+
{
717+
rseq_syscall(regs);
718+
}
719+
#endif

arch/arm/tools/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,4 @@
412412
395 common pkey_alloc sys_pkey_alloc
413413
396 common pkey_free sys_pkey_free
414414
397 common statx sys_statx
415+
398 common rseq sys_rseq

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ config PPC
220220
select HAVE_SYSCALL_TRACEPOINTS
221221
select HAVE_VIRT_CPU_ACCOUNTING
222222
select HAVE_IRQ_TIME_ACCOUNTING
223+
select HAVE_RSEQ
223224
select IOMMU_HELPER if PPC64
224225
select IRQ_DOMAIN
225226
select IRQ_FORCED_THREADING

arch/powerpc/include/asm/systbl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,4 @@ SYSCALL(statx)
392392
SYSCALL(pkey_alloc)
393393
SYSCALL(pkey_free)
394394
SYSCALL(pkey_mprotect)
395+
SYSCALL(rseq)

arch/powerpc/include/asm/unistd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <uapi/asm/unistd.h>
1313

1414

15-
#define NR_syscalls 387
15+
#define NR_syscalls 388
1616

1717
#define __NR__exit __NR_exit
1818

arch/powerpc/include/uapi/asm/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,5 +398,6 @@
398398
#define __NR_pkey_alloc 384
399399
#define __NR_pkey_free 385
400400
#define __NR_pkey_mprotect 386
401+
#define __NR_rseq 387
401402

402403
#endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */

arch/powerpc/kernel/entry_32.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ syscall_dotrace_cont:
365365
blrl /* Call handler */
366366
.globl ret_from_syscall
367367
ret_from_syscall:
368+
#ifdef CONFIG_DEBUG_RSEQ
369+
/* Check whether the syscall is issued inside a restartable sequence */
370+
stw r3,GPR3(r1)
371+
addi r3,r1,STACK_FRAME_OVERHEAD
372+
bl rseq_syscall
373+
lwz r3,GPR3(r1)
374+
#endif
368375
mr r6,r3
369376
CURRENT_THREAD_INFO(r12, r1)
370377
/* disable interrupts so current_thread_info()->flags can't change */

arch/powerpc/kernel/entry_64.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ system_call: /* label this so stack traces look sane */
194194

195195
.Lsyscall_exit:
196196
std r3,RESULT(r1)
197+
198+
#ifdef CONFIG_DEBUG_RSEQ
199+
/* Check whether the syscall is issued inside a restartable sequence */
200+
addi r3,r1,STACK_FRAME_OVERHEAD
201+
bl rseq_syscall
202+
ld r3,RESULT(r1)
203+
#endif
204+
197205
CURRENT_THREAD_INFO(r12, r1)
198206

199207
ld r8,_MSR(r1)

arch/powerpc/kernel/signal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ static void do_signal(struct task_struct *tsk)
134134
/* Re-enable the breakpoints for the signal stack */
135135
thread_change_pc(tsk, tsk->thread.regs);
136136

137+
rseq_signal_deliver(tsk->thread.regs);
138+
137139
if (is32) {
138140
if (ksig.ka.sa.sa_flags & SA_SIGINFO)
139141
ret = handle_rt_signal32(&ksig, oldset, tsk);
@@ -168,6 +170,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
168170
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
169171
clear_thread_flag(TIF_NOTIFY_RESUME);
170172
tracehook_notify_resume(regs);
173+
rseq_handle_notify_resume(regs);
171174
}
172175

173176
user_enter();

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ config X86
183183
select HAVE_REGS_AND_STACK_ACCESS_API
184184
select HAVE_RELIABLE_STACKTRACE if X86_64 && UNWINDER_FRAME_POINTER && STACK_VALIDATION
185185
select HAVE_STACK_VALIDATION if X86_64
186+
select HAVE_RSEQ
186187
select HAVE_SYSCALL_TRACEPOINTS
187188
select HAVE_UNSTABLE_SCHED_CLOCK
188189
select HAVE_USER_RETURN_NOTIFIER

arch/x86/entry/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
164164
if (cached_flags & _TIF_NOTIFY_RESUME) {
165165
clear_thread_flag(TIF_NOTIFY_RESUME);
166166
tracehook_notify_resume(regs);
167+
rseq_handle_notify_resume(regs);
167168
}
168169

169170
if (cached_flags & _TIF_USER_RETURN_NOTIFY)
@@ -254,6 +255,8 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)
254255
WARN(irqs_disabled(), "syscall %ld left IRQs disabled", regs->orig_ax))
255256
local_irq_enable();
256257

258+
rseq_syscall(regs);
259+
257260
/*
258261
* First do one-time work. If these work items are enabled, we
259262
* want to run them exactly once per syscall exit with IRQs on.

arch/x86/entry/syscalls/syscall_32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,4 @@
397397
383 i386 statx sys_statx __ia32_sys_statx
398398
384 i386 arch_prctl sys_arch_prctl __ia32_compat_sys_arch_prctl
399399
385 i386 io_pgetevents sys_io_pgetevents __ia32_compat_sys_io_pgetevents
400+
386 i386 rseq sys_rseq __ia32_sys_rseq

arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@
342342
331 common pkey_free __x64_sys_pkey_free
343343
332 common statx __x64_sys_statx
344344
333 common io_pgetevents __x64_sys_io_pgetevents
345+
334 common rseq __x64_sys_rseq
345346

346347
#
347348
# x32-specific system call numbers start at 512 to avoid cache impact

arch/x86/kernel/signal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
688688
sigset_t *set = sigmask_to_save();
689689
compat_sigset_t *cset = (compat_sigset_t *) set;
690690

691+
/*
692+
* Increment event counter and perform fixup for the pre-signal
693+
* frame.
694+
*/
695+
rseq_signal_deliver(regs);
696+
691697
/* Set up the stack frame */
692698
if (is_ia32_frame(ksig)) {
693699
if (ksig->ka.sa.sa_flags & SA_SIGINFO)

fs/exec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ static int __do_execve_file(int fd, struct filename *filename,
18241824
current->fs->in_exec = 0;
18251825
current->in_execve = 0;
18261826
membarrier_execve(current);
1827+
rseq_execve(current);
18271828
acct_update_integrals(current);
18281829
task_numa_free(current);
18291830
free_bprm(bprm);

0 commit comments

Comments
 (0)