]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
csky: Add support for restartable sequence
authorGuo Ren <guoren@linux.alibaba.com>
Tue, 5 Nov 2019 01:58:33 +0000 (09:58 +0800)
committerGuo Ren <guoren@linux.alibaba.com>
Sun, 8 Mar 2020 12:55:14 +0000 (20:55 +0800)
Copied and adapted from vincent's patch, but modified for csky.

ref:
https://lore.kernel.org/linux-riscv/1572919114-3886-3-git-send-email-vincent.chen@sifive.com/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 <guoren@linux.alibaba.com>
arch/csky/Kconfig
arch/csky/kernel/entry.S
arch/csky/kernel/signal.c

index 2dfd3fb07db96a407c16083b82cf4527ae9d0fd9..0e9b14367fa80bc10fe2d5b6313577fcd6cf8671 100644 (file)
@@ -49,6 +49,7 @@ config CSKY
        select HAVE_PERF_USER_STACK_DUMP
        select HAVE_DMA_CONTIGUOUS
        select HAVE_REGS_AND_STACK_ACCESS_API
+       select HAVE_RSEQ
        select HAVE_STACKPROTECTOR
        select HAVE_SYSCALL_TRACEPOINTS
        select MAY_HAVE_SPARSE_IRQ
index 00770632800005baebc0525a0eb887f48e118de6..0bde1d9fd2770ef01bc0b4917ac59cfaebab1da6 100644 (file)
@@ -128,7 +128,10 @@ tlbop_end 1
 ENTRY(csky_systemcall)
        SAVE_ALL TRAP0_SIZE
        zero_fp
-
+#ifdef CONFIG_RSEQ_DEBUG
+       mov     a0, sp
+       jbsr    rseq_syscall
+#endif
        psrset  ee, ie
 
        lrw     r11, __NR_syscalls
index 9b1b7c039ddf9c33ecf569c55b055b34de384ee3..3d6b728cbb725840f2639a1d1ad886d6f8fc6277 100644 (file)
@@ -175,6 +175,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
        sigset_t *oldset = sigmask_to_save();
        int ret;
 
+       rseq_signal_deliver(ksig, regs);
+
        /* Are we from a system call? */
        if (in_syscall(regs)) {
                /* Avoid additional syscall restarting via ret_from_exception */
@@ -258,5 +260,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
        if (thread_info_flags & _TIF_NOTIFY_RESUME) {
                clear_thread_flag(TIF_NOTIFY_RESUME);
                tracehook_notify_resume(regs);
+               rseq_handle_notify_resume(NULL, regs);
        }
 }