Skip to contentSkip to conversation

s390: rework compat wrapper generation

PATCH In review Arnd Bergmann 3 participants 17 messages Jan 16, 2019 – Jan 21, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover s390: rework compat wrapper generation

Hi Heiko and Martin,

As promised, I gave this a go and changed the SYSCALL_DEFINEx() infrastructure to always include the wrappers for doing the 31-bit argument conversion on s390 compat mode.

This does three main things:

- The UID16 rework saved a lot of duplicated code, and would probably make sense by itself, but is also required as we can no longer call sys_*() functions directly after the last step.

- Removing the compat_wrapper.c file is of course the main goal here, in order to remove the need to maintain the compat_wrapper.c file when new system calls get added. Unfortunately, this requires adding some complexity in syscall_wrapper.h, and trades a small reduction in source code lines for a small increase in binary size for unused wrappers.

- As an added benefit, the use of syscall_wrapper.h now makes it easy to change the syscall wrappers so they no longer see all user space register contents, similar to changes done in commits fa697140f9a2 ("syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls") and 4378a7d4be30 ("arm64: implement syscall wrappers").
I leave the actual implementation of this for you, if you want to do it later.

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

Arnd

Arnd Bergmann (5):
s390: open-code s390_personality syscall
ipc: introduce ksys_ipc()/compat_ksys_ipc() for s390
s390: use generic UID16 implementation
s390: autogenerate compat syscall wrappers
s390: remove compat_wrapper.c

 arch/s390/Kconfig                        |   2 +
 arch/s390/include/asm/syscall_wrapper.h  | 136 +++++++++++
 arch/s390/include/uapi/asm/posix_types.h |   6 +
 arch/s390/kernel/Makefile                |   2 +-
 arch/s390/kernel/compat_linux.c          | 235 +------------------
 arch/s390/kernel/compat_wrapper.c        | 186 ---------------
 arch/s390/kernel/entry.S                 |   4 +-
 arch/s390/kernel/sys_s390.c              |  14 +-
 arch/s390/kernel/syscalls/syscall.tbl    | 286 +++++++++++------------
 include/linux/syscalls.h                 |   4 +
 ipc/syscall.c                            |  20 +-
 11 files changed, 322 insertions(+), 573 deletions(-)
 create mode 100644 arch/s390/include/asm/syscall_wrapper.h
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
Signature · 1 line
2.20.0
#1 lore raw

PATCH 1/5 s390: open-code s390_personality syscall

The sys_personality function is not meant to be called from other system calls. We could introduce an intermediate ksys_personality function, but it does almost nothing, so this just moves the implementation into the caller.

---
 arch/s390/kernel/sys_s390.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/s390/kernel/sys_s390.c +5 -2
index 31cefe0c28c0..560bdaf8a74f 100644
@@ -79,12 +79,15 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
 
 SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
 {
-	unsigned int ret;
+	unsigned int ret = current->personality;
 
 	if (personality(current->personality) == PER_LINUX32 &&
 	    personality(personality) == PER_LINUX)
 		personality |= PER_LINUX32;
-	ret = sys_personality(personality);
+
+	if (personality != 0xffffffff)
+		set_personality(personality);
+
 	if (personality(ret) == PER_LINUX32)
 		ret &= ~PER_LINUX32;
 
Signature · 1 line
2.20.0
#2 lore raw

PATCH 2/5 ipc: introduce ksys_ipc()/compat_ksys_ipc() for s390

In reply to Arnd Bergmann

The sys_ipc() and compat_ksys_ipc() functions are meant to only be used from the system call table, not called by another function.

Introduce ksys_*() interfaces for this purpose, as we have done for many other system calls.

---
 arch/s390/kernel/compat_linux.c |  2 +-
 arch/s390/kernel/sys_s390.c     |  2 +-
 include/linux/syscalls.h        |  4 ++++
 ipc/syscall.c                   | 20 ++++++++++++++++----
 4 files changed, 22 insertions(+), 6 deletions(-)
arch/s390/kernel/compat_linux.c +1 -1
index 8ac38d51ed7d..a47f6d3c6d5b 100644
@@ -296,7 +296,7 @@ COMPAT_SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, compat_ulong_t, second,
 {
 	if (call >> 16)		/* hack for backward compatibility */
 		return -EINVAL;
-	return compat_sys_ipc(call, first, second, third, ptr, third);
+	return compat_ksys_ipc(call, first, second, third, ptr, third);
 }
 #endif
 
arch/s390/kernel/sys_s390.c +1 -1
index 560bdaf8a74f..6aa8fe00b39e 100644
@@ -74,7 +74,7 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
 	 * Therefore we can call the generic variant by simply passing the
 	 * third parameter also as fifth parameter.
 	 */
-	return sys_ipc(call, first, second, third, ptr, third);
+	return ksys_ipc(call, first, second, third, ptr, third);
 }
 
 SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
include/linux/syscalls.h +4 -0
index 257cccba3062..fb63045a0fb6 100644
@@ -1185,6 +1185,10 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
 			      unsigned long prot, unsigned long flags,
 			      unsigned long fd, unsigned long pgoff);
 ssize_t ksys_readahead(int fd, loff_t offset, size_t count);
