History

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.

Arnd Bergmann committed 2 years ago

Commit 3db80c91 parent 77122bf9 files · +40 −44Browse files

Unified · Split

9 files
  1. arch/riscv/include/asm/Kbuild +3 −0
  2. arch/riscv/include/asm/syscall_table.h +7 −0
  3. arch/riscv/include/asm/unistd.h +8 −5
  4. arch/riscv/include/uapi/asm/Kbuild +2 −0
  5. arch/riscv/include/uapi/asm/unistd.h +5 −35
  6. arch/riscv/kernel/Makefile.syscalls +4 −0
  7. arch/riscv/kernel/compat_syscall_table.c +4 −2
  8. arch/riscv/kernel/syscall_table.c +4 −2
  9. scripts/syscall.tbl +3 −0
arch/riscv/include/asm/Kbuild+3−0
@@ -1,4 +1,7 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2syscall-y += syscall_table_32.h
3syscall-y += syscall_table_64.h
4
2generic-y += early_ioremap.h5generic-y += early_ioremap.h
3generic-y += flat.h6generic-y += flat.h
4generic-y += kvm_para.h7generic-y += kvm_para.h
arch/riscv/include/asm/syscall_table.h+7−0
@@ -0,0 +1,7 @@
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
arch/riscv/include/asm/unistd.h+8−5
@@ -3,11 +3,6 @@ · 2 unmodified lines
3 * Copyright (C) 2012 Regents of the University of California3 * 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#define __ARCH_WANT_SYS_CLONE6#define __ARCH_WANT_SYS_CLONE
12 7
13#ifdef CONFIG_COMPAT8#ifdef CONFIG_COMPAT
@@ -21,6 +16,14 @@ · 7 unmodified lines
21#define __ARCH_WANT_COMPAT_FADVISE64_6416#define __ARCH_WANT_COMPAT_FADVISE64_64
22#endif17#endif
23 18
19#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)
20#define __ARCH_WANT_NEW_STAT
21#define __ARCH_WANT_SET_GET_RLIMIT
22#endif /* __LP64__ */
23
24#define __ARCH_WANT_MEMFD_SECRET
25
26
24#include <uapi/asm/unistd.h>27#include <uapi/asm/unistd.h>
25 28
26#define NR_syscalls (__NR_syscalls)29#define NR_syscalls (__NR_syscalls)
arch/riscv/include/uapi/asm/Kbuild+2−0
@@ -1 +1,3 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2syscall-y += unistd_32.h
3syscall-y += unistd_64.h
arch/riscv/include/uapi/asm/unistd.h+5−35
@@ -14,40 +14,10 @@ · 13 unmodified lines
14 * You should have received a copy of the GNU General Public License14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.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#if __BITS_PER_LONG == 64
19#define __ARCH_WANT_NEW_STAT20#include <asm/unistd_64.h>
20#define __ARCH_WANT_SET_GET_RLIMIT21#else
21#endif /* __LP64__ */22#include <asm/unistd_32.h>
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)
43#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#endif23#endif
53__SYSCALL(__NR_riscv_hwprobe, sys_riscv_hwprobe)
arch/riscv/kernel/Makefile.syscalls+4−0
@@ -0,0 +1,4 @@
1# SPDX-License-Identifier: GPL-2.0
2
3syscall_abis_32 += riscv memfd_secret
4syscall_abis_64 += riscv newstat rlimit memfd_secret
arch/riscv/kernel/compat_syscall_table.c+4−2
@@ -8,9 +8,11 @@ · 7 unmodified lines
8#include <asm-generic/syscalls.h>8#include <asm-generic/syscalls.h>
9#include <asm/syscall.h>9#include <asm/syscall.h>
10 10
11#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
12
11#undef __SYSCALL13#undef __SYSCALL
12#define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *);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#undef __SYSCALL17#undef __SYSCALL
16#define __SYSCALL(nr, call) [nr] = __riscv_##call,18#define __SYSCALL(nr, call) [nr] = __riscv_##call,
@@ -19,5 +21,5 @@ asmlinkage long compat_sys_rt_sigreturn(void); · 2 unmodified lines
19 21
20void * const compat_sys_call_table[__NR_syscalls] = {22void * const compat_sys_call_table[__NR_syscalls] = {
21 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,23 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,
22#include <asm/unistd.h>24#include <asm/syscall_table_32.h>
23};25};
arch/riscv/kernel/syscall_table.c+4−2
@@ -9,14 +9,16 @@ · 8 unmodified lines
9#include <asm-generic/syscalls.h>9#include <asm-generic/syscalls.h>
10#include <asm/syscall.h>10#include <asm/syscall.h>
11 11
12#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
13
12#undef __SYSCALL14#undef __SYSCALL
13#define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *);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#undef __SYSCALL18#undef __SYSCALL
17#define __SYSCALL(nr, call) [nr] = __riscv_##call,19#define __SYSCALL(nr, call) [nr] = __riscv_##call,
18 20
19void * const sys_call_table[__NR_syscalls] = {21void * const sys_call_table[__NR_syscalls] = {
20 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,22 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,
21#include <asm/unistd.h>23#include <asm/syscall_table.h>
22};24};
scripts/syscall.tbl+3−0
@@ -301,6 +301,9 @@ · 300 unmodified lines
301 301
302244 or1k or1k_atomic sys_or1k_atomic302244 or1k or1k_atomic sys_or1k_atomic
303 303
304258 riscv riscv_hwprobe sys_riscv_hwprobe
305259 riscv riscv_flush_icache sys_riscv_flush_icache
306
304260 time32 wait4 sys_wait4 compat_sys_wait4307260 time32 wait4 sys_wait4 compat_sys_wait4
305260 64 wait4 sys_wait4308260 64 wait4 sys_wait4
306261 common prlimit64 sys_prlimit64309261 common prlimit64 sys_prlimit64