summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2018-03-11 06:34:55 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2018-04-02 14:16:00 -0400
commit2ca2a09d6215fd9621aa3e2db7cc9428a61f2911 (patch)
treea1999670bbdba36d98ba32fcca130dafcb238fd0
parent411d9475cf901b5a6d2996b46cb5726184a4fa50 (diff)
fs: add ksys_close() wrapper; remove in-kernel calls to sys_close()
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.c2
-rw-r--r--fs/binfmt_misc.c2
-rw-r--r--fs/file.c1
-rw-r--r--fs/open.c1
-rw-r--r--include/linux/syscalls.h12
-rw-r--r--init/do_mounts.c4
-rw-r--r--init/do_mounts_initrd.c2
-rw-r--r--init/do_mounts_md.c8
-rw-r--r--init/do_mounts_rd.c6
-rw-r--r--init/initramfs.c8
10 files changed, 29 insertions, 17 deletions
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index b7c816f39404..26f6b4f41ce6 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -310,7 +310,7 @@ static int autofs_dev_ioctl_closemount(struct file *fp,
310 struct autofs_sb_info *sbi, 310 struct autofs_sb_info *sbi,
311 struct autofs_dev_ioctl *param) 311 struct autofs_dev_ioctl *param)
312{ 312{
313 return sys_close(param->ioctlfd); 313 return ksys_close(param->ioctlfd);
314} 314}
315 315
316/* 316/*
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index a7c5a9861bef..a41b48f82a70 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -241,7 +241,7 @@ ret:
241 return retval; 241 return retval;
242error: 242error:
243 if (fd_binary > 0) 243 if (fd_binary > 0)
244 sys_close(fd_binary); 244 ksys_close(fd_binary);
245 bprm->interp_flags = 0; 245 bprm->interp_flags = 0;
246 bprm->interp_data = 0; 246 bprm->interp_data = 0;
247 goto ret; 247 goto ret;
diff --git a/fs/file.c b/fs/file.c
index d304004f0b65..7ffd6e9d103d 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -638,6 +638,7 @@ out_unlock:
638 spin_unlock(&files->file_lock); 638 spin_unlock(&files->file_lock);
639 return -EBADF; 639 return -EBADF;
640} 640}
641EXPORT_SYMBOL(__close_fd); /* for ksys_close() */
641 642
642void do_close_on_exec(struct files_struct *files) 643void do_close_on_exec(struct files_struct *files)
643{ 644{
diff --git a/fs/open.c b/fs/open.c
index b3f3b2cd9f19..710102fc262b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1200,7 +1200,6 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
1200 1200
1201 return retval; 1201 return retval;
1202} 1202}
1203EXPORT_SYMBOL(sys_close);
1204 1203
1205/* 1204/*
1206 * This routine simulates a hangup on the tty, to arrange that users 1205 * 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 41023177c8ec..38805f3447ea 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1045,4 +1045,16 @@ static inline long ksys_ftruncate(unsigned int fd, unsigned long length)
1045 return do_sys_ftruncate(fd, length, 1); 1045 return do_sys_ftruncate(fd, length, 1);
1046} 1046}
1047 1047
1048extern int __close_fd(struct files_struct *files, unsigned int fd);
1049
1050/*
1051 * In contrast to sys_close(), this stub does not check whether the syscall
1052 * should or should not be restarted, but returns the raw error codes from
1053 * __close_fd().
1054 */
1055static inline int ksys_close(unsigned int fd)
1056{
1057 return __close_fd(current->files, fd);
1058}
1059
1048#endif 1060#endif
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 89f18985fa90..a28dd42d1f84 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -492,7 +492,7 @@ void __init change_floppy(char *fmt, ...)
492 fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); 492 fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
493 if (fd >= 0) { 493 if (fd >= 0) {
494 sys_ioctl(fd, FDEJECT, 0); 494 sys_ioctl(fd, FDEJECT, 0);
495 sys_close(fd); 495 ksys_close(fd);
496 } 496 }
497 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); 497 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
498 fd = sys_open("/dev/console", O_RDWR, 0); 498 fd = sys_open("/dev/console", O_RDWR, 0);
@@ -503,7 +503,7 @@ void __init change_floppy(char *fmt, ...)
503 sys_read(fd, &c, 1); 503 sys_read(fd, &c, 1);
504 termios.c_lflag |= ICANON; 504 termios.c_lflag |= ICANON;
505 sys_ioctl(fd, TCSETSF, (long)&termios); 505 sys_ioctl(fd, TCSETSF, (long)&termios);
506 sys_close(fd); 506 ksys_close(fd);
507 } 507 }
508} 508}
509#endif 509#endif
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 99922d1ebfe6..6907c6dbc443 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -111,7 +111,7 @@ static void __init handle_initrd(void)
111 error = fd; 111 error = fd;
112 } else { 112 } else {
113 error = sys_ioctl(fd, BLKFLSBUF, 0); 113 error = sys_ioctl(fd, BLKFLSBUF, 0);
114 sys_close(fd); 114 ksys_close(fd);
115 } 115 }
116 printk(!error ? "okay\n" : "failed\n"); 116 printk(!error ? "okay\n" : "failed\n");
117 } 117 }
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
index 3f733c760a8c..ebd4013d589e 100644
--- a/init/do_mounts_md.c
+++ b/init/do_mounts_md.c
@@ -191,7 +191,7 @@ static void __init md_setup_drive(void)
191 printk(KERN_WARNING 191 printk(KERN_WARNING
192 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n", 192 "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n",
193 minor); 193 minor);
194 sys_close(fd); 194 ksys_close(fd);
195 continue; 195 continue;
196 } 196 }
197 197
@@ -243,11 +243,11 @@ static void __init md_setup_drive(void)
243 * boot a kernel with devfs compiled in from partitioned md 243 * boot a kernel with devfs compiled in from partitioned md
244 * array without it 244 * array without it
245 */ 245 */
246 sys_close(fd); 246 ksys_close(fd);
247 fd = sys_open(name, 0, 0); 247 fd = sys_open(name, 0, 0);
248 sys_ioctl(fd, BLKRRPART, 0); 248 sys_ioctl(fd, BLKRRPART, 0);
249 } 249 }
250 sys_close(fd); 250 ksys_close(fd);
251 } 251 }
252} 252}
253 253
@@ -297,7 +297,7 @@ static void __init autodetect_raid(void)
297 fd = sys_open("/dev/md0", 0, 0); 297 fd = sys_open("/dev/md0", 0, 0);
298 if (fd >= 0) { 298 if (fd >= 0) {
299 sys_ioctl(fd, RAID_AUTORUN, raid_autopart); 299 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
300 sys_close(fd); 300 ksys_close(fd);
301 } 301 }
302} 302}
303 303
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 5b69056f610a..f1aa341862d3 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -257,7 +257,7 @@ int __init rd_load_image(char *from)
257 if (i && (i % devblocks == 0)) { 257 if (i && (i % devblocks == 0)) {
258 printk("done disk #%d.\n", disk++); 258 printk("done disk #%d.\n", disk++);
259 rotate = 0; 259 rotate = 0;
260 if (sys_close(in_fd)) { 260 if (ksys_close(in_fd)) {
261 printk("Error closing the disk.\n"); 261 printk("Error closing the disk.\n");
262 goto noclose_input; 262 goto noclose_input;
263 } 263 }
@@ -283,9 +283,9 @@ int __init rd_load_image(char *from)
283successful_load: 283successful_load:
284 res = 1; 284 res = 1;
285done: 285done:
286 sys_close(in_fd); 286 ksys_close(in_fd);
287noclose_input: 287noclose_input:
288 sys_close(out_fd); 288 ksys_close(out_fd);
289out: 289out:
290 kfree(buf); 290 kfree(buf);
291 ksys_unlink("/dev/ram"); 291 ksys_unlink("/dev/ram");
diff --git a/init/initramfs.c b/init/initramfs.c
index 0d3b001b0dc5..ce2bcad97cdf 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -373,7 +373,7 @@ static int __init do_copy(void)
373 if (byte_count >= body_len) { 373 if (byte_count >= body_len) {
374 if (xwrite(wfd, victim, body_len) != body_len) 374 if (xwrite(wfd, victim, body_len) != body_len)
375 error("write error"); 375 error("write error");
376 sys_close(wfd); 376 ksys_close(wfd);
377 do_utime(vcollected, mtime); 377 do_utime(vcollected, mtime);
378 kfree(vcollected); 378 kfree(vcollected);
379 eat(body_len); 379 eat(body_len);
@@ -574,7 +574,7 @@ static void __init clean_rootfs(void)
574 buf = kzalloc(BUF_SIZE, GFP_KERNEL); 574 buf = kzalloc(BUF_SIZE, GFP_KERNEL);
575 WARN_ON(!buf); 575 WARN_ON(!buf);
576 if (!buf) { 576 if (!buf) {
577 sys_close(fd); 577 ksys_close(fd);
578 return; 578 return;
579 } 579 }
580 580
@@ -602,7 +602,7 @@ static void __init clean_rootfs(void)
602 num = sys_getdents64(fd, dirp, BUF_SIZE); 602 num = sys_getdents64(fd, dirp, BUF_SIZE);
603 } 603 }
604 604
605 sys_close(fd); 605 ksys_close(fd);
606 kfree(buf); 606 kfree(buf);
607} 607}
608#endif 608#endif
@@ -639,7 +639,7 @@ static int __init populate_rootfs(void)
639 pr_err("/initrd.image: incomplete write (%zd != %ld)\n", 639 pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
640 written, initrd_end - initrd_start); 640 written, initrd_end - initrd_start);
641 641
642 sys_close(fd); 642 ksys_close(fd);
643 free_initrd(); 643 free_initrd();
644 } 644 }
645 done: 645 done: