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

fs: add ksys_write() helper; remove in-kernel calls to sys_write()

Using this helper allows us to avoid the in-kernel calls to the sys_write()
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_write().

In the near future, the do_mounts / initramfs callers of ksys_write()
should be converted to use filp_open() and vfs_write() instead.

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: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-s390@vger.kernel.org
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

+12 -6
+1 -1
arch/s390/kernel/compat_linux.c
··· 468 468 if ((compat_ssize_t) count < 0) 469 469 return -EINVAL; 470 470 471 - return sys_write(fd, buf, count); 471 + return ksys_write(fd, buf, count); 472 472 } 473 473 474 474 /*
+7 -2
fs/read_write.c
··· 578 578 return ret; 579 579 } 580 580 581 - SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, 582 - size_t, count) 581 + ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count) 583 582 { 584 583 struct fd f = fdget_pos(fd); 585 584 ssize_t ret = -EBADF; ··· 592 593 } 593 594 594 595 return ret; 596 + } 597 + 598 + SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, 599 + size_t, count) 600 + { 601 + return ksys_write(fd, buf, count); 595 602 } 596 603 597 604 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
+1
include/linux/syscalls.h
··· 951 951 int ksys_umount(char __user *name, int flags); 952 952 int ksys_dup(unsigned int fildes); 953 953 int ksys_chroot(const char __user *filename); 954 + ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count); 954 955 955 956 #endif
+2 -2
init/do_mounts_rd.c
··· 270 270 printk("Loading disk #%d... ", disk); 271 271 } 272 272 sys_read(in_fd, buf, BLOCK_SIZE); 273 - sys_write(out_fd, buf, BLOCK_SIZE); 273 + ksys_write(out_fd, buf, BLOCK_SIZE); 274 274 #if !defined(CONFIG_S390) 275 275 if (!(i % 16)) { 276 276 pr_cont("%c\b", rotator[rotate & 0x3]); ··· 317 317 318 318 static long __init compr_flush(void *window, unsigned long outcnt) 319 319 { 320 - long written = sys_write(crd_outfd, window, outcnt); 320 + long written = ksys_write(crd_outfd, window, outcnt); 321 321 if (written != outcnt) { 322 322 if (decompress_error == 0) 323 323 printk(KERN_ERR
+1 -1
init/initramfs.c
··· 27 27 28 28 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */ 29 29 while (count) { 30 - ssize_t rv = sys_write(fd, p, count); 30 + ssize_t rv = ksys_write(fd, p, count); 31 31 32 32 if (rv < 0) { 33 33 if (rv == -EINTR || rv == -EAGAIN)