From patchwork Sun Mar 18 16:10:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Brodowski X-Patchwork-Id: 887414 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dominikbrodowski.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40444F1QMpz9sTL for ; Mon, 19 Mar 2018 03:13:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754492AbeCRQMr (ORCPT ); Sun, 18 Mar 2018 12:12:47 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:46692 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754588AbeCRQMB (ORCPT ); Sun, 18 Mar 2018 12:12:01 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 222D4200913; Sun, 18 Mar 2018 16:11:58 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id E27F220CA8; Sun, 18 Mar 2018 17:11:12 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, arnd@arndb.de, viro@ZenIV.linux.org.uk Cc: linux-arch@vger.kernel.org, Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org, "David S . Miller" , sparclinux@vger.kernel.org, Ingo Molnar , Jiri Slaby , x86@kernel.org Subject: [RFC PATCH 1/6] fs: provide a generic compat_sys_fallocate() implementation Date: Sun, 18 Mar 2018 17:10:51 +0100 Message-Id: <20180318161056.5377-2-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180318161056.5377-1-linux@dominikbrodowski.net> References: <20180318161056.5377-1-linux@dominikbrodowski.net> Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The compat_sys_fallocate() implementations in mips, powerpc, s390, sparc and x86 only differed based on the endianness of the u64 being passed as parameters (3, 4) and (5, 6). In addition, do not call sys_fallocate() from compat_sys_fallocate(), but use a common do_fallocate() helper instead. This patch is part of a series which tries to remove in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. Cc: Ralf Baechle Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux-s390@vger.kernel.org Cc: David S. Miller Cc: sparclinux@vger.kernel.org Cc: Ingo Molnar Cc: Jiri Slaby Cc: x86@kernel.org Cc: Al Viro Signed-off-by: Dominik Brodowski --- arch/mips/include/asm/unistd.h | 4 ++++ arch/mips/kernel/linux32.c | 7 ------- arch/mips/kernel/scall64-o32.S | 2 +- arch/powerpc/include/asm/unistd.h | 1 + arch/powerpc/kernel/sys_ppc32.c | 7 ------- arch/s390/include/asm/unistd.h | 1 + arch/s390/kernel/compat_linux.c | 7 ------- arch/s390/kernel/compat_linux.h | 1 - arch/s390/kernel/syscalls/syscall.tbl | 2 +- arch/sparc/include/asm/unistd.h | 1 + arch/sparc/kernel/sys_sparc32.c | 7 ------- arch/sparc/kernel/systbls.h | 2 -- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- arch/x86/ia32/sys_ia32.c | 8 -------- arch/x86/include/asm/sys_ia32.h | 2 -- arch/x86/include/asm/unistd.h | 2 ++ fs/open.c | 24 +++++++++++++++++++++++- include/linux/compat.h | 6 ++++++ 18 files changed, 41 insertions(+), 45 deletions(-) diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h index 3c09450908aa..bec9c6f55956 100644 --- a/arch/mips/include/asm/unistd.h +++ b/arch/mips/include/asm/unistd.h @@ -45,6 +45,10 @@ # endif # ifdef CONFIG_MIPS32_O32 # define __ARCH_WANT_COMPAT_SYS_TIME +# define __ARCH_WANT_COMPAT_SYS_FALLOCATE +# ifdef __MIPSEL__ +# define __ARCH_WANT_LE_COMPAT_SYS +# endif # endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_CLONE diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c index b332f6fc1e72..f6e6cb41c01f 100644 --- a/arch/mips/kernel/linux32.c +++ b/arch/mips/kernel/linux32.c @@ -153,10 +153,3 @@ asmlinkage long sys32_fadvise64_64(int fd, int __pad, merge_64(a2, a3), merge_64(a4, a5), flags); } - -asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2, - unsigned offset_a3, unsigned len_a4, unsigned len_a5) -{ - return sys_fallocate(fd, mode, merge_64(offset_a2, offset_a3), - merge_64(len_a4, len_a5)); -} diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S index 9ebe3e2403b1..da8babc2c1f5 100644 --- a/arch/mips/kernel/scall64-o32.S +++ b/arch/mips/kernel/scall64-o32.S @@ -536,7 +536,7 @@ EXPORT(sys32_call_table) PTR compat_sys_signalfd PTR sys_ni_syscall /* was timerfd */ PTR sys_eventfd - PTR sys32_fallocate /* 4320 */ + PTR compat_sys_fallocate /* 4320 */ PTR sys_timerfd_create PTR compat_sys_timerfd_gettime PTR compat_sys_timerfd_settime diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h index daf1ba97a00c..46890687fb1d 100644 --- a/arch/powerpc/include/asm/unistd.h +++ b/arch/powerpc/include/asm/unistd.h @@ -49,6 +49,7 @@ #define __ARCH_WANT_COMPAT_SYS_TIME #define __ARCH_WANT_SYS_NEWFSTATAT #define __ARCH_WANT_COMPAT_SYS_SENDFILE +#define __ARCH_WANT_COMPAT_SYS_FALLOCATE #endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c index 15f216d022e2..7c6da6273367 100644 --- a/arch/powerpc/kernel/sys_ppc32.c +++ b/arch/powerpc/kernel/sys_ppc32.c @@ -97,13 +97,6 @@ asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4, return sys_truncate(path, (high << 32) | low); } -asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, - u32 lenhi, u32 lenlo) -{ - return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, - ((loff_t)lenhi << 32) | lenlo); -} - asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, unsigned long low) { diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h index fd79c0d35dc4..5e919c11c11f 100644 --- a/arch/s390/include/asm/unistd.h +++ b/arch/s390/include/asm/unistd.h @@ -34,6 +34,7 @@ #define __ARCH_WANT_SYS_SIGPROCMASK # ifdef CONFIG_COMPAT # define __ARCH_WANT_COMPAT_SYS_TIME +# define __ARCH_WANT_COMPAT_SYS_FALLOCATE # endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 79b7a3438d54..3052f8e5ba42 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c @@ -512,10 +512,3 @@ COMPAT_SYSCALL_DEFINE6(s390_sync_file_range, int, fd, u32, offhigh, u32, offlow, return sys_sync_file_range(fd, ((loff_t)offhigh << 32) + offlow, ((u64)nhigh << 32) + nlow, flags); } - -COMPAT_SYSCALL_DEFINE6(s390_fallocate, int, fd, int, mode, u32, offhigh, u32, offlow, - u32, lenhigh, u32, lenlow) -{ - return sys_fallocate(fd, mode, ((loff_t)offhigh << 32) + offlow, - ((u64)lenhigh << 32) + lenlow); -} diff --git a/arch/s390/kernel/compat_linux.h b/arch/s390/kernel/compat_linux.h index 64509e7dbd3b..cfc3d42603a8 100644 --- a/arch/s390/kernel/compat_linux.h +++ b/arch/s390/kernel/compat_linux.h @@ -123,7 +123,6 @@ long compat_sys_s390_write(unsigned int fd, const char __user * buf, compat_size long compat_sys_s390_fadvise64(int fd, u32 high, u32 low, compat_size_t len, int advise); long compat_sys_s390_fadvise64_64(struct fadvise64_64_args __user *args); long compat_sys_s390_sync_file_range(int fd, u32 offhigh, u32 offlow, u32 nhigh, u32 nlow, unsigned int flags); -long compat_sys_s390_fallocate(int fd, int mode, u32 offhigh, u32 offlow, u32 lenhigh, u32 lenlow); long compat_sys_sigreturn(void); long compat_sys_rt_sigreturn(void); diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index b38d48464368..652863bb7fcb 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -321,7 +321,7 @@ 311 common getcpu sys_getcpu compat_sys_getcpu 312 common epoll_pwait sys_epoll_pwait compat_sys_epoll_pwait 313 common utimes sys_utimes compat_sys_utimes -314 common fallocate sys_fallocate compat_sys_s390_fallocate +314 common fallocate sys_fallocate compat_sys_fallocate 315 common utimensat sys_utimensat compat_sys_utimensat 316 common signalfd sys_signalfd compat_sys_signalfd 317 common timerfd - - diff --git a/arch/sparc/include/asm/unistd.h b/arch/sparc/include/asm/unistd.h index b2a6a955113e..0c875169a77b 100644 --- a/arch/sparc/include/asm/unistd.h +++ b/arch/sparc/include/asm/unistd.h @@ -43,6 +43,7 @@ #else #define __ARCH_WANT_COMPAT_SYS_TIME #define __ARCH_WANT_COMPAT_SYS_SENDFILE +#define __ARCH_WANT_COMPAT_SYS_FALLOCATE #endif #endif /* _SPARC_UNISTD_H */ diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c index 6d964bdefbaa..6c266582328b 100644 --- a/arch/sparc/kernel/sys_sparc32.c +++ b/arch/sparc/kernel/sys_sparc32.c @@ -246,10 +246,3 @@ long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned lon (nb_high << 32) | nb_low, flags); } - -asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, - u32 lenhi, u32 lenlo) -{ - return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, - ((loff_t)lenhi << 32) | lenlo); -} diff --git a/arch/sparc/kernel/systbls.h b/arch/sparc/kernel/systbls.h index 5a01cfe19a0e..ec8b097be3fe 100644 --- a/arch/sparc/kernel/systbls.h +++ b/arch/sparc/kernel/systbls.h @@ -92,8 +92,6 @@ long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, unsigned int flags); -asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, - u32 lenhi, u32 lenlo); asmlinkage long compat_sys_fstat64(unsigned int fd, struct compat_stat64 __user * statbuf); asmlinkage long compat_sys_fstatat64(unsigned int dfd, diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 2a5e99cff859..0d2a8239f63f 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -330,7 +330,7 @@ 321 i386 signalfd sys_signalfd compat_sys_signalfd 322 i386 timerfd_create sys_timerfd_create 323 i386 eventfd sys_eventfd -324 i386 fallocate sys_fallocate compat_sys_x86_fallocate +324 i386 fallocate sys_fallocate compat_sys_fallocate 325 i386 timerfd_settime sys_timerfd_settime compat_sys_timerfd_settime 326 i386 timerfd_gettime sys_timerfd_gettime compat_sys_timerfd_gettime 327 i386 signalfd4 sys_signalfd4 compat_sys_signalfd4 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index 6512498bbef6..3cc430b999a8 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c @@ -226,14 +226,6 @@ COMPAT_SYSCALL_DEFINE5(x86_fadvise64, int, fd, unsigned int, offset_lo, len, advice); } -COMPAT_SYSCALL_DEFINE6(x86_fallocate, int, fd, int, mode, - unsigned int, offset_lo, unsigned int, offset_hi, - unsigned int, len_lo, unsigned int, len_hi) -{ - return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo, - ((u64)len_hi << 32) | len_lo); -} - /* * The 32-bit clone ABI is CONFIG_CLONE_BACKWARDS */ diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index 906794aa034e..e0e375b04506 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h @@ -53,8 +53,6 @@ asmlinkage long compat_sys_x86_sync_file_range(int, unsigned int, unsigned int, int); asmlinkage long compat_sys_x86_fadvise64(int, unsigned int, unsigned int, size_t, int); -asmlinkage long compat_sys_x86_fallocate(int, int, unsigned int, unsigned int, - unsigned int, unsigned int); asmlinkage long compat_sys_x86_clone(unsigned long, unsigned long, int __user *, unsigned long, int __user *); diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h index 51c4eee00732..baf24bf65d4a 100644 --- a/arch/x86/include/asm/unistd.h +++ b/arch/x86/include/asm/unistd.h @@ -28,6 +28,8 @@ # define __ARCH_WANT_COMPAT_SYS_PWRITEV64 # define __ARCH_WANT_COMPAT_SYS_PREADV64V2 # define __ARCH_WANT_COMPAT_SYS_PWRITEV64V2 +# define __ARCH_WANT_LE_COMPAT_SYS +# define __ARCH_WANT_COMPAT_SYS_FALLOCATE # endif diff --git a/fs/open.c b/fs/open.c index 7ea118471dce..4fcf95ef8baa 100644 --- a/fs/open.c +++ b/fs/open.c @@ -333,7 +333,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) } EXPORT_SYMBOL_GPL(vfs_fallocate); -SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) +static int do_fallocate(int fd, int mode, loff_t offset, loff_t len) { struct fd f = fdget(fd); int error = -EBADF; @@ -345,6 +345,28 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) return error; } +SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) +{ + return do_fallocate(fd, mode, offset, len); +} + +#ifdef __ARCH_WANT_COMPAT_SYS_FALLOCATE +#ifdef __ARCH_WANT_LE_COMPAT_SYS +COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, + unsigned int, offset_lo, unsigned int, offset_hi, + unsigned int, len_lo, unsigned int, len_hi) +#else /* __ARCH_WANT_LE_COMPAT_SYS */ +COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, + unsigned int, offset_hi, unsigned int, offset_lo, + unsigned int, len_hi, unsigned int, len_lo) +#endif /* __ARCH_WANT_LE_COMPAT_SYS */ +{ + return do_fallocate(fd, mode, ((loff_t) offset_hi << 32) | offset_lo, + ((loff_t) len_hi << 32) | len_lo); +} +#endif /* __ARCH_WANT_COMPAT_SYS_FALLOCATE */ + + /* * access() needs to use the real uid/gid, not the effective uid/gid. * We do this by temporarily clearing all FS-related capabilities and diff --git a/include/linux/compat.h b/include/linux/compat.h index 16c3027074a2..978011c03075 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -840,6 +840,12 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset compat_old_sigset_t __user *oset); #endif +#ifdef __ARCH_WANT_COMPAT_SYS_FALLOCATE +/* __ARCH_WANT_LE_COMPAT_SYS determines order of lo and hi */ +asmlinkage long compat_sys_fallocate(int, int, unsigned int, unsigned int, + unsigned int, unsigned int); +#endif + int compat_restore_altstack(const compat_stack_t __user *uss); int __compat_save_altstack(compat_stack_t __user *, unsigned long); #define compat_save_altstack_ex(uss, sp) do { \ From patchwork Sun Mar 18 16:10:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Brodowski X-Patchwork-Id: 887416 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dominikbrodowski.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40444J6XHrz9sMM for ; Mon, 19 Mar 2018 03:13:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751977AbeCRQNT (ORCPT ); Sun, 18 Mar 2018 12:13:19 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:46552 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754147AbeCRQMA (ORCPT ); Sun, 18 Mar 2018 12:12:00 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 2221220090B; Sun, 18 Mar 2018 16:11:58 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 87FFB20CAA; Sun, 18 Mar 2018 17:11:14 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, arnd@arndb.de, viro@ZenIV.linux.org.uk Cc: linux-arch@vger.kernel.org, Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org, "David S . Miller" , sparclinux@vger.kernel.org, Ingo Molnar , Jiri Slaby , x86@kernel.org Subject: [RFC PATCH 2/6] fs: provide a generic compat_sys_truncate64() implementation Date: Sun, 18 Mar 2018 17:10:52 +0100 Message-Id: <20180318161056.5377-3-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180318161056.5377-1-linux@dominikbrodowski.net> References: <20180318161056.5377-1-linux@dominikbrodowski.net> Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The compat_sys_truncate64() implementations in mips, powerpc, s390, sparc and x86 only differed based on whether the u64 parameter needed padding and on its endianness. Oh, and some defined the parameters as "unsigned long" which expanded to u64, though it only expected u32 in these parameters. This patch is part of a series which tries to remove in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. Cc: Ralf Baechle Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux-s390@vger.kernel.org Cc: David S. Miller Cc: sparclinux@vger.kernel.org Cc: Ingo Molnar Cc: Jiri Slaby Cc: x86@kernel.org Cc: Al Viro Signed-off-by: Dominik Brodowski --- arch/mips/include/asm/unistd.h | 2 ++ arch/mips/kernel/linux32.c | 6 ------ arch/mips/kernel/scall64-o32.S | 2 +- arch/powerpc/include/asm/unistd.h | 2 ++ arch/powerpc/kernel/sys_ppc32.c | 6 ------ arch/s390/include/asm/unistd.h | 1 + arch/s390/kernel/compat_linux.c | 5 ----- arch/s390/kernel/compat_linux.h | 1 - arch/s390/kernel/syscalls/syscall.tbl | 2 +- arch/sparc/include/asm/unistd.h | 1 + arch/sparc/kernel/sys_sparc32.c | 8 -------- arch/sparc/kernel/systbls.h | 3 --- arch/sparc/kernel/systbls_64.S | 2 +- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- arch/x86/ia32/sys_ia32.c | 7 ------- arch/x86/include/asm/sys_ia32.h | 2 -- arch/x86/include/asm/unistd.h | 1 + fs/open.c | 28 +++++++++++++++++++++++++++- include/linux/compat.h | 11 +++++++++++ 19 files changed, 49 insertions(+), 43 deletions(-) diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h index bec9c6f55956..8aa5b7a19133 100644 --- a/arch/mips/include/asm/unistd.h +++ b/arch/mips/include/asm/unistd.h @@ -44,8 +44,10 @@ # define __ARCH_WANT_SYS_TIME # endif # ifdef CONFIG_MIPS32_O32 +# define __ARCH_WANT_COMPAT_SYS_WITH_PADDING # define __ARCH_WANT_COMPAT_SYS_TIME # define __ARCH_WANT_COMPAT_SYS_FALLOCATE +# define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # ifdef __MIPSEL__ # define __ARCH_WANT_LE_COMPAT_SYS # endif diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c index f6e6cb41c01f..f3aad4ca5560 100644 --- a/arch/mips/kernel/linux32.c +++ b/arch/mips/kernel/linux32.c @@ -79,12 +79,6 @@ struct rlimit32 { int rlim_max; }; -SYSCALL_DEFINE4(32_truncate64, const char __user *, path, - unsigned long, __dummy, unsigned long, a2, unsigned long, a3) -{ - return sys_truncate(path, merge_64(a2, a3)); -} - SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy, unsigned long, a2, unsigned long, a3) { diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S index da8babc2c1f5..216450516b44 100644 --- a/arch/mips/kernel/scall64-o32.S +++ b/arch/mips/kernel/scall64-o32.S @@ -427,7 +427,7 @@ EXPORT(sys32_call_table) PTR sys_ni_syscall PTR sys_ni_syscall PTR sys_mips_mmap2 /* 4210 */ - PTR sys_32_truncate64 + PTR compat_sys_truncate64 PTR sys_32_ftruncate64 PTR sys_newstat PTR sys_newlstat diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h index 46890687fb1d..dca76157f27e 100644 --- a/arch/powerpc/include/asm/unistd.h +++ b/arch/powerpc/include/asm/unistd.h @@ -46,10 +46,12 @@ #define __ARCH_WANT_OLD_STAT #endif #ifdef CONFIG_PPC64 +#define __ARCH_WANT_COMPAT_SYS_WITH_PADDING #define __ARCH_WANT_COMPAT_SYS_TIME #define __ARCH_WANT_SYS_NEWFSTATAT #define __ARCH_WANT_COMPAT_SYS_SENDFILE #define __ARCH_WANT_COMPAT_SYS_FALLOCATE +#define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 #endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c index 7c6da6273367..dab9eece7731 100644 --- a/arch/powerpc/kernel/sys_ppc32.c +++ b/arch/powerpc/kernel/sys_ppc32.c @@ -91,12 +91,6 @@ compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 co return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); } -asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4, - unsigned long high, unsigned long low) -{ - return sys_truncate(path, (high << 32) | low); -} - asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, unsigned long low) { diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h index 5e919c11c11f..7667a2d0b1e1 100644 --- a/arch/s390/include/asm/unistd.h +++ b/arch/s390/include/asm/unistd.h @@ -35,6 +35,7 @@ # ifdef CONFIG_COMPAT # define __ARCH_WANT_COMPAT_SYS_TIME # define __ARCH_WANT_COMPAT_SYS_FALLOCATE +# define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 3052f8e5ba42..469addfe7a85 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c @@ -300,11 +300,6 @@ COMPAT_SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, compat_ulong_t, second, } #endif -COMPAT_SYSCALL_DEFINE3(s390_truncate64, const char __user *, path, u32, high, u32, low) -{ - return sys_truncate(path, (unsigned long)high << 32 | low); -} - COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low) { return sys_ftruncate(fd, (unsigned long)high << 32 | low); diff --git a/arch/s390/kernel/compat_linux.h b/arch/s390/kernel/compat_linux.h index cfc3d42603a8..17db19a91e63 100644 --- a/arch/s390/kernel/compat_linux.h +++ b/arch/s390/kernel/compat_linux.h @@ -107,7 +107,6 @@ long compat_sys_s390_getuid16(void); long compat_sys_s390_geteuid16(void); long compat_sys_s390_getgid16(void); long compat_sys_s390_getegid16(void); -long compat_sys_s390_truncate64(const char __user *path, u32 high, u32 low); long compat_sys_s390_ftruncate64(unsigned int fd, u32 high, u32 low); long compat_sys_s390_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, u32 high, u32 low); long compat_sys_s390_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count, u32 high, u32 low); diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index 652863bb7fcb..d8dec7c9d2a5 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -182,7 +182,7 @@ 191 32 ugetrlimit - compat_sys_getrlimit 191 64 getrlimit sys_getrlimit - 192 32 mmap2 - compat_sys_s390_mmap2 -193 32 truncate64 - compat_sys_s390_truncate64 +193 32 truncate64 - compat_sys_truncate64 194 32 ftruncate64 - compat_sys_s390_ftruncate64 195 32 stat64 - compat_sys_s390_stat64 196 32 lstat64 - compat_sys_s390_lstat64 diff --git a/arch/sparc/include/asm/unistd.h b/arch/sparc/include/asm/unistd.h index 0c875169a77b..0398d9be05a5 100644 --- a/arch/sparc/include/asm/unistd.h +++ b/arch/sparc/include/asm/unistd.h @@ -44,6 +44,7 @@ #define __ARCH_WANT_COMPAT_SYS_TIME #define __ARCH_WANT_COMPAT_SYS_SENDFILE #define __ARCH_WANT_COMPAT_SYS_FALLOCATE +#define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 #endif #endif /* _SPARC_UNISTD_H */ diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c index 6c266582328b..39f8a5845285 100644 --- a/arch/sparc/kernel/sys_sparc32.c +++ b/arch/sparc/kernel/sys_sparc32.c @@ -52,14 +52,6 @@ #include "systbls.h" -asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low) -{ - if ((int)high < 0) - return -EINVAL; - else - return sys_truncate(path, (high << 32) | low); -} - asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low) { if ((int)high < 0) diff --git a/arch/sparc/kernel/systbls.h b/arch/sparc/kernel/systbls.h index ec8b097be3fe..92659147ca76 100644 --- a/arch/sparc/kernel/systbls.h +++ b/arch/sparc/kernel/systbls.h @@ -50,9 +50,6 @@ asmlinkage long sparc_memory_ordering(unsigned long model, struct pt_regs *regs); asmlinkage void sparc64_set_context(struct pt_regs *regs); asmlinkage void sparc64_get_context(struct pt_regs *regs); -asmlinkage long sys32_truncate64(const char __user * path, - unsigned long high, - unsigned long low); asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low); diff --git a/arch/sparc/kernel/systbls_64.S b/arch/sparc/kernel/systbls_64.S index 293c1cb31262..9d718a9ec52d 100644 --- a/arch/sparc/kernel/systbls_64.S +++ b/arch/sparc/kernel/systbls_64.S @@ -34,7 +34,7 @@ sys_call_table32: /*60*/ .word sys_umask, sys_chroot, compat_sys_newfstat, compat_sys_fstat64, sys_getpagesize .word sys_msync, sys_vfork, sys32_pread64, sys32_pwrite64, sys_geteuid /*70*/ .word sys_getegid, sys_mmap, sys_setreuid, sys_munmap, sys_mprotect - .word sys_madvise, sys_vhangup, sys32_truncate64, sys_mincore, sys_getgroups16 + .word sys_madvise, sys_vhangup, compat_sys_truncate64, sys_mincore, sys_getgroups16 /*80*/ .word sys_setgroups16, sys_getpgrp, sys_setgroups, compat_sys_setitimer, sys32_ftruncate64 .word sys_swapon, compat_sys_getitimer, sys_setuid, sys_sethostname, sys_setgid /*90*/ .word sys_dup2, sys_setfsuid, compat_sys_fcntl, sys32_select, sys_setfsgid diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 0d2a8239f63f..c60caeac57f9 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -199,7 +199,7 @@ 190 i386 vfork sys_vfork 191 i386 ugetrlimit sys_getrlimit compat_sys_getrlimit 192 i386 mmap2 sys_mmap_pgoff -193 i386 truncate64 sys_truncate64 compat_sys_x86_truncate64 +193 i386 truncate64 sys_truncate64 compat_sys_truncate64 194 i386 ftruncate64 sys_ftruncate64 compat_sys_x86_ftruncate64 195 i386 stat64 sys_stat64 compat_sys_x86_stat64 196 i386 lstat64 sys_lstat64 compat_sys_x86_lstat64 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index 3cc430b999a8..56e2e605892c 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c @@ -50,13 +50,6 @@ #define AA(__x) ((unsigned long)(__x)) - -COMPAT_SYSCALL_DEFINE3(x86_truncate64, const char __user *, filename, - unsigned long, offset_low, unsigned long, offset_high) -{ - return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low); -} - COMPAT_SYSCALL_DEFINE3(x86_ftruncate64, unsigned int, fd, unsigned long, offset_low, unsigned long, offset_high) { diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index e0e375b04506..9d928ec5b78a 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h @@ -20,8 +20,6 @@ #include /* ia32/sys_ia32.c */ -asmlinkage long compat_sys_x86_truncate64(const char __user *, unsigned long, - unsigned long); asmlinkage long compat_sys_x86_ftruncate64(unsigned int, unsigned long, unsigned long); diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h index baf24bf65d4a..382b1e5272db 100644 --- a/arch/x86/include/asm/unistd.h +++ b/arch/x86/include/asm/unistd.h @@ -30,6 +30,7 @@ # define __ARCH_WANT_COMPAT_SYS_PWRITEV64V2 # define __ARCH_WANT_LE_COMPAT_SYS # define __ARCH_WANT_COMPAT_SYS_FALLOCATE +# define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # endif diff --git a/fs/open.c b/fs/open.c index 4fcf95ef8baa..1a0f46de5df5 100644 --- a/fs/open.c +++ b/fs/open.c @@ -222,7 +222,7 @@ COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_ulong_t, length) } #endif -/* LFS versions of truncate are only needed on 32 bit machines */ +/* LFS versions of truncate are only needed on 32 bit machines or for compat */ #if BITS_PER_LONG == 32 SYSCALL_DEFINE2(truncate64, const char __user *, path, loff_t, length) { @@ -235,6 +235,32 @@ SYSCALL_DEFINE2(ftruncate64, unsigned int, fd, loff_t, length) } #endif /* BITS_PER_LONG == 32 */ +#ifdef __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +#if defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE4(truncate64, const char __user *, filename, u32 padding, + unsigned int, offset_low, unsigned int, offset_high) +#elif defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + !defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE4(truncate64, const char __user *, filename, u32 padding, + unsigned int, offset_high, unsigned int, offset_low) +#elif !defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, filename, + unsigned int, offset_low, unsigned int, offset_high) +#else /* no padding, big endian */ +COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, filename, + unsigned int, offset_high, unsigned int, offset_low) +#endif +{ +#ifdef CONFIG_SPARC + if ((int) offset_high < 0) + return -EINVAL; +#endif + return do_sys_truncate(filename, + ((loff_t) offset_high << 32) | offset_low); +} +#endif /* __ARCH_WANT_COMPAT_SYS_TRUNCATE64 */ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) { diff --git a/include/linux/compat.h b/include/linux/compat.h index 978011c03075..454ccad57d84 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -846,6 +846,17 @@ asmlinkage long compat_sys_fallocate(int, int, unsigned int, unsigned int, unsigned int, unsigned int); #endif +#ifdef __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +/* __ARCH_WANT_LE_COMPAT_SYS determines order of lo and hi */ +#ifdef __ARCH_WANT_COMPAT_SYS_WITH_PADDING +asmlinkage long compat_sys_truncate64(const char __user *, unsigned int, + unsigned int, unsigned int); +#else /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +asmlinkage long compat_sys_truncate64(const char __user *, + unsigned int, unsigned int); +#endif /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +#endif /* __ARCH_WANT_COMPAT_SYS_TRUNCATE64 */ + int compat_restore_altstack(const compat_stack_t __user *uss); int __compat_save_altstack(compat_stack_t __user *, unsigned long); #define compat_save_altstack_ex(uss, sp) do { \ From patchwork Sun Mar 18 16:10:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Brodowski X-Patchwork-Id: 887415 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dominikbrodowski.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40444B1BV9z9sMM for ; Mon, 19 Mar 2018 03:13:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754745AbeCRQMs (ORCPT ); Sun, 18 Mar 2018 12:12:48 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:46690 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754556AbeCRQMB (ORCPT ); Sun, 18 Mar 2018 12:12:01 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 22258200910; Sun, 18 Mar 2018 16:11:58 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 12B1A20CC8; Sun, 18 Mar 2018 17:11:15 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, arnd@arndb.de, viro@ZenIV.linux.org.uk Cc: linux-arch@vger.kernel.org, Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org, "David S . Miller" , sparclinux@vger.kernel.org, Ingo Molnar , Jiri Slaby , x86@kernel.org Subject: [RFC PATCH 3/6] fs: provide generic compat_sys_p{read, write}64() implementations Date: Sun, 18 Mar 2018 17:10:53 +0100 Message-Id: <20180318161056.5377-4-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180318161056.5377-1-linux@dominikbrodowski.net> References: <20180318161056.5377-1-linux@dominikbrodowski.net> Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The compat_sys_{read,write}64() implementations in mips, powerpc, s390, sparc and x86 only differed based on whether the u64 parameter needed padding and on their endianness. Oh, and some defined the parameters as u64 or "unsigned long" which expanded to u64, though it only expected u32 in these parameters. This patch is part of a series which tries to remove in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. Suggested-by: Al Viro Cc: Ralf Baechle Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux-s390@vger.kernel.org Cc: David S. Miller Cc: sparclinux@vger.kernel.org Cc: Ingo Molnar Cc: Jiri Slaby Cc: x86@kernel.org Cc: Al Viro Signed-off-by: Dominik Brodowski --- arch/mips/include/asm/unistd.h | 1 + arch/mips/kernel/linux32.c | 16 -------- arch/mips/kernel/scall64-o32.S | 4 +- arch/powerpc/include/asm/unistd.h | 1 + arch/powerpc/kernel/sys_ppc32.c | 12 ------ arch/s390/include/asm/unistd.h | 1 + arch/s390/kernel/compat_linux.c | 16 -------- arch/s390/kernel/compat_linux.h | 2 - arch/s390/kernel/syscalls/syscall.tbl | 4 +- arch/sparc/include/asm/unistd.h | 1 + arch/sparc/kernel/sys_sparc32.c | 18 --------- arch/sparc/kernel/systbls.h | 10 ----- arch/sparc/kernel/systbls_64.S | 2 +- arch/x86/entry/syscalls/syscall_32.tbl | 4 +- arch/x86/ia32/sys_ia32.c | 16 -------- arch/x86/include/asm/sys_ia32.h | 5 --- arch/x86/include/asm/unistd.h | 1 + fs/read_write.c | 74 ++++++++++++++++++++++++++++++++-- include/linux/compat.h | 15 +++++++ 19 files changed, 97 insertions(+), 106 deletions(-) diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h index 8aa5b7a19133..3ddc271ad77b 100644 --- a/arch/mips/include/asm/unistd.h +++ b/arch/mips/include/asm/unistd.h @@ -48,6 +48,7 @@ # define __ARCH_WANT_COMPAT_SYS_TIME # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +# define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 # ifdef __MIPSEL__ # define __ARCH_WANT_LE_COMPAT_SYS # endif diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c index f3aad4ca5560..871cda53a915 100644 --- a/arch/mips/kernel/linux32.c +++ b/arch/mips/kernel/linux32.c @@ -92,22 +92,6 @@ SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high, return sys_llseek(fd, offset_high, offset_low, result, origin); } -/* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + - lseek back to original location. They fail just like lseek does on - non-seekable files. */ - -SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count, - unsigned long, unused, unsigned long, a4, unsigned long, a5) -{ - return sys_pread64(fd, buf, count, merge_64(a4, a5)); -} - -SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf, - size_t, count, u32, unused, u64, a4, u64, a5) -{ - return sys_pwrite64(fd, buf, count, merge_64(a4, a5)); -} - SYSCALL_DEFINE1(32_personality, unsigned long, personality) { unsigned int p = personality & 0xffffffff; diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S index 216450516b44..fbc463b234a1 100644 --- a/arch/mips/kernel/scall64-o32.S +++ b/arch/mips/kernel/scall64-o32.S @@ -416,8 +416,8 @@ EXPORT(sys32_call_table) PTR compat_sys_rt_sigtimedwait PTR compat_sys_rt_sigqueueinfo PTR compat_sys_rt_sigsuspend - PTR sys_32_pread /* 4200 */ - PTR sys_32_pwrite + PTR compat_sys_pread64 /* 4200 */ + PTR compat_sys_pwrite64 PTR sys_chown PTR sys_getcwd PTR sys_capget diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h index dca76157f27e..704f2413ac30 100644 --- a/arch/powerpc/include/asm/unistd.h +++ b/arch/powerpc/include/asm/unistd.h @@ -52,6 +52,7 @@ #define __ARCH_WANT_COMPAT_SYS_SENDFILE #define __ARCH_WANT_COMPAT_SYS_FALLOCATE #define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +#define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 #endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c index dab9eece7731..ec896c8df968 100644 --- a/arch/powerpc/kernel/sys_ppc32.c +++ b/arch/powerpc/kernel/sys_ppc32.c @@ -74,18 +74,6 @@ unsigned long compat_sys_mmap2(unsigned long addr, size_t len, * The 32 bit ABI passes long longs in an odd even register pair. */ -compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, - u32 reg6, u32 poshi, u32 poslo) -{ - return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); -} - -compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count, - u32 reg6, u32 poshi, u32 poslo) -{ - return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); -} - compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) { return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h index 7667a2d0b1e1..71e6f7d65762 100644 --- a/arch/s390/include/asm/unistd.h +++ b/arch/s390/include/asm/unistd.h @@ -36,6 +36,7 @@ # define __ARCH_WANT_COMPAT_SYS_TIME # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +# define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 # endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 469addfe7a85..8dd12a9d99a3 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c @@ -305,22 +305,6 @@ COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low) return sys_ftruncate(fd, (unsigned long)high << 32 | low); } -COMPAT_SYSCALL_DEFINE5(s390_pread64, unsigned int, fd, char __user *, ubuf, - compat_size_t, count, u32, high, u32, low) -{ - if ((compat_ssize_t) count < 0) - return -EINVAL; - return sys_pread64(fd, ubuf, count, (unsigned long)high << 32 | low); -} - -COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd, const char __user *, ubuf, - compat_size_t, count, u32, high, u32, low) -{ - if ((compat_ssize_t) count < 0) - return -EINVAL; - return sys_pwrite64(fd, ubuf, count, (unsigned long)high << 32 | low); -} - COMPAT_SYSCALL_DEFINE4(s390_readahead, int, fd, u32, high, u32, low, s32, count) { return sys_readahead(fd, (unsigned long)high << 32 | low, count); diff --git a/arch/s390/kernel/compat_linux.h b/arch/s390/kernel/compat_linux.h index 17db19a91e63..35fe45225185 100644 --- a/arch/s390/kernel/compat_linux.h +++ b/arch/s390/kernel/compat_linux.h @@ -108,8 +108,6 @@ long compat_sys_s390_geteuid16(void); long compat_sys_s390_getgid16(void); long compat_sys_s390_getegid16(void); long compat_sys_s390_ftruncate64(unsigned int fd, u32 high, u32 low); -long compat_sys_s390_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, u32 high, u32 low); -long compat_sys_s390_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count, u32 high, u32 low); long compat_sys_s390_readahead(int fd, u32 high, u32 low, s32 count); long compat_sys_s390_stat64(const char __user *filename, struct stat64_emu31 __user *statbuf); long compat_sys_s390_lstat64(const char __user *filename, struct stat64_emu31 __user *statbuf); diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index d8dec7c9d2a5..ceaf5ab6ac47 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -168,8 +168,8 @@ 177 common rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait 178 common rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo 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 +180 common pread64 sys_pread64 compat_sys_pread64 +181 common pwrite64 sys_pwrite64 compat_sys_pwrite64 182 32 chown - compat_sys_s390_chown16 183 common getcwd sys_getcwd compat_sys_getcwd 184 common capget sys_capget compat_sys_capget diff --git a/arch/sparc/include/asm/unistd.h b/arch/sparc/include/asm/unistd.h index 0398d9be05a5..e04452be8db4 100644 --- a/arch/sparc/include/asm/unistd.h +++ b/arch/sparc/include/asm/unistd.h @@ -45,6 +45,7 @@ #define __ARCH_WANT_COMPAT_SYS_SENDFILE #define __ARCH_WANT_COMPAT_SYS_FALLOCATE #define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +#define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 #endif #endif /* _SPARC_UNISTD_H */ diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c index 39f8a5845285..8a4f5accf6be 100644 --- a/arch/sparc/kernel/sys_sparc32.c +++ b/arch/sparc/kernel/sys_sparc32.c @@ -186,24 +186,6 @@ COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig, return ret; } -asmlinkage compat_ssize_t sys32_pread64(unsigned int fd, - char __user *ubuf, - compat_size_t count, - unsigned long poshi, - unsigned long poslo) -{ - return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo); -} - -asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd, - char __user *ubuf, - compat_size_t count, - unsigned long poshi, - unsigned long poslo) -{ - return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo); -} - asmlinkage long compat_sys_readahead(int fd, unsigned long offhi, unsigned long offlo, diff --git a/arch/sparc/kernel/systbls.h b/arch/sparc/kernel/systbls.h index 92659147ca76..6b5fd12e821d 100644 --- a/arch/sparc/kernel/systbls.h +++ b/arch/sparc/kernel/systbls.h @@ -63,16 +63,6 @@ asmlinkage long compat_sys_fstat64(unsigned int fd, asmlinkage long compat_sys_fstatat64(unsigned int dfd, const char __user *filename, struct compat_stat64 __user * statbuf, int flag); -asmlinkage compat_ssize_t sys32_pread64(unsigned int fd, - char __user *ubuf, - compat_size_t count, - unsigned long poshi, - unsigned long poslo); -asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd, - char __user *ubuf, - compat_size_t count, - unsigned long poshi, - unsigned long poslo); asmlinkage long compat_sys_readahead(int fd, unsigned long offhi, unsigned long offlo, diff --git a/arch/sparc/kernel/systbls_64.S b/arch/sparc/kernel/systbls_64.S index 9d718a9ec52d..33731b4e8819 100644 --- a/arch/sparc/kernel/systbls_64.S +++ b/arch/sparc/kernel/systbls_64.S @@ -32,7 +32,7 @@ sys_call_table32: /*50*/ .word sys_getegid16, sys_acct, sys_nis_syscall, sys_getgid, compat_sys_ioctl .word sys_reboot, sys32_mmap2, sys_symlink, sys_readlink, sys32_execve /*60*/ .word sys_umask, sys_chroot, compat_sys_newfstat, compat_sys_fstat64, sys_getpagesize - .word sys_msync, sys_vfork, sys32_pread64, sys32_pwrite64, sys_geteuid + .word sys_msync, sys_vfork, compat_sys_pread64, compat_sys_pwrite64, sys_geteuid /*70*/ .word sys_getegid, sys_mmap, sys_setreuid, sys_munmap, sys_mprotect .word sys_madvise, sys_vhangup, compat_sys_truncate64, sys_mincore, sys_getgroups16 /*80*/ .word sys_setgroups16, sys_getpgrp, sys_setgroups, compat_sys_setitimer, sys32_ftruncate64 diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index c60caeac57f9..2f39235785d8 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -186,8 +186,8 @@ 177 i386 rt_sigtimedwait sys_rt_sigtimedwait compat_sys_rt_sigtimedwait 178 i386 rt_sigqueueinfo sys_rt_sigqueueinfo compat_sys_rt_sigqueueinfo 179 i386 rt_sigsuspend sys_rt_sigsuspend -180 i386 pread64 sys_pread64 compat_sys_x86_pread -181 i386 pwrite64 sys_pwrite64 compat_sys_x86_pwrite +180 i386 pread64 sys_pread64 compat_sys_pread64 +181 i386 pwrite64 sys_pwrite64 compat_sys_pwrite64 182 i386 chown sys_chown16 183 i386 getcwd sys_getcwd 184 i386 capget sys_capget diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index 56e2e605892c..eae207229a93 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c @@ -167,22 +167,6 @@ COMPAT_SYSCALL_DEFINE3(x86_waitpid, compat_pid_t, pid, unsigned int __user *, return compat_sys_wait4(pid, stat_addr, options, NULL); } -/* warning: next two assume little endian */ -COMPAT_SYSCALL_DEFINE5(x86_pread, unsigned int, fd, char __user *, ubuf, - u32, count, u32, poslo, u32, poshi) -{ - return sys_pread64(fd, ubuf, count, - ((loff_t)AA(poshi) << 32) | AA(poslo)); -} - -COMPAT_SYSCALL_DEFINE5(x86_pwrite, unsigned int, fd, const char __user *, ubuf, - u32, count, u32, poslo, u32, poshi) -{ - return sys_pwrite64(fd, ubuf, count, - ((loff_t)AA(poshi) << 32) | AA(poslo)); -} - - /* * Some system calls that need sign extended arguments. This could be * done by a generic wrapper. diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index 9d928ec5b78a..ded631bb33de 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h @@ -36,11 +36,6 @@ asmlinkage long compat_sys_x86_mmap(struct mmap_arg_struct32 __user *); asmlinkage long compat_sys_x86_waitpid(compat_pid_t, unsigned int __user *, int); -asmlinkage long compat_sys_x86_pread(unsigned int, char __user *, u32, u32, - u32); -asmlinkage long compat_sys_x86_pwrite(unsigned int, const char __user *, u32, - u32, u32); - asmlinkage long compat_sys_x86_fadvise64_64(int, __u32, __u32, __u32, __u32, int); diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h index 382b1e5272db..be8f52494ee3 100644 --- a/arch/x86/include/asm/unistd.h +++ b/arch/x86/include/asm/unistd.h @@ -31,6 +31,7 @@ # define __ARCH_WANT_LE_COMPAT_SYS # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 +# define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 # endif diff --git a/fs/read_write.c b/fs/read_write.c index f8547b82dfb3..071197e856fc 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -595,8 +595,8 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, return ret; } -SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf, - size_t, count, loff_t, pos) +static ssize_t do_pread64(unsigned int fd, char __user *buf, + size_t count, loff_t pos) { struct fd f; ssize_t ret = -EBADF; @@ -615,8 +615,8 @@ SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf, return ret; } -SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf, - size_t, count, loff_t, pos) +static ssize_t do_pwrite64(unsigned int fd, const char __user *buf, + size_t count, loff_t pos) { struct fd f; ssize_t ret = -EBADF; @@ -635,6 +635,72 @@ SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf, return ret; } +SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf, + size_t, count, loff_t, pos) +{ + return do_pread64(fd, buf, count, pos); +} + +SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf, + size_t, count, loff_t, pos) +{ + return do_pwrite64(fd, buf, count, pos); +} + +#ifdef __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +#if defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE6(pread64, unsigned int, fd, char __user *, ubuf, + u32, count, u32, padding, u32, poslo, u32, poshi) +#elif defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + !defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE6(pread64, unsigned int, fd, char __user *, ubuf, + u32, count, u32, padding, u32, poshi, u32, poslo) +#elif !defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, ubuf, + u32, count, u32, poslo, u32, poshi) +#else /* no padding, big endian */ +COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, ubuf, + u32, count, u32, poshi, u32, poslo) +#endif +{ +#ifdef CONFIG_S390 + if ((compat_ssize_t) count < 0) + return -EINVAL; +#endif /* CONFIG_S390 */ + return do_pread64(fd, ubuf, count, + ((loff_t) (unsigned long) (poshi) << 32) | + (unsigned long) (poslo)); +} + +#if defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE6(pwrite64, unsigned int, fd, const char __user *, ubuf, + u32, count, u32, padding, u32, poslo, u32, poshi) +#elif defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + !defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE6(pwrite64, unsigned int, fd, const char __user *, ubuf, + u32, count, u32, padding, u32, poshi, u32, poslo) +#elif !defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, const char __user *, ubuf, + u32, count, u32, poslo, u32, poshi) +#else /* no padding, big endian */ +COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, const char __user *, ubuf, + u32, count, u32, poshi, u32, poslo) +#endif +{ +#ifdef CONFIG_S390 + if ((compat_ssize_t) count < 0) + return -EINVAL; +#endif /* CONFIG_S390 */ + return do_pwrite64(fd, ubuf, count, + ((loff_t) (unsigned long) (poshi) << 32) | + (unsigned long) (poslo)); +} +#endif /* __ARCH_WANT_COMPAT_SYS_PREADWRITE64 */ + static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, loff_t *ppos, int type, rwf_t flags) { diff --git a/include/linux/compat.h b/include/linux/compat.h index 454ccad57d84..95301d1a6793 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -857,6 +857,21 @@ asmlinkage long compat_sys_truncate64(const char __user *, #endif /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ #endif /* __ARCH_WANT_COMPAT_SYS_TRUNCATE64 */ +#ifdef __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +/* __ARCH_WANT_LE_COMPAT_SYS determines order of lo and hi */ +#ifdef __ARCH_WANT_COMPAT_SYS_WITH_PADDING +asmlinkage long compat_sys_pwrite64(unsigned int, const char __user *, u32, + u32, u32, u32); +asmlinkage long compat_sys_pread64(unsigned int, char __user *, u32, + u32, u32, u32); +#else /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +asmlinkage long compat_sys_pwrite64(unsigned int, const char __user *, + u32, u32, u32); +asmlinkage long compat_sys_pread64(unsigned int, char __user *, + u32, u32, u32); +#endif /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +#endif /* __ARCH_WANT_COMPAT_SYS_PREADWRITE64 */ + int compat_restore_altstack(const compat_stack_t __user *uss); int __compat_save_altstack(compat_stack_t __user *, unsigned long); #define compat_save_altstack_ex(uss, sp) do { \ From patchwork Sun Mar 18 16:10:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominik Brodowski X-Patchwork-Id: 887418 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=sparclinux-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dominikbrodowski.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40444x3wbpz9sMM for ; Mon, 19 Mar 2018 03:13:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754790AbeCRQNW (ORCPT ); Sun, 18 Mar 2018 12:13:22 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:46482 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754127AbeCRQMA (ORCPT ); Sun, 18 Mar 2018 12:12:00 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id B2741200902; Sun, 18 Mar 2018 16:11:57 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 7D4FD20CF0; Sun, 18 Mar 2018 17:11:15 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, arnd@arndb.de, viro@ZenIV.linux.org.uk Cc: linux-arch@vger.kernel.org, Ralf Baechle , James Hogan , linux-mips@linux-mips.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org, "David S . Miller" , sparclinux@vger.kernel.org, Ingo Molnar , Jiri Slaby , x86@kernel.org Subject: [RFC PATCH 4/6] mm: provide generic compat_sys_readahead() implementation Date: Sun, 18 Mar 2018 17:10:54 +0100 Message-Id: <20180318161056.5377-5-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180318161056.5377-1-linux@dominikbrodowski.net> References: <20180318161056.5377-1-linux@dominikbrodowski.net> Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The compat_sys_readahead() implementations in mips, powerpc, s390, sparc and x86 only differed based on whether the u64 parameter needed padding and on their endianness. Oh, and some defined the parameters as u64 or "unsigned long" which expanded to u64, though it only expected u32 in these parameters. This patch is part of a series which tries to remove in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. Cc: Ralf Baechle Cc: James Hogan Cc: linux-mips@linux-mips.org Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: linux-s390@vger.kernel.org Cc: David S. Miller Cc: sparclinux@vger.kernel.org Cc: Ingo Molnar Cc: Jiri Slaby Cc: x86@kernel.org Cc: Al Viro Signed-off-by: Dominik Brodowski --- arch/mips/include/asm/unistd.h | 1 + arch/mips/kernel/linux32.c | 6 --- arch/mips/kernel/scall64-o32.S | 2 +- arch/powerpc/include/asm/unistd.h | 1 + arch/powerpc/kernel/sys_ppc32.c | 5 --- arch/s390/include/asm/unistd.h | 1 + arch/s390/kernel/compat_linux.c | 5 --- arch/s390/kernel/compat_linux.h | 1 - arch/s390/kernel/syscalls/syscall.tbl | 2 +- arch/sparc/include/asm/unistd.h | 1 + arch/sparc/kernel/sys_sparc32.c | 8 ---- arch/sparc/kernel/systbls.h | 4 -- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- arch/x86/ia32/sys_ia32.c | 6 --- arch/x86/include/asm/sys_ia32.h | 2 - arch/x86/include/asm/unistd.h | 1 + include/linux/compat.h | 10 +++++ mm/readahead.c | 81 ++++++++++++++++++++++++---------- 18 files changed, 76 insertions(+), 63 deletions(-) diff --git a/arch/mips/include/asm/unistd.h b/arch/mips/include/asm/unistd.h index 3ddc271ad77b..f8f9046164ae 100644 --- a/arch/mips/include/asm/unistd.h +++ b/arch/mips/include/asm/unistd.h @@ -49,6 +49,7 @@ # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +# define __ARCH_WANT_COMPAT_SYS_READAHEAD # ifdef __MIPSEL__ # define __ARCH_WANT_LE_COMPAT_SYS # endif diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c index 871cda53a915..c40ce08be17d 100644 --- a/arch/mips/kernel/linux32.c +++ b/arch/mips/kernel/linux32.c @@ -106,12 +106,6 @@ SYSCALL_DEFINE1(32_personality, unsigned long, personality) return ret; } -asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, - size_t count) -{ - return sys_readahead(fd, merge_64(a2, a3), count); -} - asmlinkage long sys32_sync_file_range(int fd, int __pad, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S index fbc463b234a1..eb4e66ba025a 100644 --- a/arch/mips/kernel/scall64-o32.S +++ b/arch/mips/kernel/scall64-o32.S @@ -439,7 +439,7 @@ EXPORT(sys32_call_table) PTR compat_sys_fcntl64 /* 4220 */ PTR sys_ni_syscall PTR sys_gettid - PTR sys32_readahead + PTR compat_sys_readahead PTR sys_setxattr PTR sys_lsetxattr /* 4225 */ PTR sys_fsetxattr diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h index 704f2413ac30..870317a35763 100644 --- a/arch/powerpc/include/asm/unistd.h +++ b/arch/powerpc/include/asm/unistd.h @@ -53,6 +53,7 @@ #define __ARCH_WANT_COMPAT_SYS_FALLOCATE #define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 #define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +#define __ARCH_WANT_COMPAT_SYS_READAHEAD #endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c index ec896c8df968..289ae55bb4b5 100644 --- a/arch/powerpc/kernel/sys_ppc32.c +++ b/arch/powerpc/kernel/sys_ppc32.c @@ -74,11 +74,6 @@ unsigned long compat_sys_mmap2(unsigned long addr, size_t len, * The 32 bit ABI passes long longs in an odd even register pair. */ -compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) -{ - return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); -} - asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, unsigned long low) { diff --git a/arch/s390/include/asm/unistd.h b/arch/s390/include/asm/unistd.h index 71e6f7d65762..685ad7944850 100644 --- a/arch/s390/include/asm/unistd.h +++ b/arch/s390/include/asm/unistd.h @@ -37,6 +37,7 @@ # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +# define __ARCH_WANT_COMPAT_SYS_READAHEAD # endif #define __ARCH_WANT_SYS_FORK #define __ARCH_WANT_SYS_VFORK diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 8dd12a9d99a3..9f111d1f1ec2 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c @@ -305,11 +305,6 @@ COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low) return sys_ftruncate(fd, (unsigned long)high << 32 | low); } -COMPAT_SYSCALL_DEFINE4(s390_readahead, int, fd, u32, high, u32, low, s32, count) -{ - return sys_readahead(fd, (unsigned long)high << 32 | low, count); -} - struct stat64_emu31 { unsigned long long st_dev; unsigned int __pad1; diff --git a/arch/s390/kernel/compat_linux.h b/arch/s390/kernel/compat_linux.h index 35fe45225185..cac6dd7bced0 100644 --- a/arch/s390/kernel/compat_linux.h +++ b/arch/s390/kernel/compat_linux.h @@ -108,7 +108,6 @@ long compat_sys_s390_geteuid16(void); long compat_sys_s390_getgid16(void); long compat_sys_s390_getegid16(void); long compat_sys_s390_ftruncate64(unsigned int fd, u32 high, u32 low); -long compat_sys_s390_readahead(int fd, u32 high, u32 low, s32 count); long compat_sys_s390_stat64(const char __user *filename, struct stat64_emu31 __user *statbuf); long compat_sys_s390_lstat64(const char __user *filename, struct stat64_emu31 __user *statbuf); long compat_sys_s390_fstat64(unsigned int fd, struct stat64_emu31 __user *statbuf); diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl index ceaf5ab6ac47..a7d989a292f7 100644 --- a/arch/s390/kernel/syscalls/syscall.tbl +++ b/arch/s390/kernel/syscalls/syscall.tbl @@ -230,7 +230,7 @@ 219 common madvise sys_madvise compat_sys_madvise 220 common getdents64 sys_getdents64 compat_sys_getdents64 221 32 fcntl64 - compat_sys_fcntl64 -222 common readahead sys_readahead compat_sys_s390_readahead +222 common readahead sys_readahead compat_sys_readahead 223 32 sendfile64 - compat_sys_sendfile64 224 common setxattr sys_setxattr compat_sys_setxattr 225 common lsetxattr sys_lsetxattr compat_sys_lsetxattr diff --git a/arch/sparc/include/asm/unistd.h b/arch/sparc/include/asm/unistd.h index e04452be8db4..85579de64f60 100644 --- a/arch/sparc/include/asm/unistd.h +++ b/arch/sparc/include/asm/unistd.h @@ -46,6 +46,7 @@ #define __ARCH_WANT_COMPAT_SYS_FALLOCATE #define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 #define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +#define __ARCH_WANT_COMPAT_SYS_READAHEAD #endif #endif /* _SPARC_UNISTD_H */ diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c index 8a4f5accf6be..cade09deff8d 100644 --- a/arch/sparc/kernel/sys_sparc32.c +++ b/arch/sparc/kernel/sys_sparc32.c @@ -186,14 +186,6 @@ COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig, return ret; } -asmlinkage long compat_sys_readahead(int fd, - unsigned long offhi, - unsigned long offlo, - compat_size_t count) -{ - return sys_readahead(fd, (offhi << 32) | offlo, count); -} - long compat_sys_fadvise64(int fd, unsigned long offhi, unsigned long offlo, diff --git a/arch/sparc/kernel/systbls.h b/arch/sparc/kernel/systbls.h index 6b5fd12e821d..aad40627ba52 100644 --- a/arch/sparc/kernel/systbls.h +++ b/arch/sparc/kernel/systbls.h @@ -63,10 +63,6 @@ asmlinkage long compat_sys_fstat64(unsigned int fd, asmlinkage long compat_sys_fstatat64(unsigned int dfd, const char __user *filename, struct compat_stat64 __user * statbuf, int flag); -asmlinkage long compat_sys_readahead(int fd, - unsigned long offhi, - unsigned long offlo, - compat_size_t count); long compat_sys_fadvise64(int fd, unsigned long offhi, unsigned long offlo, diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 2f39235785d8..17b8dc7130f5 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -231,7 +231,7 @@ # 222 is unused # 223 is unused 224 i386 gettid sys_gettid -225 i386 readahead sys_readahead compat_sys_x86_readahead +225 i386 readahead sys_readahead compat_sys_readahead 226 i386 setxattr sys_setxattr 227 i386 lsetxattr sys_lsetxattr 228 i386 fsetxattr sys_fsetxattr diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index eae207229a93..89dcb36d19da 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c @@ -181,12 +181,6 @@ COMPAT_SYSCALL_DEFINE6(x86_fadvise64_64, int, fd, __u32, offset_low, advice); } -COMPAT_SYSCALL_DEFINE4(x86_readahead, int, fd, unsigned int, off_lo, - unsigned int, off_hi, size_t, count) -{ - return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count); -} - COMPAT_SYSCALL_DEFINE6(x86_sync_file_range, int, fd, unsigned int, off_low, unsigned int, off_hi, unsigned int, n_low, unsigned int, n_hi, int, flags) diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index ded631bb33de..6a78bee5a314 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h @@ -39,8 +39,6 @@ asmlinkage long compat_sys_x86_waitpid(compat_pid_t, unsigned int __user *, asmlinkage long compat_sys_x86_fadvise64_64(int, __u32, __u32, __u32, __u32, int); -asmlinkage ssize_t compat_sys_x86_readahead(int, unsigned int, unsigned int, - size_t); asmlinkage long compat_sys_x86_sync_file_range(int, unsigned int, unsigned int, unsigned int, unsigned int, int); diff --git a/arch/x86/include/asm/unistd.h b/arch/x86/include/asm/unistd.h index be8f52494ee3..8d56e1dd71d6 100644 --- a/arch/x86/include/asm/unistd.h +++ b/arch/x86/include/asm/unistd.h @@ -32,6 +32,7 @@ # define __ARCH_WANT_COMPAT_SYS_FALLOCATE # define __ARCH_WANT_COMPAT_SYS_TRUNCATE64 # define __ARCH_WANT_COMPAT_SYS_PREADWRITE64 +# define __ARCH_WANT_COMPAT_SYS_READAHEAD # endif diff --git a/include/linux/compat.h b/include/linux/compat.h index 95301d1a6793..96d1244b332e 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -872,6 +872,16 @@ asmlinkage long compat_sys_pread64(unsigned int, char __user *, #endif /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ #endif /* __ARCH_WANT_COMPAT_SYS_PREADWRITE64 */ +#ifdef __ARCH_WANT_COMPAT_SYS_READAHEAD +/* __ARCH_WANT_LE_COMPAT_SYS determines order of lo and hi */ +#ifdef __ARCH_WANT_COMPAT_SYS_WITH_PADDING +asmlinkage long compat_sys_readahead(int, unsigned int, unsigned int, + unsigned int, size_t); +#else /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +asmlinkage long compat_sys_readahead(int, unsigned int, unsigned int, size_t); +#endif /* __ARCH_WANT_COMPAT_SYS_WITH_PADDING */ +#endif /* __ARCH_WANT_COMPAT_SYS_READAHEAD */ + int compat_restore_altstack(const compat_stack_t __user *uss); int __compat_save_altstack(compat_stack_t __user *, unsigned long); #define compat_save_altstack_ex(uss, sp) do { \ diff --git a/mm/readahead.c b/mm/readahead.c index c4ca70239233..092866309593 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -555,40 +556,74 @@ page_cache_async_readahead(struct address_space *mapping, } EXPORT_SYMBOL_GPL(page_cache_async_readahead); -static ssize_t -do_readahead(struct address_space *mapping, struct file *filp, - pgoff_t index, unsigned long nr) +static ssize_t do_readahead(int fd, loff_t offset, size_t count) { - if (!mapping || !mapping->a_ops) - return -EINVAL; + ssize_t ret = -EBADF; + struct fd f; + struct address_space *mapping; + pgoff_t start = offset >> PAGE_SHIFT; + pgoff_t end = (offset + count - 1) >> PAGE_SHIFT; + unsigned long len = end - start + 1; + + f = fdget(fd); + if (!f.file) + goto out; + + if (!(f.file->f_mode & FMODE_READ)) + goto put_out; + + mapping = f.file->f_mapping; + if (!mapping || !mapping->a_ops) { + ret = -EINVAL; + goto put_out; + } /* * Readahead doesn't make sense for DAX inodes, but we don't want it * to report a failure either. Instead, we just return success and * don't do any work. */ - if (dax_mapping(mapping)) - return 0; + if (dax_mapping(mapping)) { + ret = 0; + goto put_out; + } + + ret = force_page_cache_readahead(mapping, f.file, start, len); - return force_page_cache_readahead(mapping, filp, index, nr); +put_out: + fdput(f); + +out: + return ret; } SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count) { - ssize_t ret; - struct fd f; + return do_readahead(fd, offset, count); +} - ret = -EBADF; - f = fdget(fd); - if (f.file) { - if (f.file->f_mode & FMODE_READ) { - struct address_space *mapping = f.file->f_mapping; - pgoff_t start = offset >> PAGE_SHIFT; - pgoff_t end = (offset + count - 1) >> PAGE_SHIFT; - unsigned long len = end - start + 1; - ret = do_readahead(mapping, f.file, start, len); - } - fdput(f); - } - return ret; +#ifdef __ARCH_WANT_COMPAT_SYS_READAHEAD +#if defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE5(readahead, int, fd, unsigned int, padding, + unsigned int, off_lo, unsigned int, off_hi, + size_t, count) +#elif defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + !defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE5(readahead, int, fd, unsigned int, padding, + unsigned int, off_hi, unsigned int, off_lo, + size_t, count) +#elif !defined(__ARCH_WANT_COMPAT_SYS_WITH_PADDING) && \ + defined(__ARCH_WANT_LE_COMPAT_SYS) +COMPAT_SYSCALL_DEFINE4(readahead, int, fd, + unsigned int, off_lo, unsigned int, off_hi, + size_t, count) +#else /* no padding, big endian */ +COMPAT_SYSCALL_DEFINE4(readahead, int, fd, + unsigned int, off_hi, unsigned int, off_lo, + size_t, count) +#endif +{ + return do_readahead(fd, ((u64) off_hi << 32) | off_lo, count); } +#endif /* __ARCH_WANT_COMPAT_SYS_READAHEAD */