Skip to content

Commit bbde015

Browse files
RISC-V: add support for restartable sequences
Add support for RSEQ, restartable sequences, for RISC-V. This also adds support for the related selftests. Note: the selftests require a linker with 3e7bd7f2414 ("RISC-V: Fix linker problems with tls copy relocs."), which was first released in 2.33 (from 2019). * palmer/riscv-rseq: rseq/selftests: Add support for RISC-V RISC-V: Add support for restartable sequence
2 parents 6ae1af9 + 6d1a6f4 commit bbde015

File tree

6 files changed

+709
-0
lines changed

6 files changed

+709
-0
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ config RISCV
101101
select HAVE_FUNCTION_ARG_ACCESS_API
102102
select HAVE_STACKPROTECTOR
103103
select HAVE_SYSCALL_TRACEPOINTS
104+
select HAVE_RSEQ
104105
select IRQ_DOMAIN
105106
select IRQ_FORCED_THREADING
106107
select MODULES_USE_ELF_RELA if MODULES

arch/riscv/kernel/entry.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ ret_from_syscall:
225225
* (If it was configured with SECCOMP_RET_ERRNO/TRACE)
226226
*/
227227
ret_from_syscall_rejected:
228+
#ifdef CONFIG_DEBUG_RSEQ
229+
move a0, sp
230+
call rseq_syscall
231+
#endif
228232
/* Trace syscalls, but only if requested by the user. */
229233
REG_L t0, TASK_TI_FLAGS(tp)
230234
andi t0, t0, _TIF_SYSCALL_WORK

arch/riscv/kernel/signal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
258258
}
259259
}
260260

261+
rseq_signal_deliver(ksig, regs);
262+
261263
/* Set up the stack frame */
262264
ret = setup_rt_frame(ksig, oldset, regs);
263265

tools/testing/selftests/rseq/param_test.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ unsigned int yield_mod_cnt, nr_abort;
207207
"addiu " INJECT_ASM_REG ", -1\n\t" \
208208
"bnez " INJECT_ASM_REG ", 222b\n\t" \
209209
"333:\n\t"
210+
#elif defined(__riscv)
211+
212+
#define RSEQ_INJECT_INPUT \
213+
, [loop_cnt_1]"m"(loop_cnt[1]) \
214+
, [loop_cnt_2]"m"(loop_cnt[2]) \
215+
, [loop_cnt_3]"m"(loop_cnt[3]) \
216+
, [loop_cnt_4]"m"(loop_cnt[4]) \
217+
, [loop_cnt_5]"m"(loop_cnt[5]) \
218+
, [loop_cnt_6]"m"(loop_cnt[6])
219+
220+
#define INJECT_ASM_REG "t1"
221+
222+
#define RSEQ_INJECT_CLOBBER \
223+
, INJECT_ASM_REG
224+
225+
#define RSEQ_INJECT_ASM(n) \
226+
"lw " INJECT_ASM_REG ", %[loop_cnt_" #n "]\n\t" \
227+
"beqz " INJECT_ASM_REG ", 333f\n\t" \
228+
"222:\n\t" \
229+
"addi " INJECT_ASM_REG "," INJECT_ASM_REG ", -1\n\t" \
230+
"bnez " INJECT_ASM_REG ", 222b\n\t" \
231+
"333:\n\t"
232+
210233

211234
#else
212235
#error unsupported target

0 commit comments

Comments
 (0)