Skip to content

Commit

Permalink
sock: add SOCK_ZEROCOPY sockopt
Browse files Browse the repository at this point in the history
The send call ignores unknown flags. Legacy applications may already
unwittingly pass MSG_ZEROCOPY. Continue to ignore this flag unless a
socket opts in to zerocopy.

Introduce socket option SO_ZEROCOPY to enable MSG_ZEROCOPY processing.
Processes can also query this socket option to detect kernel support
for the feature. Older kernels will return ENOPROTOOPT.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Willem de Bruijn authored and David S. Miller committed Aug 4, 2017
1 parent 5226779 commit 76851d1
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/alpha/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/frv/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _ASM_SOCKET_H */

2 changes: 2 additions & 0 deletions arch/ia64/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _ASM_IA64_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/m32r/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _ASM_M32R_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mips/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mn10300/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/parisc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@

#define SO_PEERGROUPS 0x4034

#define SO_ZEROCOPY 0x4035

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/s390/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/sparc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

#define SO_PEERGROUPS 0x003d

#define SO_ZEROCOPY 0x003e

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION 0x5001
#define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* _XTENSA_SOCKET_H */
2 changes: 2 additions & 0 deletions include/uapi/asm-generic/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@

#define SO_PEERGROUPS 59

#define SO_ZEROCOPY 60

#endif /* __ASM_GENERIC_SOCKET_H */
3 changes: 3 additions & 0 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ struct ubuf_info *sock_zerocopy_alloc(struct sock *sk, size_t size)

WARN_ON_ONCE(!in_task());

if (!sock_flag(sk, SOCK_ZEROCOPY))
return NULL;

skb = sock_omalloc(sk, 0, GFP_KERNEL);
if (!skb)
return NULL;
Expand Down
18 changes: 18 additions & 0 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,20 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
if (val == 1)
dst_negative_advice(sk);
break;

case SO_ZEROCOPY:
if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
ret = -ENOTSUPP;
else if (sk->sk_protocol != IPPROTO_TCP)
ret = -ENOTSUPP;
else if (sk->sk_state != TCP_CLOSE)
ret = -EBUSY;
else if (val < 0 || val > 1)
ret = -EINVAL;
else
sock_valbool_flag(sk, SOCK_ZEROCOPY, valbool);
break;

default:
ret = -ENOPROTOOPT;
break;
Expand Down Expand Up @@ -1383,6 +1397,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val64 = sock_gen_cookie(sk);
break;

case SO_ZEROCOPY:
v.val = sock_flag(sk, SOCK_ZEROCOPY);
break;

default:
/* We implement the SO_SNDLOWAT etc to not be settable
* (1003.1g 7).
Expand Down

0 comments on commit 76851d1

Please sign in to comment.