Skip to content

Commit 36028d5

Browse files
author
Dominik Brodowski
committed
fs: add ksys_p{read,write}64() helpers; remove in-kernel calls to syscalls
Using the ksys_p{read,write}64() wrappers allows us to get rid of in-kernel calls to the sys_pread64() and sys_pwrite64() syscalls. 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_p{read,write}64(). 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 df260e2 commit 36028d5

9 files changed

Lines changed: 36 additions & 20 deletions

File tree

‎arch/mips/kernel/linux32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
105105
SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
106106
unsigned long, unused, unsigned long, a4, unsigned long, a5)
107107
{
108-
return sys_pread64(fd, buf, count, merge_64(a4, a5));
108+
return ksys_pread64(fd, buf, count, merge_64(a4, a5));
109109
}
110110

111111
SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
112112
size_t, count, u32, unused, u64, a4, u64, a5)
113113
{
114-
return sys_pwrite64(fd, buf, count, merge_64(a4, a5));
114+
return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
115115
}
116116

117117
SYSCALL_DEFINE1(32_personality, unsigned long, personality)

‎arch/parisc/kernel/sys_parisc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ asmlinkage long parisc_ftruncate64(unsigned int fd,
333333
asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
334334
unsigned int high, unsigned int low)
335335
{
336-
return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
336+
return ksys_pread64(fd, buf, count, (loff_t)high << 32 | low);
337337
}
338338

339339
asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
340340
size_t count, unsigned int high, unsigned int low)
341341
{
342-
return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
342+
return ksys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
343343
}
344344

345345
asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,

‎arch/powerpc/kernel/sys_ppc32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
7777
compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
7878
u32 reg6, u32 poshi, u32 poslo)
7979
{
80-
return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
80+
return ksys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
8181
}
8282

8383
compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count,
8484
u32 reg6, u32 poshi, u32 poslo)
8585
{
86-
return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
86+
return ksys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
8787
}
8888

8989
compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)

‎arch/s390/kernel/compat_linux.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ COMPAT_SYSCALL_DEFINE5(s390_pread64, unsigned int, fd, char __user *, ubuf,
315315
{
316316
if ((compat_ssize_t) count < 0)
317317
return -EINVAL;
318-
return sys_pread64(fd, ubuf, count, (unsigned long)high << 32 | low);
318+
return ksys_pread64(fd, ubuf, count, (unsigned long)high << 32 | low);
319319
}
320320

321321
COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd, const char __user *, ubuf,
322322
compat_size_t, count, u32, high, u32, low)
323323
{
324324
if ((compat_ssize_t) count < 0)
325325
return -EINVAL;
326-
return sys_pwrite64(fd, ubuf, count, (unsigned long)high << 32 | low);
326+
return ksys_pwrite64(fd, ubuf, count, (unsigned long)high << 32 | low);
327327
}
328328

329329
COMPAT_SYSCALL_DEFINE4(s390_readahead, int, fd, u32, high, u32, low, s32, count)

‎arch/sh/kernel/sys_sh32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ asmlinkage int sys_sh_pipe(void)
3939
asmlinkage ssize_t sys_pread_wrapper(unsigned int fd, char __user *buf,
4040
size_t count, long dummy, loff_t pos)
4141
{
42-
return sys_pread64(fd, buf, count, pos);
42+
return ksys_pread64(fd, buf, count, pos);
4343
}
4444

4545
asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char __user *buf,
4646
size_t count, long dummy, loff_t pos)
4747
{
48-
return sys_pwrite64(fd, buf, count, pos);
48+
return ksys_pwrite64(fd, buf, count, pos);
4949
}
5050

5151
asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1,

‎arch/sparc/kernel/sys_sparc32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
200200
unsigned long poshi,
201201
unsigned long poslo)
202202
{
203-
return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
203+
return ksys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
204204
}
205205

206206
asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
@@ -209,7 +209,7 @@ asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
209209
unsigned long poshi,
210210
unsigned long poslo)
211211
{
212-
return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
212+
return ksys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
213213
}
214214

215215
asmlinkage long compat_sys_readahead(int fd,

‎arch/x86/ia32/sys_ia32.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ COMPAT_SYSCALL_DEFINE1(x86_mmap, struct mmap_arg_struct32 __user *, arg)
174174
COMPAT_SYSCALL_DEFINE5(x86_pread, unsigned int, fd, char __user *, ubuf,
175175
u32, count, u32, poslo, u32, poshi)
176176
{
177-
return sys_pread64(fd, ubuf, count,
178-
((loff_t)AA(poshi) << 32) | AA(poslo));
177+
return ksys_pread64(fd, ubuf, count,
178+
((loff_t)AA(poshi) << 32) | AA(poslo));
179179
}
180180

181181
COMPAT_SYSCALL_DEFINE5(x86_pwrite, unsigned int, fd, const char __user *, ubuf,
182182
u32, count, u32, poslo, u32, poshi)
183183
{
184-
return sys_pwrite64(fd, ubuf, count,
185-
((loff_t)AA(poshi) << 32) | AA(poslo));
184+
return ksys_pwrite64(fd, ubuf, count,
185+
((loff_t)AA(poshi) << 32) | AA(poslo));
186186
}
187187

188188

‎fs/read_write.c‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
610610
return ksys_write(fd, buf, count);
611611
}
612612

613-
SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
614-
size_t, count, loff_t, pos)
613+
ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count,
614+
loff_t pos)
615615
{
616616
struct fd f;
617617
ssize_t ret = -EBADF;
@@ -630,8 +630,14 @@ SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
630630
return ret;
631631
}
632632

633-
SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
634-
size_t, count, loff_t, pos)
633+
SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
634+
size_t, count, loff_t, pos)
635+
{
636+
return ksys_pread64(fd, buf, count, pos);
637+
}
638+
639+
ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
640+
size_t count, loff_t pos)
635641
{
636642
struct fd f;
637643
ssize_t ret = -EBADF;
@@ -650,6 +656,12 @@ SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
650656
return ret;
651657
}
652658

659+
SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
660+
size_t, count, loff_t, pos)
661+
{
662+
return ksys_pwrite64(fd, buf, count, pos);
663+
}
664+
653665
static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter,
654666
loff_t *ppos, int type, rwf_t flags)
655667
{

‎include/linux/syscalls.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,10 @@ int ksys_unshare(unsigned long unshare_flags);
965965
int ksys_setsid(void);
966966
int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
967967
unsigned int flags);
968+
ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count,
969+
loff_t pos);
970+
ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
971+
size_t count, loff_t pos);
968972

969973
/*
970974
* The following kernel syscall equivalents are just wrappers to fs-internal

0 commit comments

Comments
 (0)