+int ksys_ipc(unsigned int call, int first, unsigned long second,
+	unsigned long third, void __user * ptr, long fifth);
+int compat_ksys_ipc(u32 call, int first, int second,
+	u32 third, u32 ptr, u32 fifth);
 
 /*
  * The following kernel syscall equivalents are just wrappers to fs-internal
ipc/syscall.c +16 -4
index 1ac06e3983c0..3cf8ad703a4d 100644
@@ -17,8 +17,8 @@
 #include <linux/shm.h>
 #include <linux/uaccess.h>
 
-SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
-		unsigned long, third, void __user *, ptr, long, fifth)
+int ksys_ipc(unsigned int call, int first, unsigned long second,
+	unsigned long third, void __user * ptr, long fifth)
 {
 	int version, ret;
 
@@ -106,6 +106,12 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
 		return -ENOSYS;
 	}
 }
+
+SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
+		unsigned long, third, void __user *, ptr, long, fifth)
+{
+	return ksys_ipc(call, first, second, third, ptr, fifth);
+}
 #endif
 
 #ifdef CONFIG_COMPAT
@@ -121,8 +127,8 @@ struct compat_ipc_kludge {
 };
 
 #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
-COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
-	u32, third, compat_uptr_t, ptr, u32, fifth)
+int compat_ksys_ipc(u32 call, int first, int second,
+	u32 third, compat_uptr_t ptr, u32 fifth)
 {
 	int version;
 	u32 pad;
@@ -195,5 +201,11 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
 
 	return -ENOSYS;
 }
+
+COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
+	u32, third, compat_uptr_t, ptr, u32, fifth)
+{
+	return compat_ksys_ipc(call, first, second, third, ptr, fifth);
+}
 #endif
 #endif
Signature · 1 line
2.20.0
#6 lore raw

PATCH 3/5 s390: use generic UID16 implementation

In reply to Arnd Bergmann

s390 has an almost identical copy of the code in kernel/uid16.c.

The problem here is that it requires calling the regular system calls, which the generic implementation handles correctly, but the internal interfaces are not declared in a global header for this.

The best way forward here seems to be to just use the generic code and delete the s390 specific implementation.

I keep the changes to uapi/asm/posix_types.h inside of an #ifdef check so user space does not observe any changes. As some of the system calls pass pointers, we also need wrappers in compat_wrapper.c, which I add for all calls with at least one argument. All those wrappers can be removed in a later step.

---
 arch/s390/Kconfig                        |   1 +
 arch/s390/include/uapi/asm/posix_types.h |   6 +
 arch/s390/kernel/compat_linux.c          | 233 -----------------------
 arch/s390/kernel/compat_wrapper.c        |  15 ++
 arch/s390/kernel/syscalls/syscall.tbl    |  38 ++--
 5 files changed, 41 insertions(+), 252 deletions(-)
arch/s390/Kconfig +1 -0
index ed554b09eb3f..41cafd245bbc 100644
@@ -379,6 +379,7 @@ config COMPAT
 	select COMPAT_BINFMT_ELF if BINFMT_ELF
 	select ARCH_WANT_OLD_COMPAT_IPC
 	select COMPAT_OLD_SIGACTION
+	select HAVE_UID16
 	depends on MULTIUSER
 	help
 	  Select this option if you want to enable your system kernel to
arch/s390/include/uapi/asm/posix_types.h +6 -0
index 2a3fc638414b..1913613e71b6 100644
@@ -20,6 +20,12 @@ typedef long            __kernel_ssize_t;
 typedef unsigned short	__kernel_old_dev_t;
 #define __kernel_old_dev_t __kernel_old_dev_t
 
+#ifdef __KERNEL__
+typedef unsigned short __kernel_old_uid_t;
+typedef unsigned short __kernel_old_gid_t;
+#define __kernel_old_uid_t __kernel_old_uid_t
+#endif
+
 #ifndef __s390x__
 
 typedef unsigned long   __kernel_ino_t;
arch/s390/kernel/compat_linux.c +0 -233

245 lines not on this page · raw message

arch/s390/kernel/compat_wrapper.c +15 -0
index 48c4ce668244..f54b7b73f316 100644
@@ -184,3 +184,18 @@ COMPAT_SYSCALL_WRAP5(statx, int, dfd, const char __user *, path, unsigned, flags
 COMPAT_SYSCALL_WRAP4(s390_sthyi, unsigned long, code, void __user *, info, u64 __user *, rc, unsigned long, flags);
 COMPAT_SYSCALL_WRAP5(kexec_file_load, int, kernel_fd, int, initrd_fd, unsigned long, cmdline_len, const char __user *, cmdline_ptr, unsigned long, flags)
 COMPAT_SYSCALL_WRAP4(rseq, struct rseq __user *, rseq, u32, rseq_len, int, flags, u32, sig)
+COMPAT_SYSCALL_WRAP3(chown16, const char __user *, filename, u16, user, u16, group);
+COMPAT_SYSCALL_WRAP3(lchown16, const char __user *, filename, u16, user, u16, group);
+COMPAT_SYSCALL_WRAP3(fchown16, unsigned int, fd, u16, user, u16, group);
+COMPAT_SYSCALL_WRAP2(setregid16, u16, rgid, u16, egid);
+COMPAT_SYSCALL_WRAP1(setgid16, u16, gid);
+COMPAT_SYSCALL_WRAP2(setreuid16, u16, ruid, u16, euid);
+COMPAT_SYSCALL_WRAP1(setuid16, u16, uid);
+COMPAT_SYSCALL_WRAP3(setresuid16, u16, ruid, u16, euid, u16, suid);
+COMPAT_SYSCALL_WRAP3(getresuid16, u16 __user *, ruidp, u16 __user *, euidp, u16 __user *, suidp);
+COMPAT_SYSCALL_WRAP3(setresgid16, u16, rgid, u16, egid, u16, sgid);
+COMPAT_SYSCALL_WRAP3(getresgid16, u16 __user *, rgidp, u16 __user *, egidp, u16 __user *, sgidp);
+COMPAT_SYSCALL_WRAP1(setfsuid16, u16, uid);
+COMPAT_SYSCALL_WRAP1(setfsgid16, u16, gid);
+COMPAT_SYSCALL_WRAP2(getgroups16, int, gidsetsize, u16 __user *, grouplist);
+COMPAT_SYSCALL_WRAP2(setgroups16, int, gidsetsize, u16 __user *, grouplist);
arch/s390/kernel/syscalls/syscall.tbl +19 -19
index 022fc099b628..f878f74c42fd 100644
@@ -23,13 +23,13 @@
 13   32		time			-				compat_sys_time
 14   common	mknod			sys_mknod			compat_sys_mknod
 15   common	chmod			sys_chmod			compat_sys_chmod
-16   32		lchown			-				compat_sys_s390_lchown16
+16   32		lchown			-				compat_sys_lchown16
 19   common	lseek			sys_lseek			compat_sys_lseek
 20   common	getpid			sys_getpid			sys_getpid
 21   common	mount			sys_mount			compat_sys_mount
 22   common	umount			sys_oldumount			compat_sys_oldumount
-23   32		setuid			-				compat_sys_s390_setuid16
-24   32		getuid			-				compat_sys_s390_getuid16
+23   32		setuid			-				compat_sys_setuid16
+24   32		getuid			-				sys_getuid16
 25   32		stime			-				compat_sys_stime
 26   common	ptrace			sys_ptrace			compat_sys_ptrace
 27   common	alarm			sys_alarm			sys_alarm
@@ -46,11 +46,11 @@
 42   common	pipe			sys_pipe			compat_sys_pipe
 43   common	times			sys_times			compat_sys_times
 45   common	brk			sys_brk				compat_sys_brk
-46   32		setgid			-				compat_sys_s390_setgid16
-47   32		getgid			-				compat_sys_s390_getgid16
+46   32		setgid			-				compat_sys_setgid16
+47   32		getgid			-				sys_getgid16
 48   common	signal			sys_signal			compat_sys_signal
-49   32		geteuid			-				compat_sys_s390_geteuid16
-50   32		getegid			-				compat_sys_s390_getegid16
+49   32		geteuid			-				sys_geteuid16
+50   32		getegid			-				sys_getegid16
 51   common	acct			sys_acct			compat_sys_acct
 52   common	umount2			sys_umount			compat_sys_umount
 54   common	ioctl			sys_ioctl			compat_sys_ioctl
@@ -64,8 +64,8 @@
 65   common	getpgrp			sys_getpgrp			sys_getpgrp
 66   common	setsid			sys_setsid			sys_setsid
 67   common	sigaction		sys_sigaction			compat_sys_sigaction
-70   32		setreuid		-				compat_sys_s390_setreuid16
-71   32		setregid		-				compat_sys_s390_setregid16
+70   32		setreuid		-				compat_sys_setreuid16
+71   32		setregid		-				compat_sys_setregid16
 72   common	sigsuspend		sys_sigsuspend			compat_sys_sigsuspend
 73   common	sigpending		sys_sigpending			compat_sys_sigpending
 74   common	sethostname		sys_sethostname			compat_sys_sethostname
@@ -74,8 +74,8 @@
 77   common	getrusage		sys_getrusage			compat_sys_getrusage
 78   common	gettimeofday		sys_gettimeofday		compat_sys_gettimeofday
 79   common	settimeofday		sys_settimeofday		compat_sys_settimeofday
-80   32		getgroups		-				compat_sys_s390_getgroups16
-81   32		setgroups		-				compat_sys_s390_setgroups16
+80   32		getgroups		-				compat_sys_getgroups16
+81   32		setgroups		-				compat_sys_setgroups16
 83   common	symlink			sys_symlink			compat_sys_symlink
 85   common	readlink		sys_readlink			compat_sys_readlink
 86   common	uselib			sys_uselib			compat_sys_uselib
@@ -87,7 +87,7 @@
 92   common	truncate		sys_truncate			compat_sys_truncate
 93   common	ftruncate		sys_ftruncate			compat_sys_ftruncate
 94   common	fchmod			sys_fchmod			sys_fchmod
-95   32		fchown			-				compat_sys_s390_fchown16
+95   32		fchown			-				compat_sys_fchown16
 96   common	getpriority		sys_getpriority			sys_getpriority
 97   common	setpriority		sys_setpriority			sys_setpriority
 99   common	statfs			sys_statfs			compat_sys_statfs
@@ -126,8 +126,8 @@
 135  common	sysfs			sys_sysfs			compat_sys_sysfs
 136  common	personality		sys_s390_personality		sys_s390_personality
 137  common	afs_syscall		-				-
-138  32		setfsuid		-				compat_sys_s390_setfsuid16
-139  32		setfsgid		-				compat_sys_s390_setfsgid16
+138  32		setfsuid		-				compat_sys_setfsuid16
+139  32		setfsgid		-				compat_sys_setfsgid16
 140  32		_llseek			-				compat_sys_llseek
 141  common	getdents		sys_getdents			compat_sys_getdents
 142  32		_newselect		-				compat_sys_select
@@ -153,13 +153,13 @@
 161  common	sched_rr_get_interval	sys_sched_rr_get_interval	compat_sys_sched_rr_get_interval
 162  common	nanosleep		sys_nanosleep			compat_sys_nanosleep
 163  common	mremap			sys_mremap			compat_sys_mremap
-164  32		setresuid		-				compat_sys_s390_setresuid16
-165  32		getresuid		-				compat_sys_s390_getresuid16
+164  32		setresuid		-				compat_sys_setresuid16
+165  32		getresuid		-				compat_sys_getresuid16
 167  common	query_module		-				-
 168  common	poll			sys_poll			compat_sys_poll
 169  common	nfsservctl		-				-
-170  32		setresgid		-				compat_sys_s390_setresgid16
-171  32		getresgid		-				compat_sys_s390_getresgid16
+170  32		setresgid		-				compat_sys_setresgid16
+171  32		getresgid		-				compat_sys_getresgid16
 172  common	prctl			sys_prctl			compat_sys_prctl
 173  common	rt_sigreturn		sys_rt_sigreturn		compat_sys_rt_sigreturn
 174  common	rt_sigaction		sys_rt_sigaction		compat_sys_rt_sigaction
@@ -170,7 +170,7 @@
 179  common	rt_sigsuspend		sys_rt_sigsuspend		compat_sys_rt_sigsuspend
 180  common	pread64			sys_pread64			compat_sys_s390_pread64
 181  common	pwrite64		sys_pwrite64			compat_sys_s390_pwrite64
-182  32		chown			-				compat_sys_s390_chown16
+182  32		chown			-				compat_sys_chown16
 183  common	getcwd			sys_getcwd			compat_sys_getcwd
 184  common	capget			sys_capget			compat_sys_capget
 185  common	capset			sys_capset			compat_sys_capset
Signature · 1 line
2.20.0
#7 lore raw

PATCH 4/5 s390: autogenerate compat syscall wrappers

In reply to Arnd Bergmann

Any system call that takes a pointer argument on s390 requires a wrapper function to do a 31-to-64 zero-extension, these are currently generated in arch/s390/kernel/compat_wrapper.c.

On arm64 and x86, we already generate similar wrappers for all system calls in the place of their definition, just for a different purpose (they load the arguments from pt_regs).

We can do the same thing here, by adding an asm/syscall_wrapper.h file with a copy of all the relevant macros to override the generic version. Besides the addition of the compat entry point, these also rename the entry points with a __s390_ or __s390x_ prefix, similar to what we do on arm64 and x86. This in turn requires renaming a few things, and adding a proper ni_syscall() entry point.

In order to still compile system call definitions that pass an loff_t argument, the __SC_COMPAT_CAST() macro checks for that and forces an -ENOSYS error, which was the best I could come up with. Those functions must obviously not get called from user space, but instead require hand-written compat_sys_*() handlers, which fortunately already exist.

---
 arch/s390/Kconfig                       |   1 +
 arch/s390/include/asm/syscall_wrapper.h | 136 ++++++++++++++++++++++++
 arch/s390/kernel/compat_wrapper.c       |  23 +---
 arch/s390/kernel/entry.S                |   4 +-
 arch/s390/kernel/sys_s390.c             |   5 +
 5 files changed, 148 insertions(+), 21 deletions(-)
 create mode 100644 arch/s390/include/asm/syscall_wrapper.h
arch/s390/Kconfig +1 -0
index 41cafd245bbc..b6e3d0653002 100644
@@ -75,6 +75,7 @@ config S390
 	select ARCH_HAS_SET_MEMORY
 	select ARCH_HAS_STRICT_KERNEL_RWX
 	select ARCH_HAS_STRICT_MODULE_RWX
+	select ARCH_HAS_SYSCALL_WRAPPER
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select ARCH_INLINE_READ_LOCK
arch/s390/include/asm/syscall_wrapper.h new file +136 -0

136 lines not on this page · raw message

arch/s390/kernel/compat_wrapper.c +4 -19
index f54b7b73f316..9d07cd553fc7 100644
@@ -25,21 +25,6 @@
 #define __SC_COMPAT_TYPE(t, a) \
 	__typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
 
-#define __SC_COMPAT_CAST(t, a)						\
-({									\
-	long __ReS = a;							\
-									\
-	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
-		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));		\
-	if (__TYPE_IS_L(t))						\
-		__ReS = (s32)a;						\
-	if (__TYPE_IS_UL(t))						\
-		__ReS = (u32)a;						\
-	if (__TYPE_IS_PTR(t))						\
-		__ReS = a & 0x7fffffff;					\
-	(t)__ReS;							\
-})
-
 /*
  * The COMPAT_SYSCALL_WRAP macro generates system call wrappers to be used by
  * compat tasks. These wrappers will only be used for system calls where only
@@ -53,11 +38,11 @@
  * the regular system call wrappers.
  */
 #define COMPAT_SYSCALL_WRAPx(x, name, ...)					\
-asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));			\
-asmlinkage long notrace compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__));\
-asmlinkage long notrace compat_sys##name(__MAP(x,__SC_COMPAT_TYPE,__VA_ARGS__))	\
+asmlinkage long __s390_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));		\
+asmlinkage long notrace __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
+asmlinkage long notrace __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))	\
 {										\
-	return sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__));		\
+	return __s390_sys##name(__MAP(x,__SC_ARGS,__VA_ARGS__));		\
 }
 
 COMPAT_SYSCALL_WRAP2(creat, const char __user *, pathname, umode_t, mode);
arch/s390/kernel/entry.S +2 -2
index 39191a0feed1..583d65ef5007 100644
@@ -1512,7 +1512,7 @@ cleanup_critical:
 	.quad   .Lsie_skip - .Lsie_entry
 #endif
 	.section .rodata, "a"
-#define SYSCALL(esame,emu)	.long esame
+#define SYSCALL(esame,emu)	.long __s390x_ ## esame
 	.globl	sys_call_table
 sys_call_table:
 #include "asm/syscall_table.h"
@@ -1520,7 +1520,7 @@ sys_call_table:
 
 #ifdef CONFIG_COMPAT
 
-#define SYSCALL(esame,emu)	.long emu
+#define SYSCALL(esame,emu)	.long __s390_ ## emu
 	.globl	sys_call_table_emu
 sys_call_table_emu:
 #include "asm/syscall_table.h"
