diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2018-03-11 11:34:55 +0100 |
---|---|---|
committer | Serge Hallyn <shallyn@cisco.com> | 2020-05-21 11:57:48 -0500 |
commit | 6e592024a7ac36cba1360134934fcebcb956f2a5 (patch) | |
tree | 2f29894be570cb6454952cc0f5002dd6fe33ae04 | |
parent | 13b5589e728c52168dc7100617170b76a0478b3c (diff) | |
download | linux-v4.14.180-shiftfs.tar.gz |
fs: add ksys_close() wrapper; remove in-kernel calls to sys_close()v4.14.180-shiftfs
Using the ksys_close() wrapper allows us to get rid of in-kernel calls
to the sys_close() 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_close(), with one subtle
difference:
The few places which checked the return value did not care about the return
value re-writing in sys_close(), so simply use a wrapper around
__close_fd().
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>
-rw-r--r-- | fs/autofs4/dev-ioctl.c | 2 | ||||
-rw-r--r-- | fs/binfmt_misc.c | 2 | ||||
-rw-r--r-- | fs/file.c | 1 | ||||
-rw-r--r-- | fs/open.c | 1 | ||||
-rw-r--r-- | include/linux/syscalls.h | 11 | ||||
-rw-r--r-- | init/do_mounts.c | 4 | ||||
-rw-r--r-- | init/do_mounts_initrd.c | 2 | ||||
-rw-r--r-- | init/do_mounts_md.c | 8 | ||||
-rw-r--r-- | init/do_mounts_rd.c | 6 | ||||
-rw-r--r-- | init/initramfs.c | 8 |
10 files changed, 28 insertions, 17 deletions
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c index 6dd63981787a2f..00458e985cc3f0 100644 --- a/fs/autofs4/dev-ioctl.c +++ b/fs/autofs4/dev-ioctl.c @@ -320,7 +320,7 @@ static int autofs_dev_ioctl_closemount(struct file *fp, struct autofs_sb_info *sbi, struct autofs_dev_ioctl *param) { - return sys_close(param->ioctlfd); + return ksys_close(param->ioctlfd); } /* diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index 8311e8ed76de37..4de1915632611a 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -241,7 +241,7 @@ ret: return retval; error: if (fd_binary > 0) - sys_close(fd_binary); + ksys_close(fd_binary); bprm->interp_flags = 0; bprm->interp_data = 0; goto ret; diff --git a/fs/file.c b/fs/file.c index 0c25b980affe20..4cc1c8d6543d38 100644 --- a/fs/file.c +++ b/fs/file.c @@ -642,6 +642,7 @@ out_unlock: spin_unlock(&files->file_lock); return -EBADF; } +EXPORT_SYMBOL(__close_fd); /* for ksys_close() */ void do_close_on_exec(struct files_struct *files) { diff --git a/fs/open.c b/fs/open.c index 8c6873e0caa5b2..16831c36d34457 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1203,7 +1203,6 @@ SYSCALL_DEFINE1(close, unsigned int, fd) return retval; } -EXPORT_SYMBOL(sys_close); /* * This routine simulates a hangup on the tty, to arrange that users diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a78186d826d796..f67d4a788d3f06 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -941,4 +941,15 @@ asmlinkage long sys_pkey_free(int pkey); asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, unsigned mask, struct statx __user *buffer); +extern int __close_fd(struct files_struct *files, unsigned int fd); + +/* + * In contrast to sys_close(), this stub does not check whether the syscall + * should or should not be restarted, but returns the raw error codes from + * __close_fd(). + */ +static inline int ksys_close(unsigned int fd) +{ + return __close_fd(current->files, fd); +} #endif diff --git a/init/do_mounts.c b/init/do_mounts.c index 7cf4f6dafd5f32..a296558fb48379 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -492,7 +492,7 @@ void __init change_floppy(char *fmt, ...) fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); if (fd >= 0) { sys_ioctl(fd, FDEJECT, 0); - sys_close(fd); + ksys_close(fd); } printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); fd = sys_open("/dev/console", O_RDWR, 0); @@ -503,7 +503,7 @@ void __init change_floppy(char *fmt, ...) sys_read(fd, &c, 1); termios.c_lflag |= ICANON; sys_ioctl(fd, TCSETSF, (long)&termios); - sys_close(fd); + ksys_close(fd); } } #endif diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index 53d4f0f326e74e..86924340e2a1ab 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c @@ -111,7 +111,7 @@ static void __init handle_initrd(void) error = fd; } else { error = sys_ioctl(fd, BLKFLSBUF, 0); - sys_close(fd); + ksys_close(fd); } printk(!error ? "okay\n" : "failed\n"); } diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c index 3f733c760a8c55..ebd4013d589e4d 100644 --- a/init/do_mounts_md.c +++ b/init/do_mounts_md.c @@ -191,7 +191,7 @@ static void __init md_setup_drive(void) printk(KERN_WARNING "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n", minor); - sys_close(fd); + ksys_close(fd); continue; } @@ -243,11 +243,11 @@ static void __init md_setup_drive(void) * boot a kernel with devfs compiled in from partitioned md * array without it */ - sys_close(fd); + ksys_close(fd); fd = sys_open(name, 0, 0); sys_ioctl(fd, BLKRRPART, 0); } - sys_close(fd); + ksys_close(fd); } } @@ -297,7 +297,7 @@ static void __init autodetect_raid(void) fd = sys_open("/dev/md0", 0, 0); if (fd >= 0) { sys_ioctl(fd, RAID_AUTORUN, raid_autopart); - sys_close(fd); + ksys_close(fd); } } diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index 99e0b649fc0e90..65b365c9dc473b 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c @@ -257,7 +257,7 @@ int __init rd_load_image(char *from) if (i && (i % devblocks == 0)) { printk("done disk #%d.\n", disk++); rotate = 0; - if (sys_close(in_fd)) { + if (ksys_close(in_fd)) { printk("Error closing the disk.\n"); goto noclose_input; } @@ -283,9 +283,9 @@ int __init rd_load_image(char *from) successful_load: res = 1; done: - sys_close(in_fd); + ksys_close(in_fd); noclose_input: - sys_close(out_fd); + ksys_close(out_fd); out: kfree(buf); sys_unlink("/dev/ram"); diff --git a/init/initramfs.c b/init/initramfs.c index 7046feffef6b58..0a5f5caa6a27f2 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -373,7 +373,7 @@ static int __init do_copy(void) if (byte_count >= body_len) { if (xwrite(wfd, victim, body_len) != body_len) error("write error"); - sys_close(wfd); + ksys_close(wfd); do_utime(vcollected, mtime); kfree(vcollected); eat(body_len); @@ -574,7 +574,7 @@ static void __init clean_rootfs(void) buf = kzalloc(BUF_SIZE, GFP_KERNEL); WARN_ON(!buf); if (!buf) { - sys_close(fd); + ksys_close(fd); return; } @@ -602,7 +602,7 @@ static void __init clean_rootfs(void) num = sys_getdents64(fd, dirp, BUF_SIZE); } - sys_close(fd); + ksys_close(fd); kfree(buf); } #endif @@ -639,7 +639,7 @@ static int __init populate_rootfs(void) pr_err("/initrd.image: incomplete write (%zd != %ld)\n", written, initrd_end - initrd_start); - sys_close(fd); + ksys_close(fd); free_initrd(); } done: |