mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff()
authorDominik Brodowski <linux@dominikbrodowski.net>
Sun, 11 Mar 2018 10:34:46 +0000 (11:34 +0100)
committerDominik Brodowski <linux@dominikbrodowski.net>
Mon, 2 Apr 2018 18:16:11 +0000 (20:16 +0200)
Using this helper allows us to avoid the in-kernel calls to the
sys_mmap_pgoff() syscall. The ksys_ prefix denotes that this function is
meant as a drop-in replacement for the syscall. In particular, it uses the
same calling convention as sys_mmap_pgoff().

This patch is part of a series which removes in-kernel calls to syscalls.
On this basis, the syscall entry path can be streamlined. For details, see
http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
21 files changed:
arch/alpha/kernel/osf_sys.c
arch/arm64/kernel/sys.c
arch/ia64/kernel/sys_ia64.c
arch/m68k/kernel/sys_m68k.c
arch/microblaze/kernel/sys_microblaze.c
arch/mips/kernel/linux32.c
arch/mips/kernel/syscall.c
arch/parisc/kernel/sys_parisc.c
arch/powerpc/kernel/syscalls.c
arch/riscv/kernel/sys_riscv.c
arch/s390/kernel/compat_linux.c
arch/s390/kernel/sys_s390.c
arch/sh/kernel/sys_sh.c
arch/sparc/kernel/sys_sparc_32.c
arch/sparc/kernel/sys_sparc_64.c
arch/um/kernel/syscall.c
arch/x86/ia32/sys_ia32.c
arch/x86/kernel/sys_x86_64.c
include/linux/syscalls.h
mm/mmap.c
mm/nommu.c

index fa1a392ca9a218f2327108c20c879ac9ea35b7bd..89faa6f4de47315c93db0792a586f66023cf7043 100644 (file)
@@ -189,7 +189,7 @@ SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len,
                goto out;
        if (off & ~PAGE_MASK)
                goto out;
-       ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       ret = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  out:
        return ret;
 }
index 26fe8ea93ea2b18d7f87e45203bfd9633cdfe5bc..72981bae10ebaa41d9a9b26743121640ceb40acb 100644 (file)
@@ -34,7 +34,7 @@ asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
        if (offset_in_page(off) != 0)
                return -EINVAL;
 
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 }
 
 SYSCALL_DEFINE1(arm64_personality, unsigned int, personality)
index 085adfcc74a4c3fadee3628d93a376909d769aab..9ebe1d633abca861776d486d4c9fbac9e2e113b3 100644 (file)
@@ -139,7 +139,7 @@ int ia64_mmap_check(unsigned long addr, unsigned long len,
 asmlinkage unsigned long
 sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
 {
-       addr = sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
+       addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
        if (!IS_ERR((void *) addr))
                force_successful_syscall_return();
        return addr;
@@ -151,7 +151,7 @@ sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, lo
        if (offset_in_page(off) != 0)
                return -EINVAL;
 
-       addr = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
        if (!IS_ERR((void *) addr))
                force_successful_syscall_return();
        return addr;
index 27e10af5153a300f27923e9dedc9fd27bbcdddec..6363ec83a290413594dc2fca2ff1689e309851e5 100644 (file)
@@ -46,7 +46,7 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
         * so we need to shift the argument down by 1; m68k mmap64(3)
         * (in libc) expects the last argument of mmap2 in 4Kb units.
         */
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
 }
 
 /* Convert virtual (user) address VADDR to physical address PADDR */
index f1e1f666ddde214b2cbc4a688e34b3e37acfaf63..ed9f34da1a2a49f4fb86c6cf68f373c2d7e99af7 100644 (file)
@@ -40,7 +40,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
        if (pgoff & ~PAGE_MASK)
                return -EINVAL;
 
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
 }
 
 SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
@@ -50,6 +50,6 @@ SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
        if (pgoff & (~PAGE_MASK >> 12))
                return -EINVAL;
 
-       return sys_mmap_pgoff(addr, len, prot, flags, fd,
-                             pgoff >> (PAGE_SHIFT - 12));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              pgoff >> (PAGE_SHIFT - 12));
 }
index 1c5785e72db40becf8180657170abb5cc27027b1..0571ab7b68b04ae965a08f5eb4e261b93379e47e 100644 (file)
@@ -67,8 +67,8 @@ SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
 {
        if (pgoff & (~PAGE_MASK >> 12))
                return -EINVAL;
-       return sys_mmap_pgoff(addr, len, prot, flags, fd,
-                             pgoff >> (PAGE_SHIFT-12));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              pgoff >> (PAGE_SHIFT-12));
 }
 
 #define RLIM_INFINITY32 0x7fffffff
