fs: add ksys_read() helper; remove in-kernel calls to sys_read()
authorDominik Brodowski <linux@dominikbrodowski.net>
Tue, 13 Mar 2018 20:56:26 +0000 (21:56 +0100)
committerDominik Brodowski <linux@dominikbrodowski.net>
Mon, 2 Apr 2018 18:16:04 +0000 (20:16 +0200)
Using this helper allows us to avoid the in-kernel calls to the
sys_read() 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_read().

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>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
arch/s390/kernel/compat_linux.c
fs/read_write.c
include/linux/syscalls.h
init/do_mounts.c
init/do_mounts_rd.c

index 9c5e975f71a6375f74b431906e41f3d55f89e8a8..af0469f204fdfd0cf92836e5d6612dd159665b1b 100644 (file)
@@ -460,7 +460,7 @@ COMPAT_SYSCALL_DEFINE3(s390_read, unsigned int, fd, char __user *, buf, compat_s
        if ((compat_ssize_t) count < 0)
                return -EINVAL; 
 
-       return sys_read(fd, buf, count);
+       return ksys_read(fd, buf, count);
 }
 
 COMPAT_SYSCALL_DEFINE3(s390_write, unsigned int, fd, const char __user *, buf, compat_size_t, count)
index b38b008a078ebccb4d1bbd523447a8618aabb7b2..fc441e1ac683534b14dcdb8f06734cd6641a285d 100644 (file)
@@ -568,7 +568,7 @@ static inline void file_pos_write(struct file *file, loff_t pos)
        file->f_pos = pos;
 }
 
-SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
+ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
 {
        struct fd f = fdget_pos(fd);
        ssize_t ret = -EBADF;
@@ -583,6 +583,11 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
        return ret;
 }
 
+SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
+{
+       return ksys_read(fd, buf, count);
+}
+
 ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
 {
        struct fd f = fdget_pos(fd);
index 0f24e53345696585e19757f97857f7f54a50fd92..3a2e90842ff8ab01df52ec5bf54031a83b2ec8c7 100644 (file)
@@ -959,6 +959,7 @@ int ksys_getdents64(unsigned int fd, struct linux_dirent64 __user *dirent,
                    unsigned int count);
 int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
 off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence);
+ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count);
 
 /*
  * The following kernel syscall equivalents are just wrappers to fs-internal
index b17e0095eb4edc37d876d790ae7d1c6ce21a0c1a..2c71dabe56260ee00283b78984f67ea9d5d61eba 100644 (file)
@@ -500,7 +500,7 @@ void __init change_floppy(char *fmt, ...)
                ksys_ioctl(fd, TCGETS, (long)&termios);
                termios.c_lflag &= ~ICANON;
                ksys_ioctl(fd, TCSETSF, (long)&termios);
-               sys_read(fd, &c, 1);
+               ksys_read(fd, &c, 1);
                termios.c_lflag |= ICANON;
                ksys_ioctl(fd, TCSETSF, (long)&termios);
                ksys_close(fd);
index 13e54148c0e03cbf733c91de0304ca9da0214c4e..12c159824c7bd994132d289b49fbf651f6cca750 100644 (file)
@@ -91,7 +91,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
         * Read block 0 to test for compressed kernel
         */
        ksys_lseek(fd, start_block * BLOCK_SIZE, 0);
-       sys_read(fd, buf, size);
+       ksys_read(fd, buf, size);
 
        *decompressor = decompress_method(buf, size, &compress_name);
        if (compress_name) {
@@ -137,7 +137,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
         * Read 512 bytes further to check if cramfs is padded
         */
        ksys_lseek(fd, start_block * BLOCK_SIZE + 0x200, 0);
-       sys_read(fd, buf, size);
+       ksys_read(fd, buf, size);
 
        if (cramfsb->magic == CRAMFS_MAGIC) {
                printk(KERN_NOTICE
@@ -151,7 +151,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
         * Read block 1 to test for minix and ext2 superblock
         */
        ksys_lseek(fd, (start_block+1) * BLOCK_SIZE, 0);
-       sys_read(fd, buf, size);
+       ksys_read(fd, buf, size);
 
        /* Try minix */
        if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
@@ -269,7 +269,7 @@ int __init rd_load_image(char *from)
                        }
                        printk("Loading disk #%d... ", disk);
                }
-               sys_read(in_fd, buf, BLOCK_SIZE);
+               ksys_read(in_fd, buf, BLOCK_SIZE);
                ksys_write(out_fd, buf, BLOCK_SIZE);
 #if !defined(CONFIG_S390)
                if (!(i % 16)) {
@@ -307,7 +307,7 @@ static int crd_infd, crd_outfd;
 
 static long __init compr_fill(void *buf, unsigned long len)
 {
-       long r = sys_read(crd_infd, buf, len);
+       long r = ksys_read(crd_infd, buf, len);
        if (r < 0)
                printk(KERN_ERR "RAMDISK: error while reading compressed data");
        else if (r == 0)