s390/syscalls: Switch to generic system call table generation

The s390 syscall.tbl format differs slightly from most others, and
therefore requires an s390 specific system call table generation
script.

With compat support gone use the opportunity to switch to generic
system call table generation. The abi for all 64 bit system calls is
now common, since there is no need to specify if system call entry
points are only for 64 bit anymore.

Furthermore create the system call table in C instead of assembler
code in order to get type checking for all system call functions
contained within the table.

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
This commit is contained in:
Heiko Carstens
2025-11-17 11:10:39 +01:00
parent f4e1f1b137
commit 4ac286c4a8
7 changed files with 424 additions and 746 deletions
+1 -2
View File
@@ -134,10 +134,9 @@ zfcpdump:
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
archheaders:
$(Q)$(MAKE) $(build)=$(syscalls) uapi
$(Q)$(MAKE) $(build)=$(syscalls) all
archprepare:
$(Q)$(MAKE) $(build)=$(syscalls) kapi
$(Q)$(MAKE) $(build)=$(tools) kapi $(extra_tools)
ifeq ($(KBUILD_EXTMOD),)
# We need to generate vdso-offsets.h before compiling certain files in kernel/.
+2 -1
View File
@@ -8,7 +8,8 @@
#define _ASM_S390_UNISTD_H_
#include <uapi/asm/unistd.h>
#include <asm/unistd_nr.h>
#define NR_syscalls (__NR_syscalls)
#define __ARCH_WANT_NEW_STAT
#define __ARCH_WANT_OLD_READDIR
-8
View File
@@ -606,11 +606,3 @@ SYM_DATA_START_LOCAL(daton_psw)
.quad PSW_KERNEL_BITS
.quad .Ldaton
SYM_DATA_END(daton_psw)
.section .rodata, "a"
.balign 8
#define SYSCALL(esame,emu) .quad __s390x_ ## esame
SYM_DATA_START(sys_call_table)
#include <asm/syscall_table.h>
SYM_DATA_END(sys_call_table)
#undef SYSCALL
+10
View File
@@ -39,6 +39,16 @@
#include "entry.h"
#define __SYSCALL(nr, sym) long __s390x_##sym(struct pt_regs *);
#include <asm/syscall_table.h>
#undef __SYSCALL
#define __SYSCALL(nr, sym) [nr] = (__s390x_##sym),
const sys_call_ptr_t sys_call_table[__NR_syscalls] = {
#include <asm/syscall_table.h>
};
#undef __SYSCALL
#ifdef CONFIG_SYSVIPC
/*
* sys_ipc() is the de-multiplexer for the SysV IPC calls.
+21 -37
View File
@@ -1,48 +1,32 @@
# SPDX-License-Identifier: GPL-2.0
kapi := arch/$(SRCARCH)/include/generated/asm
uapi := arch/$(SRCARCH)/include/generated/uapi/asm
gen := arch/$(ARCH)/include/generated
kapi := $(gen)/asm
uapi := $(gen)/uapi/asm
syscall := $(src)/syscall.tbl
systbl := $(src)/syscalltbl
gen-y := $(kapi)/syscall_table.h
kapi-hdrs-y := $(kapi)/unistd_nr.h
uapi-hdrs-y := $(uapi)/unistd_32.h
uapi-hdrs-y += $(uapi)/unistd_64.h
targets += $(addprefix ../../../../,$(gen-y) $(kapi-hdrs-y) $(uapi-hdrs-y))
PHONY += kapi uapi
kapi: $(gen-y) $(kapi-hdrs-y)
uapi: $(uapi-hdrs-y)
# Create output directory if not already present
$(shell mkdir -p $(uapi) $(kapi))
syscall := $(src)/syscall.tbl
syshdr := $(srctree)/scripts/syscallhdr.sh
systbl := $(srctree)/scripts/syscalltbl.sh
quiet_cmd_syshdr = SYSHDR $@
cmd_syshdr = $(CONFIG_SHELL) '$(systbl)' -H -a $(syshdr_abi_$(basetarget)) -f "$@" < $< > $@
cmd_syshdr = $(CONFIG_SHELL) $(syshdr) --emit-nr --abis common,$* $< $@
quiet_cmd_sysnr = SYSNR $@
cmd_sysnr = $(CONFIG_SHELL) '$(systbl)' -N -a $(sysnr_abi_$(basetarget)) < $< > $@
quiet_cmd_systbl = SYSTBL $@
cmd_systbl = $(CONFIG_SHELL) $(systbl) --abis common,$* $< $@
quiet_cmd_syscalls = SYSTBL $@
cmd_syscalls = $(CONFIG_SHELL) '$(systbl)' -S < $< > $@
syshdr_abi_unistd_32 := common,32
$(uapi)/unistd_32.h: $(syscall) $(systbl) FORCE
$(call if_changed,syshdr)
syshdr_abi_unistd_64 := common,64
$(uapi)/unistd_64.h: $(syscall) $(systbl) FORCE
$(uapi)/unistd_%.h: $(syscall) $(syshdr) FORCE
$(call if_changed,syshdr)
$(kapi)/syscall_table.h: $(syscall) $(systbl) FORCE
$(call if_changed,syscalls)
$(call if_changed,systbl)
sysnr_abi_unistd_nr := common,32,64
$(kapi)/unistd_nr.h: $(syscall) $(systbl) FORCE
$(call if_changed,sysnr)
uapisyshdr-y += unistd_64.h
kapisyshdr-y += syscall_table.h
uapisyshdr-y := $(addprefix $(uapi)/, $(uapisyshdr-y))
kapisyshdr-y := $(addprefix $(kapi)/, $(kapisyshdr-y))
targets += $(addprefix ../../../../, $(uapisyshdr-y) $(kapisyshdr-y))
PHONY += all
all: $(uapisyshdr-y) $(kapisyshdr-y)
@:
File diff suppressed because it is too large Load Diff
-232
View File
@@ -1,232 +0,0 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Generate system call table and header files
#
# Copyright IBM Corp. 2018
# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
#
# File path to the system call table definition.
# You can set the path with the -i option. If omitted,
# system call table definitions are read from standard input.
#
SYSCALL_TBL=""
create_syscall_table_entries()
{
local nr abi name entry64 entry32 _ignore
local temp=$(mktemp ${TMPDIR:-/tmp}/syscalltbl-common.XXXXXXXXX)
(
#
# Initialize with 0 to create an NI_SYSCALL for 0
#
local prev_nr=0 prev_32=sys_ni_syscall prev_64=sys_ni_syscall
while read nr abi name entry64 entry32 _ignore; do
test x$entry32 = x- && entry32=sys_ni_syscall
test x$entry64 = x- && entry64=sys_ni_syscall
if test $prev_nr -eq $nr; then
#
# Same syscall but different ABI, just update
# the respective entry point
#
case $abi in
32)
prev_32=$entry32
;;
64)
prev_64=$entry64
;;
esac
continue;
else
printf "%d\t%s\t%s\n" $prev_nr $prev_64 $prev_32
fi
prev_nr=$nr
prev_64=$entry64
prev_32=$entry32
done
printf "%d\t%s\t%s\n" $prev_nr $prev_64 $prev_32
) >> $temp
#
# Check for duplicate syscall numbers
#
if ! cat $temp |cut -f1 |uniq -d 2>&1; then
echo "Error: generated system call table contains duplicate entries: $temp" >&2
exit 1
fi
#
# Generate syscall table
#
prev_nr=0
while read nr entry64 entry32; do
while test $prev_nr -lt $((nr - 1)); do
printf "NI_SYSCALL\n"
prev_nr=$((prev_nr + 1))
done
if test x$entry64 = xsys_ni_syscall &&
test x$entry32 = xsys_ni_syscall; then
printf "NI_SYSCALL\n"
else
printf "SYSCALL(%s,%s)\n" $entry64 $entry32
fi
prev_nr=$nr
done < $temp
rm $temp
}
generate_syscall_table()
{
cat <<-EoHEADER
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Definitions for sys_call_table, each line represents an
* entry in the table in the form
* SYSCALL(64 bit syscall, 31 bit emulated syscall)
*
* This file is meant to be included from entry.S.
*/
#define NI_SYSCALL SYSCALL(sys_ni_syscall,sys_ni_syscall)
EoHEADER
grep -Ev '^(#|[[:blank:]]*$)' $SYSCALL_TBL \
|sort -k1 -n \
|create_syscall_table_entries
}
create_header_defines()
{
local nr abi name _ignore
while read nr abi name _ignore; do
printf "#define __NR_%s %d\n" $name $nr
done
}
normalize_fileguard()
{
local fileguard="$1"
echo "$1" |tr '[[:lower:]]' '[[:upper:]]' \
|sed -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g'
}
generate_syscall_header()
{
local abis=$(echo "($1)" | tr ',' '|')
local filename="$2"
local fileguard suffix
if test "$filename"; then
fileguard=$(normalize_fileguard "__UAPI_ASM_S390_$2")
else
case "$abis" in
*64*) suffix=64 ;;
*32*) suffix=32 ;;
esac
fileguard=$(normalize_fileguard "__UAPI_ASM_S390_SYSCALLS_$suffix")
fi
cat <<-EoHEADER
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef ${fileguard}
#define ${fileguard}
EoHEADER
grep -E "^[[:digit:]]+[[:space:]]+${abis}" $SYSCALL_TBL \
|sort -k1 -n \
|create_header_defines
cat <<-EoFOOTER
#endif /* ${fileguard} */
EoFOOTER
}
__max_syscall_nr()
{
local abis=$(echo "($1)" | tr ',' '|')
grep -E "^[[:digit:]]+[[:space:]]+${abis}" $SYSCALL_TBL \
|sed -ne 's/^\([[:digit:]]*\)[[:space:]].*/\1/p' \
|sort -n \
|tail -1
}
generate_syscall_nr()
{
local abis="$1"
local max_syscall_nr num_syscalls
max_syscall_nr=$(__max_syscall_nr "$abis")
num_syscalls=$((max_syscall_nr + 1))
cat <<-EoHEADER
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef __ASM_S390_SYSCALLS_NR
#define __ASM_S390_SYSCALLS_NR
#define NR_syscalls ${num_syscalls}
#endif /* __ASM_S390_SYSCALLS_NR */
EoHEADER
}
#
# Parse command line arguments
#
do_syscall_header=""
do_syscall_table=""
do_syscall_nr=""
output_file=""
abi_list="common,64"
filename=""
while getopts ":HNSXi:a:f:" arg; do
case $arg in
a)
abi_list="$OPTARG"
;;
i)
SYSCALL_TBL="$OPTARG"
;;
f)
filename=${OPTARG##*/}
;;
H)
do_syscall_header=1
;;
N)
do_syscall_nr=1
;;
S)
do_syscall_table=1
;;
X)
set -x
;;
:)
echo "Missing argument for -$OPTARG" >&2
exit 1
;;
\?)
echo "Invalid option specified" >&2
exit 1
;;
esac
done
test "$do_syscall_header" && generate_syscall_header "$abi_list" "$filename"
test "$do_syscall_table" && generate_syscall_table
test "$do_syscall_nr" && generate_syscall_nr "$abi_list"
exit 0