arch/s390/kernel/sys_s390.c +5 -0
index 6aa8fe00b39e..a8c2cc858864 100644
@@ -93,3 +93,8 @@ SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
 
 	return ret;
 }
+
+SYSCALL_DEFINE0(ni_syscall)
+{
+	return -ENOSYS;
+}
Signature · 1 line
2.20.0
#11 lore raw

PATCH 5/5 s390: remove compat_wrapper.c

In reply to Arnd Bergmann

Now that all these wrappers are automatically generated, we can remove the entire file, and instead point to the regualar syscalls like all other architectures do.

The 31-bit pointer extension is now handled in the __s390_sys_*() wrappers.

---
 arch/s390/kernel/Makefile             |   2 +-
 arch/s390/kernel/compat_wrapper.c     | 186 -----------------
 arch/s390/kernel/syscalls/syscall.tbl | 278 +++++++++++++-------------
 3 files changed, 140 insertions(+), 326 deletions(-)
 delete mode 100644 arch/s390/kernel/compat_wrapper.c
arch/s390/kernel/Makefile +1 -1
index e216e116a9a9..4e188a7be501 100644
@@ -65,7 +65,7 @@ obj-$(CONFIG_HIBERNATION)	+= suspend.o swsusp.o
 obj-$(CONFIG_AUDIT)		+= audit.o
 compat-obj-$(CONFIG_AUDIT)	+= compat_audit.o
 obj-$(CONFIG_COMPAT)		+= compat_linux.o compat_signal.o
