Commit bbde0152 authored by Palmer Dabbelt's avatar Palmer Dabbelt

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
parents 6ae1af9c 6d1a6f46
...@@ -101,6 +101,7 @@ config RISCV ...@@ -101,6 +101,7 @@ config RISCV
select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_FUNCTION_ARG_ACCESS_API
select HAVE_STACKPROTECTOR select HAVE_STACKPROTECTOR
select HAVE_SYSCALL_TRACEPOINTS select HAVE_SYSCALL_TRACEPOINTS
select HAVE_RSEQ
select IRQ_DOMAIN select IRQ_DOMAIN
select IRQ_FORCED_THREADING select IRQ_FORCED_THREADING
select MODULES_USE_ELF_RELA if MODULES select MODULES_USE_ELF_RELA if MODULES
......
...@@ -225,6 +225,10 @@ ret_from_syscall: ...@@ -225,6 +225,10 @@ ret_from_syscall:
* (If it was configured with SECCOMP_RET_ERRNO/TRACE) * (If it was configured with SECCOMP_RET_ERRNO/TRACE)
*/ */
ret_from_syscall_rejected: ret_from_syscall_rejected:
#ifdef CONFIG_DEBUG_RSEQ
move a0, sp
call rseq_syscall
#endif
/* Trace syscalls, but only if requested by the user. */ /* Trace syscalls, but only if requested by the user. */
REG_L t0, TASK_TI_FLAGS(tp) REG_L t0, TASK_TI_FLAGS(tp)
andi t0, t0, _TIF_SYSCALL_WORK andi t0, t0, _TIF_SYSCALL_WORK
......
...@@ -258,6 +258,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) ...@@ -258,6 +258,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
} }
} }
rseq_signal_deliver(ksig, regs);
/* Set up the stack frame */ /* Set up the stack frame */
ret = setup_rt_frame(ksig, oldset, regs); ret = setup_rt_frame(ksig, oldset, regs);
......
...@@ -207,6 +207,29 @@ unsigned int yield_mod_cnt, nr_abort; ...@@ -207,6 +207,29 @@ unsigned int yield_mod_cnt, nr_abort;
"addiu " INJECT_ASM_REG ", -1\n\t" \ "addiu " INJECT_ASM_REG ", -1\n\t" \
"bnez " INJECT_ASM_REG ", 222b\n\t" \ "bnez " INJECT_ASM_REG ", 222b\n\t" \
"333:\n\t" "333:\n\t"
#elif defined(__riscv)
#define RSEQ_INJECT_INPUT \
, [loop_cnt_1]"m"(loop_cnt[1]) \
, [loop_cnt_2]"m"(loop_cnt[2]) \
, [loop_cnt_3]"m"(loop_cnt[3]) \
, [loop_cnt_4]"m"(loop_cnt[4]) \
, [loop_cnt_5]"m"(loop_cnt[5]) \
, [loop_cnt_6]"m"(loop_cnt[6])
#define INJECT_ASM_REG "t1"
#define RSEQ_INJECT_CLOBBER \
, INJECT_ASM_REG
#define RSEQ_INJECT_ASM(n) \
"lw " INJECT_ASM_REG ", %[loop_cnt_" #n "]\n\t" \
"beqz " INJECT_ASM_REG ", 333f\n\t" \
"222:\n\t" \
"addi " INJECT_ASM_REG "," INJECT_ASM_REG ", -1\n\t" \
"bnez " INJECT_ASM_REG ", 222b\n\t" \
"333:\n\t"
#else #else
#error unsupported target #error unsupported target
......
This diff is collapsed.
...@@ -79,6 +79,8 @@ extern int __rseq_handled; ...@@ -79,6 +79,8 @@ extern int __rseq_handled;
#include <rseq-mips.h> #include <rseq-mips.h>
#elif defined(__s390__) #elif defined(__s390__)
#include <rseq-s390.h> #include <rseq-s390.h>
#elif defined(__riscv)
#include <rseq-riscv.h>
#else #else
#error unsupported target #error unsupported target
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment