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 fa1a392..89faa6f 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 26fe8ea..72981ba 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 085adfc..9ebe1d6 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 27e10af..6363ec8 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 f1e1f66..ed9f34d 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 1c5785e..0571ab7 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 58c6f63..69c17b5 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 f36ab1f..080d566 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 ecb981e..1ef3b80 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 79c7866..f7181ed 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 9bb897e..da5ef77 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 0090037..31cefe0 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 724911c..f8afc01 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 990703b..d980da4 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 55416db..ebb84dc 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 6258676..35f7047 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 401bd8e..bff71b9 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 676774b..a3f15ed 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 466d408..ec866c9 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 9efdc02..aa0dc82 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 ebb6e61..cad3296 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 */