Skip to content

Commit 87c4e19

Browse files
author
Dominik Brodowski
committed
fs: add do_mknodat() helper and ksys_mknod() wrapper; remove in-kernel calls to syscall
Using the fs-internal do_mknodat() helper allows us to get rid of fs-internal calls to the sys_mknodat() syscall. Introducing the ksys_mknod() wrapper allows us to avoid the in-kernel calls to sys_mknod() 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_mknod(). 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 b724e84 commit 87c4e19

6 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎fs/internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ extern void __init chrdev_init(void);
5555
extern int user_path_mountpoint_at(int, const char __user *, unsigned int, struct path *);
5656
extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
5757
const char *, unsigned int, struct path *);
58+
long do_mknodat(int dfd, const char __user *filename, umode_t mode,
59+
unsigned int dev);
5860
long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
5961
long do_rmdir(int dfd, const char __user *pathname);
6062
long do_unlinkat(int dfd, struct filename *name);

‎fs/namei.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,8 +3728,8 @@ static int may_mknod(umode_t mode)
37283728
}
37293729
}
37303730

3731-
SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
3732-
unsigned, dev)
3731+
long do_mknodat(int dfd, const char __user *filename, umode_t mode,
3732+
unsigned int dev)
37333733
{
37343734
struct dentry *dentry;
37353735
struct path path;
@@ -3772,9 +3772,15 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
37723772
return error;
37733773
}
37743774

3775+
SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
3776+
unsigned int, dev)
3777+
{
3778+
return do_mknodat(dfd, filename, mode, dev);
3779+
}
3780+
37753781
SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev)
37763782
{
3777-
return sys_mknodat(AT_FDCWD, filename, mode, dev);
3783+
return do_mknodat(AT_FDCWD, filename, mode, dev);
37783784
}
37793785

37803786
int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)

‎include/linux/syscalls.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,4 +988,13 @@ static inline long ksys_symlink(const char __user *oldname,
988988
return do_symlinkat(oldname, AT_FDCWD, newname);
989989
}
990990

991+
extern long do_mknodat(int dfd, const char __user *filename, umode_t mode,
992+
unsigned int dev);
993+
994+
static inline long ksys_mknod(const char __user *filename, umode_t mode,
995+
unsigned int dev)
996+
{
997+
return do_mknodat(AT_FDCWD, filename, mode, dev);
998+
}
999+
9911000
#endif

‎init/do_mounts.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern int root_mountflags;
1717
static inline int create_dev(char *name, dev_t dev)
1818
{
1919
ksys_unlink(name);
20-
return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
20+
return ksys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
2121
}
2222

2323
static inline u32 bstat(char *name)

‎init/initramfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static int __init do_name(void)
359359
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
360360
S_ISFIFO(mode) || S_ISSOCK(mode)) {
361361
if (maybe_link() == 0) {
362-
sys_mknod(collected, mode, rdev);
362+
ksys_mknod(collected, mode, rdev);
363363
sys_chown(collected, uid, gid);
364364
sys_chmod(collected, mode);
365365
do_utime(collected, mtime);

‎init/noinitramfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int __init default_rootfs(void)
3333
if (err < 0)
3434
goto out;
3535

36-
err = sys_mknod((const char __user __force *) "/dev/console",
36+
err = ksys_mknod((const char __user __force *) "/dev/console",
3737
S_IFCHR | S_IRUSR | S_IWUSR,
3838
new_encode_dev(MKDEV(5, 1)));
3939
if (err < 0)

0 commit comments

Comments
 (0)