diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2018-03-13 16:43:59 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2018-04-02 14:16:03 -0400 |
commit | cbb60b924b9f3e4d7c67a1c9dcf981718f926e4e (patch) | |
tree | f3952696484e55feb05b862849d15740b87183a8 | |
parent | 454dab3f965ec24fda8fbe135c8dad4c5b238a86 (diff) |
fs: add ksys_ioctl() helper; remove in-kernel calls to sys_ioctl()
Using this helper allows us to avoid the in-kernel calls to the
sys_ioctl() 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_ioctl().
After careful review, at least some of these calls could be converted
to do_vfs_ioctl() in future.
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>
-rw-r--r-- | fs/ioctl.c | 7 | ||||
-rw-r--r-- | include/linux/syscalls.h | 1 | ||||
-rw-r--r-- | init/do_mounts.c | 8 | ||||
-rw-r--r-- | init/do_mounts_initrd.c | 2 | ||||
-rw-r--r-- | init/do_mounts_md.c | 15 | ||||
-rw-r--r-- | init/do_mounts_rd.c | 4 |
6 files changed, 22 insertions, 15 deletions
diff --git a/fs/ioctl.c b/fs/ioctl.c index 5ace7efb0d04..4823431d1c9d 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c | |||
@@ -689,7 +689,7 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, | |||
689 | return error; | 689 | return error; |
690 | } | 690 | } |
691 | 691 | ||
692 | SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) | 692 | int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
693 | { | 693 | { |
694 | int error; | 694 | int error; |
695 | struct fd f = fdget(fd); | 695 | struct fd f = fdget(fd); |
@@ -702,3 +702,8 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) | |||
702 | fdput(f); | 702 | fdput(f); |
703 | return error; | 703 | return error; |
704 | } | 704 | } |
705 | |||
706 | SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) | ||
707 | { | ||
708 | return ksys_ioctl(fd, cmd, arg); | ||
709 | } | ||
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index c056aff6d7ad..5a959efd8fb7 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -957,6 +957,7 @@ int ksys_fchmod(unsigned int fd, umode_t mode); | |||
957 | int ksys_fchown(unsigned int fd, uid_t user, gid_t group); | 957 | int ksys_fchown(unsigned int fd, uid_t user, gid_t group); |
958 | int ksys_getdents64(unsigned int fd, struct linux_dirent64 __user *dirent, | 958 | int ksys_getdents64(unsigned int fd, struct linux_dirent64 __user *dirent, |
959 | unsigned int count); | 959 | unsigned int count); |
960 | int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg); | ||
960 | 961 | ||
961 | /* | 962 | /* |
962 | * The following kernel syscall equivalents are just wrappers to fs-internal | 963 | * The following kernel syscall equivalents are just wrappers to fs-internal |
diff --git a/init/do_mounts.c b/init/do_mounts.c index cc1103477071..b17e0095eb4e 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c | |||
@@ -491,18 +491,18 @@ void __init change_floppy(char *fmt, ...) | |||
491 | va_end(args); | 491 | va_end(args); |
492 | fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0); | 492 | fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0); |
493 | if (fd >= 0) { | 493 | if (fd >= 0) { |
494 | sys_ioctl(fd, FDEJECT, 0); | 494 | ksys_ioctl(fd, FDEJECT, 0); |
495 | ksys_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 = ksys_open("/dev/console", O_RDWR, 0); | 498 | fd = ksys_open("/dev/console", O_RDWR, 0); |
499 | if (fd >= 0) { | 499 | if (fd >= 0) { |
500 | sys_ioctl(fd, TCGETS, (long)&termios); | 500 | ksys_ioctl(fd, TCGETS, (long)&termios); |
501 | termios.c_lflag &= ~ICANON; | 501 | termios.c_lflag &= ~ICANON; |
502 | sys_ioctl(fd, TCSETSF, (long)&termios); | 502 | ksys_ioctl(fd, TCSETSF, (long)&termios); |
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 | ksys_ioctl(fd, TCSETSF, (long)&termios); |
506 | ksys_close(fd); | 506 | ksys_close(fd); |
507 | } | 507 | } |
508 | } | 508 | } |
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index cedca8fd2590..03ec0c1b7553 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c | |||
@@ -110,7 +110,7 @@ static void __init handle_initrd(void) | |||
110 | if (fd < 0) { | 110 | if (fd < 0) { |
111 | error = fd; | 111 | error = fd; |
112 | } else { | 112 | } else { |
113 | error = sys_ioctl(fd, BLKFLSBUF, 0); | 113 | error = ksys_ioctl(fd, BLKFLSBUF, 0); |
114 | ksys_close(fd); | 114 | ksys_close(fd); |
115 | } | 115 | } |
116 | printk(!error ? "okay\n" : "failed\n"); | 116 | printk(!error ? "okay\n" : "failed\n"); |
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c index 76dcfaada3ed..7d85d172bc7e 100644 --- a/init/do_mounts_md.c +++ b/init/do_mounts_md.c | |||
@@ -187,7 +187,7 @@ static void __init md_setup_drive(void) | |||
187 | "array %s\n", name); | 187 | "array %s\n", name); |
188 | continue; | 188 | continue; |
189 | } | 189 | } |
190 | if (sys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) { | 190 | if (ksys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) { |
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); |
@@ -210,7 +210,7 @@ static void __init md_setup_drive(void) | |||
210 | ainfo.state = (1 << MD_SB_CLEAN); | 210 | ainfo.state = (1 << MD_SB_CLEAN); |
211 | ainfo.layout = 0; | 211 | ainfo.layout = 0; |
212 | ainfo.chunk_size = md_setup_args[ent].chunk; | 212 | ainfo.chunk_size = md_setup_args[ent].chunk; |
213 | err = sys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo); | 213 | err = ksys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo); |
214 | for (i = 0; !err && i <= MD_SB_DISKS; i++) { | 214 | for (i = 0; !err && i <= MD_SB_DISKS; i++) { |
215 | dev = devices[i]; | 215 | dev = devices[i]; |
216 | if (!dev) | 216 | if (!dev) |
@@ -220,7 +220,8 @@ static void __init md_setup_drive(void) | |||
220 | dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC); | 220 | dinfo.state = (1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC); |
221 | dinfo.major = MAJOR(dev); | 221 | dinfo.major = MAJOR(dev); |
222 | dinfo.minor = MINOR(dev); | 222 | dinfo.minor = MINOR(dev); |
223 | err = sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo); | 223 | err = ksys_ioctl(fd, ADD_NEW_DISK, |
224 | (long)&dinfo); | ||
224 | } | 225 | } |
225 | } else { | 226 | } else { |
226 | /* persistent */ | 227 | /* persistent */ |
@@ -230,11 +231,11 @@ static void __init md_setup_drive(void) | |||
230 | break; | 231 | break; |
231 | dinfo.major = MAJOR(dev); | 232 | dinfo.major = MAJOR(dev); |
232 | dinfo.minor = MINOR(dev); | 233 | dinfo.minor = MINOR(dev); |
233 | sys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo); | 234 | ksys_ioctl(fd, ADD_NEW_DISK, (long)&dinfo); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | if (!err) | 237 | if (!err) |
237 | err = sys_ioctl(fd, RUN_ARRAY, 0); | 238 | err = ksys_ioctl(fd, RUN_ARRAY, 0); |
238 | if (err) | 239 | if (err) |
239 | printk(KERN_WARNING "md: starting md%d failed\n", minor); | 240 | printk(KERN_WARNING "md: starting md%d failed\n", minor); |
240 | else { | 241 | else { |
@@ -245,7 +246,7 @@ static void __init md_setup_drive(void) | |||
245 | */ | 246 | */ |
246 | ksys_close(fd); | 247 | ksys_close(fd); |
247 | fd = ksys_open(name, 0, 0); | 248 | fd = ksys_open(name, 0, 0); |
248 | sys_ioctl(fd, BLKRRPART, 0); | 249 | ksys_ioctl(fd, BLKRRPART, 0); |
249 | } | 250 | } |
250 | ksys_close(fd); | 251 | ksys_close(fd); |
251 | } | 252 | } |
@@ -296,7 +297,7 @@ static void __init autodetect_raid(void) | |||
296 | 297 | ||
297 | fd = ksys_open("/dev/md0", 0, 0); | 298 | fd = ksys_open("/dev/md0", 0, 0); |
298 | if (fd >= 0) { | 299 | if (fd >= 0) { |
299 | sys_ioctl(fd, RAID_AUTORUN, raid_autopart); | 300 | ksys_ioctl(fd, RAID_AUTORUN, raid_autopart); |
300 | ksys_close(fd); | 301 | ksys_close(fd); |
301 | } | 302 | } |
302 | } | 303 | } |
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index a6706314baa7..4dafaed5736f 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c | |||
@@ -218,7 +218,7 @@ int __init rd_load_image(char *from) | |||
218 | * NOTE NOTE: nblocks is not actually blocks but | 218 | * NOTE NOTE: nblocks is not actually blocks but |
219 | * the number of kibibytes of data to load into a ramdisk. | 219 | * the number of kibibytes of data to load into a ramdisk. |
220 | */ | 220 | */ |
221 | if (sys_ioctl(out_fd, BLKGETSIZE, (unsigned long)&rd_blocks) < 0) | 221 | if (ksys_ioctl(out_fd, BLKGETSIZE, (unsigned long)&rd_blocks) < 0) |
222 | rd_blocks = 0; | 222 | rd_blocks = 0; |
223 | else | 223 | else |
224 | rd_blocks >>= 1; | 224 | rd_blocks >>= 1; |
@@ -232,7 +232,7 @@ int __init rd_load_image(char *from) | |||
232 | /* | 232 | /* |
233 | * OK, time to copy in the data | 233 | * OK, time to copy in the data |
234 | */ | 234 | */ |
235 | if (sys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0) | 235 | if (ksys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0) |
236 | devblocks = 0; | 236 | devblocks = 0; |
237 | else | 237 | else |
238 | devblocks >>= 1; | 238 | devblocks >>= 1; |