Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: add ksys_unlink() wrapper; remove in-kernel calls to sys_unlink()

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>

+17 -6
+11
include/linux/syscalls.h
··· 954 954 ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count); 955 955 int ksys_chdir(const char __user *filename); 956 956 957 + /* 958 + * The following kernel syscall equivalents are just wrappers to fs-internal 959 + * functions. Therefore, provide stubs to be inlined at the callsites. 960 + */ 961 + extern long do_unlinkat(int dfd, struct filename *name); 962 + 963 + static inline long ksys_unlink(const char __user *pathname) 964 + { 965 + return do_unlinkat(AT_FDCWD, getname(pathname)); 966 + } 967 + 957 968 #endif
+1 -1
init/do_mounts.h
··· 16 16 17 17 static inline int create_dev(char *name, dev_t dev) 18 18 { 19 - sys_unlink(name); 19 + ksys_unlink(name); 20 20 return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev)); 21 21 } 22 22
+2 -2
init/do_mounts_initrd.c
··· 128 128 * mounted in the normal path. 129 129 */ 130 130 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) { 131 - sys_unlink("/initrd.image"); 131 + ksys_unlink("/initrd.image"); 132 132 handle_initrd(); 133 133 return true; 134 134 } 135 135 } 136 - sys_unlink("/initrd.image"); 136 + ksys_unlink("/initrd.image"); 137 137 return false; 138 138 }
+1 -1
init/do_mounts_rd.c
··· 288 288 sys_close(out_fd); 289 289 out: 290 290 kfree(buf); 291 - sys_unlink("/dev/ram"); 291 + ksys_unlink("/dev/ram"); 292 292 return res; 293 293 } 294 294
+2 -2
init/initramfs.c
··· 319 319 if (S_ISDIR(st.mode)) 320 320 sys_rmdir(path); 321 321 else 322 - sys_unlink(path); 322 + ksys_unlink(path); 323 323 } 324 324 } 325 325 ··· 591 591 if (S_ISDIR(st.mode)) 592 592 sys_rmdir(dirp->d_name); 593 593 else 594 - sys_unlink(dirp->d_name); 594 + ksys_unlink(dirp->d_name); 595 595 } 596 596 597 597 num -= dirp->d_reclen;