Skip to content

Commit bae217e

Browse files
author
Dominik Brodowski
committed
fs: add ksys_open() wrapper; remove in-kernel calls to sys_open()
Using this wrapper allows us to avoid the in-kernel calls to the sys_open() 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_open(). 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>
1 parent 2ca2a09 commit bae217e

8 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎fs/open.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla
11511151
*/
11521152
SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
11531153
{
1154-
return sys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
1154+
return ksys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
11551155
}
11561156

11571157
#endif

‎include/linux/syscalls.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,4 +1057,15 @@ static inline int ksys_close(unsigned int fd)
10571057
return __close_fd(current->files, fd);
10581058
}
10591059

1060+
extern long do_sys_open(int dfd, const char __user *filename, int flags,
1061+
umode_t mode);
1062+
1063+
static inline long ksys_open(const char __user *filename, int flags,
1064+
umode_t mode)
1065+
{
1066+
if (force_o_largefile())
1067+
flags |= O_LARGEFILE;
1068+
return do_sys_open(AT_FDCWD, filename, flags, mode);
1069+
}
1070+
10601071
#endif

‎init/do_mounts.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,13 @@ void __init change_floppy(char *fmt, ...)
489489
va_start(args, fmt);
490490
vsprintf(buf, fmt, args);
491491
va_end(args);
492-
fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
492+
fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0);
493493
if (fd >= 0) {
494494
sys_ioctl(fd, FDEJECT, 0);
495495
ksys_close(fd);
496496
}
497497
printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
498-
fd = sys_open("/dev/console", O_RDWR, 0);
498+
fd = ksys_open("/dev/console", O_RDWR, 0);
499499
if (fd >= 0) {
500500
sys_ioctl(fd, TCGETS, (long)&termios);
501501
termios.c_lflag &= ~ICANON;

‎init/do_mounts_initrd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
3838
{
3939
sys_unshare(CLONE_FS | CLONE_FILES);
4040
/* stdin/stdout/stderr for /linuxrc */
41-
sys_open("/dev/console", O_RDWR, 0);
41+
ksys_open("/dev/console", O_RDWR, 0);
4242
ksys_dup(0);
4343
ksys_dup(0);
4444
/* move initrd over / and chdir/chroot in initrd root */
@@ -99,7 +99,7 @@ static void __init handle_initrd(void)
9999
if (!error)
100100
printk("okay\n");
101101
else {
102-
int fd = sys_open("/dev/root.old", O_RDWR, 0);
102+
int fd = ksys_open("/dev/root.old", O_RDWR, 0);
103103
if (error == -ENOENT)
104104
printk("/initrd does not exist. Ignored.\n");
105105
else

‎init/do_mounts_md.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void __init md_setup_drive(void)
181181
partitioned ? "_d" : "", minor,
182182
md_setup_args[ent].device_names);
183183

184-
fd = sys_open(name, 0, 0);
184+
fd = ksys_open(name, 0, 0);
185185
if (fd < 0) {
186186
printk(KERN_ERR "md: open failed - cannot start "
187187
"array %s\n", name);
@@ -244,7 +244,7 @@ static void __init md_setup_drive(void)
244244
* array without it
245245
*/
246246
ksys_close(fd);
247-
fd = sys_open(name, 0, 0);
247+
fd = ksys_open(name, 0, 0);
248248
sys_ioctl(fd, BLKRRPART, 0);
249249
}
250250
ksys_close(fd);
@@ -294,7 +294,7 @@ static void __init autodetect_raid(void)
294294

295295
wait_for_device_probe();
296296

297-
fd = sys_open("/dev/md0", 0, 0);
297+
fd = ksys_open("/dev/md0", 0, 0);
298298
if (fd >= 0) {
299299
sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
300300
ksys_close(fd);

‎init/do_mounts_rd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ int __init rd_load_image(char *from)
196196
char rotator[4] = { '|' , '/' , '-' , '\\' };
197197
#endif
198198

199-
out_fd = sys_open("/dev/ram", O_RDWR, 0);
199+
out_fd = ksys_open("/dev/ram", O_RDWR, 0);
200200
if (out_fd < 0)
201201
goto out;
202202

203-
in_fd = sys_open(from, O_RDONLY, 0);
203+
in_fd = ksys_open(from, O_RDONLY, 0);
204204
if (in_fd < 0)
205205
goto noclose_input;
206206

@@ -262,7 +262,7 @@ int __init rd_load_image(char *from)
262262
goto noclose_input;
263263
}
264264
change_floppy("disk #%d", disk);
265-
in_fd = sys_open(from, O_RDONLY, 0);
265+
in_fd = ksys_open(from, O_RDONLY, 0);
266266
if (in_fd < 0) {
267267
printk("Error opening disk.\n");
268268
goto noclose_input;

‎init/initramfs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int __init do_name(void)
340340
int openflags = O_WRONLY|O_CREAT;
341341
if (ml != 1)
342342
openflags |= O_TRUNC;
343-
wfd = sys_open(collected, openflags, mode);
343+
wfd = ksys_open(collected, openflags, mode);
344344

345345
if (wfd >= 0) {
346346
ksys_fchown(wfd, uid, gid);
@@ -567,7 +567,7 @@ static void __init clean_rootfs(void)
567567
struct linux_dirent64 *dirp;
568568
int num;
569569

570-
fd = sys_open("/", O_RDONLY, 0);
570+
fd = ksys_open("/", O_RDONLY, 0);
571571
WARN_ON(fd < 0);
572572
if (fd < 0)
573573
return;
@@ -629,7 +629,7 @@ static int __init populate_rootfs(void)
629629
}
630630
printk(KERN_INFO "rootfs image is not initramfs (%s)"
631631
"; looks like an initrd\n", err);
632-
fd = sys_open("/initrd.image",
632+
fd = ksys_open("/initrd.image",
633633
O_WRONLY|O_CREAT, 0700);
634634
if (fd >= 0) {
635635
ssize_t written = xwrite(fd, (char *)initrd_start,

‎init/main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ static noinline void __init kernel_init_freeable(void)
10741074
do_basic_setup();
10751075

10761076
/* Open the /dev/console on the rootfs, this should never fail */
1077-
if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1077+
if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
10781078
pr_err("Warning: unable to open an initial console.\n");
10791079

10801080
(void) ksys_dup(0);

0 commit comments

Comments
 (0)