Re: [RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections
Hi Dave, [auto build test ERROR on v4.3-rc6 -- if it's inappropriate base, please suggest rules for selecting the more suitable base] url: https://github.com/0day-ci/linux/commits/Dave-Watson/restartable-sequences-benchmarks/20151023-020939 config: openrisc-allmodconfig (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=openrisc All errors (new ones prefixed by >>): In file included from include/asm-generic/unistd.h:1:0, from arch/openrisc/include/uapi/asm/unistd.h:26, from arch/openrisc/kernel/sys_call_table.c:27: >> include/uapi/asm-generic/unistd.h:717:1: error: 'sys_restartable_sequences' >> undeclared here (not in a function) vim +/sys_restartable_sequences +717 include/uapi/asm-generic/unistd.h 711 __SC_COMP(__NR_execveat, sys_execveat, compat_sys_execveat) 712 #define __NR_userfaultfd 282 713 __SYSCALL(__NR_userfaultfd, sys_userfaultfd) 714 #define __NR_membarrier 283 715 __SYSCALL(__NR_membarrier, sys_membarrier) 716 #define __NR_restartable_sequences 284 > 717 __SYSCALL(__NR_restartable_sequences, sys_restartable_sequences) 718 719 #undef __NR_syscalls 720 #define __NR_syscalls 285 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: Binary data
Re: [RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections
Hi Dave, [auto build test WARNING on v4.3-rc6 -- if it's inappropriate base, please suggest rules for selecting the more suitable base] url: https://github.com/0day-ci/linux/commits/Dave-Watson/restartable-sequences-benchmarks/20151023-020939 reproduce: # apt-get install sparse make ARCH=x86_64 allmodconfig make C=1 CF=-D__CHECK_ENDIAN__ sparse warnings: (new ones prefixed by >>) include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got } include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) -- include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got } -- mm/page_alloc.c:6010:1: sparse: directive in argument list mm/page_alloc.c:6012:1: sparse: directive in argument list mm/page_alloc.c:6019:1: sparse: directive in argument list mm/page_alloc.c:6021:1: sparse: directive in argument list include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got } -- include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got } include/linux/radix-tree.h:212:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) include/linux/radix-tree.h:196:16: sparse: incompatible types in comparison expression (different address spaces) -- mm/debug.c:176:1: sparse: directive in argument list mm/debug.c:178:1: sparse: directive in argument list mm/debug.c:187:1: sparse: directive in argument list mm/debug.c:189:1: sparse: directive in argument list mm/debug.c:190:1: sparse: directive in argument list mm/debug.c:192:1: sparse: directive in argument list mm/debug.c:194:1: sparse: directive in argument list mm/debug.c:196:1: sparse: directive in argument list mm/debug.c:197:1: sparse: directive in argument list mm/debug.c:199:1: sparse: directive in argument list mm/debug.c:200:1: sparse: directive in argument list mm/debug.c:202:1: sparse: directive in argument list mm/debug.c:206:1: sparse: directive in argument list mm/debug.c:208:1: sparse: directive in argument list mm/debug.c:221:1: sparse: directive in argument list mm/debug.c:223:1: sparse: directive in argument list mm/debug.c:224:1: sparse: directive in argument list mm/debug.c:226:1: sparse: directive in argument list mm/debug.c:228:1: sparse: directive in argument list mm/debug.c:230:1: sparse: directive in argument list mm/debug.c:231:1: sparse: directive in argument list mm/debug.c:233:1: sparse: directive in argument list mm/debug.c:234:1: sparse: directive in argument list mm/debug.c:236:1: sparse: directive in argument list include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at the end of type declaration include/linux/sched.h:1190:1: sparse: got } -- include/linux/sched.h:1189:34: sparse: Expected ) in function declarator include/linux/sched.h:1189:34: sparse: got ( >> builtin:0:0: sparse: expected ; at end of declaration include/linux/sched.h:1190:1: sparse: Expected ; at
[RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections
Introduce the notion of 'restartable sequence'. This is a user-defined range within which we guarantee user-execution will occur serially with respect to scheduling events such as migration or competition with other threads. Preemption, or other interruption within this region, results in control being transferred to a user-defined restart handler when rescheduled. This handler may arrange for the original operation to be retried, including potentially resynchronizing with dependent state that may have been updated in the interim. This may be used in combination with an in-memory cpu-id to allow user programs to implement cpu-local data-structures and primitives, without the use/overhead of any atomics. The kernel ABI generally consists of: - A critical region, with start, end and restart addresses - A (per-thread) memory location which will be kept current with its cpu The definition of the above is performed via a new syscall, SYSCALL_DEFINE5(restartable_sequences, int, op, int, flags, long, val1, long, val2, long, val3) There are currently 2 possible operations, 1) Configure the critical region(s) 2) Configure the per-thread cpu pointer [ See kernel/restartable_sequences.c for full documentation ] A thread that has not configured (2) will not be restarted when executing in (1). This patch introduces the general framework for configuration, as well as exposing the syscall. We minimally expose x86 as having support (even though the actual ABI is added by a subsequent patch) so that this can be compile tested in isolation. Ptrace is modified to avoid setting a breakpoint in the critical region, since doing so would always restart the critical section, and may not work correctly if the breakpoint is also the restart address. --- arch/Kconfig | 7 ++ arch/x86/Kconfig | 1 + fs/exec.c | 3 +- include/linux/sched.h | 39 ++ include/uapi/asm-generic/unistd.h | 4 +- init/Kconfig | 9 ++ kernel/Makefile | 2 +- kernel/fork.c | 1 + kernel/ptrace.c | 15 ++- kernel/restartable_sequences.c| 250 ++ kernel/sched/core.c | 5 + kernel/sched/sched.h | 3 + kernel/sys_ni.c | 3 + 13 files changed, 335 insertions(+), 7 deletions(-) create mode 100644 kernel/restartable_sequences.c diff --git a/arch/Kconfig b/arch/Kconfig index 4e949e5..93c18fa 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -241,6 +241,13 @@ config HAVE_REGS_AND_STACK_ACCESS_API declared in asm/ptrace.h For example the kprobes-based event tracer needs this API. +config HAVE_RESTARTABLE_SEQUENCE_SUPPORT + bool + depends on HAVE_REGS_AND_STACK_ACCESS_API + help + This symbol should be selected by an architecture if it supports an + implementation of restartable sequences. + config HAVE_CLK bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 96d058a..865e795 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -112,6 +112,7 @@ config X86 select HAVE_IOREMAP_PROT select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64 select HAVE_IRQ_TIME_ACCOUNTING + select HAVE_RESTARTABLE_SEQUENCE_SUPPORT select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP select HAVE_KERNEL_LZ4 diff --git a/fs/exec.c b/fs/exec.c index b06623a..aa94834 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -19,7 +19,7 @@ * current->executable is only used by the procfs. This allows a dispatch * table to check for several different types of binary formats. We keep * trying until we recognize the file or we run out of supported binary - * formats. + * formats. */ #include @@ -1596,6 +1596,7 @@ static int do_execveat_common(int fd, struct filename *filename, current->in_execve = 0; acct_update_integrals(current); task_numa_free(current); + rseq_clear_state_exec(current); free_bprm(bprm); kfree(pathbuf); putname(filename); diff --git a/include/linux/sched.h b/include/linux/sched.h index b7b9501..a7b6e24 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1182,6 +1182,31 @@ struct mempolicy; struct pipe_inode_info; struct uts_namespace; +#ifdef CONFIG_RESTARTABLE_SEQUENCES +struct restartable_sequence_section { + /* Start and end of an address space's critical section. */ + struct rb_node node; + void __user *crit_start, __user *crit_end, __user *crit_restart; +}; +struct restartable_sequence_state { + struct rb_root sections; + /* Thread's current CPU, typically in TLS. */ + int __user *cpu_pointer; + struct preempt_notifier notifier; +}; + +void rseq_clear_state_exec(struct task_struct *p); +unsigned long rseq_lookup(struct task_struct *p, unsigne
[RFC PATCH 1/3] restartable sequences: user-space per-cpu critical sections
Introduce the notion of 'restartable sequence'. This is a user-defined range within which we guarantee user-execution will occur serially with respect to scheduling events such as migration or competition with other threads. Preemption, or other interruption within this region, results in control being transferred to a user-defined restart handler when rescheduled. This handler may arrange for the original operation to be retried, including potentially resynchronizing with dependent state that may have been updated in the interim. This may be used in combination with an in-memory cpu-id to allow user programs to implement cpu-local data-structures and primitives, without the use/overhead of any atomics. The kernel ABI generally consists of: - A single (per-address space) critical region - A restart handler which pairs with the region above - A (per-thread) memory location which will be kept current with its cpu The definition of the above is performed via a new syscall, SYSCALL_DEFINE5(restartable_sequences, int, op, int, flags, long, val1, long, val2, long, val3) There are currently 2 possible operations, 1) Configure the critical region (and restart handler) 2) Configure the per-thread cpu pointer [ See kernel/restartable_sequences.c for full documentation ] A thread that has not configured (2) will not be restarted when executing in (1). Note that while the kernel only sees a single critical region, arbitrarily many sequences can be composed via multiplexing of the user-space restart handler. This patch introduces the general framework for configuration, as well as exposing the syscall. We minimally expose x86 as having support (even though the actual ABI is added by a subsequent patch) so that this can be compile tested in isolation. Signed-off-by: Paul Turner --- arch/Kconfig |7 + arch/x86/Kconfig |1 arch/x86/syscalls/syscall_64.tbl |1 fs/exec.c |1 include/linux/sched.h | 28 ++ include/uapi/asm-generic/unistd.h |5 + init/Kconfig |9 ++ kernel/Makefile |1 kernel/restartable_sequences.c| 185 + kernel/sched/core.c |4 + kernel/sched/sched.h |3 + kernel/sys_ni.c |3 + 12 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 kernel/restartable_sequences.c diff --git a/arch/Kconfig b/arch/Kconfig index a65eafb..fb31981 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -229,6 +229,13 @@ config HAVE_REGS_AND_STACK_ACCESS_API declared in asm/ptrace.h For example the kprobes-based event tracer needs this API. +config HAVE_RESTARTABLE_SEQUENCE_SUPPORT + bool + depends on HAVE_REGS_AND_STACK_ACCESS_API + help + This symbol should be selected by an architecture if it supports an + implementation of restartable sequences. + config HAVE_CLK bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 8fec044..9c9c92f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -67,6 +67,7 @@ config X86 select HAVE_EFFICIENT_UNALIGNED_ACCESS select USER_STACKTRACE_SUPPORT select HAVE_REGS_AND_STACK_ACCESS_API + select HAVE_RESTARTABLE_SEQUENCE_SUPPORT select HAVE_DMA_API_DEBUG select HAVE_KERNEL_GZIP select HAVE_KERNEL_BZIP2 diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl index 9ef32d5..1de5cbc 100644 --- a/arch/x86/syscalls/syscall_64.tbl +++ b/arch/x86/syscalls/syscall_64.tbl @@ -329,6 +329,7 @@ 320common kexec_file_load sys_kexec_file_load 321common bpf sys_bpf 32264 execveatstub_execveat +323common restartable_sequences sys_restartable_sequences # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/fs/exec.c b/fs/exec.c index 1977c2a..acd38f6 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1590,6 +1590,7 @@ static int do_execveat_common(int fd, struct filename *filename, current->in_execve = 0; acct_update_integrals(current); task_numa_free(current); + rseq_clear_state_exec(); free_bprm(bprm); kfree(pathbuf); putname(filename); diff --git a/include/linux/sched.h b/include/linux/sched.h index af0eeba..0540735 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1178,6 +1178,22 @@ struct mempolicy; struct pipe_inode_info; struct uts_namespace; +#ifdef CONFIG_RESTARTABLE_SEQUENCES +struct restartable_sequence_state { + /* Start and end of an address space's critical section. */ + void __user *crit_start, __user *crit_end; + /* Where preempted threads will be restarted. */ + void __user *crit_restart; + /* Thread's current CPU, typically in TLS. */ +