Re: [PATCH v2 3/4] powerpc: add system call table generation support

2018-11-19 Thread Arnd Bergmann
On Wed, Nov 14, 2018 at 11:04 AM Firoz Khan  wrote:

> Adding a new table entry consisting of:
> - System call number.
> - ABI.
> - System call name.
> - Entry point name.
> - Compat entry name, if required.
>
> syscallhdr.sh and syscalltbl.sh will generate uapi header-
> unistd_32/64.h and syscall_table_32/64/c32.h files respect-
> ively. File syscall_table_32/64/c32.h is included by sys-
> call.S - the real system call table. Both .sh files will
> parse the content syscall.tbl to generate the header and
> table files.

You don't mention how this handles the SPU, which seems to be the main
difference from the other architectures.

> +# The format is:
> +#  
> +#
> +# The  can be common, 64, or 32 for this file.
> +#
> +0  common  restart_syscall sys_restart_syscall   
>   sys_restart_syscall
> +1  common  exitsys_exit  
>   sys_exit
> +2  common  forkppc_fork  
>   ppc_fork
> +3  common  readsys_read  
>   sys_readsys_read
> +4  common  write   sys_write 
>   sys_write   sys_write
> +5  common  opensys_open  
>   compat_sys_open sys_open
> +6  common  close   sys_close 
>   sys_close   sys_close
> +7  common  waitpid sys_waitpid   
>   sys_waitpid sys_waitpid
> +8  common  creat   sys_creat 
>   sys_creat   sys_creat

The SPU syscall is always the same as the 64-bit syscall, so listing it
explictily in the last column seems to add a lot of duplication, and
makes the format different from the other architectures.

Have you considered using the  field (second column) to decide whether
a syscall is used for SPU or not instead?

I would have done it like

|+0  nospu  restart_syscall sys_restart_syscall
 sys_restart_syscall
|+1  nospu  exitsys_exit
 sys_exit
|+2  nospu  forkppc_fork
 ppc_fork
|+3  common  readsys_read
  sys_read
|+4  common  write   sys_write
  sys_write
|+5  common  opensys_open
  compat_sys_open
|+6  common  close   sys_close
  sys_close
...
|+29132  fstatat64   sys_fstatat64
  sys_fstatat64
|+29164  newfstatat  sys_newfstatat
|+291spu  newfstatat  sys_newfstatat
...

with 'nospu' meaning 64+32+compat.

> +9  common  linksys_link  
>   sys_linksys_link
> +10 common  unlink  sys_unlink
>   sys_unlink  sys_unlink
> +11 common  execve  sys_execve
>   compat_sys_execve
> +12 common  chdir   sys_chdir 
>   sys_chdir   sys_chdir
> +13 common  timesys_time  
>   compat_sys_time sys_time
> +14 common  mknod   sys_mknod 
>   sys_mknod   sys_mknod
> +15 common  chmod   sys_chmod 
>   sys_chmod   sys_chmod
> +16 common  lchown  sys_lchown
>   sys_lchown  sys_lchown
> +17 common  break   sys_ni_syscall
>   sys_ni_syscall
> +18 32  oldstat sys_stat  
>   sys_ni_syscall
> +18 64  oldstat sys_ni_syscall

'oldstat' seems odd. Your conversion is correct, but the existing
behavior of not
providing support for the syscall in compat mode feels wrong. We have four
calls in this category:

arch/powerpc/include/asm/systbl.h:OLDSYS(stat)
arch/powerpc/include/asm/systbl.h:OLDSYS(fstat)
arch/powerpc/include/asm/systbl.h:OLDSYS(lstat)
arch/powerpc/include/asm/systbl.h:OLDSYS(debug_setcontext)

For the first three, it seems that the 64-bit kernel ought to set
'__ARCH_WANT_OLD_STAT':

diff --git a/arch/powerpc/include/asm/unistd.h
b/arch/powerpc/include/asm/unistd.h
index 96ddce5c76c3..335dfcc47f20 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ 

[PATCH v2 3/4] powerpc: add system call table generation support

2018-11-14 Thread Firoz Khan
The system call tables are in different format in all
architecture and it will be difficult to manually add or
modify the system calls in the respective files. To make
it easy by keeping a script and which will generate the
uapi header and syscall table file. This change will also
help to unify the implementation across all architectures.

The system call table generation script is added in
syscalls directory which contain the script to generate
both uapi header file and system call table files.
The syscall.tbl file will be the input for the scripts.

syscall.tbl contains the list of available system calls
along with system call number and corresponding entry point.
Add a new system call in this architecture will be possible
by adding new entry in the syscall.tbl file.