index 58c6f634b5506a32858fb9f036c7aff465363fb5..69c17b549fd3cc598946bbfc67f424b4751161b1 100644 (file)
@@ -63,7 +63,8 @@ SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
 {
        if (offset & ~PAGE_MASK)
                return -EINVAL;
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              offset >> PAGE_SHIFT);
 }
 
 SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
@@ -73,7 +74,8 @@ SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
        if (pgoff & (~PAGE_MASK >> 12))
                return -EINVAL;
 
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              pgoff >> (PAGE_SHIFT - 12));
 }
 
 save_static_function(sys_fork);
index f36ab1f09595db9b1c9b341efb9aca3f00f0c1a6..080d566654ea96c06d7599c5cda4e31bda633d28 100644 (file)
@@ -270,8 +270,8 @@ asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
 {
        /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
           we have. */
-       return sys_mmap_pgoff(addr, len, prot, flags, fd,
-                             pgoff >> (PAGE_SHIFT - 12));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              pgoff >> (PAGE_SHIFT - 12));
 }
 
 asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
@@ -279,7 +279,7 @@ asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
                unsigned long offset)
 {
        if (!(offset & ~PAGE_MASK)) {
-               return sys_mmap_pgoff(addr, len, prot, flags, fd,
+               return ksys_mmap_pgoff(addr, len, prot, flags, fd,
                                        offset >> PAGE_SHIFT);
        } else {
                return -EINVAL;
index ecb981eea74b78dfe413bbc517104b1c49784ef3..1ef3b80b62a6cba0a983ccfc70b3ad02a665f2b6 100644 (file)
@@ -57,7 +57,7 @@ static inline long do_mmap2(unsigned long addr, size_t len,
                off >>= shift;
        }
 
-       ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off);
+       ret = ksys_mmap_pgoff(addr, len, prot, flags, fd, off);
 out:
        return ret;
 }
index 79c78668258ede202086c072c63352ca14585903..f7181ed8aafc64f94040a65fe99e8adab281cb86 100644 (file)
@@ -24,8 +24,8 @@ static long riscv_sys_mmap(unsigned long addr, unsigned long len,
 {
        if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
                return -EINVAL;
-       return sys_mmap_pgoff(addr, len, prot, flags, fd,
-                             offset >> (PAGE_SHIFT - page_shift_offset));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              offset >> (PAGE_SHIFT - page_shift_offset));
 }
 
 #ifdef CONFIG_64BIT
index 9bb897e443a64424e07fe91f820389a9f98da533..da5ef7718254e3753d216f6dc0db0ea3929da56b 100644 (file)
@@ -442,8 +442,8 @@ COMPAT_SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct_emu31 __user *, arg
                return -EFAULT;
        if (a.offset & ~PAGE_MASK)
                return -EINVAL;
-       return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
-                             a.offset >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
+                              a.offset >> PAGE_SHIFT);
 }
 
 COMPAT_SYSCALL_DEFINE1(s390_mmap2, struct mmap_arg_struct_emu31 __user *, arg)
@@ -452,7 +452,7 @@ COMPAT_SYSCALL_DEFINE1(s390_mmap2, struct mmap_arg_struct_emu31 __user *, arg)
 
        if (copy_from_user(&a, arg, sizeof(a)))
                return -EFAULT;
-       return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
+       return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
 }
 
 COMPAT_SYSCALL_DEFINE3(s390_read, unsigned int, fd, char __user *, buf, compat_size_t, count)
index 0090037ab1482bd9d38391387e551015ecb9e080..31cefe0c28c0ed4b3603568213eb194239b75272 100644 (file)
@@ -53,7 +53,7 @@ SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
 
        if (copy_from_user(&a, arg, sizeof(a)))
                goto out;
-       error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
+       error = ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
 out:
        return error;
 }
index 724911c59e7dafa8d028f51505c26e2fa0219b8a..f8afc014e084114d8d2444f47b9f2ed437b72d45 100644 (file)
@@ -35,7 +35,7 @@ asmlinkage int old_mmap(unsigned long addr, unsigned long len,
 {
        if (off & ~PAGE_MASK)
                return -EINVAL;
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
 }
 
 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
@@ -51,7 +51,7 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
 
        pgoff >>= PAGE_SHIFT - 12;
 
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
 }
 
 /* sys_cacheflush -- flush (part of) the processor cache.  */
index 990703b7cf4d7d47d26152e510706bc32528d488..d980da4ffd7bfdb59bdb5d12c9b85849ebaaf1e5 100644 (file)
@@ -104,8 +104,8 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
 {
        /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
           we have. */
-       return sys_mmap_pgoff(addr, len, prot, flags, fd,
-                             pgoff >> (PAGE_SHIFT - 12));
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd,
+                              pgoff >> (PAGE_SHIFT - 12));
 }
 
 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