-obj-$(CONFIG_COMPAT)		+= compat_wrapper.o $(compat-obj-y)
+obj-$(CONFIG_COMPAT)		+= $(compat-obj-y)
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 obj-$(CONFIG_STACKTRACE)	+= stacktrace.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
arch/s390/kernel/compat_wrapper.c deleted +0 -186

186 lines not on this page · raw message

arch/s390/kernel/syscalls/syscall.tbl +139 -139

479 lines not on this page · raw message

Signature · 1 line
2.20.0
#12 lore raw
In reply to Arnd Bergmann
Quoted 30 lines · Arnd Bergmann

Hi Heiko and Martin,

As promised, I gave this a go and changed the SYSCALL_DEFINEx() infrastructure to always include the wrappers for doing the 31-bit argument conversion on s390 compat mode.

This does three main things:

- The UID16 rework saved a lot of duplicated code, and would probably make sense by itself, but is also required as we can no longer call sys_*() functions directly after the last step.

- Removing the compat_wrapper.c file is of course the main goal here, in order to remove the need to maintain the compat_wrapper.c file when new system calls get added. Unfortunately, this requires adding some complexity in syscall_wrapper.h, and trades a small reduction in source code lines for a small increase in binary size for unused wrappers.

- As an added benefit, the use of syscall_wrapper.h now makes it easy to change the syscall wrappers so they no longer see all user space register contents, similar to changes done in commits fa697140f9a2 ("syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls") and 4378a7d4be30 ("arm64: implement syscall wrappers").
I leave the actual implementation of this for you, if you want to do it later.

Quoted 3 lines

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

This work is highly appreciated! I'll look into this tomorrow.

Thanks!

#3 lore raw

Re: [PATCH 2/5] ipc: introduce ksys_ipc()/compat_ksys_ipc() for s390

In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

The sys_ipc() and compat_ksys_ipc() functions are meant to only be used from the system call table, not called by another function.

Introduce ksys_*() interfaces for this purpose, as we have done for many other system calls.

Quoted 7 lines
---
 arch/s390/kernel/compat_linux.c |  2 +-
 arch/s390/kernel/sys_s390.c     |  2 +-
 include/linux/syscalls.h        |  4 ++++
 ipc/syscall.c                   | 20 ++++++++++++++++----
 4 files changed, 22 insertions(+), 6 deletions(-)

