Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv: convert to generic syscall table

The uapi/asm/unistd_{32,64}.h and asm/syscall_table_{32,64}.h headers can
now be generated from scripts/syscall.tbl, which makes this consistent
with the other architectures that have their own syscall.tbl.

riscv has two extra system call that gets added to scripts/syscall.tbl.

The newstat and rlimit entries in the syscall_abis_64 line are for system
calls that were part of the generic ABI when riscv64 got added but are
no longer enabled by default for new architectures. Both riscv32 and
riscv64 also implement memfd_secret, which is optional for all
architectures.

Unlike all the other 32-bit architectures, the time32 and stat64
sets of syscalls are not enabled on riscv32.

Both the user visible side of asm/unistd.h and the internal syscall
table in the kernel should have the same effective contents after this.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+40 -44
+3
arch/riscv/include/asm/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + syscall-y += syscall_table_32.h 3 + syscall-y += syscall_table_64.h 4 + 2 5 generic-y += early_ioremap.h 3 6 generic-y += flat.h 4 7 generic-y += kvm_para.h
+7
arch/riscv/include/asm/syscall_table.h
··· 1 + #include <asm/bitsperlong.h> 2 + 3 + #if __BITS_PER_LONG == 64 4 + #include <asm/syscall_table_64.h> 5 + #else 6 + #include <asm/syscall_table_32.h> 7 + #endif
+8 -5
arch/riscv/include/asm/unistd.h
··· 3 3 * Copyright (C) 2012 Regents of the University of California 4 4 */ 5 5 6 - /* 7 - * There is explicitly no include guard here because this file is expected to 8 - * be included multiple times. 9 - */ 10 - 11 6 #define __ARCH_WANT_SYS_CLONE 12 7 13 8 #ifdef CONFIG_COMPAT ··· 15 20 #define __ARCH_WANT_COMPAT_READAHEAD 16 21 #define __ARCH_WANT_COMPAT_FADVISE64_64 17 22 #endif 23 + 24 + #if defined(__LP64__) && !defined(__SYSCALL_COMPAT) 25 + #define __ARCH_WANT_NEW_STAT 26 + #define __ARCH_WANT_SET_GET_RLIMIT 27 + #endif /* __LP64__ */ 28 + 29 + #define __ARCH_WANT_MEMFD_SECRET 30 + 18 31 19 32 #include <uapi/asm/unistd.h> 20 33
+2
arch/riscv/include/uapi/asm/Kbuild
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 + syscall-y += unistd_32.h 3 + syscall-y += unistd_64.h
+5 -35
arch/riscv/include/uapi/asm/unistd.h
··· 14 14 * You should have received a copy of the GNU General Public License 15 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 16 */ 17 + #include <asm/bitsperlong.h> 17 18 18 - #if defined(__LP64__) && !defined(__SYSCALL_COMPAT) 19 - #define __ARCH_WANT_NEW_STAT 20 - #define __ARCH_WANT_SET_GET_RLIMIT 21 - #endif /* __LP64__ */ 22 - 23 - #define __ARCH_WANT_MEMFD_SECRET 24 - 25 - #include <asm-generic/unistd.h> 26 - 27 - /* 28 - * Allows the instruction cache to be flushed from userspace. Despite RISC-V 29 - * having a direct 'fence.i' instruction available to userspace (which we 30 - * can't trap!), that's not actually viable when running on Linux because the 31 - * kernel might schedule a process on another hart. There is no way for 32 - * userspace to handle this without invoking the kernel (as it doesn't know the 33 - * thread->hart mappings), so we've defined a RISC-V specific system call to 34 - * flush the instruction cache. 35 - * 36 - * __NR_riscv_flush_icache is defined to flush the instruction cache over an 37 - * address range, with the flush applying to either all threads or just the 38 - * caller. We don't currently do anything with the address range, that's just 39 - * in there for forwards compatibility. 40 - */ 41 - #ifndef __NR_riscv_flush_icache 42 - #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) 19 + #if __BITS_PER_LONG == 64 20 + #include <asm/unistd_64.h> 21 + #else 22 + #include <asm/unistd_32.h> 43 23 #endif 44 - __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache) 45 - 46 - /* 47 - * Allows userspace to query the kernel for CPU architecture and 48 - * microarchitecture details across a given set of CPUs. 49 - */ 50 - #ifndef __NR_riscv_hwprobe 51 - #define __NR_riscv_hwprobe (__NR_arch_specific_syscall + 14) 52 - #endif 53 - __SYSCALL(__NR_riscv_hwprobe, sys_riscv_hwprobe)
+4
arch/riscv/kernel/Makefile.syscalls
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + syscall_abis_32 += riscv memfd_secret 4 + syscall_abis_64 += riscv newstat rlimit memfd_secret
+4 -2
arch/riscv/kernel/compat_syscall_table.c
··· 8 8 #include <asm-generic/syscalls.h> 9 9 #include <asm/syscall.h> 10 10 11 + #define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat) 12 + 11 13 #undef __SYSCALL 12 14 #define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *); 13 - #include <asm/unistd.h> 15 + #include <asm/syscall_table_32.h> 14 16 15 17 #undef __SYSCALL 16 18 #define __SYSCALL(nr, call) [nr] = __riscv_##call, ··· 21 19 22 20 void * const compat_sys_call_table[__NR_syscalls] = { 23 21 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, 24 - #include <asm/unistd.h> 22 + #include <asm/syscall_table_32.h> 25 23 };
+4 -2
arch/riscv/kernel/syscall_table.c
··· 9 9 #include <asm-generic/syscalls.h> 10 10 #include <asm/syscall.h> 11 11 12 + #define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native) 13 + 12 14 #undef __SYSCALL 13 15 #define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *); 14 - #include <asm/unistd.h> 16 + #include <asm/syscall_table.h> 15 17 16 18 #undef __SYSCALL 17 19 #define __SYSCALL(nr, call) [nr] = __riscv_##call, 18 20 19 21 void * const sys_call_table[__NR_syscalls] = { 20 22 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, 21 - #include <asm/unistd.h> 23 + #include <asm/syscall_table.h> 22 24 };
+3
scripts/syscall.tbl
··· 301 301 302 302 244 or1k or1k_atomic sys_or1k_atomic 303 303 304 + 258 riscv riscv_hwprobe sys_riscv_hwprobe 305 + 259 riscv riscv_flush_icache sys_riscv_flush_icache 306 + 304 307 260 time32 wait4 sys_wait4 compat_sys_wait4 305 308 260 64 wait4 sys_wait4 306 309 261 common prlimit64 sys_prlimit64