syscalls: Add a shared table for all archs
Subsystems (4)
v2 cover syscalls: Add a shared table for all archs
While implementing a new syscall, we need to wire up it's number to the arch table. Since syscall number 403, all architectures are on sync regarding the number (except alpha), which make things a lot easier but more repetitive as well. Have a look at commit b36d4b6aa88 ("arch: hookup listns() system call"), with 15 lines of mostly:
+470 common listns sys_listns
There's already a "common" table shared with a bunch of archs at scripts/syscall.tbl, but due to historical reasons some archs will never be able to move to this table and share all the numbers.
The generic table starts from 403 (clock_gettime64), the first common syscall. The scripts are adapted to x86 specifics, like not generating the compat entry point for x86_64 and placing x86_x32 things in the proper order. x32 is likely to be dropped from Linux soon but for the moment I left the support there. If this sounds good, next revision I can add the docs bits too.
I've tested this with x86 and arm64, by comparing the syscalls_*.h and unistd_*.h files generated before and after this patchset and they are identical.
Thanks!
André
Changes in v2:
- Managed to move to the real first common syscall: 403 (clock_gettime64)
- Added -no-compat option to be used with x86_64
- v1: https://patch.msgid.link/[email protected]
---
André Almeida (4):
syscalls: Create unified partial table for all archs
syscalls: Add support for x86_x32 for the common syscall table
x86: Use common syscall table
scripts/syscall.tbl: Use the common table
arch/arm64/tools/syscall_32.tbl | 68 ---------------------------- arch/x86/entry/syscalls/Makefile | 16 ++++--- arch/x86/entry/syscalls/syscall_32.tbl | 68 ---------------------------- arch/x86/entry/syscalls/syscall_64.tbl | 48 -------------------- scripts/Makefile.asm-headers | 4 +- scripts/syscall.tbl | 68 ---------------------------- scripts/syscall_common.tbl | 72 +++++++++++++++++++++++++++++ scripts/syscallhdr.sh | 83 ++++++++++++++++++++++++++++------ scripts/syscalltbl.sh | 35 +++++++++++--- 9 files changed, 181 insertions(+), 281 deletions(-)
---
base-commit: af5e34a41cd607c00ef752e00331736570992354
change-id: 20260724-tonyk-syscall_table-928bbb1b26bb
Best regards,
Signature · 1 line
André Almeida <[email protected]>
RFC PATCH v2 1/4 syscalls: Create unified partial table for all archs
To take advantage of the subset of syscall numbers that are guaranteed to be shared, create a new table and adapt generation scripts to use it. In that way, every new syscall can be added to a single file.
--- scripts/syscall_common.tbl | 72 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/syscallhdr.sh | 57 +++++++++++++++++++++++++++--------- scripts/syscalltbl.sh | 35 +++++++++++++++++----- 3 files changed, 143 insertions(+), 21 deletions(-)
scripts/syscall_common.tbl new file +72 -0
@@ -0,0 +1,72 @@ +# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +# +# syscall numbers shared by architectures + +403 32 clock_gettime64 sys_clock_gettime +404 32 clock_settime64 sys_clock_settime +405 32 clock_adjtime64 sys_clock_adjtime +406 32 clock_getres_time64 sys_clock_getres +407 32 clock_nanosleep_time64 sys_clock_nanosleep +408 32 timer_gettime64 sys_timer_gettime +409 32 timer_settime64 sys_timer_settime +410 32 timerfd_gettime64 sys_timerfd_gettime +411 32 timerfd_settime64 sys_timerfd_settime +412 32 utimensat_time64 sys_utimensat +413 32 pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 +414 32 ppoll_time64 sys_ppoll compat_sys_ppoll_time64 +416 32 io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 +417 32 recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 +418 32 mq_timedsend_time64 sys_mq_timedsend +419 32 mq_timedreceive_time64 sys_mq_timedreceive +420 32 semtimedop_time64 sys_semtimedop +421 32 rt_sigtimedwait_time64 sys_rt_sigtimedwait compat_sys_rt_sigtimedwait_time64 +422 32 futex_time64 sys_futex +423 32 sched_rr_get_interval_time64 sys_sched_rr_get_interval +424 common pidfd_send_signal sys_pidfd_send_signal +425 common io_uring_setup sys_io_uring_setup +426 common io_uring_enter sys_io_uring_enter +427 common io_uring_register sys_io_uring_register +428 common open_tree sys_open_tree +429 common move_mount sys_move_mount +430 common fsopen sys_fsopen +431 common fsconfig sys_fsconfig +432 common fsmount sys_fsmount +433 common fspick sys_fspick +434 common pidfd_open sys_pidfd_open +435 common clone3 sys_clone3 +436 common close_range sys_close_range +437 common openat2 sys_openat2 +438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 +440 common process_madvise sys_process_madvise +441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr +443 common quotactl_fd sys_quotactl_fd +444 common landlock_create_ruleset sys_landlock_create_ruleset +445 common landlock_add_rule sys_landlock_add_rule +446 common landlock_restrict_self sys_landlock_restrict_self +447 memfd_secret memfd_secret sys_memfd_secret +448 common process_mrelease sys_process_mrelease +449 common futex_waitv sys_futex_waitv +450 common set_mempolicy_home_node sys_set_mempolicy_home_node +451 common cachestat sys_cachestat +452 common fchmodat2 sys_fchmodat2 +453 common map_shadow_stack sys_map_shadow_stack +454 common futex_wake sys_futex_wake +455 common futex_wait sys_futex_wait +456 common futex_requeue sys_futex_requeue +457 common statmount sys_statmount +458 common listmount sys_listmount +459 common lsm_get_self_attr sys_lsm_get_self_attr +460 common lsm_set_self_attr sys_lsm_set_self_attr +461 common lsm_list_modules sys_lsm_list_modules +462 common mseal sys_mseal +463 common setxattrat sys_setxattrat +464 common getxattrat sys_getxattrat +465 common listxattrat sys_listxattrat +466 common removexattrat sys_removexattrat +467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr +470 common listns sys_listns +471 common rseq_slice_yield sys_rseq_slice_yield
scripts/syscallhdr.sh +43 -14
96 lines not on this page · raw message
scripts/syscalltbl.sh +28 -7
@@ -16,18 +16,23 @@ set -e usage() { - echo >&2 "usage: $0 [--abis ABIS] INFILE OUTFILE" >&2 + echo >&2 "usage: $0 [--abis ABIS] [--common-tbl] [--no-compat] INFILE OUTFILE" >&2 echo >&2 echo >&2 " INFILE input syscall table" echo >&2 " OUTFILE output header file" echo >&2 echo >&2 "options:" echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)" + echo >&2 " --common-tbl Use the common syscall number table" + echo >&2 " --no-compat Don't generated the compat version" exit 1 } # default unless specified by options abis= +common_tbl= +no_compat= +COMMON_TBL_PATH="../scripts/syscall_common.tbl" while [ $# -gt 0 ] do
@@ -35,6 +40,12 @@ do --abis) abis=$(echo "($2)" | tr ',' '|') shift 2;; + --common-tbl) + common_tbl=1 + shift 1;; + --no-compat) + no_compat=1 + shift 1;; -*) echo "$1: unknown option" >&2 usage;;
@@ -52,12 +63,14 @@ outfile="$2" nxt=0 -grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { +# gen_tbl(infile) +gen_tbl() { + input=$1 while read nr abi name native compat noreturn; do if [ $nxt -gt $nr ]; then - echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2 + echo "error: $input: syscall table is not sorted or duplicates the same syscall number" >&2 exit 1 fi
@@ -66,13 +79,13 @@ grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { nxt=$((nxt + 1)) done - if [ "$compat" = "-" ]; then + if [ "$compat" = "-" ] || [ -n "$no_compat" ]; then unset compat fi if [ -n "$noreturn" ]; then if [ "$noreturn" != "noreturn" ]; then - echo "error: $infile: invalid string \"$noreturn\" in 'noreturn' column" + echo "error: $input: invalid string \"$noreturn\" in 'noreturn' column" exit 1 fi if [ -n "$compat" ]; then
@@ -88,5 +101,13 @@ grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { echo "__SYSCALL($nr, sys_ni_syscall)" fi nxt=$((nr + 1)) - done -} > "$outfile" + + done < <(grep -E "^[0-9]+[[:space:]]+$abis" "$input") + +} + +gen_tbl $infile > "$outfile" + +if [ -n "$common_tbl" ]; then + gen_tbl $COMMON_TBL_PATH >> "$outfile" +fi
Signature · 1 line
2.55.0
Re: [PATCH RFC v2 1/4] syscalls: Create unified partial table for all archs
scripts/syscalltbl.sh line 28
Quoted 6 lines · André Almeida
(quoted diff) +0
-0echo >&2 "options:" echo >&2 " --abis ABIS ABI(s) to handle (By default, alllines are handled)"
scripts/syscalltbl.sh +2
-0+ echo >&2 " --common-tbl Use the common syscall number table" + echo >&2 " --no-compat Don't generated the compat version" exit 1
You don't explain what the --no-compat flag is good for.
I would hope we can avoid adding even more flags here since there may be other (external) scripts that process the same data and that need to stay in sync.
Quoted 1 line
+COMMON_TBL_PATH="../scripts/syscall_common.tbl"
Hardcoding the path here means the script can no longer work outside of the kernel tree. Maybe you can you combine this with the --common-tbl argument to pass the file name?
Arnd
RFC PATCH v2 2/4 syscalls: Add support for x86_x32 for the common syscall table
In reply to André Almeidax86_x32 has a peculiar ordering: first, goes the x86 syscalls. Then, the shared syscall numbers from the common table, and finally the x86_x32 syscall numbers. Adapt syscallhdr.sh script to take this into account.
Let's hope that x32 is deprecated before the syscall table reaches syscall 512, to avoid making the shared table more confusing.
--- scripts/syscallhdr.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
scripts/syscallhdr.sh +31 -3
@@ -72,6 +72,12 @@ fi infile="$1" outfile="$2" +is_x32= + +if [[ "$abis" == *"x32"* ]]; then + is_x32=1 +fi + guard=_UAPI_ASM_$(basename "$outfile" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g')
@@ -116,10 +122,32 @@ gen_hdr() { emit_start_guard > $outfile -gen_hdr $infile >> $outfile +# x32 has a special ordering. We need to get first the common numbers from x86 +# table, then the common numbers from scripts/syscall_common.tbl and finally the +# x32 numbers +if [ -n "$is_x32" ]; then + + abis="${abis//x32|/}" + abis="${abis//|x32/}" + abis="${abis//x32/}" + + if [[ $abis != "()" ]]; then + gen_hdr $infile >> $outfile + + if [ -n "$common_tbl" ]; then + gen_hdr $COMMON_TBL_PATH >> "$outfile" + fi + fi + + abis="(x32)" + + gen_hdr $infile >> "$outfile" +else + gen_hdr $infile >> $outfile -if [ -n "$common_tbl" ]; then - gen_hdr $COMMON_TBL_PATH >> "$outfile" + if [ -n "$common_tbl" ]; then + gen_hdr $COMMON_TBL_PATH >> "$outfile" + fi fi emit_nr $(($max + 1)) $prefix >> $outfile
Signature · 1 line
2.55.0
RFC PATCH v2 3/4 x86: Use common syscall table
In reply to André AlmeidaUse common syscall table and drop the shared numbers from the x86 tables.
--- arch/x86/entry/syscalls/Makefile | 16 ++++---- arch/x86/entry/syscalls/syscall_32.tbl | 68 ---------------------------------- arch/x86/entry/syscalls/syscall_64.tbl | 48 ------------------------ 3 files changed, 9 insertions(+), 123 deletions(-)
arch/x86/entry/syscalls/Makefile +9 -7
@@ -15,30 +15,31 @@ prefix := quiet_cmd_syshdr = SYSHDR $@ cmd_syshdr = $(CONFIG_SHELL) $(syshdr) --abis $(abis) --emit-nr \ + --common-tbl \ $(if $(offset),--offset $(offset)) \ $(if $(prefix),--prefix $(prefix)) \ $< $@ quiet_cmd_systbl = SYSTBL $@ - cmd_systbl = $(CONFIG_SHELL) $(systbl) --abis $(abis) $< $@ + cmd_systbl = $(CONFIG_SHELL) $(systbl) --abis $(abis) --common-tbl $(no-compat) $< $@ quiet_cmd_hypercalls = HYPERCALLS $@ cmd_hypercalls = $(CONFIG_SHELL) '$<' $@ $(filter-out $<, $(real-prereqs)) -$(uapi)/unistd_32.h: abis := i386 +$(uapi)/unistd_32.h: abis := common,i386,memfd_secret,32 $(uapi)/unistd_32.h: $(syscall32) $(syshdr) FORCE $(call if_changed,syshdr) -$(out)/unistd_32_ia32.h: abis := i386 +$(out)/unistd_32_ia32.h: abis := common,i386,memfd_secret,32 $(out)/unistd_32_ia32.h: prefix := ia32_ $(out)/unistd_32_ia32.h: $(syscall32) $(syshdr) FORCE $(call if_changed,syshdr) -$(uapi)/unistd_x32.h: abis := common,x32 +$(uapi)/unistd_x32.h: abis := common,x32,memfd_secret $(uapi)/unistd_x32.h: offset := __X32_SYSCALL_BIT $(uapi)/unistd_x32.h: $(syscall64) $(syshdr) FORCE $(call if_changed,syshdr) -$(uapi)/unistd_64.h: abis := common,64 +$(uapi)/unistd_64.h: abis := common,64,memfd_secret $(uapi)/unistd_64.h: $(syscall64) $(syshdr) FORCE $(call if_changed,syshdr)
@@ -47,10 +48,11 @@ $(out)/unistd_64_x32.h: prefix := x32_ $(out)/unistd_64_x32.h: $(syscall64) $(syshdr) FORCE $(call if_changed,syshdr) -$(out)/syscalls_32.h: abis := i386 +$(out)/syscalls_32.h: abis := common,i386,memfd_secret,32 $(out)/syscalls_32.h: $(syscall32) $(systbl) FORCE $(call if_changed,systbl) -$(out)/syscalls_64.h: abis := common,64 +$(out)/syscalls_64.h: abis := common,64,memfd_secret +$(out)/syscalls_64.h: no-compat:= --no-compat $(out)/syscalls_64.h: $(syscall64) $(systbl) FORCE $(call if_changed,systbl) $(out)/syscalls_x32.h: abis := common,x32
arch/x86/entry/syscalls/syscall_32.tbl +0 -68
71 lines not on this page · raw message
arch/x86/entry/syscalls/syscall_64.tbl +0 -48
54 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC PATCH v2 4/4 scripts/syscall.tbl: Use the common table
In reply to André AlmeidaUse the common syscall number table and drop the shared numbers from the table.
--- arch/arm64/tools/syscall_32.tbl | 68 ----------------------------------------- scripts/Makefile.asm-headers | 4 +-- scripts/syscall.tbl | 68 ----------------------------------------- 3 files changed, 2 insertions(+), 138 deletions(-)
arch/arm64/tools/syscall_32.tbl +0 -68
@@ -415,71 +415,3 @@ 400 common migrate_pages sys_migrate_pages 401 common kexec_file_load sys_kexec_file_load # 402 is unused -403 common clock_gettime64 sys_clock_gettime -404 common clock_settime64 sys_clock_settime -405 common clock_adjtime64 sys_clock_adjtime -406 common clock_getres_time64 sys_clock_getres -407 common clock_nanosleep_time64 sys_clock_nanosleep -408 common timer_gettime64 sys_timer_gettime -409 common timer_settime64 sys_timer_settime -410 common timerfd_gettime64 sys_timerfd_gettime -411 common timerfd_settime64 sys_timerfd_settime -412 common utimensat_time64 sys_utimensat -413 common pselect6_time64 sys_pselect6 compat_sys_pselect6_time64 -414 common ppoll_time64 sys_ppoll compat_sys_ppoll_time64 -416 common io_pgetevents_time64 sys_io_pgetevents compat_sys_io_pgetevents_time64 -417 common recvmmsg_time64 sys_recvmmsg compat_sys_recvmmsg_time64 -418 common mq_timedsend_time64 sys_mq_timedsend -419 common mq_timedreceive_time64 sys_mq_timedreceive -420 common semtimedop_time64 sys_semtimedop -421 common rt_sigtimedwait_time64 sys_rt_sigtimedwait compat_sys_rt_sigtimedwait_time64 -422 common futex_time64 sys_futex -423 common sched_rr_get_interval_time64 sys_sched_rr_get_interval -424 common pidfd_send_signal sys_pidfd_send_signal -425 common io_uring_setup sys_io_uring_setup -426 common io_uring_enter sys_io_uring_enter -427 common io_uring_register sys_io_uring_register -428 common open_tree sys_open_tree -429 common move_mount sys_move_mount -430 common fsopen sys_fsopen -431 common fsconfig sys_fsconfig -432 common fsmount sys_fsmount -433 common fspick sys_fspick -434 common pidfd_open sys_pidfd_open -435 common clone3 sys_clone3 -436 common close_range sys_close_range -437 common openat2 sys_openat2 -438 common pidfd_getfd sys_pidfd_getfd -439 common faccessat2 sys_faccessat2 -440 common process_madvise sys_process_madvise -441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 -442 common mount_setattr sys_mount_setattr -443 common quotactl_fd sys_quotactl_fd -444 common landlock_create_ruleset sys_landlock_create_ruleset -445 common landlock_add_rule sys_landlock_add_rule -446 common landlock_restrict_self sys_landlock_restrict_self -# 447 reserved for memfd_secret -448 common process_mrelease sys_process_mrelease -449 common futex_waitv sys_futex_waitv -450 common set_mempolicy_home_node sys_set_mempolicy_home_node -451 common cachestat sys_cachestat -452 common fchmodat2 sys_fchmodat2 -453 common map_shadow_stack sys_map_shadow_stack -454 common futex_wake sys_futex_wake -455 common futex_wait sys_futex_wait -456 common futex_requeue sys_futex_requeue -457 common statmount sys_statmount -458 common listmount sys_listmount -459 common lsm_get_self_attr sys_lsm_get_self_attr -460 common lsm_set_self_attr sys_lsm_set_self_attr -461 common lsm_list_modules sys_lsm_list_modules -462 common mseal sys_mseal -463 common setxattrat sys_setxattrat -464 common getxattrat sys_getxattrat -465 common listxattrat sys_listxattrat -466 common removexattrat sys_removexattrat -467 common open_tree_attr sys_open_tree_attr -468 common file_getattr sys_file_getattr -469 common file_setattr sys_file_setattr -470 common listns sys_listns -471 common rseq_slice_yield sys_rseq_slice_yield
scripts/Makefile.asm-headers +2 -2
@@ -58,14 +58,14 @@ quiet_cmd_remove = REMOVE $(unwanted) cmd_remove = rm -f $(unwanted) quiet_cmd_syshdr = SYSHDR $@ - cmd_syshdr = $(CONFIG_SHELL) $(syshdr) \ + cmd_syshdr = $(CONFIG_SHELL) $(syshdr) --common-tbl \ $(if $(syshdr-args-$*),$(syshdr-args-$*),$(syshdr-args)) \ $(if $(syscall_compat),--prefix "compat$*_") \ --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ $< $@ quiet_cmd_systbl = SYSTBL $@ - cmd_systbl = $(CONFIG_SHELL) $(systbl) \ + cmd_systbl = $(CONFIG_SHELL) $(systbl) --common-tbl \ $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \ --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ $< $@
scripts/syscall.tbl +0 -68
71 lines not on this page · raw message
Signature · 1 line
2.55.0
Quoted 5 lines · André Almeida
The generic table starts from 403 (
clock_gettime64), the first common syscall. The scripts are adapted to x86 specifics, like not generating the compat entry point forx86_64and placingx86_x32things in the proper order. x32 is likely to be dropped from Linux soon but for the moment I left the support there. If this sounds good, next revision I can add the docs bits too.
It may be easier to skip x32/x86-64 for the moment and focus on the architectures that we know need small changes (mips, powerpc, alpha).
The patch at
https://lore.kernel.org/all/[email protected]/
still hasn't been picked up yet. If your series is done before we actually remove x32, we may still need to add a temporary workaround for it, but it would be easier to avoid that altogether by waiting a bit.
Quoted 3 lines
I've tested this with x86 and arm64, by comparing the syscalls_*.h and unistd_*.h files generated before and after this patchset and they are identical.
I've had another look at what I tried previously, here is the list of things we have to figure out to do this properly across all architectures:
- separate offsets for base and common table on alpha. Maybe we can just process the two tables separately here and combine the output files afterwards?
- special __sys_clone3 entry points on alpha, m68k, mips, parisc and sparc.
- combine mips n32/n64 tables into a single file with regular use of compat entries for n32, in order to handle compat entry for the common calls (epoll_pwait2, pselect_time64, ppoll_time64, io_pgetevents_time64, recvmmsg_time64, rt_sigtimedwait_time64)
- come up with a solution for nospu syscalls on powerpc (clone3, set_mempolicy_home_node, rseq_slice_yield). Possibly dropping support for spu syscalls entirely, making all common syscalls implicitly nospu, incorporating this in the common table, or handling this in the syscall implementation where necessary.
note that newlib still supports spu syscalls, but only lists numbers up to __NR_sync_file_range2 (#308). gcc-10 and higher no longer support SPU at all.
Arnd