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

In the near future, all callers of ksys_unlink() should be converted to
call do_unlinkat() directly or, at least, to operate on regular kernel
pointers.

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: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
include/linux/syscalls.h
init/do_mounts.h
init/do_mounts_initrd.c
init/do_mounts_rd.c
init/initramfs.c

index 090645b4844745360cfe689d2292e39684d0e334..7cbfb41e666b600b1904fda657e1764a953ffb45 100644 (file)
@@ -954,4 +954,15 @@ int ksys_chroot(const char __user *filename);
 ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
 int ksys_chdir(const char __user *filename);
 
+/*
+ * The following kernel syscall equivalents are just wrappers to fs-internal
+ * functions. Therefore, provide stubs to be inlined at the callsites.
+ */
+extern long do_unlinkat(int dfd, struct filename *name);
+
+static inline long ksys_unlink(const char __user *pathname)
+{
+       return do_unlinkat(AT_FDCWD, getname(pathname));
+}
+
 #endif
index 5b05c8f93f476c622f7ec95160c1759fee2d2503..401f90ee1eebc80ac8b920446b19b3c0fb21f60f 100644 (file)
@@ -16,7 +16,7 @@ extern int root_mountflags;
 
 static inline int create_dev(char *name, dev_t dev)
 {
-       sys_unlink(name);
+       ksys_unlink(name);
        return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
 }
 
index 83f396d30b9a3fb8044208e0111ecc226c8d9006..e9e9e1c67d315c33f859c2929942fab2b9849a39 100644 (file)
@@ -128,11 +128,11 @@ bool __init initrd_load(void)
                 * mounted in the normal path.
                 */
                if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
-                       sys_unlink("/initrd.image");
+                       ksys_unlink("/initrd.image");
                        handle_initrd();
                        return true;
                }
        }
-       sys_unlink("/initrd.image");
+       ksys_unlink("/initrd.image");
        return false;
 }
index 2d365c398ccc491a6f35771996c8d802698a1846..5b69056f610aca4a126b92430bdf456f14f2f559 100644 (file)
@@ -288,7 +288,7 @@ noclose_input:
        sys_close(out_fd);
 out:
        kfree(buf);
-       sys_unlink("/dev/ram");
+       ksys_unlink("/dev/ram");
        return res;
 }
 
index 6f972df15bf262ff005e17d14c281a658bc4ba0a..08eb551168a80d1488d03b700783698efe47fa65 100644 (file)
@@ -319,7 +319,7 @@ static void __init clean_path(char *path, umode_t fmode)
                if (S_ISDIR(st.mode))
                        sys_rmdir(path);
                else
-                       sys_unlink(path);
+                       ksys_unlink(path);
        }
 }
 
@@ -591,7 +591,7 @@ static void __init clean_rootfs(void)
                                if (S_ISDIR(st.mode))
                                        sys_rmdir(dirp->d_name);
                                else
-                                       sys_unlink(dirp->d_name);
+                                       ksys_unlink(dirp->d_name);
                        }
 
                        num -= dirp->d_reclen;