Skip to content

Commit 9866d14

Browse files
committed
csky: Add support for restartable sequence
Copied and adapted from vincent's patch, but modified for csky. ref: https://lore.kernel.org/linux-riscv/[email protected]/raw Add calls to rseq_signal_deliver(), rseq_handle_notify_resume() and rseq_syscall() to introduce RSEQ support. 1. Call the rseq_handle_notify_resume() function on return to userspace if TIF_NOTIFY_RESUME thread flag is set. 2. Call the rseq_signal_deliver() function to fixup on the pre-signal frame when a signal is delivered on top of a restartable sequence critical section. 3. Check that system calls are not invoked from within rseq critical sections by invoking rseq_signal() from ret_from_syscall(). With CONFIG_DEBUG_RSEQ, such behavior results in termination of the process with SIGSEGV. Signed-off-by: Guo Ren <[email protected]>
1 parent bfe47f3 commit 9866d14

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

arch/csky/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ config CSKY
4949
select HAVE_PERF_USER_STACK_DUMP
5050
select HAVE_DMA_CONTIGUOUS
5151
select HAVE_REGS_AND_STACK_ACCESS_API
52+
select HAVE_RSEQ
5253
select HAVE_STACKPROTECTOR
5354
select HAVE_SYSCALL_TRACEPOINTS
5455
select MAY_HAVE_SPARSE_IRQ

arch/csky/kernel/entry.S

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ tlbop_end 1
128128
ENTRY(csky_systemcall)
129129
SAVE_ALL TRAP0_SIZE
130130
zero_fp
131-
131+
#ifdef CONFIG_RSEQ_DEBUG
132+
mov a0, sp
133+
jbsr rseq_syscall
134+
#endif
132135
psrset ee, ie
133136

134137
lrw r11, __NR_syscalls

arch/csky/kernel/signal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
175175
sigset_t *oldset = sigmask_to_save();
176176
int ret;
177177

178+
rseq_signal_deliver(ksig, regs);
179+
178180
/* Are we from a system call? */
179181
if (in_syscall(regs)) {
180182
/* Avoid additional syscall restarting via ret_from_exception */
@@ -258,5 +260,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
258260
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
259261
clear_thread_flag(TIF_NOTIFY_RESUME);
260262
tracehook_notify_resume(regs);
263+
rseq_handle_notify_resume(NULL, regs);
261264
}
262265
}

0 commit comments

Comments
 (0)