Adding a new table entry consisting of:
- System call number.
- ABI.
- System call name.
- Entry point name.
- Compat entry name, if required.

syscallhdr.sh and syscalltbl.sh will generate uapi header-
unistd_32/64.h and syscall_table_32/64/c32.h files respect-
ively. File syscall_table_32/64/c32.h is included by sys-
call.S - the real system call table. Both .sh files will
parse the content syscall.tbl to generate the header and
table files.

ARM, s390 and x86 architecuture does have the similar support.
I leverage their implementation to come up with a generic
solution.

Signed-off-by: Firoz Khan 
---
 arch/powerpc/kernel/syscalls/Makefile  |  61 +
 arch/powerpc/kernel/syscalls/syscall.tbl   | 408 +
 arch/powerpc/kernel/syscalls/syscallhdr.sh |  36 +++
 arch/powerpc/kernel/syscalls/syscalltbl.sh |  41 +++
 4 files changed, 546 insertions(+)
 create mode 100644 arch/powerpc/kernel/syscalls/Makefile
 create mode 100644 arch/powerpc/kernel/syscalls/syscall.tbl
 create mode 100644 arch/powerpc/kernel/syscalls/syscallhdr.sh
 create mode 100644 arch/powerpc/kernel/syscalls/syscalltbl.sh

diff --git a/arch/powerpc/kernel/syscalls/Makefile 
b/arch/powerpc/kernel/syscalls/Makefile
new file mode 100644
index 000..6615c24
--- /dev/null
+++ b/arch/powerpc/kernel/syscalls/Makefile
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0
+kapi := arch/$(SRCARCH)/include/generated/asm
+uapi := arch/$(SRCARCH)/include/generated/uapi/asm
+
+_dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)')  \
+ $(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)')
+
+syscall := $(srctree)/$(src)/syscall.tbl
+syshdr := $(srctree)/$(src)/syscallhdr.sh
+systbl := $(srctree)/$(src)/syscalltbl.sh
+
+quiet_cmd_syshdr = SYSHDR  $@
+  cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@'   \
+  '$(syshdr_abis_$(basetarget))'   \
+  '$(syshdr_pfx_$(basetarget))'\
+  '$(syshdr_offset_$(basetarget))'
+
+quiet_cmd_systbl = SYSTBL  $@
+  cmd_systbl = $(CONFIG_SHELL) '$(systbl)' '$<' '$@'   \
+  '$(systbl_abis_$(basetarget))'   \
+  '$(systbl_abi_$(basetarget))'\
+  '$(systbl_offset_$(basetarget))'
+
+syshdr_abis_unistd_32 := common,32
+$(uapi)/unistd_32.h: $(syscall) $(syshdr)
+   $(call if_changed,syshdr)
+
+syshdr_abis_unistd_64 := common,64
+$(uapi)/unistd_64.h: $(syscall) $(syshdr)
+   $(call if_changed,syshdr)
+
+systbl_abis_syscall_table_32 := common,32
+$(kapi)/syscall_table_32.h: $(syscall) $(systbl)
+   $(call if_changed,systbl)
+
+systbl_abis_syscall_table_64 := common,64
+$(kapi)/syscall_table_64.h: $(syscall) $(systbl)
+   $(call if_changed,systbl)
+
+systbl_abis_syscall_table_c32 := common,32
+systbl_abi_syscall_table_c32 := c32
+$(kapi)/syscall_table_c32.h: $(syscall) $(systbl)
+   $(call if_changed,systbl)
+
+systbl_abis_syscall_table_spu := common,32
+systbl_abi_syscall_table_spu := spu
+$(kapi)/syscall_table_spu.h: $(syscall) $(systbl)
+   $(call if_changed,systbl)
+
+uapisyshdr-y   += unistd_32.h unistd_64.h
+kapisyshdr-y   += syscall_table_32.h   \
+  syscall_table_64.h   \
+  syscall_table_c32.h  \
+  syscall_table_spu.h
+
+targets+= $(uapisyshdr-y) $(kapisyshdr-y)
+
+PHONY += all
+all: $(addprefix $(uapi)/,$(uapisyshdr-y))
+all: $(addprefix $(kapi)/,$(kapisyshdr-y))
+   @:
diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl 
b/arch/powerpc/kernel/syscalls/syscall.tbl
new file mode 100644
index 000..4d90f30
--- /dev/null
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -0,0 +1,408 @@
+# SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
+#
+# system call numbers and entry vectors for powerpc
+#
+# The format is:
+#  
+#
+# The  can be common, 64, or 32 for this file.
+#
+0  common  restart_syscall sys_restart_syscall 
sys_restart_syscall
+1  common  exitsys_exit
sys