net: socket: add __sys_recvfrom() helper; remove in-kernel call to syscall

Using the net-internal helper __sys_recvfrom() allows us to avoid the
internal calls to the sys_recvfrom() syscall.

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: David S. Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
Dominik Brodowski 2018-03-13 19:10:06 +01:00
parent b51d3cdf44
commit 7a09e1eb9c
3 changed files with 21 additions and 9 deletions

View File

@ -353,4 +353,10 @@ extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen
unsigned int flags, struct timespec *timeout); unsigned int flags, struct timespec *timeout);
extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
unsigned int vlen, unsigned int flags); unsigned int vlen, unsigned int flags);
/* helpers which do the actual work for syscalls */
extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
unsigned int flags, struct sockaddr __user *addr,
int __user *addr_len);
#endif /* _LINUX_SOCKET_H */ #endif /* _LINUX_SOCKET_H */

View File

@ -760,7 +760,8 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len
unsigned int, flags, struct sockaddr __user *, addr, unsigned int, flags, struct sockaddr __user *, addr,
int __user *, addrlen) int __user *, addrlen)
{ {
return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, addrlen); return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr,
addrlen);
} }
COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,

View File

@ -1767,10 +1767,8 @@ SYSCALL_DEFINE4(send, int, fd, void __user *, buff, size_t, len,
* sender. We verify the buffers are writable and if needed move the * sender. We verify the buffers are writable and if needed move the
* sender address from kernel to user space. * sender address from kernel to user space.
*/ */
int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size, struct sockaddr __user *addr, int __user *addr_len)
unsigned int, flags, struct sockaddr __user *, addr,
int __user *, addr_len)
{ {
struct socket *sock; struct socket *sock;
struct iovec iov; struct iovec iov;
@ -1810,6 +1808,13 @@ out:
return err; return err;
} }
SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
unsigned int, flags, struct sockaddr __user *, addr,
int __user *, addr_len)
{
return __sys_recvfrom(fd, ubuf, size, flags, addr, addr_len);
}
/* /*
* Receive a datagram from a socket. * Receive a datagram from a socket.
*/ */
@ -1817,7 +1822,7 @@ out:
SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size, SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
unsigned int, flags) unsigned int, flags)
{ {
return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL); return __sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
} }
/* /*
@ -2486,9 +2491,9 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
err = sys_recv(a0, (void __user *)a1, a[2], a[3]); err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
break; break;
case SYS_RECVFROM: case SYS_RECVFROM:
err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3], err = __sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
(struct sockaddr __user *)a[4], (struct sockaddr __user *)a[4],
(int __user *)a[5]); (int __user *)a[5]);
break; break;
case SYS_SHUTDOWN: case SYS_SHUTDOWN:
err = sys_shutdown(a0, a1); err = sys_shutdown(a0, a1);