The patch below is needed as compile fix (allnoconfig). I will add this to your patch, no resend needed.

arch/s390/kernel/sys_s390.c +2 -0
index 6aa8fe00b39e..fd0cbbed4d9f 100644
@@ -58,6 +58,7 @@ SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
 	return error;
 }
 
+#ifdef CONFIG_SYSVIPC
 /*
  * sys_ipc() is the de-multiplexer for the SysV IPC calls.
  */
@@ -76,6 +77,7 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
 	 */
 	return ksys_ipc(call, first, second, third, ptr, third);
 }
+#endif /* CONFIG_SYSVIPC */
 
 SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
 {
kernel/sys_ni.c +1 -1
index ab9d0e3c6d50..ad016a7db0ea 100644
@@ -366,7 +366,7 @@ COND_SYSCALL(kexec_file_load);
 /* s390 */
 COND_SYSCALL(s390_pci_mmio_read);
 COND_SYSCALL(s390_pci_mmio_write);
-COND_SYSCALL_COMPAT(s390_ipc);
+COND_SYSCALL(s390_ipc);
 
 /* powerpc */
 COND_SYSCALL(rtas);
#8 lore raw

Re: [PATCH 4/5] s390: autogenerate compat syscall wrappers

In reply to Arnd Bergmann
Quoted 23 lines · Arnd Bergmann

Any system call that takes a pointer argument on s390 requires a wrapper function to do a 31-to-64 zero-extension, these are currently generated in arch/s390/kernel/compat_wrapper.c.

On arm64 and x86, we already generate similar wrappers for all system calls in the place of their definition, just for a different purpose (they load the arguments from pt_regs).

We can do the same thing here, by adding an asm/syscall_wrapper.h file with a copy of all the relevant macros to override the generic version. Besides the addition of the compat entry point, these also rename the entry points with a __s390_ or __s390x_ prefix, similar to what we do on arm64 and x86. This in turn requires renaming a few things, and adding a proper ni_syscall() entry point.

In order to still compile system call definitions that pass an loff_t argument, the __SC_COMPAT_CAST() macro checks for that and forces an -ENOSYS error, which was the best I could come up with. Those functions must obviously not get called from user space, but instead require hand-written compat_sys_*() handlers, which fortunately already exist.

Quoted 8 lines
---
 arch/s390/Kconfig                       |   1 +
 arch/s390/include/asm/syscall_wrapper.h | 136 ++++++++++++++++++++++++
 arch/s390/kernel/compat_wrapper.c       |  23 +---
 arch/s390/kernel/entry.S                |   4 +-
 arch/s390/kernel/sys_s390.c             |   5 +
 5 files changed, 148 insertions(+), 21 deletions(-)
 create mode 100644 arch/s390/include/asm/syscall_wrapper.h

The patch below is needed as compile fix (allnoconfig). I will add this to your patch, no resend needed.

arch/s390/include/asm/syscall_wrapper.h +2 -3
index 27ebe871692f..873e7a7794b3 100644
@@ -106,11 +106,10 @@
 	asmlinkage long __s390x_sys_##sname(void)
 
 #define COND_SYSCALL(name)						\
-	cond_syscall(__s390x_sys_##name)				\
-	cond_syscall(__s390_sys_##name)
+	cond_syscall(__s390x_sys_##name)
 
 #define SYS_NI(name)							\
-	SYSCALL_ALIAS(__s390_sys_##name, sys_ni_posix_timers);
+	SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers);
 
 #endif /* CONFIG_COMPAT */
 
#13 lore raw
In reply to Arnd Bergmann
Quoted 30 lines · Arnd Bergmann

Hi Heiko and Martin,

As promised, I gave this a go and changed the SYSCALL_DEFINEx() infrastructure to always include the wrappers for doing the 31-bit argument conversion on s390 compat mode.

This does three main things:

- The UID16 rework saved a lot of duplicated code, and would probably make sense by itself, but is also required as we can no longer call sys_*() functions directly after the last step.

- Removing the compat_wrapper.c file is of course the main goal here, in order to remove the need to maintain the compat_wrapper.c file when new system calls get added. Unfortunately, this requires adding some complexity in syscall_wrapper.h, and trades a small reduction in source code lines for a small increase in binary size for unused wrappers.

- As an added benefit, the use of syscall_wrapper.h now makes it easy to change the syscall wrappers so they no longer see all user space register contents, similar to changes done in commits fa697140f9a2 ("syscalls/x86: Use 'struct pt_regs' based syscall calling convention for 64-bit syscalls") and 4378a7d4be30 ("arm64: implement syscall wrappers").
I leave the actual implementation of this for you, if you want to do it later.

Quoted 3 lines

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

All looks good and seems to work fine. This is a very nice simplification of our compat code, even if it adds some dead code to the kernel image.

I did some tests and it all looks good. Also the generated code looks fine. So, if nothing breaks, this will go upstream with next merge window via the s390 tree.

Thanks again for your work!

#14 lore raw
Quoted 11 lines · Heiko Carstens
Quoted 3 lines · Arnd Bergmann

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

All looks good and seems to work fine. This is a very nice simplification of our compat code, even if it adds some dead code to the kernel image.

Quoted 5 lines

I did some tests and it all looks good. Also the generated code looks fine. So, if nothing breaks, this will go upstream with next merge window via the s390 tree.

Thanks again for your work!

Awesome, thanks for testing it so quickly and agreeing to merge it!

There is a dependency that I now have for my y2038 syscall series of course, so I'd need to have those patches on top of the s390 series.

I think we can either have a shared git branch that gets merged both into your s390 tree and my y2038 tree, or we merge it only through my tree, with your Ack.

Does that work for you?

Arnd

#9 lore raw

Re: [PATCH 4/5] s390: autogenerate compat syscall wrappers

In reply to Heiko Carstens
Quoted 3 lines · Heiko Carstens

The patch below is needed as compile fix (allnoconfig). I will add this to your patch, no resend needed.

Ok, good catch! This is obviously the right fix.

Arnd

Quoted 19 lines
arch/s390/include/asm/syscall_wrapper.h +2 -3
index 27ebe871692f..873e7a7794b3 100644
@@ -106,11 +106,10 @@
        asmlinkage long __s390x_sys_##sname(void)
 
 #define COND_SYSCALL(name)                                             \
-       cond_syscall(__s390x_sys_##name)                                \
-       cond_syscall(__s390_sys_##name)
+       cond_syscall(__s390x_sys_##name)
 
 #define SYS_NI(name)                                                   \
-       SYSCALL_ALIAS(__s390_sys_##name, sys_ni_posix_timers);
+       SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers);
 
 #endif /* CONFIG_COMPAT */
 
#4 lore raw

Re: [PATCH 2/5] ipc: introduce ksys_ipc()/compat_ksys_ipc() for s390

In reply to Heiko Carstens
Quoted 13 lines · Heiko Carstens
arch/s390/kernel/sys_s390.c +1 -0
index 6aa8fe00b39e..fd0cbbed4d9f 100644
@@ -58,6 +58,7 @@ SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
        return error;
 }
 
+#ifdef CONFIG_SYSVIPC
 /*
  * sys_ipc() is the de-multiplexer for the SysV IPC calls.
  */

arch/s390/kernel/sys_s390.c SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second, · line 80

Quoted 4 lines
arch/s390/kernel/sys_s390.c +1 -0
@@ -76,6 +77,7 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
         */
        return ksys_ipc(call, first, second, third, ptr, third);
 }
+#endif /* CONFIG_SYSVIPC */

Ack.

Quoted 7 lines
arch/s390/kernel/sys_s390.c +0 -0
 SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
 {
kernel/sys_ni.c +0 -0
index ab9d0e3c6d50..ad016a7db0ea 100644

kernel/sys_ni.c COND_SYSCALL(kexec_file_load); · line 372

Quoted 8 lines
kernel/sys_ni.c +1 -1
@@ -366,7 +366,7 @@ COND_SYSCALL(kexec_file_load);
 /* s390 */
 COND_SYSCALL(s390_pci_mmio_read);
 COND_SYSCALL(s390_pci_mmio_write);
-COND_SYSCALL_COMPAT(s390_ipc);
+COND_SYSCALL(s390_ipc);
 
 /* powerpc */
 COND_SYSCALL(rtas);

I think you need to keep the

COND_SYSCALL_COMPAT(s390_ipc);

here, otherwise it still fails with CONFIG_SYSV_IPC=n, CONFIG_COMPAT=y, right?

Arnd

#5 lore raw

Re: [PATCH 2/5] ipc: introduce ksys_ipc()/compat_ksys_ipc() for s390

Quoted 14 lines · Arnd Bergmann

On Thu, Jan 17, 2019 at 2:29 PM Heiko Carstens

Quoted 13 lines

SYSCALL_DEFINE1(s390_personality, unsigned int, personality) {

kernel/sys_ni.c +1 -1
index ab9d0e3c6d50..ad016a7db0ea 100644
@@ -366,7 +366,7 @@ COND_SYSCALL(kexec_file_load);
 /* s390 */
 COND_SYSCALL(s390_pci_mmio_read);
 COND_SYSCALL(s390_pci_mmio_write);
-COND_SYSCALL_COMPAT(s390_ipc);
+COND_SYSCALL(s390_ipc);
 
Quoted 8 lines

kernel/sys_ni.c COND_SYSCALL(kexec_file_load); · line 372

Quoted 2 lines
kernel/sys_ni.c +0 -0
 /* powerpc */
 COND_SYSCALL(rtas);

I think you need to keep the

COND_SYSCALL_COMPAT(s390_ipc);

here, otherwise it still fails with CONFIG_SYSV_IPC=n, CONFIG_COMPAT=y, right?

Yes, you're right.

#15 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann
Quoted 11 lines · Heiko Carstens
Quoted 3 lines · Arnd Bergmann

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

All looks good and seems to work fine. This is a very nice simplification of our compat code, even if it adds some dead code to the kernel image.

Quoted 5 lines

I did some tests and it all looks good. Also the generated code looks fine. So, if nothing breaks, this will go upstream with next merge window via the s390 tree.

Thanks again for your work!

Awesome, thanks for testing it so quickly and agreeing to merge it!

Quoted 8 lines

There is a dependency that I now have for my y2038 syscall series of course, so I'd need to have those patches on top of the s390 series.

I think we can either have a shared git branch that gets merged both into your s390 tree and my y2038 tree, or we merge it only through my tree, with your Ack.

Does that work for you?

I'll discuss this with Martin tomorrow, however I think a shared git branch would be the best solution. I want to get as much testing as possible for this patch set, which means this must also be in the s390 tree.

#16 lore raw
Quoted 29 lines · On Thu, 17 Jan 2019 21:19:20 +0100 Heiko Carstens <[email protected]>…
Quoted 28 lines · Arnd Bergmann
Quoted 11 lines · Heiko Carstens
Quoted 3 lines · Arnd Bergmann

I did not test the changes at runtime, but I looked at the generated object code, which seems fine here and includes the same conversions as before.

All looks good and seems to work fine. This is a very nice simplification of our compat code, even if it adds some dead code to the kernel image.

Quoted 5 lines

I did some tests and it all looks good. Also the generated code looks fine. So, if nothing breaks, this will go upstream with next merge window via the s390 tree.

Thanks again for your work!

Awesome, thanks for testing it so quickly and agreeing to merge it!

There is a dependency that I now have for my y2038 syscall series of course, so I'd need to have those patches on top of the s390 series.

I think we can either have a shared git branch that gets merged both into your s390 tree and my y2038 tree, or we merge it only through my tree, with your Ack.

Quoted 6 lines
Quoted 1 line

Does that work for you?

I'll discuss this with Martin tomorrow, however I think a shared git branch would be the best solution. I want to get as much testing as possible for this patch set, which means this must also be in the s390 tree.

Yes, a shared git branch seems like the best solutoin, this is now available as a topic branch on the s390/linux:

git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git compat

The branch has been merged to the features branch for v5.1.

Thanks for the work on the compat code, good stuff!

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#10 lore raw

Re: [PATCH 4/5] s390: autogenerate compat syscall wrappers

In reply to Arnd Bergmann
Quoted 23 lines · Arnd Bergmann

Any system call that takes a pointer argument on s390 requires a wrapper function to do a 31-to-64 zero-extension, these are currently generated in arch/s390/kernel/compat_wrapper.c.

On arm64 and x86, we already generate similar wrappers for all system calls in the place of their definition, just for a different purpose (they load the arguments from pt_regs).

We can do the same thing here, by adding an asm/syscall_wrapper.h file with a copy of all the relevant macros to override the generic version. Besides the addition of the compat entry point, these also rename the entry points with a __s390_ or __s390x_ prefix, similar to what we do on arm64 and x86. This in turn requires renaming a few things, and adding a proper ni_syscall() entry point.

In order to still compile system call definitions that pass an loff_t argument, the __SC_COMPAT_CAST() macro checks for that and forces an -ENOSYS error, which was the best I could come up with. Those functions must obviously not get called from user space, but instead require hand-written compat_sys_*() handlers, which fortunately already exist.

Quoted 8 lines
---
 arch/s390/Kconfig                       |   1 +
 arch/s390/include/asm/syscall_wrapper.h | 136 ++++++++++++++++++++++++
 arch/s390/kernel/compat_wrapper.c       |  23 +---
 arch/s390/kernel/entry.S                |   4 +-
 arch/s390/kernel/sys_s390.c             |   5 +
 5 files changed, 148 insertions(+), 21 deletions(-)
 create mode 100644 arch/s390/include/asm/syscall_wrapper.h

This broke system call tracing. We also need the patch below. If there aren't any objections this should be added to Martin's 'compat' branch.

From 71880dcdc62e2f89dc206a4e46c1c60e59ce3b0d Mon Sep 17 00:00:00 2001
From: Heiko Carstens <[email protected]>
Date: Mon, 21 Jan 2019 10:30:44 +0100
Subject: [PATCH] s390: fix system call tracing

When converting to autogenerated compat syscall wrappers all system call entry points got a different symbol name: they all got a __s390x_ prefix.

This caused breakage with system call tracing, since an appropriate arch_syscall_match_sym_name() was not provided. Add this function, and while at it also add code to avoid compat system call tracing. s390 has different system call tables for native 64 bit system calls and compat system calls. This isn't really supported in the common code. However there are hardly any compat binaries left, therefore just ignore compat system calls, like x86 and arm64 also do for the same reason.

Fixes aa0d6e70d3b3 ("s390: autogenerate compat syscall wrappers")
---
 arch/s390/include/asm/ftrace.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/s390/include/asm/ftrace.h +21 -0
index 8ea270fdc7fb..1e14341201c5 100644
@@ -81,5 +81,26 @@ static inline void ftrace_generate_call_insn(struct ftrace_insn *insn,
 #endif
 }
 
+/*
+ * Even though the system call numbers are identical for s390/s390x a
+ * different system call table is used for compat tasks. This may lead
+ * to e.g. incorrect or missing trace event sysfs files.
+ * Therefore simply do not trace compat system calls at all.
+ * See kernel/trace/trace_syscalls.c.
+ */
+#define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
+static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
+{
+	return is_compat_task();
+}
+
+#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
+static inline bool arch_syscall_match_sym_name(const char *sym,
+					       const char *name)
+{
+	/* skip __s390x_ prefix */
+	return !strcmp(sym + 8, name);
+}
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_S390_FTRACE_H */
Signature · 1 line
2.16.4