Skip to content

Commit e7a3e8b

Browse files
author
Dominik Brodowski
committed
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>
1 parent a16fe33 commit e7a3e8b

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎arch/s390/kernel/compat_linux.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ COMPAT_SYSCALL_DEFINE3(s390_write, unsigned int, fd, const char __user *, buf, c
468468
if ((compat_ssize_t) count < 0)
469469
return -EINVAL;
470470

471-
return sys_write(fd, buf, count);
471+
return ksys_write(fd, buf, count);
472472
}
473473

474474
/*

‎fs/read_write.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
578578
return ret;
579579
}
580580

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)
583582
{
584583
struct fd f = fdget_pos(fd);
585584
ssize_t ret = -EBADF;
@@ -595,6 +594,12 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
595594
return ret;
596595
}
597596

597+
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
598+
size_t, count)
599+
{
600+
return ksys_write(fd, buf, count);
601+
}
602+
598603
SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
599604
size_t, count, loff_t, pos)
600605
{

‎include/linux/syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,5 +951,6 @@ int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
951951
int ksys_umount(char __user *name, int flags);
952952
int ksys_dup(unsigned int fildes);
953953
int ksys_chroot(const char __user *filename);
954+
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
954955

955956
#endif

‎init/do_mounts_rd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int __init rd_load_image(char *from)
270270
printk("Loading disk #%d... ", disk);
271271
}
272272
sys_read(in_fd, buf, BLOCK_SIZE);
273-
sys_write(out_fd, buf, BLOCK_SIZE);
273+
ksys_write(out_fd, buf, BLOCK_SIZE);
274274
#if !defined(CONFIG_S390)
275275
if (!(i % 16)) {
276276
pr_cont("%c\b", rotator[rotate & 0x3]);
@@ -317,7 +317,7 @@ static long __init compr_fill(void *buf, unsigned long len)
317317

318318
static long __init compr_flush(void *window, unsigned long outcnt)
319319
{
320-
long written = sys_write(crd_outfd, window, outcnt);
320+
long written = ksys_write(crd_outfd, window, outcnt);
321321
if (written != outcnt) {
322322
if (decompress_error == 0)
323323
printk(KERN_ERR

‎init/initramfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
2727

2828
/* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
2929
while (count) {
30-
ssize_t rv = sys_write(fd, p, count);
30+
ssize_t rv = ksys_write(fd, p, count);
3131

3232
if (rv < 0) {
3333
if (rv == -EINTR || rv == -EAGAIN)

0 commit comments

Comments
 (0)