Skip to content

Commit

Permalink
fs: add ksys_read() helper; remove in-kernel calls to sys_read()
Browse files Browse the repository at this point in the history
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/[email protected]

Cc: Alexander Viro <[email protected]>
Signed-off-by: Dominik Brodowski <[email protected]>
  • Loading branch information
Dominik Brodowski committed Apr 2, 2018
1 parent 76847e4 commit 3ce4a7b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion arch/s390/kernel/compat_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions init/do_mounts_rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 ||
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3ce4a7b

Please sign in to comment.