@@ -113,7 +113,7 @@ asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
        unsigned long off)
 {
        /* no alignment check? */
-       return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 }
 
 long sparc_remap_file_pages(unsigned long start, unsigned long size,
index 55416db482add475baf4c2fc312605577442470f..ebb84dc8a5a701c27765d67e056431b031aad519 100644 (file)
@@ -458,7 +458,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
                goto out;
        if (off & ~PAGE_MASK)
                goto out;
-       retval = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       retval = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 out:
        return retval;
 }
index 6258676bed85a4a472768cbdcc354793f86c50c8..35f7047bdebcadb0e692a6d53f3391b5cab2d013 100644 (file)
@@ -22,7 +22,7 @@ long old_mmap(unsigned long addr, unsigned long len,
        if (offset & ~PAGE_MASK)
                goto out;
 
-       err = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+       err = ksys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  out:
        return err;
 }
index 401bd8ec9cf0fc66755f2a84550bd77735ac9096..bff71b9ae3f50b53a8aa9b57c6bc96df40bc09de 100644 (file)
@@ -166,7 +166,7 @@ COMPAT_SYSCALL_DEFINE1(x86_mmap, struct mmap_arg_struct32 __user *, arg)
        if (a.offset & ~PAGE_MASK)
                return -EINVAL;
 
-       return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
+       return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
                               a.offset>>PAGE_SHIFT);
 }
 
index 676774b9bb8d1300837c9771782ae6f28a4d8bca..a3f15ed545b560759fda579f1e3bd29f752269a3 100644 (file)
@@ -97,7 +97,7 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
        if (off & ~PAGE_MASK)
                goto out;
 
-       error = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
+       error = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
 out:
        return error;
 }
index 466d408deefd3534f000bf6e1351b44f7f637463..ec866c959e7dbd0d6d27d44b8b8643390407e0ea 100644 (file)
@@ -979,6 +979,9 @@ static inline int ksys_fadvise64_64(int fd, loff_t offset, loff_t len,
        return -EINVAL;
 }
 #endif
+unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
+                             unsigned long prot, unsigned long flags,
+                             unsigned long fd, unsigned long pgoff);
 
 /*
  * The following kernel syscall equivalents are just wrappers to fs-internal
index 9efdc021ad2202fc9ebd7e55fe572813136d2f2c..aa0dc8231c0d0df33d1137199290b5d3422d2ca2 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1488,9 +1488,9 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
        return addr;
 }
 
-SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
-               unsigned long, prot, unsigned long, flags,
-               unsigned long, fd, unsigned long, pgoff)
+unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
+                             unsigned long prot, unsigned long flags,
+                             unsigned long fd, unsigned long pgoff)
 {
        struct file *file = NULL;
        unsigned long retval;
@@ -1537,6 +1537,13 @@ out_fput:
        return retval;
 }
 
+SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
+               unsigned long, prot, unsigned long, flags,
+               unsigned long, fd, unsigned long, pgoff)
+{
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
+}
+
 #ifdef __ARCH_WANT_SYS_OLD_MMAP
 struct mmap_arg_struct {
        unsigned long addr;
@@ -1556,8 +1563,8 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg)
        if (offset_in_page(a.offset))
                return -EINVAL;
 
-       return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
-                             a.offset >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
+                              a.offset >> PAGE_SHIFT);
 }
 #endif /* __ARCH_WANT_SYS_OLD_MMAP */
 
index ebb6e618dade241084f10a07555af5b92a118e66..cad329629530f58c25deb0acea62aa9403ccb9ec 100644 (file)
@@ -1423,9 +1423,9 @@ error_getting_region:
        return -ENOMEM;
 }
 
-SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
-               unsigned long, prot, unsigned long, flags,
-               unsigned long, fd, unsigned long, pgoff)
+unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,
+                             unsigned long prot, unsigned long flags,
+                             unsigned long fd, unsigned long pgoff)
 {
        struct file *file = NULL;
        unsigned long retval = -EBADF;
@@ -1447,6 +1447,13 @@ out:
        return retval;
 }
 
+SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
+               unsigned long, prot, unsigned long, flags,
+               unsigned long, fd, unsigned long, pgoff)
+{
+       return ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
+}
+
 #ifdef __ARCH_WANT_SYS_OLD_MMAP
 struct mmap_arg_struct {
        unsigned long addr;
@@ -1466,8 +1473,8 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg)
        if (offset_in_page(a.offset))
                return -EINVAL;
 
-       return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
-                             a.offset >> PAGE_SHIFT);
+       return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
+                              a.offset >> PAGE_SHIFT);
 }
 #endif /* __ARCH_WANT_SYS_OLD_MMAP */