Skip to content

Commit 04190bf

Browse files
Snorchdavem330
authored andcommitted
sock: allow reading and changing sk_userlocks with setsockopt
SOCK_SNDBUF_LOCK and SOCK_RCVBUF_LOCK flags disable automatic socket buffers adjustment done by kernel (see tcp_fixup_rcvbuf() and tcp_sndbuf_expand()). If we've just created a new socket this adjustment is enabled on it, but if one changes the socket buffer size by setsockopt(SO_{SND,RCV}BUF*) it becomes disabled. CRIU needs to call setsockopt(SO_{SND,RCV}BUF*) on each socket on restore as it first needs to increase buffer sizes for packet queues restore and second it needs to restore back original buffer sizes. So after CRIU restore all sockets become non-auto-adjustable, which can decrease network performance of restored applications significantly. CRIU need to be able to restore sockets with enabled/disabled adjustment to the same state it was before dump, so let's add special setsockopt for it. Let's also export SOCK_SNDBUF_LOCK and SOCK_RCVBUF_LOCK flags to uAPI so that using these interface one can reenable automatic socket buffer adjustment on their sockets. Signed-off-by: Pavel Tikhomirov <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 625af9f commit 04190bf

File tree

8 files changed

+29
-2
lines changed

8 files changed

+29
-2
lines changed

arch/alpha/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129

130130
#define SO_NETNS_COOKIE 71
131131

132+
#define SO_BUF_LOCK 72
133+
132134
#if !defined(__KERNEL__)
133135

134136
#if __BITS_PER_LONG == 64

arch/mips/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@
140140

141141
#define SO_NETNS_COOKIE 71
142142

143+
#define SO_BUF_LOCK 72
144+
143145
#if !defined(__KERNEL__)
144146

145147
#if __BITS_PER_LONG == 64

arch/parisc/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121

122122
#define SO_NETNS_COOKIE 0x4045
123123

124+
#define SO_BUF_LOCK 0x4046
125+
124126
#if !defined(__KERNEL__)
125127

126128
#if __BITS_PER_LONG == 64

arch/sparc/include/uapi/asm/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122

123123
#define SO_NETNS_COOKIE 0x0050
124124

125+
#define SO_BUF_LOCK 0x0051
126+
125127
#if !defined(__KERNEL__)
126128

127129

include/net/sock.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include <net/tcp_states.h>
6969
#include <linux/net_tstamp.h>
7070
#include <net/l3mdev.h>
71+
#include <uapi/linux/socket.h>
7172

7273
/*
7374
* This structure really needs to be cleaned up.
@@ -1438,8 +1439,6 @@ static inline int __sk_prot_rehash(struct sock *sk)
14381439
#define RCV_SHUTDOWN 1
14391440
#define SEND_SHUTDOWN 2
14401441

1441-
#define SOCK_SNDBUF_LOCK 1
1442-
#define SOCK_RCVBUF_LOCK 2
14431442
#define SOCK_BINDADDR_LOCK 4
14441443
#define SOCK_BINDPORT_LOCK 8
14451444

include/uapi/asm-generic/socket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124

125125
#define SO_NETNS_COOKIE 71
126126

127+
#define SO_BUF_LOCK 72
128+
127129
#if !defined(__KERNEL__)
128130

129131
#if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))

include/uapi/linux/socket.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ struct __kernel_sockaddr_storage {
2626
};
2727
};
2828

29+
#define SOCK_SNDBUF_LOCK 1
30+
#define SOCK_RCVBUF_LOCK 2
31+
32+
#define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK)
33+
2934
#endif /* _UAPI_LINUX_SOCKET_H */

net/core/sock.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,15 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
13581358
ret = sock_bindtoindex_locked(sk, val);
13591359
break;
13601360

1361+
case SO_BUF_LOCK:
1362+
if (val & ~SOCK_BUF_LOCK_MASK) {
1363+
ret = -EINVAL;
1364+
break;
1365+
}
1366+
sk->sk_userlocks = val | (sk->sk_userlocks &
1367+
~SOCK_BUF_LOCK_MASK);
1368+
break;
1369+
13611370
default:
13621371
ret = -ENOPROTOOPT;
13631372
break;
@@ -1720,6 +1729,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
17201729
v.val64 = sock_net(sk)->net_cookie;
17211730
break;
17221731

1732+
case SO_BUF_LOCK:
1733+
v.val = sk->sk_userlocks & SOCK_BUF_LOCK_MASK;
1734+
break;
1735+
17231736
default:
17241737
/* We implement the SO_SNDLOWAT etc to not be settable
17251738
* (1003.1g 7).

0 commit comments

Comments
 (0)