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 @@
11 # SPDX-License-Identifier: GPL-2.0
2+syscall-y += syscall_table_32.h
3+syscall-y += syscall_table_64.h
4+
25 generic-y += early_ioremap.h
36 generic-y += flat.h
47 generic-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
33 * Copyright (C) 2012 Regents of the University of California
44 */
55
6−/*
7− * There is explicitly no include guard here because this file is expected to
8− * be included multiple times.
9− */
10−
116 #define __ARCH_WANT_SYS_CLONE
127
138 #ifdef CONFIG_COMPAT
@@ -21,6 +16,14 @@ · 7 unmodified lines
2116 #define __ARCH_WANT_COMPAT_FADVISE64_64
2217 #endif
2318
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+
2427 #include <uapi/asm/unistd.h>
2528
2629 #define NR_syscalls (__NR_syscalls)
arch/riscv/include/uapi/asm/Kbuild+2−0
@@ -1 +1,3 @@
11 # SPDX-License-Identifier: GPL-2.0
2+syscall-y += unistd_32.h
3+syscall-y += unistd_64.h
arch/riscv/include/uapi/asm/unistd.h+5−35
@@ -14,40 +14,10 @@ · 13 unmodified lines
1414 * You should have received a copy of the GNU General Public License
1515 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1616 */
17+#include <asm/bitsperlong.h>
1718
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)
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)
19+#if __BITS_PER_LONG == 64
20+#include <asm/unistd_64.h>
21+#else
22+#include <asm/unistd_32.h>
5223 #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+
3+syscall_abis_32 += riscv memfd_secret
4+syscall_abis_64 += riscv newstat rlimit memfd_secret
arch/riscv/kernel/compat_syscall_table.c+4−2
@@ -8,9 +8,11 @@ · 7 unmodified lines
88 #include <asm-generic/syscalls.h>
99 #include <asm/syscall.h>
1010
11+#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
12+
1113 #undef __SYSCALL
1214 #define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *);
13−#include <asm/unistd.h>
15+#include <asm/syscall_table_32.h>
1416
1517 #undef __SYSCALL
1618 #define __SYSCALL(nr, call) [nr] = __riscv_##call,
@@ -19,5 +21,5 @@ asmlinkage long compat_sys_rt_sigreturn(void); · 2 unmodified lines
1921
2022 void * const compat_sys_call_table[__NR_syscalls] = {
2123 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,
22−#include <asm/unistd.h>
24+#include <asm/syscall_table_32.h>
2325 };
arch/riscv/kernel/syscall_table.c+4−2
@@ -9,14 +9,16 @@ · 8 unmodified lines
99 #include <asm-generic/syscalls.h>
1010 #include <asm/syscall.h>
1111
12+#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
13+
1214 #undef __SYSCALL
1315 #define __SYSCALL(nr, call) asmlinkage long __riscv_##call(const struct pt_regs *);
14−#include <asm/unistd.h>
16+#include <asm/syscall_table.h>
1517
1618 #undef __SYSCALL
1719 #define __SYSCALL(nr, call) [nr] = __riscv_##call,
1820
1921 void * const sys_call_table[__NR_syscalls] = {
2022 [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall,
21−#include <asm/unistd.h>
23+#include <asm/syscall_table.h>
2224 };
scripts/syscall.tbl+3−0
@@ -301,6 +301,9 @@ · 300 unmodified lines
301301
302302 244 or1k or1k_atomic sys_or1k_atomic
303303
304+258 riscv riscv_hwprobe sys_riscv_hwprobe
305+259 riscv riscv_flush_icache sys_riscv_flush_icache
306+
304307 260 time32 wait4 sys_wait4 compat_sys_wait4
305308 260 64 wait4 sys_wait4
306309 261 common prlimit64 sys_prlimit64