Branch data Line data Source code
1 : : // SPDX-License-Identifier: GPL-2.0
2 : : /* Multipath TCP
3 : : *
4 : : * Copyright (c) 2017 - 2019, Intel Corporation.
5 : : */
6 : :
7 : : #define pr_fmt(fmt) "MPTCP: " fmt
8 : :
9 : : #include <linux/kernel.h>
10 : : #include <linux/module.h>
11 : : #include <linux/netdevice.h>
12 : : #include <linux/sched/signal.h>
13 : : #include <linux/atomic.h>
14 : : #include <net/aligned_data.h>
15 : : #include <net/rps.h>
16 : : #include <net/sock.h>
17 : : #include <net/inet_common.h>
18 : : #include <net/inet_hashtables.h>
19 : : #include <net/protocol.h>
20 : : #include <net/tcp_states.h>
21 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
22 : : #include <net/transp_v6.h>
23 : : #endif
24 : : #include <net/mptcp.h>
25 : : #include <net/hotdata.h>
26 : : #include <net/xfrm.h>
27 : : #include <asm/ioctls.h>
28 : : #include "protocol.h"
29 : : #include "mib.h"
30 : :
31 : : static unsigned int mptcp_inq_hint(const struct sock *sk);
32 : :
33 : : #define CREATE_TRACE_POINTS
34 : : #include <trace/events/mptcp.h>
35 : :
36 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
37 : : struct mptcp6_sock {
38 : : struct mptcp_sock msk;
39 : : struct ipv6_pinfo np;
40 : : };
41 : : #endif
42 : :
43 : : enum {
44 : : MPTCP_CMSG_TS = BIT(0),
45 : : MPTCP_CMSG_INQ = BIT(1),
46 : : };
47 : :
48 : : static struct percpu_counter mptcp_sockets_allocated ____cacheline_aligned_in_smp;
49 : :
50 : : static void __mptcp_destroy_sock(struct sock *sk);
51 : : static void mptcp_check_send_data_fin(struct sock *sk);
52 : :
53 : : DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions) = {
54 : : .bh_lock = INIT_LOCAL_LOCK(bh_lock),
55 : : };
56 : : static struct net_device *mptcp_napi_dev;
57 : :
58 : : /* Returns end sequence number of the receiver's advertised window */
59 : 24 : static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
60 : : {
61 : 1853008 : return READ_ONCE(msk->wnd_end);
62 : : }
63 : :
64 : 178 : static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
65 : : {
66 : 178 : unsigned short family = READ_ONCE(sk->sk_family);
67 : :
68 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
69 [ + + ]: 178 : if (family == AF_INET6)
70 : : return &inet6_stream_ops;
71 : : #endif
72 [ - + ]: 88 : WARN_ON_ONCE(family != AF_INET);
73 : : return &inet_stream_ops;
74 : : }
75 : :
76 : 214 : bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
77 : : {
78 : 214 : struct net *net = sock_net((struct sock *)msk);
79 : :
80 [ - + ]: 214 : if (__mptcp_check_fallback(msk))
81 : : return true;
82 : :
83 : : /* The caller possibly is not holding the msk socket lock, but
84 : : * in the fallback case only the current subflow is touching
85 : : * the OoO queue.
86 : : */
87 [ - + ]: 214 : if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
88 : : return false;
89 : :
90 : 214 : spin_lock_bh(&msk->fallback_lock);
91 [ - + + + ]: 214 : if (!msk->allow_infinite_fallback) {
[ + + ]
92 : 12 : spin_unlock_bh(&msk->fallback_lock);
93 : 12 : return false;
94 : : }
95 : :
96 : 202 : msk->allow_subflows = false;
97 : 202 : set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
98 [ + - ]: 202 : __MPTCP_INC_STATS(net, fb_mib);
99 : 202 : spin_unlock_bh(&msk->fallback_lock);
100 : 202 : return true;
101 : : }
102 : :
103 : 3438 : static int __mptcp_socket_create(struct mptcp_sock *msk)
104 : : {
105 : 3438 : struct mptcp_subflow_context *subflow;
106 : 3438 : struct sock *sk = (struct sock *)msk;
107 : 3438 : struct socket *ssock;
108 : 3438 : int err;
109 : :
110 : 3438 : err = mptcp_subflow_create_socket(sk, sk->sk_family, &ssock);
111 [ + - ]: 3438 : if (err)
112 : : return err;
113 : :
114 [ - + ]: 3438 : msk->scaling_ratio = tcp_sk(ssock->sk)->scaling_ratio;
115 : 3438 : WRITE_ONCE(msk->first, ssock->sk);
116 : 3438 : subflow = mptcp_subflow_ctx(ssock->sk);
117 : 3438 : list_add(&subflow->node, &msk->conn_list);
118 : 3438 : sock_hold(ssock->sk);
119 : 3438 : subflow->request_mptcp = 1;
120 : 3438 : subflow->subflow_id = msk->subflow_id++;
121 : :
122 : : /* This is the first subflow, always with id 0 */
123 : 3438 : WRITE_ONCE(subflow->local_id, 0);
124 : 3438 : mptcp_sock_graft(msk->first, sk->sk_socket);
125 : 3438 : iput(SOCK_INODE(ssock));
126 : :
127 : 3438 : return 0;
128 : : }
129 : :
130 : : /* If the MPC handshake is not started, returns the first subflow,
131 : : * eventually allocating it.
132 : : */
133 : 10054 : struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk)
134 : : {
135 : 10054 : struct sock *sk = (struct sock *)msk;
136 : 10054 : int ret;
137 : :
138 [ - + + + ]: 10054 : if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
[ + + ]
139 : : return ERR_PTR(-EINVAL);
140 : :
141 [ + + ]: 10036 : if (!msk->first) {
142 : 3438 : ret = __mptcp_socket_create(msk);
143 [ - + ]: 3438 : if (ret)
144 : 0 : return ERR_PTR(ret);
145 : : }
146 : :
147 : 10036 : return msk->first;
148 : : }
149 : :
150 : 642 : static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
151 : : {
152 : : /* The skb forward memory was already transferred to sk by
153 : : * mptcp_borrow_fwdmem(), even before setting the destructor.
154 : : */
155 [ + + ]: 642 : if (!skb->destructor)
156 : 500 : sk_mem_reclaim(sk);
157 : :
158 : 642 : sk_drops_skbadd(sk, skb);
159 : 642 : __kfree_skb(skb);
160 : 642 : }
161 : :
162 : 608490 : static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
163 : : struct sk_buff *from, bool *fragstolen,
164 : : int *delta)
165 : : {
166 : 608490 : int limit = READ_ONCE(sk->sk_rcvbuf);
167 : :
168 [ + + ]: 608490 : if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
169 [ + + ]: 608465 : MPTCP_SKB_CB(from)->offset ||
170 [ + + + + ]: 1166270 : ((to->len + from->len) > (limit >> 3)) ||
171 : 557817 : !skb_try_coalesce(to, from, fragstolen, delta))
172 : 182316 : return false;
173 : :
174 [ - + - - ]: 426174 : pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
175 : : MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
176 : : to->len, MPTCP_SKB_CB(from)->end_seq);
177 : 426174 : MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
178 : 426174 : return true;
179 : : }
180 : :
181 : 535985 : static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
182 : : struct sk_buff *from)
183 : : {
184 : 535985 : bool fragstolen;
185 : 535985 : int delta;
186 : :
187 [ + + ]: 535985 : if (!__mptcp_try_coalesce(sk, to, from, &fragstolen, &delta))
188 : : return false;
189 : :
190 : : /* note the fwd memory can reach a negative value after accounting
191 : : * for the delta, but the later skb free will restore a non
192 : : * negative one
193 : : */
194 : 385467 : atomic_add(delta, &sk->sk_rmem_alloc);
195 [ + - ]: 385467 : sk_mem_charge(sk, delta);
196 [ - + ]: 385467 : kfree_skb_partial(from, fragstolen);
197 : :
198 : 385467 : return true;
199 : : }
200 : :
201 : 0 : static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
202 : : struct sk_buff *from)
203 : : {
204 [ + + ]: 39022 : if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq)
205 : : return false;
206 : :
207 : 218731 : return mptcp_try_coalesce((struct sock *)msk, to, from);
208 : : }
209 : :
210 : : /* "inspired" by tcp_rcvbuf_grow(), main difference:
211 : : * - mptcp does not maintain a msk-level window clamp
212 : : * - returns true when the receive buffer is actually updated
213 : : */
214 : 5589 : static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
215 : : {
216 [ - + ]: 5589 : struct mptcp_sock *msk = mptcp_sk(sk);
217 [ + - ]: 5589 : const struct net *net = sock_net(sk);
218 : 5589 : u32 rcvwin, rcvbuf, cap, oldval;
219 : 5589 : u64 grow;
220 : :
221 : 5589 : oldval = msk->rcvq_space.space;
222 : 5589 : msk->rcvq_space.space = newval;
223 [ + - ]: 5589 : if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
224 [ - + ]: 5589 : (sk->sk_userlocks & SOCK_RCVBUF_LOCK))
225 : : return false;
226 : :
227 : : /* DRS is always one RTT late. */
228 : 5589 : rcvwin = newval << 1;
229 : :
230 : : /* slow start: allow the sender to double its rate. */
231 : 5589 : grow = (u64)rcvwin * (newval - oldval);
232 : 5589 : do_div(grow, oldval);
233 : 5589 : rcvwin += grow << 1;
234 : :
235 : 5589 : cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]);
236 : :
237 : 5589 : rcvbuf = min_t(u32, mptcp_space_from_win(sk, rcvwin), cap);
238 [ + + ]: 5589 : if (rcvbuf > sk->sk_rcvbuf) {
239 : 2998 : WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
240 : 2998 : return true;
241 : : }
242 : : return false;
243 : : }
244 : :
245 : : /* "inspired" by tcp_data_queue_ofo(), main differences:
246 : : * - use mptcp seqs
247 : : * - don't cope with sacks
248 : : */
249 : 194846 : static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
250 : : {
251 : 194846 : struct sock *sk = (struct sock *)msk;
252 : 194846 : struct rb_node **p, *parent;
253 : 194846 : u64 seq, end_seq, max_seq;
254 : 194846 : struct sk_buff *skb1;
255 : :
256 : 194846 : seq = MPTCP_SKB_CB(skb)->map_seq;
257 : 194846 : end_seq = MPTCP_SKB_CB(skb)->end_seq;
258 [ - + ]: 194846 : max_seq = atomic64_read(&msk->rcv_wnd_sent);
259 : :
260 [ - + - - ]: 194846 : pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
261 : : RB_EMPTY_ROOT(&msk->out_of_order_queue));
262 [ + + ]: 194846 : if (after64(end_seq, max_seq)) {
263 : : /* out of window */
264 : 45 : mptcp_drop(sk, skb);
265 [ - + - - ]: 45 : pr_debug("oow by %lld, rcv_wnd_sent %llu\n",
266 : : (unsigned long long)end_seq - (unsigned long)max_seq,
267 : : (unsigned long long)atomic64_read(&msk->rcv_wnd_sent));
268 [ + - ]: 45 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_NODSSWINDOW);
269 : 45 : return;
270 : : }
271 : :
272 : 194801 : p = &msk->out_of_order_queue.rb_node;
273 [ + - ]: 194801 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
274 [ + + ]: 194801 : if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
275 : 5600 : rb_link_node(&skb->rbnode, NULL, p);
276 : 5600 : rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
277 : 5600 : msk->ooo_last_skb = skb;
278 : 5600 : goto end;
279 : : }
280 : :
281 : : /* with 2 subflows, adding at end of ooo queue is quite likely
282 : : * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
283 : : */
284 [ + + + + ]: 350520 : if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb)) {
285 [ + - ]: 142132 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
286 [ + - ]: 142132 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
287 : 142132 : return;
288 : : }
289 : :
290 : : /* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
291 [ + + ]: 47069 : if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
292 [ + - ]: 25725 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
293 : 25725 : parent = &msk->ooo_last_skb->rbnode;
294 : 25725 : p = &parent->rb_right;
295 : 25725 : goto insert;
296 : : }
297 : :
298 : : /* Find place to insert this segment. Handle overlaps on the way. */
299 : : parent = NULL;
300 [ + + ]: 115508 : while (*p) {
301 : 107694 : parent = *p;
302 : 107694 : skb1 = rb_to_skb(parent);
303 [ + + ]: 107694 : if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
304 : 32822 : p = &parent->rb_left;
305 : 32822 : continue;
306 : : }
307 [ + + ]: 74872 : if (before64(seq, MPTCP_SKB_CB(skb1)->end_seq)) {
308 [ + + ]: 525 : if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
309 : : /* All the bits are present. Drop. */
310 : 443 : mptcp_drop(sk, skb);
311 [ + - ]: 443 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
312 : 443 : return;
313 : : }
314 [ + + ]: 82 : if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
315 : : /* partial overlap:
316 : : * | skb |
317 : : * | skb1 |
318 : : * continue traversing
319 : : */
320 : : } else {
321 : : /* skb's seq == skb1's seq and skb covers skb1.
322 : : * Replace skb1 with skb.
323 : : */
324 : 25 : rb_replace_node(&skb1->rbnode, &skb->rbnode,
325 : : &msk->out_of_order_queue);
326 : 25 : mptcp_drop(sk, skb1);
327 [ + - ]: 25 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
328 : 25 : goto merge_right;
329 : : }
330 [ + + + + ]: 93110 : } else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
331 [ + - ]: 13062 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
332 : 13062 : return;
333 : : }
334 : 61342 : p = &parent->rb_right;
335 : : }
336 : :
337 : 7814 : insert:
338 : : /* Insert segment into RB tree. */
339 : 33539 : rb_link_node(&skb->rbnode, parent, p);
340 : 33539 : rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
341 : :
342 : : merge_right:
343 : : /* Remove other segments covered by skb. */
344 [ + + ]: 33590 : while ((skb1 = skb_rb_next(skb)) != NULL) {
345 [ + + ]: 7865 : if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq))
346 : : break;
347 : 26 : rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
348 : 26 : mptcp_drop(sk, skb1);
349 [ + - ]: 26 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
350 : : }
351 : : /* If there is no skb after us, we are the last_skb ! */
352 [ + + ]: 33564 : if (!skb1)
353 : 25725 : msk->ooo_last_skb = skb;
354 : :
355 : 7839 : end:
356 : 39164 : skb_condense(skb);
357 : 39164 : skb_set_owner_r(skb, sk);
358 : : }
359 : :
360 : 1190713 : static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
361 : : int copy_len)
362 : : {
363 : 1190713 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
364 : 1190713 : bool has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
365 : :
366 : : /* the skb map_seq accounts for the skb offset:
367 : : * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
368 : : * value
369 : : */
370 : 1190713 : MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
371 : 1190713 : MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
372 : 1190713 : MPTCP_SKB_CB(skb)->offset = offset;
373 : 1190713 : MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
374 : 1190713 : MPTCP_SKB_CB(skb)->cant_coalesce = 0;
375 : :
376 : 1190713 : __skb_unlink(skb, &ssk->sk_receive_queue);
377 : :
378 : 1190713 : skb_ext_reset(skb);
379 [ - + ]: 1190713 : skb_dst_drop(skb);
380 : 1190713 : }
381 : :
382 : 1150004 : static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
383 : : {
384 : 1150004 : u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
385 [ - + ]: 1150004 : struct mptcp_sock *msk = mptcp_sk(sk);
386 : 1150004 : struct sk_buff *tail;
387 : :
388 : 1150004 : mptcp_borrow_fwdmem(sk, skb);
389 : :
390 [ + + ]: 1150004 : if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
391 : : /* in sequence */
392 : 955146 : msk->bytes_received += copy_len;
393 : 955146 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
394 [ + + ]: 955146 : tail = skb_peek_tail(&sk->sk_receive_queue);
395 [ + - + + ]: 317254 : if (tail && mptcp_try_coalesce(sk, tail, skb))
396 : : return true;
397 : :
398 : 742306 : skb_set_owner_r(skb, sk);
399 : 742306 : __skb_queue_tail(&sk->sk_receive_queue, skb);
400 : 742306 : return true;
401 [ + + ]: 194858 : } else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) {
402 : 194846 : mptcp_data_queue_ofo(msk, skb);
403 : 194846 : return false;
404 : : }
405 : :
406 : : /* Completely old data? */
407 [ + - ]: 12 : if (!after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) {
408 [ + - ]: 12 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
409 : 12 : mptcp_drop(sk, skb);
410 : 12 : return false;
411 : : }
412 : :
413 : : /* Partial packet: map_seq < ack_seq < end_seq.
414 : : * Skip the already-acked bytes and enqueue the new data.
415 : : */
416 : 0 : copy_len = MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq;
417 : 0 : MPTCP_SKB_CB(skb)->offset += msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
418 : 0 : MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
419 : : MPTCP_SKB_CB(skb)->map_seq;
420 : 0 : msk->bytes_received += copy_len;
421 : 0 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
422 : :
423 : 0 : skb_set_owner_r(skb, sk);
424 : 0 : __skb_queue_tail(&sk->sk_receive_queue, skb);
425 : 0 : return true;
426 : : }
427 : :
428 : 63700 : static void mptcp_stop_rtx_timer(struct sock *sk)
429 : : {
430 : 63700 : sk_stop_timer(sk, &sk->mptcp_retransmit_timer);
431 [ - + ]: 63700 : mptcp_sk(sk)->timer_ival = 0;
432 : 63700 : }
433 : :
434 : 6636 : static void mptcp_close_wake_up(struct sock *sk)
435 : : {
436 [ + + ]: 6636 : if (sock_flag(sk, SOCK_DEAD))
437 : : return;
438 : :
439 : 4382 : sk->sk_state_change(sk);
440 [ + + ]: 4382 : if (sk->sk_shutdown == SHUTDOWN_MASK ||
441 [ + + ]: 2139 : sk->sk_state == TCP_CLOSE)
442 : 2299 : sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
443 : : else
444 : 2083 : sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
445 : : }
446 : :
447 : 2325 : static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
448 : : {
449 : 2325 : struct mptcp_subflow_context *subflow;
450 : :
451 [ + + ]: 5488 : mptcp_for_each_subflow(msk, subflow) {
452 : 3163 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
453 : 3163 : bool slow;
454 : :
455 : 3163 : slow = lock_sock_fast(ssk);
456 : 3163 : tcp_shutdown(ssk, SEND_SHUTDOWN);
457 : 3163 : unlock_sock_fast(ssk, slow);
458 : : }
459 : 2325 : }
460 : :
461 : : /* called under the msk socket lock */
462 : 455222 : static bool mptcp_pending_data_fin_ack(struct sock *sk)
463 : : {
464 [ - + ]: 455222 : struct mptcp_sock *msk = mptcp_sk(sk);
465 : :
466 : 223535 : return ((1 << sk->sk_state) &
467 [ - + + + ]: 455222 : (TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK)) &&
[ + + ]
468 [ + + ]: 80887 : msk->write_seq == READ_ONCE(msk->snd_una);
469 : : }
470 : :
471 : 12514 : static void mptcp_check_data_fin_ack(struct sock *sk)
472 : : {
473 [ - + ]: 12514 : struct mptcp_sock *msk = mptcp_sk(sk);
474 : :
475 : : /* Look for an acknowledged DATA_FIN */
476 [ + + ]: 12514 : if (mptcp_pending_data_fin_ack(sk)) {
477 : 2484 : WRITE_ONCE(msk->snd_data_fin_enable, 0);
478 : :
479 [ + + - ]: 2484 : switch (sk->sk_state) {
480 : 1314 : case TCP_FIN_WAIT1:
481 : 1314 : mptcp_set_state(sk, TCP_FIN_WAIT2);
482 : 1314 : break;
483 : 1170 : case TCP_CLOSING:
484 : : case TCP_LAST_ACK:
485 : 1170 : mptcp_shutdown_subflows(msk);
486 : 1170 : mptcp_set_state(sk, TCP_CLOSE);
487 : 1170 : break;
488 : : }
489 : :
490 : 2484 : mptcp_close_wake_up(sk);
491 : : }
492 : 12514 : }
493 : :
494 : : /* can be called with no lock acquired */
495 : 1073634 : static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
496 : : {
497 [ - + ]: 1073634 : struct mptcp_sock *msk = mptcp_sk(sk);
498 : :
499 [ - + + + : 1101561 : if (READ_ONCE(msk->rcv_data_fin) &&
- + + + ]
[ - + + +
- + ][ + + ]
[ + + + + ]
500 [ - + ]: 26 : ((1 << inet_sk_state_load(sk)) &
501 : : (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
502 : 27096 : u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
503 : :
504 [ + + ]: 27096 : if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
505 [ + + ]: 3056 : if (seq)
506 : 2466 : *seq = rcv_data_fin_seq;
507 : :
508 : 3056 : return true;
509 : : }
510 : : }
511 : :
512 : : return false;
513 : : }
514 : :
515 : 1345 : static void mptcp_set_datafin_timeout(struct sock *sk)
516 : : {
517 : 1345 : struct inet_connection_sock *icsk = inet_csk(sk);
518 : 1345 : u32 retransmits;
519 : :
520 : 1345 : retransmits = min_t(u32, icsk->icsk_retransmits,
521 : : ilog2(TCP_RTO_MAX / TCP_RTO_MIN));
522 : :
523 [ - + ]: 1345 : mptcp_sk(sk)->timer_ival = TCP_RTO_MIN << retransmits;
524 : 1345 : }
525 : :
526 : 1194931 : static void __mptcp_set_timeout(struct sock *sk, long tout)
527 : : {
528 [ + + - + ]: 2002086 : mptcp_sk(sk)->timer_ival = tout > 0 ? tout : TCP_RTO_MIN;
529 : 1194931 : }
530 : :
531 : 24 : static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subflow)
532 : : {
533 : 1640888 : const struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
534 : :
535 [ + + + + ]: 1319421 : return inet_csk(ssk)->icsk_pending && !subflow->stale_count ?
536 [ + + + + ]: 2733640 : tcp_timeout_expires(ssk) - jiffies : 0;
537 : : }
538 : :
539 : 411360 : static void mptcp_set_timeout(struct sock *sk)
540 : : {
541 : 411360 : struct mptcp_subflow_context *subflow;
542 : 411360 : long tout = 0;
543 : :
544 [ - + - + : 908861 : mptcp_for_each_subflow(mptcp_sk(sk), subflow)
+ + ]
545 [ + + ]: 859549 : tout = max(tout, mptcp_timeout_from_subflow(subflow));
546 : 411360 : __mptcp_set_timeout(sk, tout);
547 : 411360 : }
548 : :
549 : 376632 : static inline bool tcp_can_send_ack(const struct sock *ssk)
550 : : {
551 [ - + ]: 763028 : return !((1 << inet_sk_state_load(ssk)) &
552 : : (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_TIME_WAIT | TCPF_CLOSE | TCPF_LISTEN));
553 : : }
554 : :
555 : 6189 : void __mptcp_subflow_send_ack(struct sock *ssk)
556 : : {
557 [ + + ]: 6189 : if (tcp_can_send_ack(ssk))
558 : 6018 : tcp_send_ack(ssk);
559 : 6189 : }
560 : :
561 : 5151 : static void mptcp_subflow_send_ack(struct sock *ssk)
562 : : {
563 : 5151 : bool slow;
564 : :
565 : 5151 : slow = lock_sock_fast(ssk);
566 : 5151 : __mptcp_subflow_send_ack(ssk);
567 : 5151 : unlock_sock_fast(ssk, slow);
568 : 5151 : }
569 : :
570 : 3658 : static void mptcp_send_ack(struct mptcp_sock *msk)
571 : : {
572 : 3658 : struct mptcp_subflow_context *subflow;
573 : :
574 [ + + ]: 8809 : mptcp_for_each_subflow(msk, subflow)
575 : 5151 : mptcp_subflow_send_ack(mptcp_subflow_tcp_sock(subflow));
576 : 3658 : }
577 : :
578 : 563661 : static void mptcp_subflow_cleanup_rbuf(struct sock *ssk, int copied)
579 : : {
580 : 563661 : bool slow;
581 : :
582 : 563661 : slow = lock_sock_fast(ssk);
583 [ + + ]: 563661 : if (tcp_can_send_ack(ssk))
584 : 561947 : tcp_cleanup_rbuf(ssk, copied);
585 : 563661 : unlock_sock_fast(ssk, slow);
586 : 563661 : }
587 : :
588 : 1530635 : static bool mptcp_subflow_could_cleanup(const struct sock *ssk, bool rx_empty)
589 : : {
590 : 1530635 : const struct inet_connection_sock *icsk = inet_csk(ssk);
591 : 1530635 : u8 ack_pending = READ_ONCE(icsk->icsk_ack.pending);
592 [ - + ]: 1530635 : const struct tcp_sock *tp = tcp_sk(ssk);
593 : :
594 [ + + ]: 1530635 : return (ack_pending & ICSK_ACK_SCHED) &&
595 : 728938 : ((READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->rcv_wup) >
596 [ + + + + ]: 728938 : READ_ONCE(icsk->icsk_ack.rcv_mss)) ||
597 [ + + ]: 195425 : (rx_empty && ack_pending &
598 : : (ICSK_ACK_PUSHED2 | ICSK_ACK_PUSHED)));
599 : : }
600 : :
601 : 1396449 : static void mptcp_cleanup_rbuf(struct mptcp_sock *msk, int copied)
602 : : {
603 : 1396449 : int old_space = READ_ONCE(msk->old_wspace);
604 : 1396449 : struct mptcp_subflow_context *subflow;
605 : 1396449 : struct sock *sk = (struct sock *)msk;
606 : 1396449 : int space = __mptcp_space(sk);
607 : 1396449 : bool cleanup, rx_empty;
608 : :
609 [ + + + + : 1396449 : cleanup = (space > 0) && (space >= (old_space << 1)) && copied;
+ + ]
610 [ + + + + ]: 1396449 : rx_empty = !sk_rmem_alloc_get(sk) && copied;
611 : :
612 [ + + ]: 3161180 : mptcp_for_each_subflow(msk, subflow) {
613 [ + + ]: 1764731 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
614 : :
615 [ + + + + ]: 1764731 : if (cleanup || mptcp_subflow_could_cleanup(ssk, rx_empty))
616 : 563661 : mptcp_subflow_cleanup_rbuf(ssk, copied);
617 : : }
618 : 1396449 : }
619 : :
620 : 175881 : static void mptcp_check_data_fin(struct sock *sk)
621 : : {
622 [ - + ]: 175881 : struct mptcp_sock *msk = mptcp_sk(sk);
623 : 175881 : u64 rcv_data_fin_seq;
624 : :
625 : : /* Need to ack a DATA_FIN received from a peer while this side
626 : : * of the connection is in ESTABLISHED, FIN_WAIT1, or FIN_WAIT2.
627 : : * msk->rcv_data_fin was set when parsing the incoming options
628 : : * at the subflow level and the msk lock was not held, so this
629 : : * is the first opportunity to act on the DATA_FIN and change
630 : : * the msk state.
631 : : *
632 : : * If we are caught up to the sequence number of the incoming
633 : : * DATA_FIN, send the DATA_ACK now and do state transition. If
634 : : * not caught up, do nothing and let the recv code send DATA_ACK
635 : : * when catching up.
636 : : */
637 : :
638 [ + + ]: 175881 : if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
639 : 2466 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
640 : 2466 : WRITE_ONCE(msk->rcv_data_fin, 0);
641 : :
642 : 2466 : WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
643 : 2466 : smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
644 : :
645 [ + + + - ]: 2466 : switch (sk->sk_state) {
646 : : case TCP_ESTABLISHED:
647 : 1006 : mptcp_set_state(sk, TCP_CLOSE_WAIT);
648 : 1006 : break;
649 : 305 : case TCP_FIN_WAIT1:
650 : 305 : mptcp_set_state(sk, TCP_CLOSING);
651 : 305 : break;
652 : 1155 : case TCP_FIN_WAIT2:
653 : 1155 : mptcp_shutdown_subflows(msk);
654 : 1155 : mptcp_set_state(sk, TCP_CLOSE);
655 : 1155 : break;
656 : : default:
657 : : /* Other states not expected */
658 : 0 : WARN_ON_ONCE(1);
659 : 0 : break;
660 : : }
661 : :
662 [ + + ]: 2466 : if (!__mptcp_check_fallback(msk))
663 : 2313 : mptcp_send_ack(msk);
664 : 2466 : mptcp_close_wake_up(sk);
665 : : }
666 : 175881 : }
667 : :
668 : 0 : static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk)
669 : : {
670 [ # # ]: 0 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
671 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
672 : 0 : mptcp_subflow_reset(ssk);
673 : : }
674 : 0 : }
675 : :
676 : 240891 : static void __mptcp_add_backlog(struct sock *sk,
677 : : struct mptcp_subflow_context *subflow,
678 : : struct sk_buff *skb)
679 : : {
680 [ - + ]: 240891 : struct mptcp_sock *msk = mptcp_sk(sk);
681 : 240891 : struct sk_buff *tail = NULL;
682 : 240891 : struct sock *ssk = skb->sk;
683 : 240891 : bool fragstolen;
684 : 240891 : int delta;
685 : :
686 [ + + ]: 240891 : if (unlikely(sk->sk_state == TCP_CLOSE)) {
687 : 2 : kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
688 : 2 : return;
689 : : }
690 : :
691 : : /* Try to coalesce with the last skb in our backlog */
692 [ + + ]: 240889 : if (!list_empty(&msk->backlog_list))
693 : 74145 : tail = list_last_entry(&msk->backlog_list, struct sk_buff, list);
694 : :
695 [ + - + + ]: 74145 : if (tail && MPTCP_SKB_CB(skb)->map_seq == MPTCP_SKB_CB(tail)->end_seq &&
696 [ + + + + ]: 145018 : ssk == tail->sk &&
697 : 72505 : __mptcp_try_coalesce(sk, tail, skb, &fragstolen, &delta)) {
698 : 40707 : skb->truesize -= delta;
699 [ - + ]: 40707 : kfree_skb_partial(skb, fragstolen);
700 : 40707 : __mptcp_subflow_lend_fwdmem(subflow, delta);
701 : 40707 : goto account;
702 : : }
703 : :
704 : 200182 : list_add_tail(&skb->list, &msk->backlog_list);
705 : 200182 : mptcp_subflow_lend_fwdmem(subflow, skb);
706 : 200182 : delta = skb->truesize;
707 : :
708 : 240889 : account:
709 : 240889 : WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
710 : :
711 : : /* Possibly not accept()ed yet, keep track of memory not CG
712 : : * accounted, mptcp_graft_subflows() will handle it.
713 : : */
714 [ + - ]: 240889 : if (!mem_cgroup_from_sk(ssk))
715 : 240889 : msk->backlog_unaccounted += delta;
716 : : }
717 : :
718 : 1123745 : static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
719 : : struct sock *ssk, bool own_msk)
720 : : {
721 [ - + ]: 1123745 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
722 : 1123745 : struct sock *sk = (struct sock *)msk;
723 : 1123745 : bool more_data_avail;
724 : 1123745 : struct tcp_sock *tp;
725 : 1123745 : bool ret = false;
726 : :
727 [ - + - - ]: 1123745 : pr_debug("msk=%p ssk=%p\n", msk, ssk);
728 [ - + ]: 1123745 : tp = tcp_sk(ssk);
729 : 1190756 : do {
730 : 1190756 : u32 map_remaining, offset;
731 : 1190756 : u32 seq = tp->copied_seq;
732 : 1190756 : struct sk_buff *skb;
733 : 1190756 : bool fin;
734 : :
735 : : /* try to move as much data as available */
736 : 2381512 : map_remaining = subflow->map_data_len -
737 : 1190756 : mptcp_subflow_get_map_offset(subflow);
738 : :
739 [ + - ]: 1190756 : skb = skb_peek(&ssk->sk_receive_queue);
740 [ + - ]: 1190756 : if (unlikely(!skb))
741 : : break;
742 : :
743 [ + + ]: 1190756 : if (__mptcp_check_fallback(msk)) {
744 : : /* Under fallback skbs have no MPTCP extension and TCP could
745 : : * collapse them between the dummy map creation and the
746 : : * current dequeue. Be sure to adjust the map size.
747 : : */
748 : 17548 : map_remaining = skb->len;
749 : 17548 : subflow->map_data_len = skb->len;
750 : : }
751 : :
752 : 1190756 : offset = seq - TCP_SKB_CB(skb)->seq;
753 : 1190756 : fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
754 [ + + ]: 1190756 : if (fin)
755 : 154 : seq++;
756 : :
757 [ + + ]: 1190756 : if (offset < skb->len) {
758 : 1190713 : size_t len = skb->len - offset;
759 : :
760 : 1190713 : mptcp_init_skb(ssk, skb, offset, len);
761 : :
762 [ + + + + ]: 1756779 : if (own_msk && sk_rmem_alloc_get(sk) < sk->sk_rcvbuf) {
763 : 949822 : mptcp_subflow_lend_fwdmem(subflow, skb);
764 : 949822 : ret |= __mptcp_move_skb(sk, skb);
765 : : } else {
766 : 240891 : __mptcp_add_backlog(sk, subflow, skb);
767 : : }
768 : 1190713 : seq += len;
769 : :
770 [ - + ]: 1190713 : if (unlikely(map_remaining < len)) {
771 : 0 : DEBUG_NET_WARN_ON_ONCE(1);
772 : 0 : mptcp_dss_corruption(msk, ssk);
773 : : }
774 : : } else {
775 [ - + ]: 43 : if (unlikely(!fin)) {
776 : 0 : DEBUG_NET_WARN_ON_ONCE(1);
777 : 0 : mptcp_dss_corruption(msk, ssk);
778 : : }
779 : :
780 : 43 : sk_eat_skb(ssk, skb);
781 : : }
782 : :
783 : 1190756 : WRITE_ONCE(tp->copied_seq, seq);
784 : 1190756 : more_data_avail = mptcp_subflow_data_available(ssk);
785 : :
786 [ + + ]: 1190756 : } while (more_data_avail);
787 : :
788 [ + + ]: 1123745 : if (ret)
789 : 712024 : msk->last_data_recv = tcp_jiffies32;
790 : 1123745 : return ret;
791 : : }
792 : :
793 : 1064578 : static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
794 : : {
795 : 1064578 : struct sock *sk = (struct sock *)msk;
796 : 1064578 : struct sk_buff *skb, *tail;
797 : 1064578 : bool moved = false;
798 : 1064578 : struct rb_node *p;
799 : 1064578 : u64 end_seq;
800 : :
801 [ + + ]: 1064578 : p = rb_first(&msk->out_of_order_queue);
802 [ - + - - ]: 1064578 : pr_debug("msk=%p empty=%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
803 [ + + ]: 1103691 : while (p) {
804 : 342664 : skb = rb_to_skb(p);
805 [ + + ]: 342664 : if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
806 : : break;
807 : :
808 : 39113 : p = rb_next(p);
809 : 39113 : rb_erase(&skb->rbnode, &msk->out_of_order_queue);
810 : :
811 [ + + ]: 39113 : if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
812 : : msk->ack_seq))) {
813 : 91 : mptcp_drop(sk, skb);
814 [ + - ]: 91 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
815 : 91 : continue;
816 : : }
817 : :
818 : 39022 : end_seq = MPTCP_SKB_CB(skb)->end_seq;
819 [ + - ]: 39022 : tail = skb_peek_tail(&sk->sk_receive_queue);
820 [ + - + + ]: 77671 : if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {
821 : 21589 : int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
822 : :
823 : : /* skip overlapping data, if any */
824 [ - + - - ]: 21589 : pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d\n",
825 : : MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
826 : : delta);
827 : 21589 : MPTCP_SKB_CB(skb)->offset += delta;
828 : 21589 : MPTCP_SKB_CB(skb)->map_seq += delta;
829 : 21589 : __skb_queue_tail(&sk->sk_receive_queue, skb);
830 : : }
831 : 39022 : msk->bytes_received += end_seq - msk->ack_seq;
832 : 39022 : WRITE_ONCE(msk->ack_seq, end_seq);
833 : 39022 : moved = true;
834 : : }
835 : 1064578 : return moved;
836 : : }
837 : :
838 : 7507 : static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
839 : : {
840 : 7507 : int ssk_state;
841 : 7507 : int err;
842 : :
843 : : /* only propagate errors on fallen-back sockets or
844 : : * on MPC connect
845 : : */
846 [ + + - + : 7507 : if (sk->sk_state != TCP_SYN_SENT && !__mptcp_check_fallback(mptcp_sk(sk)))
+ + ]
847 : : return false;
848 : :
849 [ + + ]: 232 : err = sock_error(ssk);
850 [ + + ]: 149 : if (!err)
851 : 83 : return false;
852 : :
853 : : /* We need to propagate only transition to CLOSE state.
854 : : * Orphaned socket will see such state change via
855 : : * subflow_sched_work_if_closed() and that path will properly
856 : : * destroy the msk as needed.
857 : : */
858 : 45 : ssk_state = inet_sk_state_load(ssk);
859 [ + - + + ]: 45 : if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
860 : 26 : mptcp_set_state(sk, ssk_state);
861 : 45 : WRITE_ONCE(sk->sk_err, -err);
862 : :
863 : : /* This barrier is coupled with smp_rmb() in mptcp_poll() */
864 : 45 : smp_wmb();
865 : 45 : sk_error_report(sk);
866 : 45 : return true;
867 : : }
868 : :
869 : 1015 : void __mptcp_error_report(struct sock *sk)
870 : : {
871 : 1015 : struct mptcp_subflow_context *subflow;
872 [ - + ]: 1015 : struct mptcp_sock *msk = mptcp_sk(sk);
873 : :
874 [ + + ]: 2307 : mptcp_for_each_subflow(msk, subflow)
875 [ + + ]: 1318 : if (__mptcp_subflow_error_report(sk, mptcp_subflow_tcp_sock(subflow)))
876 : : break;
877 : 1015 : }
878 : :
879 : : /* In most cases we will be able to lock the mptcp socket. If its already
880 : : * owned, we need to defer to the work queue to avoid ABBA deadlock.
881 : : */
882 : 897753 : static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
883 : : {
884 : 897753 : struct sock *sk = (struct sock *)msk;
885 : 897753 : bool moved;
886 : :
887 : 897753 : moved = __mptcp_move_skbs_from_subflow(msk, ssk, true);
888 : 897753 : __mptcp_ofo_queue(msk);
889 [ - + ]: 897753 : if (unlikely(ssk->sk_err))
890 : 0 : __mptcp_subflow_error_report(sk, ssk);
891 : :
892 : : /* If the moves have caught up with the DATA_FIN sequence number
893 : : * it's time to ack the DATA_FIN and change socket state, but
894 : : * this is not a good place to change state. Let the workqueue
895 : : * do it.
896 : : */
897 [ + + ]: 897753 : if (mptcp_pending_data_fin(sk, NULL))
898 : 590 : mptcp_schedule_work(sk);
899 : 897753 : return moved;
900 : : }
901 : :
902 : 1123745 : static void mptcp_rcv_rtt_update(struct mptcp_sock *msk,
903 : : struct mptcp_subflow_context *subflow)
904 : : {
905 [ - + ]: 1123745 : const struct tcp_sock *tp = tcp_sk(subflow->tcp_sock);
906 : 1123745 : u32 rtt_us = tp->rcv_rtt_est.rtt_us;
907 : 1123745 : int id;
908 : :
909 : : /* Update once per subflow per rcvwnd to avoid touching the msk
910 : : * too often.
911 : : */
912 [ + + + + ]: 1123745 : if (!rtt_us || tp->rcv_rtt_est.seq == subflow->prev_rtt_seq)
913 : : return;
914 : :
915 : 27915 : subflow->prev_rtt_seq = tp->rcv_rtt_est.seq;
916 : :
917 : : /* Pairs with READ_ONCE() in mptcp_rtt_us_est(). */
918 : 27915 : id = msk->rcv_rtt_est.next_sample;
919 : 27915 : WRITE_ONCE(msk->rcv_rtt_est.samples[id], rtt_us);
920 [ + + ]: 27915 : if (++msk->rcv_rtt_est.next_sample == MPTCP_RTT_SAMPLES)
921 : 5082 : msk->rcv_rtt_est.next_sample = 0;
922 : :
923 : : /* EWMA among the incoming subflows */
924 : 27915 : msk->scaling_ratio = ((msk->scaling_ratio << 3) - msk->scaling_ratio +
925 : 27915 : tp->scaling_ratio) >> 3;
926 : : }
927 : :
928 : 1123745 : void mptcp_data_ready(struct sock *sk, struct sock *ssk)
929 : : {
930 [ - + ]: 1123745 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
931 [ - + ]: 1123745 : struct mptcp_sock *msk = mptcp_sk(sk);
932 : :
933 : : /* The peer can send data while we are shutting down this
934 : : * subflow at subflow destruction time, but we must avoid enqueuing
935 : : * more data to the msk receive queue
936 : : */
937 [ + - ]: 1123745 : if (unlikely(subflow->closing))
938 : : return;
939 : :
940 : 1123745 : mptcp_data_lock(sk);
941 : 1123745 : mptcp_rcv_rtt_update(msk, subflow);
942 [ + + ]: 1123745 : if (!sock_owned_by_user(sk)) {
943 : : /* Wake-up the reader only for in-sequence data */
944 [ + + + - ]: 897753 : if (move_skbs_to_msk(msk, ssk) && mptcp_epollin_ready(sk))
945 : 712024 : sk->sk_data_ready(sk);
946 : : } else {
947 : 225992 : __mptcp_move_skbs_from_subflow(msk, ssk, false);
948 : : }
949 : 1123745 : mptcp_data_unlock(sk);
950 : : }
951 : :
952 : 1200 : static void mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk)
953 : : {
954 : 1200 : mptcp_subflow_ctx(ssk)->map_seq = READ_ONCE(msk->ack_seq);
955 : 1200 : msk->allow_infinite_fallback = false;
956 : 1200 : mptcp_event(MPTCP_EVENT_SUB_ESTABLISHED, msk, ssk, GFP_ATOMIC);
957 : 1200 : }
958 : :
959 : 612 : static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
960 : : {
961 : 612 : struct sock *sk = (struct sock *)msk;
962 : :
963 [ - + ]: 612 : if (sk->sk_state != TCP_ESTABLISHED)
964 : : return false;
965 : :
966 : 612 : spin_lock_bh(&msk->fallback_lock);
967 [ - + - + ]: 612 : if (!msk->allow_subflows) {
[ - + ]
968 : 0 : spin_unlock_bh(&msk->fallback_lock);
969 : 0 : return false;
970 : : }
971 : 612 : mptcp_subflow_joined(msk, ssk);
972 : 612 : spin_unlock_bh(&msk->fallback_lock);
973 : :
974 : 612 : mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
975 : 612 : mptcp_sockopt_sync_locked(msk, ssk);
976 : 612 : mptcp_stop_tout_timer(sk);
977 [ + - ]: 612 : __mptcp_propagate_sndbuf(sk, ssk);
978 : : return true;
979 : : }
980 : :
981 : 12 : static void __mptcp_flush_join_list(struct sock *sk, struct list_head *join_list)
982 : : {
983 : 12 : struct mptcp_subflow_context *tmp, *subflow;
984 [ - + ]: 12 : struct mptcp_sock *msk = mptcp_sk(sk);
985 : :
986 [ + + ]: 18 : list_for_each_entry_safe(subflow, tmp, join_list, node) {
987 : 6 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
988 : 6 : bool slow = lock_sock_fast(ssk);
989 : :
990 : 6 : list_move_tail(&subflow->node, &msk->conn_list);
991 [ - + ]: 6 : if (!__mptcp_finish_join(msk, ssk))
992 : 0 : mptcp_subflow_reset(ssk);
993 : 6 : unlock_sock_fast(ssk, slow);
994 : : }
995 : 12 : }
996 : :
997 : 0 : static bool mptcp_rtx_timer_pending(struct sock *sk)
998 : : {
999 : 527346 : return timer_pending(&sk->mptcp_retransmit_timer);
1000 : : }
1001 : :
1002 : 432317 : static void mptcp_reset_rtx_timer(struct sock *sk)
1003 : : {
1004 : 432317 : unsigned long tout;
1005 : :
1006 : : /* prevent rescheduling on close */
1007 [ + + ]: 432317 : if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
1008 : : return;
1009 : :
1010 [ - + ]: 432248 : tout = mptcp_sk(sk)->timer_ival;
1011 : 432248 : sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
1012 : : }
1013 : :
1014 : 16078 : bool mptcp_schedule_work(struct sock *sk)
1015 : : {
1016 [ + + ]: 16078 : if (inet_sk_state_load(sk) == TCP_CLOSE)
1017 : : return false;
1018 : :
1019 : : /* Get a reference on this socket, mptcp_worker() will release it.
1020 : : * As mptcp_worker() might complete before us, we can not avoid
1021 : : * a sock_hold()/sock_put() if schedule_work() returns false.
1022 : : */
1023 : 15261 : sock_hold(sk);
1024 : :
1025 [ - + + + ]: 15261 : if (schedule_work(&mptcp_sk(sk)->work))
1026 : : return true;
1027 : :
1028 : 1692 : sock_put(sk);
1029 : 1692 : return false;
1030 : : }
1031 : :
1032 : 767802 : static bool mptcp_skb_can_collapse_to(u64 write_seq,
1033 : : const struct sk_buff *skb,
1034 : : const struct mptcp_ext *mpext)
1035 : : {
1036 [ + + ]: 767802 : if (!tcp_skb_can_collapse_to(skb))
1037 : : return false;
1038 : :
1039 : : /* can collapse only if MPTCP level sequence is in order and this
1040 : : * mapping has not been xmitted yet
1041 : : */
1042 [ + - + + ]: 1422792 : return mpext && mpext->data_seq + mpext->data_len == write_seq &&
1043 [ + + ]: 688020 : !mpext->frozen;
1044 : : }
1045 : :
1046 : : /* we can append data to the given data frag if:
1047 : : * - there is space available in the backing page_frag
1048 : : * - the data frag tail matches the current page_frag free offset
1049 : : * - the data frag end sequence number matches the current write seq
1050 : : */
1051 : 713036 : static bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
1052 : : const struct page_frag *pfrag,
1053 : : const struct mptcp_data_frag *df)
1054 : : {
1055 [ + - ]: 364689 : return df && !df->eor &&
1056 [ + - ]: 364689 : pfrag->page == df->page &&
1057 [ + + ]: 364689 : pfrag->size - pfrag->offset > 0 &&
1058 [ + + + - ]: 888406 : pfrag->offset == (df->offset + df->data_len) &&
1059 [ - + ]: 175370 : df->data_seq + df->data_len == msk->write_seq;
1060 : : }
1061 : :
1062 : 0 : static void dfrag_uncharge(struct sock *sk, int len)
1063 : : {
1064 : 833915 : sk_mem_uncharge(sk, len);
1065 : 833915 : sk_wmem_queued_add(sk, -len);
1066 : 296270 : }
1067 : :
1068 : 537657 : static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
1069 : : {
1070 : 537657 : int len = dfrag->data_len + dfrag->overhead;
1071 : :
1072 : 537657 : list_del(&dfrag->list);
1073 : 537657 : dfrag_uncharge(sk, len);
1074 : 537657 : put_page(dfrag->page);
1075 : 537657 : }
1076 : :
1077 : : /* called under both the msk socket lock and the data lock */
1078 : 442708 : static void __mptcp_clean_una(struct sock *sk)
1079 : : {
1080 [ - + ]: 442708 : struct mptcp_sock *msk = mptcp_sk(sk);
1081 : 442708 : struct mptcp_data_frag *dtmp, *dfrag;
1082 : 442708 : u64 snd_una;
1083 : :
1084 : 442708 : snd_una = msk->snd_una;
1085 [ + + ]: 980001 : list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list) {
1086 [ + + ]: 905216 : if (after64(dfrag->data_seq + dfrag->data_len, snd_una))
1087 : : break;
1088 : :
1089 [ - + ]: 537293 : if (unlikely(dfrag == msk->first_pending)) {
1090 : : /* in recovery mode can see ack after the current snd head */
1091 [ # # # # ]: 0 : if (WARN_ON_ONCE(!msk->recovery))
[ # # ]
1092 : : break;
1093 : :
1094 : 0 : msk->first_pending = mptcp_send_next(sk);
1095 : : }
1096 : :
1097 : 537293 : dfrag_clear(sk, dfrag);
1098 : : }
1099 : :
1100 : 442708 : dfrag = mptcp_rtx_head(sk);
1101 [ + + + + ]: 442708 : if (dfrag && after64(snd_una, dfrag->data_seq)) {
1102 : 296270 : u64 delta = snd_una - dfrag->data_seq;
1103 : :
1104 : : /* prevent wrap around in recovery mode */
1105 [ - + ]: 296270 : if (unlikely(delta > dfrag->already_sent)) {
1106 [ # # # # ]: 0 : if (WARN_ON_ONCE(!msk->recovery))
[ # # ]
1107 : 0 : goto out;
1108 [ # # # # ]: 0 : if (WARN_ON_ONCE(delta > dfrag->data_len))
1109 : 0 : goto out;
1110 : 0 : dfrag->already_sent += delta - dfrag->already_sent;
1111 : : }
1112 : :
1113 : 296270 : dfrag->data_seq += delta;
1114 : 296270 : dfrag->offset += delta;
1115 : 296270 : dfrag->data_len -= delta;
1116 : 296270 : dfrag->already_sent -= delta;
1117 : :
1118 : 296270 : dfrag_uncharge(sk, delta);
1119 : : }
1120 : :
1121 : : /* all retransmitted data acked, recovery completed */
1122 [ - + + + : 442708 : if (unlikely(msk->recovery) && after64(msk->snd_una, msk->recovery_snd_nxt))
+ + ]
[ + + + + ]
1123 : 45 : msk->recovery = false;
1124 : :
1125 : 70539 : out:
1126 [ + + + + ]: 442708 : if (snd_una == msk->snd_nxt && snd_una == msk->write_seq) {
1127 [ + + + + ]: 72807 : if (mptcp_rtx_timer_pending(sk) && !mptcp_data_fin_enabled(msk))
[ + + ]
1128 : 58631 : mptcp_stop_rtx_timer(sk);
1129 : : } else {
1130 : 369901 : mptcp_reset_rtx_timer(sk);
1131 : : }
1132 : :
1133 [ + + ]: 442708 : if (mptcp_pending_data_fin_ack(sk))
1134 : 2521 : mptcp_schedule_work(sk);
1135 : 442708 : }
1136 : :
1137 : 82849 : static void __mptcp_clean_una_wakeup(struct sock *sk)
1138 : : {
1139 [ + - - + ]: 137379 : lockdep_assert_held_once(&sk->sk_lock.slock);
1140 : :
1141 : 137379 : __mptcp_clean_una(sk);
1142 : 137373 : mptcp_write_space(sk);
1143 : 133941 : }
1144 : :
1145 : 6756 : static void mptcp_clean_una_wakeup(struct sock *sk)
1146 : : {
1147 : 6756 : mptcp_data_lock(sk);
1148 : 6756 : __mptcp_clean_una_wakeup(sk);
1149 : 6756 : mptcp_data_unlock(sk);
1150 : 6756 : }
1151 : :
1152 : 0 : static void mptcp_enter_memory_pressure(struct sock *sk)
1153 : : {
1154 : 0 : struct mptcp_subflow_context *subflow;
1155 [ # # ]: 0 : struct mptcp_sock *msk = mptcp_sk(sk);
1156 : 0 : bool first = true;
1157 : :
1158 [ # # ]: 0 : mptcp_for_each_subflow(msk, subflow) {
1159 [ # # ]: 0 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
1160 : :
1161 [ # # # # ]: 0 : if (first && !ssk->sk_bypass_prot_mem) {
1162 : 0 : tcp_enter_memory_pressure(ssk);
1163 : 0 : first = false;
1164 : : }
1165 : :
1166 : 0 : sk_stream_moderate_sndbuf(ssk);
1167 : : }
1168 : 0 : __mptcp_sync_sndbuf(sk);
1169 : 0 : }
1170 : :
1171 : : /* ensure we get enough memory for the frag hdr, beyond some minimal amount of
1172 : : * data
1173 : : */
1174 : 537666 : static bool mptcp_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
1175 : : {
1176 [ - + ]: 537666 : if (likely(skb_page_frag_refill(32U + sizeof(struct mptcp_data_frag),
1177 : : pfrag, sk->sk_allocation)))
1178 : : return true;
1179 : :
1180 : 0 : mptcp_enter_memory_pressure(sk);
1181 : 0 : return false;
1182 : : }
1183 : :
1184 : : static struct mptcp_data_frag *
1185 : 537666 : mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
1186 : : int orig_offset)
1187 : : {
1188 : 537666 : int offset = ALIGN(orig_offset, sizeof(long));
1189 : 537666 : struct mptcp_data_frag *dfrag;
1190 : :
1191 : 537666 : dfrag = (struct mptcp_data_frag *)(page_to_virt(pfrag->page) + offset);
1192 : 537666 : dfrag->data_len = 0;
1193 : 537666 : dfrag->data_seq = msk->write_seq;
1194 : 537666 : dfrag->overhead = offset - orig_offset + sizeof(struct mptcp_data_frag);
1195 : 537666 : dfrag->offset = offset + sizeof(struct mptcp_data_frag);
1196 : 537666 : dfrag->already_sent = 0;
1197 : 537666 : dfrag->page = pfrag->page;
1198 : 537666 : dfrag->eor = 0;
1199 : :
1200 : 537666 : return dfrag;
1201 : : }
1202 : :
1203 : : struct mptcp_sendmsg_info {
1204 : : int mss_now;
1205 : : int size_goal;
1206 : : u16 limit;
1207 : : u16 sent;
1208 : : unsigned int flags;
1209 : : bool data_lock_held;
1210 : : };
1211 : :
1212 : 1229999 : static size_t mptcp_check_allowed_size(const struct mptcp_sock *msk,
1213 : : struct sock *ssk, u64 data_seq,
1214 : : size_t avail_size)
1215 : : {
1216 : 1229999 : u64 window_end = mptcp_wnd_end(msk);
1217 : 1229999 : u64 mptcp_snd_wnd;
1218 : :
1219 [ + + ]: 1229999 : if (__mptcp_check_fallback(msk))
1220 : : return avail_size;
1221 : :
1222 : 1142044 : mptcp_snd_wnd = window_end - data_seq;
1223 : 1142044 : avail_size = min(mptcp_snd_wnd, avail_size);
1224 : :
1225 [ - + + + ]: 1142044 : if (unlikely(tcp_sk(ssk)->snd_wnd < mptcp_snd_wnd)) {
1226 [ - + ]: 8848 : tcp_sk(ssk)->snd_wnd = min_t(u64, U32_MAX, mptcp_snd_wnd);
1227 [ + - ]: 8848 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_SNDWNDSHARED);
1228 : : }
1229 : :
1230 : : return avail_size;
1231 : : }
1232 : :
1233 : 613780 : static bool __mptcp_add_ext(struct sk_buff *skb, gfp_t gfp)
1234 : : {
1235 : 613780 : struct skb_ext *mpext = __skb_ext_alloc(gfp);
1236 : :
1237 [ + - ]: 613780 : if (!mpext)
1238 : : return false;
1239 : 613780 : __skb_ext_set(skb, SKB_EXT_MPTCP, mpext);
1240 : 613780 : return true;
1241 : : }
1242 : :
1243 : 613780 : static struct sk_buff *__mptcp_do_alloc_tx_skb(struct sock *sk, gfp_t gfp)
1244 : : {
1245 : 613780 : struct sk_buff *skb;
1246 : :
1247 : 613780 : skb = alloc_skb_fclone(MAX_TCP_HEADER, gfp);
1248 [ + - ]: 613780 : if (likely(skb)) {
1249 [ + - ]: 613780 : if (likely(__mptcp_add_ext(skb, gfp))) {
1250 : 613780 : skb_reserve(skb, MAX_TCP_HEADER);
1251 : 613780 : skb->ip_summed = CHECKSUM_PARTIAL;
1252 : 613780 : INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
1253 : 613780 : return skb;
1254 : : }
1255 : 0 : __kfree_skb(skb);
1256 : : } else {
1257 : 0 : mptcp_enter_memory_pressure(sk);
1258 : : }
1259 : : return NULL;
1260 : : }
1261 : :
1262 : 613780 : static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t gfp)
1263 : : {
1264 : 613780 : struct sk_buff *skb;
1265 : :
1266 : 613780 : skb = __mptcp_do_alloc_tx_skb(sk, gfp);
1267 [ - + ]: 613780 : if (!skb)
1268 : : return NULL;
1269 : :
1270 [ + - ]: 613780 : if (likely(sk_wmem_schedule(ssk, skb->truesize))) {
1271 : 613780 : tcp_skb_entail(ssk, skb);
1272 : 613780 : return skb;
1273 : : }
1274 : 0 : tcp_skb_tsorted_anchor_cleanup(skb);
1275 : 0 : kfree_skb(skb);
1276 : 0 : return NULL;
1277 : : }
1278 : :
1279 : 12 : static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool data_lock_held)
1280 : : {
1281 : 386279 : gfp_t gfp = data_lock_held ? GFP_ATOMIC : sk->sk_allocation;
1282 : :
1283 : 613780 : return __mptcp_alloc_tx_skb(sk, ssk, gfp);
1284 : : }
1285 : :
1286 : : /* note: this always recompute the csum on the whole skb, even
1287 : : * if we just appended a single frag. More status info needed
1288 : : */
1289 : 175883 : static void mptcp_update_data_checksum(struct sk_buff *skb, int added)
1290 : : {
1291 [ + - ]: 175883 : struct mptcp_ext *mpext = mptcp_get_ext(skb);
1292 : 175883 : __wsum csum = ~csum_unfold(mpext->csum);
1293 : 175883 : int offset = skb->len - added;
1294 : :
1295 [ # # ]: 175883 : mpext->csum = csum_fold(csum_block_add(csum, skb_checksum(skb, offset, added, 0), offset));
1296 : 175883 : }
1297 : :
1298 : 2 : static void mptcp_update_infinite_map(struct mptcp_sock *msk,
1299 : : struct sock *ssk,
1300 : : struct mptcp_ext *mpext)
1301 : : {
1302 [ + - ]: 2 : if (!mpext)
1303 : : return;
1304 : :
1305 : 2 : mpext->infinite_map = 1;
1306 : 2 : mpext->data_len = 0;
1307 : :
1308 [ - + ]: 2 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_INFINITEMAPTX)) {
1309 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
1310 : 0 : mptcp_subflow_reset(ssk);
1311 : 0 : return;
1312 : : }
1313 : :
1314 : 2 : mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
1315 : : }
1316 : :
1317 : : #define MPTCP_MAX_GSO_SIZE (GSO_LEGACY_MAX_SIZE - (MAX_TCP_HEADER + 1))
1318 : :
1319 : 1230000 : static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
1320 : : struct mptcp_data_frag *dfrag,
1321 : : struct mptcp_sendmsg_info *info)
1322 : : {
1323 : 1230000 : u64 data_seq = dfrag->data_seq + info->sent;
1324 : 1230000 : int offset = dfrag->offset + info->sent;
1325 [ - + ]: 1230000 : struct mptcp_sock *msk = mptcp_sk(sk);
1326 : 1230000 : bool zero_window_probe = false;
1327 : 1230000 : struct mptcp_ext *mpext = NULL;
1328 : 1230000 : bool can_coalesce = false;
1329 : 1230000 : bool reuse_skb = true;
1330 : 1230000 : struct sk_buff *skb;
1331 : 1230000 : size_t copy;
1332 : 1230000 : int i;
1333 : :
1334 [ - + - - ]: 1230000 : pr_debug("msk=%p ssk=%p sending dfrag at seq=%llu len=%u already sent=%u\n",
1335 : : msk, ssk, dfrag->data_seq, dfrag->data_len, info->sent);
1336 : :
1337 [ + - - + ]: 1230000 : if (WARN_ON_ONCE(info->sent > info->limit ||
1338 : : info->limit > dfrag->data_len))
1339 : 0 : return 0;
1340 : :
1341 [ + + ]: 1230000 : if (unlikely(!__tcp_can_send(ssk)))
1342 : : return -EAGAIN;
1343 : :
1344 : : /* compute send limit */
1345 [ - + ]: 1229999 : if (unlikely(ssk->sk_gso_max_size > MPTCP_MAX_GSO_SIZE))
1346 : 0 : ssk->sk_gso_max_size = MPTCP_MAX_GSO_SIZE;
1347 : 1229999 : info->mss_now = tcp_send_mss(ssk, &info->size_goal, info->flags);
1348 : 1229999 : copy = info->size_goal;
1349 : :
1350 [ + + ]: 1229999 : skb = tcp_write_queue_tail(ssk);
1351 [ + - + + ]: 1066928 : if (skb && copy > skb->len) {
1352 : : /* Limit the write to the size available in the
1353 : : * current skb, if any, so that we create at most a new skb.
1354 : : * Explicitly tells TCP internals to avoid collapsing on later
1355 : : * queue management operation, to avoid breaking the ext <->
1356 : : * SSN association set here
1357 : : */
1358 [ + - ]: 767802 : mpext = mptcp_get_ext(skb);
1359 [ + + ]: 767802 : if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) {
1360 : 151147 : TCP_SKB_CB(skb)->eor = 1;
1361 [ - + ]: 151147 : tcp_mark_push(tcp_sk(ssk), skb);
1362 : 151147 : goto alloc_skb;
1363 : : }
1364 : :
1365 [ + + ]: 616655 : i = skb_shinfo(skb)->nr_frags;
1366 [ + + ]: 616655 : can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset);
1367 [ + + + + ]: 616655 : if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) {
1368 [ - + ]: 436 : tcp_mark_push(tcp_sk(ssk), skb);
1369 : 436 : goto alloc_skb;
1370 : : }
1371 : :
1372 : 616219 : copy -= skb->len;
1373 : : } else {
1374 [ + + ]: 12 : alloc_skb:
1375 [ - + + + ]: 613780 : skb = mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held);
[ + + ]
1376 [ - + ]: 613780 : if (!skb)
1377 : : return -ENOMEM;
1378 : :
1379 [ + - ]: 613780 : i = skb_shinfo(skb)->nr_frags;
1380 : 613780 : reuse_skb = false;
1381 [ + - ]: 613780 : mpext = mptcp_get_ext(skb);
1382 : : }
1383 : :
1384 : : /* Zero window and all data acked? Probe. */
1385 : 1229999 : copy = mptcp_check_allowed_size(msk, ssk, data_seq, copy);
1386 [ + + ]: 1229999 : if (copy == 0) {
1387 : 304058 : u64 snd_una = READ_ONCE(msk->snd_una);
1388 : :
1389 : : /* No need for zero probe if there are any data pending
1390 : : * either at the msk or ssk level; skb is the current write
1391 : : * queue tail and can be empty at this point.
1392 : : */
1393 [ + + + - : 317123 : if (snd_una != msk->snd_nxt || skb->len ||
+ + ]
[ # # # # ]
1394 [ # # ]: 0 : skb != tcp_send_head(ssk)) {
1395 : 300444 : tcp_remove_empty_skb(ssk);
1396 : 300444 : return 0;
1397 : : }
1398 : :
1399 : 3614 : zero_window_probe = true;
1400 : 3614 : data_seq = snd_una - 1;
1401 : 3614 : copy = 1;
1402 : : }
1403 : :
1404 : 929555 : copy = min_t(size_t, copy, info->limit - info->sent);
1405 [ - + ]: 929555 : if (!sk_wmem_schedule(ssk, copy)) {
1406 : 0 : tcp_remove_empty_skb(ssk);
1407 : 0 : return -ENOMEM;
1408 : : }
1409 : :
1410 [ + + ]: 929555 : if (can_coalesce) {
1411 : 56949 : skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
1412 : : } else {
1413 : 872606 : get_page(dfrag->page);
1414 [ - + ]: 872618 : skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
1415 : : }
1416 : :
1417 : 929555 : skb->len += copy;
1418 : 929555 : skb->data_len += copy;
1419 : 929555 : skb->truesize += copy;
1420 [ + - ]: 929555 : sk_wmem_queued_add(ssk, copy);
1421 [ + - ]: 929555 : sk_mem_charge(ssk, copy);
1422 [ - + - + ]: 929555 : WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
1423 : 929555 : TCP_SKB_CB(skb)->end_seq += copy;
1424 [ + + ]: 929555 : tcp_skb_pcount_set(skb, 0);
1425 : :
1426 : : /* on skb reuse we just need to update the DSS len */
1427 [ + + ]: 929555 : if (reuse_skb) {
1428 : 393171 : TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH;
1429 : 393171 : mpext->data_len += copy;
1430 : 393171 : goto out;
1431 : : }
1432 : :
1433 : 536384 : memset(mpext, 0, sizeof(*mpext));
1434 : 536384 : mpext->data_seq = data_seq;
1435 [ - + ]: 536384 : mpext->subflow_seq = mptcp_subflow_ctx(ssk)->rel_write_seq;
1436 : 536384 : mpext->data_len = copy;
1437 : 536384 : mpext->use_map = 1;
1438 : 536384 : mpext->dsn64 = 1;
1439 : :
1440 [ - + - - ]: 536384 : pr_debug("data_seq=%llu subflow_seq=%u data_len=%u dsn64=%d\n",
1441 : : mpext->data_seq, mpext->subflow_seq, mpext->data_len,
1442 : : mpext->dsn64);
1443 : :
1444 [ + + ]: 536384 : if (zero_window_probe) {
1445 [ + - ]: 3614 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_WINPROBE);
1446 [ + + ]: 3614 : mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
1447 : 3614 : mpext->frozen = 1;
1448 [ - + + + ]: 3614 : if (READ_ONCE(msk->csum_enabled))
[ + + ]
1449 : 2537 : mptcp_update_data_checksum(skb, copy);
1450 : 3614 : tcp_push_pending_frames(ssk);
1451 : 3614 : return 0;
1452 : : }
1453 : 532770 : out:
1454 [ - + + + ]: 925941 : if (READ_ONCE(msk->csum_enabled))
[ + + ]
1455 : 173346 : mptcp_update_data_checksum(skb, copy);
1456 [ + + ]: 925941 : if (mptcp_subflow_ctx(ssk)->send_infinite_map)
1457 : 2 : mptcp_update_infinite_map(msk, ssk, mpext);
1458 : 925941 : trace_mptcp_sendmsg_frag(mpext);
1459 [ + + ]: 925941 : mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
1460 : :
1461 : : /* if this is the last chunk of a dfrag with MSG_EOR set,
1462 : : * mark the skb to prevent coalescing with subsequent data.
1463 : : */
1464 [ + + - + ]: 925941 : if (dfrag->eor && info->sent + copy >= dfrag->data_len)
1465 : 6 : TCP_SKB_CB(skb)->eor = 1;
1466 : :
1467 : : return copy;
1468 : : }
1469 : :
1470 : : #define MPTCP_SEND_BURST_SIZE ((1 << 16) - \
1471 : : sizeof(struct tcphdr) - \
1472 : : MAX_TCP_OPTION_SPACE - \
1473 : : sizeof(struct ipv6hdr) - \
1474 : : sizeof(struct frag_hdr))
1475 : :
1476 : : struct subflow_send_info {
1477 : : struct sock *ssk;
1478 : : u64 linger_time;
1479 : : };
1480 : :
1481 : 189 : void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow)
1482 : : {
1483 [ - + ]: 189 : if (!subflow->stale)
1484 : : return;
1485 : :
1486 : 0 : subflow->stale = 0;
1487 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(mptcp_subflow_tcp_sock(subflow)), MPTCP_MIB_SUBFLOWRECOVER);
1488 : : }
1489 : :
1490 : 1680498 : bool mptcp_subflow_active(struct mptcp_subflow_context *subflow)
1491 : : {
1492 [ + + ]: 1680498 : if (unlikely(subflow->stale)) {
1493 [ - + ]: 122883 : u32 rcv_tstamp = READ_ONCE(tcp_sk(mptcp_subflow_tcp_sock(subflow))->rcv_tstamp);
1494 : :
1495 [ - + ]: 122883 : if (subflow->stale_rcv_tstamp == rcv_tstamp)
1496 : : return false;
1497 : :
1498 : 0 : mptcp_subflow_set_active(subflow);
1499 : : }
1500 : 1557615 : return __mptcp_subflow_active(subflow);
1501 : : }
1502 : :
1503 : : #define SSK_MODE_ACTIVE 0
1504 : : #define SSK_MODE_BACKUP 1
1505 : : #define SSK_MODE_MAX 2
1506 : :
1507 : : /* implement the mptcp packet scheduler;
1508 : : * returns the subflow that will transmit the next DSS
1509 : : * additionally updates the rtx timeout
1510 : : */
1511 : 783571 : struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
1512 : : {
1513 : 783571 : struct subflow_send_info send_info[SSK_MODE_MAX];
1514 : 783571 : struct mptcp_subflow_context *subflow;
1515 : 783571 : struct sock *sk = (struct sock *)msk;
1516 : 783571 : u32 pace, burst, wmem;
1517 : 783571 : int i, nr_active = 0;
1518 : 783571 : struct sock *ssk;
1519 : 783571 : u64 linger_time;
1520 : 783571 : long tout = 0;
1521 : :
1522 : : /* pick the subflow with the lower wmem/wspace ratio */
1523 [ + + ]: 2350713 : for (i = 0; i < SSK_MODE_MAX; ++i) {
1524 : 1567142 : send_info[i].ssk = NULL;
1525 : 1567142 : send_info[i].linger_time = -1;
1526 : : }
1527 : :
1528 [ + + ]: 2051220 : mptcp_for_each_subflow(msk, subflow) {
1529 [ + + + + ]: 1267649 : bool backup = subflow->backup || subflow->request_bkup;
1530 : :
1531 : 1267649 : trace_mptcp_subflow_get_send(subflow);
1532 : 1267649 : ssk = mptcp_subflow_tcp_sock(subflow);
1533 [ + + ]: 1267649 : if (!mptcp_subflow_active(subflow))
1534 : 124262 : continue;
1535 : :
1536 [ + + ]: 1143387 : tout = max(tout, mptcp_timeout_from_subflow(subflow));
1537 : 1143387 : nr_active += !backup;
1538 : 1143387 : pace = subflow->avg_pacing_rate;
1539 [ + + ]: 1143387 : if (unlikely(!pace)) {
1540 : : /* init pacing rate from socket */
1541 : 3532 : subflow->avg_pacing_rate = READ_ONCE(ssk->sk_pacing_rate);
1542 : 3532 : pace = subflow->avg_pacing_rate;
1543 [ - + ]: 3532 : if (!pace)
1544 : 0 : continue;
1545 : : }
1546 : :
1547 [ + + ]: 1143387 : linger_time = div_u64((u64)READ_ONCE(ssk->sk_wmem_queued) << 32, pace);
1548 [ + + ]: 1143387 : if (linger_time < send_info[backup].linger_time) {
1549 : 913178 : send_info[backup].ssk = ssk;
1550 : 913178 : send_info[backup].linger_time = linger_time;
1551 : : }
1552 : : }
1553 : 783571 : __mptcp_set_timeout(sk, tout);
1554 : :
1555 : : /* pick the best backup if no other subflow is active */
1556 [ + + ]: 783571 : if (!nr_active)
1557 : 44637 : send_info[SSK_MODE_ACTIVE].ssk = send_info[SSK_MODE_BACKUP].ssk;
1558 : :
1559 : : /* According to the blest algorithm, to avoid HoL blocking for the
1560 : : * faster flow, we need to:
1561 : : * - estimate the faster flow linger time
1562 : : * - use the above to estimate the amount of byte transferred
1563 : : * by the faster flow
1564 : : * - check that the amount of queued data is greater than the above,
1565 : : * otherwise do not use the picked, slower, subflow
1566 : : * We select the subflow with the shorter estimated time to flush
1567 : : * the queued mem, which basically ensure the above. We just need
1568 : : * to check that subflow has a non empty cwin.
1569 : : */
1570 : 783571 : ssk = send_info[SSK_MODE_ACTIVE].ssk;
1571 [ + + + + ]: 1567115 : if (!ssk || !sk_stream_memory_free(ssk))
1572 : 160562 : return NULL;
1573 : :
1574 : 623009 : burst = min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt);
1575 : 623009 : wmem = READ_ONCE(ssk->sk_wmem_queued);
1576 [ + + ]: 623009 : if (!burst)
1577 : : return ssk;
1578 : :
1579 : 400976 : subflow = mptcp_subflow_ctx(ssk);
1580 : 400976 : subflow->avg_pacing_rate = div_u64((u64)subflow->avg_pacing_rate * wmem +
1581 : 400976 : READ_ONCE(ssk->sk_pacing_rate) * burst,
1582 : : burst + wmem);
1583 : 400976 : msk->snd_burst = burst;
1584 : 400976 : return ssk;
1585 : : }
1586 : :
1587 : 490529 : static void mptcp_push_release(struct sock *ssk, struct mptcp_sendmsg_info *info)
1588 : : {
1589 [ - + ]: 490529 : tcp_push(ssk, 0, info->mss_now, tcp_sk(ssk)->nonagle, info->size_goal);
1590 : 490529 : release_sock(ssk);
1591 : 490529 : }
1592 : :
1593 : 925699 : static void mptcp_update_post_push(struct mptcp_sock *msk,
1594 : : struct mptcp_data_frag *dfrag,
1595 : : u32 sent)
1596 : : {
1597 : 925699 : u64 snd_nxt_new = dfrag->data_seq;
1598 : :
1599 : 925699 : dfrag->already_sent += sent;
1600 : :
1601 : 925699 : msk->snd_burst -= sent;
1602 : :
1603 : 925699 : snd_nxt_new += dfrag->already_sent;
1604 : :
1605 : : /* snd_nxt_new can be smaller than snd_nxt in case mptcp
1606 : : * is recovering after a failover. In that event, this re-sends
1607 : : * old segments.
1608 : : *
1609 : : * Thus compute snd_nxt_new candidate based on
1610 : : * the dfrag->data_seq that was sent and the data
1611 : : * that has been handed to the subflow for transmission
1612 : : * and skip update in case it was old dfrag.
1613 : : */
1614 [ + + ]: 925699 : if (likely(after64(snd_nxt_new, msk->snd_nxt))) {
1615 : 921392 : msk->bytes_sent += snd_nxt_new - msk->snd_nxt;
1616 : 921392 : WRITE_ONCE(msk->snd_nxt, snd_nxt_new);
1617 : : }
1618 : 925699 : }
1619 : :
1620 : 5121 : void mptcp_check_and_set_pending(struct sock *sk)
1621 : : {
1622 [ + + ]: 5121 : if (mptcp_send_head(sk)) {
1623 : 394 : mptcp_data_lock(sk);
1624 [ - + ]: 394 : mptcp_sk(sk)->cb_flags |= BIT(MPTCP_PUSH_PENDING);
1625 : 394 : mptcp_data_unlock(sk);
1626 : : }
1627 : 5121 : }
1628 : :
1629 : 702675 : static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
1630 : : struct mptcp_sendmsg_info *info)
1631 : : {
1632 [ - + ]: 702675 : struct mptcp_sock *msk = mptcp_sk(sk);
1633 : 24 : struct mptcp_data_frag *dfrag;
1634 : 24 : int len, copied = 0, err = 0;
1635 : :
1636 [ + + ]: 1114035 : while ((dfrag = mptcp_send_head(sk))) {
1637 : 845680 : info->sent = dfrag->already_sent;
1638 : 845680 : info->limit = dfrag->data_len;
1639 : 845680 : len = dfrag->data_len - dfrag->already_sent;
1640 [ + + ]: 1771379 : while (len > 0) {
1641 : 1229758 : int ret = 0;
1642 : :
1643 : 1229758 : ret = mptcp_sendmsg_frag(sk, ssk, dfrag, info);
1644 [ + + ]: 1229758 : if (ret <= 0) {
1645 [ + + ]: 304059 : err = copied ? : ret;
1646 : 304059 : goto out;
1647 : : }
1648 : :
1649 : 925699 : info->sent += ret;
1650 : 925699 : copied += ret;
1651 : 925699 : len -= ret;
1652 : :
1653 : 925699 : mptcp_update_post_push(msk, dfrag, ret);
1654 : : }
1655 : 541621 : msk->first_pending = mptcp_send_next(sk);
1656 : :
1657 [ + + + + ]: 968178 : if (msk->snd_burst <= 0 ||
[ + - ]
1658 [ - + ]: 411372 : !sk_stream_memory_free(ssk) ||
[ + - - + ]
1659 : 411360 : !mptcp_subflow_active(mptcp_subflow_ctx(ssk))) {
1660 : 130261 : err = copied;
1661 : 130261 : goto out;
1662 : : }
1663 : 411360 : mptcp_set_timeout(sk);
1664 : : }
1665 : : err = copied;
1666 : :
1667 : 702675 : out:
1668 [ + + ]: 702675 : if (err > 0)
1669 : 484681 : msk->last_data_sent = tcp_jiffies32;
1670 : 702675 : return err;
1671 : : }
1672 : :
1673 : 746620 : void __mptcp_push_pending(struct sock *sk, unsigned int flags)
1674 : : {
1675 : 746620 : struct sock *prev_ssk = NULL, *ssk = NULL;
1676 [ - + ]: 746620 : struct mptcp_sock *msk = mptcp_sk(sk);
1677 : 746620 : struct mptcp_sendmsg_info info = {
1678 : : .flags = flags,
1679 : : };
1680 : 746620 : bool copied = false;
1681 : 746620 : int push_count = 1;
1682 : :
1683 [ + + + + ]: 1280987 : while (mptcp_send_head(sk) && (push_count > 0)) {
1684 : 585665 : struct mptcp_subflow_context *subflow;
1685 : 585665 : int ret = 0;
1686 : :
1687 [ + + ]: 585665 : if (mptcp_sched_get_send(msk))
1688 : : break;
1689 : :
1690 : 534367 : push_count = 0;
1691 : :
1692 [ + + ]: 1228273 : mptcp_for_each_subflow(msk, subflow) {
1693 [ - + + + ]: 693906 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1694 : 534367 : mptcp_subflow_set_scheduled(subflow, false);
1695 : :
1696 : 534367 : prev_ssk = ssk;
1697 [ + + ]: 534367 : ssk = mptcp_subflow_tcp_sock(subflow);
1698 [ + + ]: 534367 : if (ssk != prev_ssk) {
1699 : : /* First check. If the ssk has changed since
1700 : : * the last round, release prev_ssk
1701 : : */
1702 [ + + ]: 490529 : if (prev_ssk)
1703 : 2042 : mptcp_push_release(prev_ssk, &info);
1704 : :
1705 : : /* Need to lock the new subflow only if different
1706 : : * from the previous one, otherwise we are still
1707 : : * helding the relevant lock
1708 : : */
1709 : 490529 : lock_sock(ssk);
1710 : : }
1711 : :
1712 : 534367 : push_count++;
1713 : :
1714 : 534367 : ret = __subflow_push_pending(sk, ssk, &info);
1715 [ + + ]: 534367 : if (ret <= 0) {
1716 [ + + + - ]: 145355 : if (ret != -EAGAIN ||
[ - + ]
1717 [ - + ]: 1 : (1 << ssk->sk_state) &
1718 : : (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSE))
1719 : 74135 : push_count--;
1720 : 145354 : continue;
1721 : : }
1722 : : copied = true;
1723 : : }
1724 : : }
1725 : : }
1726 : :
1727 : : /* at this point we held the socket lock for the last subflow we used */
1728 [ + + ]: 746620 : if (ssk)
1729 : 488487 : mptcp_push_release(ssk, &info);
1730 : :
1731 : : /* Avoid scheduling the rtx timer if no data has been pushed; the timer
1732 : : * will be updated on positive acks by __mptcp_cleanup_una().
1733 : : */
1734 [ + + ]: 746620 : if (copied) {
1735 [ + + ]: 355553 : if (!mptcp_rtx_timer_pending(sk))
1736 : 60422 : mptcp_reset_rtx_timer(sk);
1737 : 355553 : mptcp_check_send_data_fin(sk);
1738 : : }
1739 : 746620 : }
1740 : :
1741 : 1418779 : static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool first)
1742 : : {
1743 [ - + ]: 1418779 : struct mptcp_sock *msk = mptcp_sk(sk);
1744 : 1418779 : struct mptcp_sendmsg_info info = {
1745 : : .data_lock_held = true,
1746 : : };
1747 : 1418779 : bool keep_pushing = true;
1748 : 1418779 : struct sock *xmit_ssk;
1749 : 1418779 : int copied = 0;
1750 : :
1751 : 1418779 : info.flags = 0;
1752 [ + + + + ]: 1594971 : while (mptcp_send_head(sk) && keep_pushing) {
1753 [ + + ]: 290581 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1754 : 290581 : int ret = 0;
1755 : :
1756 : : /* check for a different subflow usage only after
1757 : : * spooling the first chunk of data
1758 : : */
1759 [ + + ]: 290581 : if (first) {
1760 : 9731 : mptcp_subflow_set_scheduled(subflow, false);
1761 : 9731 : ret = __subflow_push_pending(sk, ssk, &info);
1762 : 9731 : first = false;
1763 [ + + ]: 9731 : if (ret <= 0)
1764 : : break;
1765 : 6001 : copied += ret;
1766 : 6001 : continue;
1767 : : }
1768 : :
1769 [ + + ]: 280850 : if (mptcp_sched_get_send(msk))
1770 : 110659 : goto out;
1771 : :
1772 [ - + + + ]: 170191 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1773 : 158577 : mptcp_subflow_set_scheduled(subflow, false);
1774 : 158577 : ret = __subflow_push_pending(sk, ssk, &info);
1775 [ + + ]: 158577 : if (ret <= 0)
1776 : 68910 : keep_pushing = false;
1777 : 158577 : copied += ret;
1778 : : }
1779 : :
1780 [ + + ]: 466811 : mptcp_for_each_subflow(msk, subflow) {
1781 [ - + + + ]: 296620 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1782 [ + - ]: 11614 : xmit_ssk = mptcp_subflow_tcp_sock(subflow);
1783 [ + - ]: 11614 : if (xmit_ssk != ssk) {
1784 : 11614 : mptcp_subflow_delegate(subflow,
1785 : : MPTCP_DELEGATE_SEND);
1786 : 11614 : keep_pushing = false;
1787 : : }
1788 : : }
1789 : : }
1790 : : }
1791 : :
1792 : 1308055 : out:
1793 : : /* __mptcp_alloc_tx_skb could have released some wmem and we are
1794 : : * not going to flush it via release_sock()
1795 : : */
1796 [ + + ]: 1418779 : if (copied) {
1797 [ - + ]: 90141 : tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
1798 : : info.size_goal);
1799 [ + + ]: 90141 : if (!mptcp_rtx_timer_pending(sk))
1800 : 25 : mptcp_reset_rtx_timer(sk);
1801 : :
1802 [ - + + + ]: 90141 : if (msk->snd_data_fin_enable &&
[ + + ]
1803 [ + + ]: 11097 : msk->snd_nxt + 1 == msk->write_seq)
1804 : 359 : mptcp_schedule_work(sk);
1805 : : }
1806 : 1418779 : }
1807 : :
1808 : : static int mptcp_disconnect(struct sock *sk, int flags);
1809 : :
1810 : 112 : static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1811 : : size_t len, int *copied_syn)
1812 : : {
1813 : 112 : unsigned int saved_flags = msg->msg_flags;
1814 [ - + ]: 112 : struct mptcp_sock *msk = mptcp_sk(sk);
1815 : 112 : struct sock *ssk;
1816 : 112 : int ret;
1817 : :
1818 : : /* on flags based fastopen the mptcp is supposed to create the
1819 : : * first subflow right now. Otherwise we are in the defer_connect
1820 : : * path, and the first subflow must be already present.
1821 : : * Since the defer_connect flag is cleared after the first succsful
1822 : : * fastopen attempt, no need to check for additional subflow status.
1823 : : */
1824 [ + + ]: 112 : if (msg->msg_flags & MSG_FASTOPEN) {
1825 : 76 : ssk = __mptcp_nmpc_sk(msk);
1826 [ + + ]: 76 : if (IS_ERR(ssk))
1827 : 6 : return PTR_ERR(ssk);
1828 : : }
1829 [ + - ]: 106 : if (!msk->first)
1830 : : return -EINVAL;
1831 : :
1832 : 106 : ssk = msk->first;
1833 : :
1834 : 106 : lock_sock(ssk);
1835 : 106 : msg->msg_flags |= MSG_DONTWAIT;
1836 : 106 : msk->fastopening = 1;
1837 : 106 : ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
1838 : 106 : msk->fastopening = 0;
1839 : 106 : msg->msg_flags = saved_flags;
1840 : 106 : release_sock(ssk);
1841 : :
1842 : : /* do the blocking bits of inet_stream_connect outside the ssk socket lock */
1843 [ + - + + ]: 106 : if (ret == -EINPROGRESS && !(msg->msg_flags & MSG_DONTWAIT)) {
1844 : 46 : ret = __inet_stream_connect(sk->sk_socket, msg->msg_name,
1845 : : msg->msg_namelen, msg->msg_flags, 1);
1846 : :
1847 : : /* Keep the same behaviour of plain TCP: zero the copied bytes in
1848 : : * case of any error, except timeout or signal
1849 : : */
1850 [ - + - - ]: 46 : if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
1851 : 0 : *copied_syn = 0;
1852 [ + - ]: 60 : } else if (ret && ret != -EINPROGRESS) {
1853 : : /* The disconnect() op called by tcp_sendmsg_fastopen()/
1854 : : * __inet_stream_connect() can fail, due to looking check,
1855 : : * see mptcp_disconnect().
1856 : : * Attempt it again outside the problematic scope.
1857 : : */
1858 [ # # ]: 0 : if (!mptcp_disconnect(sk, 0)) {
1859 : 0 : sk->sk_disconnects++;
1860 : 0 : sk->sk_socket->state = SS_UNCONNECTED;
1861 : : }
1862 : : }
1863 : 106 : inet_clear_bit(DEFER_CONNECT, sk);
1864 : :
1865 : 106 : return ret;
1866 : : }
1867 : :
1868 : 713036 : static int do_copy_data_nocache(struct sock *sk, int copy,
1869 : : struct iov_iter *from, char *to)
1870 : : {
1871 [ - + ]: 713036 : if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) {
1872 [ # # ]: 0 : if (!copy_from_iter_full_nocache(to, copy, from))
1873 : 0 : return -EFAULT;
1874 [ - + ]: 713036 : } else if (!copy_from_iter_full(to, copy, from)) {
1875 : 0 : return -EFAULT;
1876 : : }
1877 : : return 0;
1878 : : }
1879 : :
1880 : : /* open-code sk_stream_memory_free() plus sent limit computation to
1881 : : * avoid indirect calls in fast-path.
1882 : : * Called under the msk socket lock, so we can avoid a bunch of ONCE
1883 : : * annotations.
1884 : : */
1885 : 717889 : static u32 mptcp_send_limit(const struct sock *sk)
1886 : : {
1887 [ - + ]: 717889 : const struct mptcp_sock *msk = mptcp_sk(sk);
1888 : 717889 : u32 limit, not_sent;
1889 : :
1890 [ + + ]: 717889 : if (sk->sk_wmem_queued >= READ_ONCE(sk->sk_sndbuf))
1891 : : return 0;
1892 : :
1893 : 713042 : limit = mptcp_notsent_lowat(sk);
1894 [ + + ]: 713042 : if (limit == UINT_MAX)
1895 : : return UINT_MAX;
1896 : :
1897 : 12 : not_sent = msk->write_seq - msk->snd_nxt;
1898 [ + + ]: 12 : if (not_sent >= limit)
1899 : : return 0;
1900 : :
1901 : 6 : return limit - not_sent;
1902 : : }
1903 : :
1904 : 1628580 : static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
1905 : : {
1906 : 1628580 : struct mptcp_subflow_context *subflow;
1907 : :
1908 [ - + ]: 1628580 : if (!rfs_is_needed())
1909 : : return;
1910 : :
1911 [ # # ]: 0 : mptcp_for_each_subflow(msk, subflow) {
1912 : 0 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
1913 : :
1914 : 0 : sock_rps_record_flow(ssk);
1915 : : }
1916 : : }
1917 : :
1918 : 521237 : static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
1919 : : {
1920 [ - + ]: 521237 : struct mptcp_sock *msk = mptcp_sk(sk);
1921 : 521237 : struct page_frag *pfrag;
1922 : 521237 : size_t copied = 0;
1923 : 521237 : int ret = 0;
1924 : 521237 : long timeo;
1925 : :
1926 : : /* silently ignore everything else */
1927 : 521237 : msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
1928 : : MSG_FASTOPEN | MSG_EOR;
1929 : :
1930 : 521237 : lock_sock(sk);
1931 : :
1932 : 521237 : mptcp_rps_record_subflows(msk);
1933 : :
1934 [ + + + + ]: 521237 : if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
1935 : : msg->msg_flags & MSG_FASTOPEN)) {
1936 : 112 : int copied_syn = 0;
1937 : :
1938 : 112 : ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn);
1939 : 112 : copied += copied_syn;
1940 [ + + + + ]: 112 : if (ret == -EINPROGRESS && copied_syn > 0)
1941 : 42 : goto out;
1942 [ + + ]: 70 : else if (ret)
1943 : 24 : goto do_error;
1944 : : }
1945 : :
1946 [ + + ]: 521171 : timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1947 : :
1948 [ - + + + ]: 521171 : if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
[ + + ]
1949 : 44 : ret = sk_stream_wait_connect(sk, &timeo);
1950 [ + - ]: 44 : if (ret)
1951 : 44 : goto do_error;
1952 : : }
1953 : :
1954 : 521127 : ret = -EPIPE;
1955 [ + - - + ]: 521127 : if (unlikely(sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)))
1956 : 0 : goto do_error;
1957 : :
1958 [ + - ]: 521127 : pfrag = sk_page_frag(sk);
1959 : :
1960 [ + + ]: 1239010 : while (msg_data_left(msg)) {
1961 : 717889 : int total_ts, frag_truesize = 0;
1962 : 717889 : struct mptcp_data_frag *dfrag;
1963 : 717889 : bool dfrag_collapsed;
1964 : 717889 : size_t psize, offset;
1965 : 717889 : u32 copy_limit;
1966 : :
1967 : : /* ensure fitting the notsent_lowat() constraint */
1968 : 717889 : copy_limit = mptcp_send_limit(sk);
1969 [ + + ]: 717889 : if (!copy_limit)
1970 : 4853 : goto wait_for_memory;
1971 : :
1972 : : /* reuse tail pfrag, if possible, or carve a new one from the
1973 : : * page allocator
1974 : : */
1975 : 713036 : dfrag = mptcp_pending_tail(sk);
1976 : 713036 : dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
1977 [ + + ]: 713036 : if (!dfrag_collapsed) {
1978 [ - + ]: 537666 : if (!mptcp_page_frag_refill(sk, pfrag))
1979 : 0 : goto wait_for_memory;
1980 : :
1981 : 537666 : dfrag = mptcp_carve_data_frag(msk, pfrag, pfrag->offset);
1982 : 537666 : frag_truesize = dfrag->overhead;
1983 : : }
1984 : :
1985 : : /* we do not bound vs wspace, to allow a single packet.
1986 : : * memory accounting will prevent execessive memory usage
1987 : : * anyway
1988 : : */
1989 : 713036 : offset = dfrag->offset + dfrag->data_len;
1990 : 713036 : psize = pfrag->size - offset;
1991 : 713036 : psize = min_t(size_t, psize, msg_data_left(msg));
1992 : 713036 : psize = min_t(size_t, psize, copy_limit);
1993 : 713036 : total_ts = psize + frag_truesize;
1994 : :
1995 [ - + ]: 713036 : if (!sk_wmem_schedule(sk, total_ts))
1996 : 0 : goto wait_for_memory;
1997 : :
1998 : 713048 : ret = do_copy_data_nocache(sk, psize, &msg->msg_iter,
1999 : 713036 : page_address(dfrag->page) + offset);
2000 [ - + ]: 713036 : if (ret)
2001 : 0 : goto do_error;
2002 : :
2003 : : /* data successfully copied into the write queue */
2004 [ + + ]: 713036 : sk_forward_alloc_add(sk, -total_ts);
2005 : 713036 : copied += psize;
2006 : 713036 : dfrag->data_len += psize;
2007 : 713036 : frag_truesize += psize;
2008 : 713036 : pfrag->offset += frag_truesize;
2009 : 713036 : WRITE_ONCE(msk->write_seq, msk->write_seq + psize);
2010 : :
2011 : : /* charge data on mptcp pending queue to the msk socket
2012 : : * Note: we charge such data both to sk and ssk
2013 : : */
2014 [ + + ]: 713036 : sk_wmem_queued_add(sk, frag_truesize);
2015 [ + + ]: 713036 : if (!dfrag_collapsed) {
2016 : 537666 : get_page(dfrag->page);
2017 [ + + ]: 537666 : list_add_tail(&dfrag->list, &msk->rtx_queue);
2018 [ + + ]: 537666 : if (!msk->first_pending)
2019 : 348347 : msk->first_pending = dfrag;
2020 : : }
2021 [ - + - - ]: 713036 : pr_debug("msk=%p dfrag at seq=%llu len=%u sent=%u new=%d\n", msk,
2022 : : dfrag->data_seq, dfrag->data_len, dfrag->already_sent,
2023 : : !dfrag_collapsed);
2024 : :
2025 : 713036 : continue;
2026 : :
2027 : 4853 : wait_for_memory:
2028 : 4853 : set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
2029 : 4853 : __mptcp_push_pending(sk, msg->msg_flags);
2030 : 4853 : ret = sk_stream_wait_memory(sk, &timeo);
2031 [ + + ]: 4853 : if (ret)
2032 : 6 : goto do_error;
2033 : : }
2034 : :
2035 [ + + ]: 521121 : if (copied) {
2036 : : /* mark the last dfrag with EOR if MSG_EOR was set */
2037 [ + + ]: 521096 : if (msg->msg_flags & MSG_EOR) {
2038 : 6 : struct mptcp_data_frag *dfrag = mptcp_pending_tail(sk);
2039 : :
2040 [ + - ]: 6 : if (dfrag)
2041 : 6 : dfrag->eor = 1;
2042 : : }
2043 : 521096 : __mptcp_push_pending(sk, msg->msg_flags);
2044 : : }
2045 : :
2046 : 25 : out:
2047 : 521237 : release_sock(sk);
2048 : 521237 : return copied;
2049 : :
2050 : 74 : do_error:
2051 [ + + ]: 74 : if (copied)
2052 : 6 : goto out;
2053 : :
2054 : 68 : copied = sk_stream_error(sk, msg->msg_flags, ret);
2055 : 68 : goto out;
2056 : : }
2057 : :
2058 : : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
2059 : :
2060 : 763575 : static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
2061 : : {
2062 : : /* avoid the indirect call, we know the destructor is sock_rfree */
2063 : 763575 : skb->destructor = NULL;
2064 : 763575 : skb->sk = NULL;
2065 : 763575 : atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
2066 : 763575 : sk_mem_uncharge(sk, skb->truesize);
2067 : 763575 : __skb_unlink(skb, &sk->sk_receive_queue);
2068 : 763575 : skb_attempt_defer_free(skb);
2069 : 763575 : }
2070 : :
2071 : 1139929 : static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
2072 : : size_t len, int flags, int copied_total,
2073 : : struct scm_timestamping_internal *tss,
2074 : : int *cmsg_flags, struct sk_buff **last)
2075 : : {
2076 [ - + ]: 1139929 : struct mptcp_sock *msk = mptcp_sk(sk);
2077 : 1139929 : struct sk_buff *skb, *tmp;
2078 : 1139929 : int total_data_len = 0;
2079 : 1139929 : int copied = 0;
2080 : :
2081 [ + + ]: 1763117 : skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
2082 : 1133722 : u32 delta, offset = MPTCP_SKB_CB(skb)->offset;
2083 : 1133722 : u32 data_len = skb->len - offset;
2084 : 1133722 : u32 count;
2085 : 1133722 : int err;
2086 : :
2087 [ + + ]: 1133722 : if (flags & MSG_PEEK) {
2088 : : /* skip already peeked skbs */
2089 [ + + ]: 51921 : if (total_data_len + data_len <= copied_total) {
2090 : 9 : total_data_len += data_len;
2091 : 9 : *last = skb;
2092 : 9 : continue;
2093 : : }
2094 : :
2095 : : /* skip the already peeked data in the current skb */
2096 : 51912 : delta = copied_total - total_data_len;
2097 : 51912 : offset += delta;
2098 : 51912 : data_len -= delta;
2099 : : }
2100 : :
2101 : 1133713 : count = min_t(size_t, len - copied, data_len);
2102 [ + - ]: 1133713 : if (!(flags & MSG_TRUNC)) {
2103 : 1133713 : err = skb_copy_datagram_msg(skb, offset, msg, count);
2104 [ - + ]: 1133713 : if (unlikely(err < 0)) {
2105 [ # # ]: 0 : if (!copied)
2106 : : return err;
2107 : : break;
2108 : : }
2109 : : }
2110 : :
2111 [ + + ]: 1133713 : if (MPTCP_SKB_CB(skb)->has_rxtstamp) {
2112 : 719 : tcp_update_recv_tstamps(skb, tss);
2113 : 719 : *cmsg_flags |= MPTCP_CMSG_TS;
2114 : : }
2115 : :
2116 : 1133713 : copied += count;
2117 : :
2118 [ + + ]: 1133713 : if (!(flags & MSG_PEEK)) {
2119 : 1081801 : msk->bytes_consumed += count;
2120 [ + + ]: 1081801 : if (count < data_len) {
2121 : 434918 : MPTCP_SKB_CB(skb)->offset += count;
2122 : 434918 : MPTCP_SKB_CB(skb)->map_seq += count;
2123 : 434918 : break;
2124 : : }
2125 : :
2126 : 646883 : mptcp_eat_recv_skb(sk, skb);
2127 : : } else {
2128 : 51912 : *last = skb;
2129 : : }
2130 : :
2131 [ + + ]: 698795 : if (copied >= len)
2132 : : break;
2133 : : }
2134 : :
2135 : 1139929 : mptcp_rcv_space_adjust(msk, copied);
2136 : 1139929 : return copied;
2137 : : }
2138 : :
2139 : 2748 : static void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk)
2140 : : {
2141 [ - + ]: 2748 : const struct tcp_sock *tp = tcp_sk(ssk);
2142 : :
2143 : 2748 : msk->rcvspace_init = 1;
2144 : 2748 : msk->rcvq_space.copied = 0;
2145 : :
2146 : : /* initial rcv_space offering made to peer */
2147 : 2748 : msk->rcvq_space.space = min_t(u32, tp->rcv_wnd,
2148 : : TCP_INIT_CWND * tp->advmss);
2149 [ + + ]: 2748 : if (msk->rcvq_space.space == 0)
2150 : 1 : msk->rcvq_space.space = TCP_INIT_CWND * TCP_MSS_DEFAULT;
2151 : 2748 : }
2152 : :
2153 : : /* receive buffer autotuning. See tcp_rcv_space_adjust for more information.
2154 : : *
2155 : : * Only difference: Use lowest rtt estimate of the subflows in use, see
2156 : : * mptcp_rcv_rtt_update() and mptcp_rtt_us_est().
2157 : : */
2158 : 1410149 : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
2159 : : {
2160 : 1410149 : struct mptcp_subflow_context *subflow;
2161 : 1410149 : struct sock *sk = (struct sock *)msk;
2162 : 1410149 : u32 time, rtt_us;
2163 : 1410149 : u64 mstamp;
2164 : :
2165 : 1410149 : msk_owned_by_me(msk);
2166 : :
2167 [ + + ]: 1410149 : if (copied <= 0)
2168 : : return;
2169 : :
2170 [ + + ]: 1122617 : if (!msk->rcvspace_init)
2171 : 1126 : mptcp_rcv_space_init(msk, msk->first);
2172 : :
2173 : 1122617 : msk->rcvq_space.copied += copied;
2174 : :
2175 : 1122617 : mstamp = mptcp_stamp();
2176 : 1122617 : time = tcp_stamp_us_delta(mstamp, READ_ONCE(msk->rcvq_space.time));
2177 : :
2178 : 1122617 : rtt_us = mptcp_rtt_us_est(msk);
2179 [ + + + + ]: 1122617 : if (rtt_us == U32_MAX || time < (rtt_us >> 3))
2180 : : return;
2181 : :
2182 : 107788 : copied = msk->rcvq_space.copied;
2183 : 107788 : copied -= mptcp_inq_hint(sk);
2184 [ + + ]: 107788 : if (copied <= msk->rcvq_space.space)
2185 : 102199 : goto new_measure;
2186 : :
2187 : 5589 : trace_mptcp_rcvbuf_grow(sk, time);
2188 [ + + ]: 5589 : if (mptcp_rcvbuf_grow(sk, copied)) {
2189 : : /* Make subflows follow along. If we do not do this, we
2190 : : * get drops at subflow level if skbs can't be moved to
2191 : : * the mptcp rx queue fast enough (announced rcv_win can
2192 : : * exceed ssk->sk_rcvbuf).
2193 : : */
2194 [ + + ]: 6245 : mptcp_for_each_subflow(msk, subflow) {
2195 : 3247 : struct sock *ssk;
2196 : 3247 : bool slow;
2197 : :
2198 : 3247 : ssk = mptcp_subflow_tcp_sock(subflow);
2199 : 3247 : slow = lock_sock_fast(ssk);
2200 : : /* subflows can be added before tcp_init_transfer() */
2201 [ - + + - ]: 3247 : if (tcp_sk(ssk)->rcvq_space.space)
2202 : 3247 : tcp_rcvbuf_grow(ssk, copied);
2203 : 3247 : unlock_sock_fast(ssk, slow);
2204 : : }
2205 : : }
2206 : :
2207 : 5589 : new_measure:
2208 : 107788 : msk->rcvq_space.copied = 0;
2209 : 107788 : msk->rcvq_space.time = mstamp;
2210 : : }
2211 : :
2212 : 166825 : static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delta)
2213 : : {
2214 : 166825 : struct sk_buff *skb = list_first_entry(skbs, struct sk_buff, list);
2215 [ - + ]: 166825 : struct mptcp_sock *msk = mptcp_sk(sk);
2216 : 166825 : bool moved = false;
2217 : :
2218 : 166825 : *delta = 0;
2219 : 233701 : while (1) {
2220 : : /* If the msk recvbuf is full stop, don't drop */
2221 [ + + ]: 200263 : if (sk_rmem_alloc_get(sk) > sk->sk_rcvbuf)
2222 : : break;
2223 : :
2224 : 200182 : prefetch(skb->next);
2225 : 200182 : list_del(&skb->list);
2226 : 200182 : *delta += skb->truesize;
2227 : :
2228 : 200182 : moved |= __mptcp_move_skb(sk, skb);
2229 [ + + ]: 200182 : if (list_empty(skbs))
2230 : : break;
2231 : :
2232 : 33438 : skb = list_first_entry(skbs, struct sk_buff, list);
2233 : : }
2234 : :
2235 : 166825 : __mptcp_ofo_queue(msk);
2236 [ + + ]: 166825 : if (moved)
2237 : 163367 : mptcp_check_data_fin((struct sock *)msk);
2238 : 166825 : return moved;
2239 : : }
2240 : :
2241 : 2305087 : static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
2242 : : {
2243 [ - + ]: 2305087 : struct mptcp_sock *msk = mptcp_sk(sk);
2244 : :
2245 : : /* After CG initialization, subflows should never add skb before
2246 : : * gaining the CG themself.
2247 : : */
2248 [ + + + + : 2305087 : DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
- + ]
2249 : : mem_cgroup_from_sk(sk));
2250 : :
2251 : : /* Don't spool the backlog if the rcvbuf is full. */
2252 [ + + ]: 2305087 : if (list_empty(&msk->backlog_list) ||
2253 [ + + ]: 167199 : sk_rmem_alloc_get(sk) > sk->sk_rcvbuf)
2254 : 1387063 : return false;
2255 : :
2256 [ + - ]: 166825 : INIT_LIST_HEAD(skbs);
2257 [ + - ]: 166825 : list_splice_init(&msk->backlog_list, skbs);
2258 : : return true;
2259 : : }
2260 : :
2261 : 166825 : static void mptcp_backlog_spooled(struct sock *sk, u32 moved,
2262 : : struct list_head *skbs)
2263 : : {
2264 [ - + ]: 166825 : struct mptcp_sock *msk = mptcp_sk(sk);
2265 : :
2266 : 166825 : WRITE_ONCE(msk->backlog_len, msk->backlog_len - moved);
2267 [ + + ]: 166825 : list_splice(skbs, &msk->backlog_list);
2268 : 166825 : }
2269 : :
2270 : 15033 : static bool mptcp_move_skbs(struct sock *sk)
2271 : : {
2272 : 15033 : struct list_head skbs;
2273 : 15033 : bool enqueued = false;
2274 : 15033 : u32 moved;
2275 : :
2276 : 15033 : mptcp_data_lock(sk);
2277 [ + + ]: 45584 : while (mptcp_can_spool_backlog(sk, &skbs)) {
2278 : 15518 : mptcp_data_unlock(sk);
2279 : 15518 : enqueued |= __mptcp_move_skbs(sk, &skbs, &moved);
2280 : :
2281 : 15518 : mptcp_data_lock(sk);
2282 : 15518 : mptcp_backlog_spooled(sk, moved, &skbs);
2283 : : }
2284 : 15033 : mptcp_data_unlock(sk);
2285 : :
2286 [ + + + - ]: 15033 : if (enqueued && mptcp_epollin_ready(sk))
2287 : 14430 : sk->sk_data_ready(sk);
2288 : :
2289 : 15033 : return enqueued;
2290 : : }
2291 : :
2292 : 108213 : static unsigned int mptcp_inq_hint(const struct sock *sk)
2293 : : {
2294 [ - + ]: 108213 : const struct mptcp_sock *msk = mptcp_sk(sk);
2295 : 108213 : const struct sk_buff *skb;
2296 : :
2297 [ + + ]: 108213 : skb = skb_peek(&sk->sk_receive_queue);
2298 [ + - ]: 69994 : if (skb) {
2299 : 69994 : u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
2300 : :
2301 [ + - ]: 69994 : if (hint_val >= INT_MAX)
2302 : : return INT_MAX;
2303 : :
2304 : 69994 : return (unsigned int)hint_val;
2305 : : }
2306 : :
2307 [ + + + + ]: 38219 : if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
2308 : 283 : return 1;
2309 : :
2310 : : return 0;
2311 : : }
2312 : :
2313 : 1005617 : static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
2314 : : int flags)
2315 : : {
2316 [ - + ]: 1005617 : struct mptcp_sock *msk = mptcp_sk(sk);
2317 : 1005617 : struct scm_timestamping_internal tss;
2318 : 1005617 : int copied = 0, cmsg_flags = 0;
2319 : 1005617 : int target;
2320 : 1005617 : long timeo;
2321 : :
2322 : : /* MSG_ERRQUEUE is really a no-op till we support IP_RECVERR */
2323 [ - + ]: 1005617 : if (unlikely(flags & MSG_ERRQUEUE))
2324 : 0 : return inet_recv_error(sk, msg, len);
2325 : :
2326 : 1005617 : lock_sock(sk);
2327 [ - + ]: 1005617 : if (unlikely(sk->sk_state == TCP_LISTEN)) {
2328 : 0 : copied = -ENOTCONN;
2329 : 0 : goto out_err;
2330 : : }
2331 : :
2332 : 1005617 : mptcp_rps_record_subflows(msk);
2333 : :
2334 [ + + ]: 1005617 : timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
2335 : :
2336 : 1005617 : len = min_t(size_t, len, INT_MAX);
2337 [ + + ]: 1005617 : target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
2338 : :
2339 [ + + ]: 1005617 : if (unlikely(msk->recvmsg_inq))
2340 : 425 : cmsg_flags = MPTCP_CMSG_INQ;
2341 : :
2342 [ + + ]: 1145784 : while (copied < len) {
2343 : 1139929 : struct sk_buff *last = NULL;
2344 : 1139929 : int err, bytes_read;
2345 : :
2346 : 1139929 : bytes_read = __mptcp_recvmsg_mskq(sk, msg, len - copied, flags,
2347 : : copied, &tss, &cmsg_flags,
2348 : : &last);
2349 [ - + ]: 1139929 : if (unlikely(bytes_read < 0)) {
2350 [ # # ]: 0 : if (!copied)
2351 : 0 : copied = bytes_read;
2352 : 0 : goto out_err;
2353 : : }
2354 : :
2355 : 1139929 : copied += bytes_read;
2356 : :
2357 [ + + + + ]: 1139929 : if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
2358 : 11299 : continue;
2359 : :
2360 : : /* only the MPTCP socket status is relevant here. The exit
2361 : : * conditions mirror closely tcp_recvmsg()
2362 : : */
2363 [ + + ]: 1128630 : if (copied >= target)
2364 : : break;
2365 : :
2366 [ + + ]: 130858 : if (copied) {
2367 [ + - ]: 5 : if (tcp_recv_should_stop(sk) ||
2368 [ + - ]: 5 : !timeo)
2369 : : break;
2370 : : } else {
2371 [ + + ]: 130853 : if (sk->sk_err) {
2372 : 2 : copied = sock_error(sk);
2373 : 2 : break;
2374 : : }
2375 : :
2376 [ + + ]: 130851 : if (sk->sk_shutdown & RCV_SHUTDOWN)
2377 : : break;
2378 : :
2379 [ + + ]: 128881 : if (sk->sk_state == TCP_CLOSE) {
2380 : : copied = -ENOTCONN;
2381 : : break;
2382 : : }
2383 : :
2384 [ + - ]: 128863 : if (!timeo) {
2385 : : copied = -EAGAIN;
2386 : : break;
2387 : : }
2388 : :
2389 [ - + ]: 128863 : if (signal_pending(current)) {
2390 [ - - ]: 6 : copied = sock_intr_errno(timeo);
2391 : : break;
2392 : : }
2393 : : }
2394 : :
2395 [ - + - - ]: 128868 : pr_debug("block timeout %ld\n", timeo);
2396 : 128868 : mptcp_cleanup_rbuf(msk, copied);
2397 : 128868 : err = sk_wait_data(sk, &timeo, last);
2398 [ - + ]: 128868 : if (err < 0) {
2399 : 0 : err = copied ? : err;
2400 : 0 : goto out_err;
2401 : : }
2402 : : }
2403 : :
2404 : 1005617 : mptcp_cleanup_rbuf(msk, copied);
2405 : :
2406 : 1005617 : out_err:
2407 [ + + + - ]: 1005617 : if (cmsg_flags && copied >= 0) {
2408 [ + + ]: 686 : if (cmsg_flags & MPTCP_CMSG_TS)
2409 : 678 : tcp_recv_timestamp(msg, sk, &tss);
2410 : :
2411 [ + + ]: 686 : if (cmsg_flags & MPTCP_CMSG_INQ) {
2412 : 425 : unsigned int inq = mptcp_inq_hint(sk);
2413 : :
2414 : 425 : put_cmsg(msg, SOL_TCP, TCP_CM_INQ, sizeof(inq), &inq);
2415 : : }
2416 : : }
2417 : :
2418 [ - + - - ]: 1005617 : pr_debug("msk=%p rx queue empty=%d copied=%d\n",
2419 : : msk, skb_queue_empty(&sk->sk_receive_queue), copied);
2420 : :
2421 : 1005617 : release_sock(sk);
2422 : 1005617 : return copied;
2423 : : }
2424 : :
2425 : 6978 : static void mptcp_retransmit_timer(struct timer_list *t)
2426 : : {
2427 : 6978 : struct sock *sk = timer_container_of(sk, t, mptcp_retransmit_timer);
2428 [ - + ]: 6978 : struct mptcp_sock *msk = mptcp_sk(sk);
2429 : :
2430 : 6978 : bh_lock_sock(sk);
2431 [ + + ]: 6978 : if (!sock_owned_by_user(sk)) {
2432 : : /* we need a process context to retransmit */
2433 [ + + ]: 8457 : if (!test_and_set_bit(MPTCP_WORK_RTX, &msk->flags))
2434 : 5330 : mptcp_schedule_work(sk);
2435 : : } else {
2436 : : /* delegate our work to tcp_release_cb() */
2437 [ - + - - : 1634 : __set_bit(MPTCP_RETRANSMIT, &msk->cb_flags);
- - ]
2438 : : }
2439 : 6978 : bh_unlock_sock(sk);
2440 : 6978 : sock_put(sk);
2441 : 6978 : }
2442 : :
2443 : 131 : static void mptcp_tout_timer(struct timer_list *t)
2444 : : {
2445 : 131 : struct inet_connection_sock *icsk =
2446 : 131 : timer_container_of(icsk, t, mptcp_tout_timer);
2447 : 131 : struct sock *sk = &icsk->icsk_inet.sk;
2448 : :
2449 : 131 : mptcp_schedule_work(sk);
2450 : 131 : sock_put(sk);
2451 : 131 : }
2452 : :
2453 : : /* Find an idle subflow. Return NULL if there is unacked data at tcp
2454 : : * level.
2455 : : *
2456 : : * A backup subflow is returned only if that is the only kind available.
2457 : : */
2458 : 4820 : struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk)
2459 : : {
2460 : 4820 : struct sock *backup = NULL, *pick = NULL;
2461 : 4820 : struct mptcp_subflow_context *subflow;
2462 : 4820 : int min_stale_count = INT_MAX;
2463 : :
2464 [ + + ]: 12246 : mptcp_for_each_subflow(msk, subflow) {
2465 : 7426 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2466 : :
2467 [ + + ]: 7426 : if (!__mptcp_subflow_active(subflow))
2468 : 1828 : continue;
2469 : :
2470 : : /* still data outstanding at TCP level? skip this */
2471 [ + + ]: 5598 : if (!tcp_rtx_and_write_queues_empty(ssk)) {
2472 : 2569 : mptcp_pm_subflow_chk_stale(msk, ssk);
2473 : 2569 : min_stale_count = min_t(int, min_stale_count, subflow->stale_count);
2474 : 2569 : continue;
2475 : : }
2476 : :
2477 [ + + + + ]: 3029 : if (subflow->backup || subflow->request_bkup) {
2478 [ + + ]: 80 : if (!backup)
2479 : 69 : backup = ssk;
2480 : 80 : continue;
2481 : : }
2482 : :
2483 [ + + ]: 2949 : if (!pick)
2484 : 2204 : pick = ssk;
2485 : : }
2486 : :
2487 [ + + ]: 4820 : if (pick)
2488 : : return pick;
2489 : :
2490 : : /* use backup only if there are no progresses anywhere */
2491 [ + + ]: 2616 : return min_stale_count > 1 ? backup : NULL;
2492 : : }
2493 : :
2494 : 2198 : bool __mptcp_retransmit_pending_data(struct sock *sk)
2495 : : {
2496 : 2198 : struct mptcp_data_frag *cur, *rtx_head;
2497 [ - + ]: 2198 : struct mptcp_sock *msk = mptcp_sk(sk);
2498 : :
2499 [ + + ]: 2198 : if (__mptcp_check_fallback(msk))
2500 : : return false;
2501 : :
2502 : : /* the closing socket has some data untransmitted and/or unacked:
2503 : : * some data in the mptcp rtx queue has not really xmitted yet.
2504 : : * keep it simple and re-inject the whole mptcp level rtx queue
2505 : : */
2506 : 2125 : mptcp_data_lock(sk);
2507 : 2125 : __mptcp_clean_una_wakeup(sk);
2508 : 2125 : rtx_head = mptcp_rtx_head(sk);
2509 [ + + ]: 2125 : if (!rtx_head) {
2510 : 2057 : mptcp_data_unlock(sk);
2511 : 2057 : return false;
2512 : : }
2513 : :
2514 : 68 : msk->recovery_snd_nxt = msk->snd_nxt;
2515 : 68 : msk->recovery = true;
2516 : 68 : mptcp_data_unlock(sk);
2517 : :
2518 : 68 : msk->first_pending = rtx_head;
2519 : 68 : msk->snd_burst = 0;
2520 : :
2521 : : /* be sure to clear the "sent status" on all re-injected fragments */
2522 [ + + ]: 4075 : list_for_each_entry(cur, &msk->rtx_queue, list) {
2523 [ + + ]: 4029 : if (!cur->already_sent)
2524 : : break;
2525 : 4007 : cur->already_sent = 0;
2526 : : }
2527 : :
2528 : : return true;
2529 : : }
2530 : :
2531 : : /* flags for __mptcp_close_ssk() */
2532 : : #define MPTCP_CF_PUSH BIT(1)
2533 : :
2534 : : /* be sure to send a reset only if the caller asked for it, also
2535 : : * clean completely the subflow status when the subflow reaches
2536 : : * TCP_CLOSE state
2537 : : */
2538 : 1614 : static void __mptcp_subflow_disconnect(struct sock *ssk,
2539 : : struct mptcp_subflow_context *subflow,
2540 : : bool fastclosing)
2541 : : {
2542 [ - + + + : 1614 : if (((1 << ssk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
+ + ]
[ + + + + ]
2543 : : fastclosing) {
2544 : : /* The MPTCP code never wait on the subflow sockets, TCP-level
2545 : : * disconnect should never fail
2546 : : */
2547 [ - + ]: 1590 : WARN_ON_ONCE(tcp_disconnect(ssk, 0));
2548 : 1590 : mptcp_subflow_ctx_reset(subflow);
2549 : : } else {
2550 : 24 : tcp_shutdown(ssk, SEND_SHUTDOWN);
2551 : : }
2552 : 1614 : }
2553 : :
2554 : 2179 : static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
2555 : : {
2556 [ - + ]: 2179 : struct mptcp_sock *msk = mptcp_sk(sk);
2557 : 2179 : struct sk_buff *skb;
2558 : :
2559 : 2179 : mptcp_data_lock(sk);
2560 [ + + ]: 2187 : list_for_each_entry(skb, &msk->backlog_list, list) {
2561 [ + - ]: 8 : if (skb->sk != ssk)
2562 : 8 : continue;
2563 : :
2564 : 0 : atomic_sub(skb->truesize, &skb->sk->sk_rmem_alloc);
2565 : 0 : skb->sk = NULL;
2566 : : }
2567 : 2179 : mptcp_data_unlock(sk);
2568 : 2179 : }
2569 : :
2570 : : /* subflow sockets can be either outgoing (connect) or incoming
2571 : : * (accept).
2572 : : *
2573 : : * Outgoing subflows use in-kernel sockets.
2574 : : * Incoming subflows do not have their own 'struct socket' allocated,
2575 : : * so we need to use tcp_close() after detaching them from the mptcp
2576 : : * parent socket.
2577 : : */
2578 : 7803 : static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
2579 : : struct mptcp_subflow_context *subflow,
2580 : : unsigned int flags)
2581 : : {
2582 [ - + ]: 7803 : struct mptcp_sock *msk = mptcp_sk(sk);
2583 : 7803 : bool dispose_it, need_push = false;
2584 : 7803 : int fwd_remaining;
2585 : :
2586 : : /* Do not pass RX data to the msk, even if the subflow socket is not
2587 : : * going to be freed (i.e. even for the first subflow on graceful
2588 : : * subflow close.
2589 : : */
2590 : 7803 : lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
2591 : 7803 : subflow->closing = 1;
2592 : :
2593 [ + + ]: 7803 : if (flags & MPTCP_CF_PUSH)
2594 : 2179 : mptcp_cleanup_ssk_backlog(sk, ssk);
2595 : :
2596 : : /* Borrow the fwd allocated page left-over; fwd memory for the subflow
2597 : : * could be negative at this point, but will be reach zero soon - when
2598 : : * the data allocated using such fragment will be freed.
2599 : : */
2600 [ + + ]: 7803 : if (subflow->lent_mem_frag) {
2601 : 2863 : fwd_remaining = PAGE_SIZE - subflow->lent_mem_frag;
2602 : 2863 : sk_forward_alloc_add(sk, fwd_remaining);
2603 : 2863 : sk_forward_alloc_add(ssk, -fwd_remaining);
2604 : 2863 : subflow->lent_mem_frag = 0;
2605 : : }
2606 : :
2607 : : /* If the first subflow moved to a close state before accept, e.g. due
2608 : : * to an incoming reset or listener shutdown, the subflow socket is
2609 : : * already deleted by inet_child_forget() and the mptcp socket can't
2610 : : * survive too.
2611 : : */
2612 [ + + + + : 7839 : if (msk->in_accept_queue && msk->first == ssk &&
- + ]
2613 [ - - ]: 36 : (sock_flag(sk, SOCK_DEAD) || sock_flag(ssk, SOCK_DEAD))) {
2614 : : /* ensure later check in mptcp_worker() will dispose the msk */
2615 : 36 : sock_set_flag(sk, SOCK_DEAD);
2616 : 36 : mptcp_set_close_tout(sk, tcp_jiffies32 - (mptcp_close_timeout(sk) + 1));
2617 : 36 : mptcp_subflow_drop_ctx(ssk);
2618 : 36 : goto out_release;
2619 : : }
2620 : :
2621 [ + + + + ]: 7767 : dispose_it = msk->free_first || ssk != msk->first;
2622 : : if (dispose_it)
2623 : 6153 : list_del(&subflow->node);
2624 : :
2625 [ + + + - ]: 7767 : if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
2626 : 420 : tcp_set_state(ssk, TCP_CLOSE);
2627 : :
2628 [ + + + + ]: 7767 : need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
2629 [ + + ]: 7767 : if (!dispose_it) {
2630 : 1614 : __mptcp_subflow_disconnect(ssk, subflow, msk->fastclosing);
2631 : 1614 : release_sock(ssk);
2632 : :
2633 : 1614 : goto out;
2634 : : }
2635 : :
2636 : 6153 : subflow->disposable = 1;
2637 : :
2638 : : /* if ssk hit tcp_done(), tcp_cleanup_ulp() cleared the related ops
2639 : : * the ssk has been already destroyed, we just need to release the
2640 : : * reference owned by msk;
2641 : : */
2642 [ - + ]: 6153 : if (!inet_csk(ssk)->icsk_ulp_ops) {
2643 [ # # ]: 0 : WARN_ON_ONCE(!sock_flag(ssk, SOCK_DEAD));
2644 [ # # ]: 0 : kfree_rcu(subflow, rcu);
2645 : : } else {
2646 : : /* otherwise tcp will dispose of the ssk and subflow ctx */
2647 : 6153 : __tcp_close(ssk, 0);
2648 : :
2649 : : /* close acquired an extra ref */
2650 : 6153 : __sock_put(ssk);
2651 : : }
2652 : :
2653 : 6189 : out_release:
2654 : 6189 : __mptcp_subflow_error_report(sk, ssk);
2655 : 6189 : release_sock(ssk);
2656 : :
2657 : 6189 : sock_put(ssk);
2658 : :
2659 [ + + ]: 6189 : if (ssk == msk->first)
2660 : 4951 : WRITE_ONCE(msk->first, NULL);
2661 : :
2662 : 1238 : out:
2663 : 7803 : __mptcp_sync_sndbuf(sk);
2664 [ + + ]: 7803 : if (need_push)
2665 : 49 : __mptcp_push_pending(sk, 0);
2666 : :
2667 : : /* Catch every 'all subflows closed' scenario, including peers silently
2668 : : * closing them, e.g. due to timeout.
2669 : : * For established sockets, allow an additional timeout before closing,
2670 : : * as the protocol can still create more subflows.
2671 : : */
2672 [ + + + + : 11452 : if (list_is_singular(&msk->conn_list) && msk->first &&
+ + ]
[ + + + + ]
2673 [ + - ]: 30 : inet_sk_state_load(msk->first) == TCP_CLOSE) {
2674 [ + + + - ]: 1578 : if (sk->sk_state != TCP_ESTABLISHED ||
2675 [ - + ]: 26 : msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) {
2676 : 1552 : mptcp_set_state(sk, TCP_CLOSE);
2677 : 1552 : mptcp_close_wake_up(sk);
2678 : : } else {
2679 : 26 : mptcp_start_tout_timer(sk);
2680 : : }
2681 : : }
2682 : 7803 : }
2683 : :
2684 : 2228 : void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
2685 : : struct mptcp_subflow_context *subflow)
2686 : : {
2687 : : /* The first subflow can already be closed or disconnected */
2688 [ + + + + ]: 2228 : if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
2689 : : return;
2690 : :
2691 : 2179 : subflow->close_event_done = true;
2692 : :
2693 [ + + ]: 2179 : if (sk->sk_state == TCP_ESTABLISHED)
2694 [ - + ]: 328 : mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
2695 : :
2696 : : /* subflow aborted before reaching the fully_established status
2697 : : * attempt the creation of the next subflow
2698 : : */
2699 [ - + ]: 2179 : mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
2700 : :
2701 : 2179 : __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
2702 : : }
2703 : :
2704 : 0 : static unsigned int mptcp_sync_mss(struct sock *sk, u32 pmtu)
2705 : : {
2706 : 0 : return 0;
2707 : : }
2708 : :
2709 : 1582 : static void __mptcp_close_subflow(struct sock *sk)
2710 : : {
2711 : 1582 : struct mptcp_subflow_context *subflow, *tmp;
2712 [ - + ]: 1582 : struct mptcp_sock *msk = mptcp_sk(sk);
2713 : :
2714 : 1582 : might_sleep();
2715 : :
2716 [ + + ]: 3979 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2717 : 2397 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2718 : 2397 : int ssk_state = inet_sk_state_load(ssk);
2719 : :
2720 [ + + + + ]: 2397 : if (ssk_state != TCP_CLOSE &&
2721 [ + + ]: 98 : (ssk_state != TCP_CLOSE_WAIT ||
2722 [ - + ]: 42 : inet_sk_state_load(sk) != TCP_ESTABLISHED ||
[ # # # # ]
2723 : 42 : __mptcp_check_fallback(msk)))
2724 : 367 : continue;
2725 : :
2726 : : /* 'subflow_data_ready' will re-sched once rx queue is empty */
2727 [ - + ]: 2030 : if (!skb_queue_empty_lockless(&ssk->sk_receive_queue))
2728 : 0 : continue;
2729 : :
2730 : 2030 : mptcp_close_ssk(sk, ssk, subflow);
2731 : : }
2732 : :
2733 : 1582 : }
2734 : :
2735 : 12514 : static bool mptcp_close_tout_expired(const struct sock *sk)
2736 : : {
2737 [ + + ]: 12514 : if (!inet_csk(sk)->icsk_mtup.probe_timestamp ||
2738 [ + + ]: 4850 : sk->sk_state == TCP_CLOSE)
2739 : : return false;
2740 : :
2741 : 3637 : return time_after32(tcp_jiffies32,
2742 : : inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
2743 : : }
2744 : :
2745 : 12514 : static void mptcp_check_fastclose(struct mptcp_sock *msk)
2746 : : {
2747 : 12514 : struct mptcp_subflow_context *subflow, *tmp;
2748 : 12514 : struct sock *sk = (struct sock *)msk;
2749 : :
2750 [ - + + + ]: 12514 : if (likely(!READ_ONCE(msk->rcv_fastclose)))
[ + + ]
2751 : : return;
2752 : :
2753 : 233 : mptcp_token_destroy(msk);
2754 : :
2755 [ + + ]: 510 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2756 : 277 : struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
2757 : 277 : bool slow;
2758 : :
2759 : 277 : slow = lock_sock_fast(tcp_sk);
2760 [ + + ]: 277 : if (tcp_sk->sk_state != TCP_CLOSE) {
2761 : 26 : mptcp_send_active_reset_reason(tcp_sk);
2762 : 26 : tcp_set_state(tcp_sk, TCP_CLOSE);
2763 : : }
2764 : 277 : unlock_sock_fast(tcp_sk, slow);
2765 : : }
2766 : :
2767 : : /* Mirror the tcp_reset() error propagation */
2768 [ - + + - ]: 233 : switch (sk->sk_state) {
2769 : : case TCP_SYN_SENT:
2770 : 0 : WRITE_ONCE(sk->sk_err, ECONNREFUSED);
2771 : 0 : break;
2772 : : case TCP_CLOSE_WAIT:
2773 : 14 : WRITE_ONCE(sk->sk_err, EPIPE);
2774 : 14 : break;
2775 : : case TCP_CLOSE:
2776 : : return;
2777 : : default:
2778 : 219 : WRITE_ONCE(sk->sk_err, ECONNRESET);
2779 : : }
2780 : :
2781 : 233 : mptcp_set_state(sk, TCP_CLOSE);
2782 : 233 : WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
2783 : 233 : smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
2784 : 233 : set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
2785 : :
2786 : : /* the calling mptcp_worker will properly destroy the socket */
2787 [ + + ]: 233 : if (sock_flag(sk, SOCK_DEAD))
2788 : : return;
2789 : :
2790 : 131 : sk->sk_state_change(sk);
2791 : 131 : sk_error_report(sk);
2792 : : }
2793 : :
2794 : 6756 : static void __mptcp_retrans(struct sock *sk)
2795 : : {
2796 : 6756 : struct mptcp_sendmsg_info info = { .data_lock_held = true, };
2797 [ - + ]: 6756 : struct mptcp_sock *msk = mptcp_sk(sk);
2798 : 6756 : struct mptcp_subflow_context *subflow;
2799 : 6756 : struct mptcp_data_frag *dfrag;
2800 : 6756 : struct sock *ssk;
2801 : 6756 : int ret, err;
2802 : 6756 : u16 len = 0;
2803 : :
2804 : 6756 : mptcp_clean_una_wakeup(sk);
2805 : :
2806 : : /* first check ssk: need to kick "stale" logic */
2807 : 6756 : err = mptcp_sched_get_retrans(msk);
2808 : 6756 : dfrag = mptcp_rtx_head(sk);
2809 [ + + ]: 6756 : if (!dfrag) {
2810 [ + + ]: 3120 : if (mptcp_data_fin_enabled(msk)) {
2811 : 1345 : struct inet_connection_sock *icsk = inet_csk(sk);
2812 : :
2813 : 1345 : WRITE_ONCE(icsk->icsk_retransmits,
2814 : : icsk->icsk_retransmits + 1);
2815 : 1345 : mptcp_set_datafin_timeout(sk);
2816 : 1345 : mptcp_send_ack(msk);
2817 : :
2818 : 1345 : goto reset_timer;
2819 : : }
2820 : :
2821 [ + + ]: 1775 : if (!mptcp_send_head(sk))
2822 : 1665 : goto clear_scheduled;
2823 : :
2824 : 110 : goto reset_timer;
2825 : : }
2826 : :
2827 [ + + ]: 3636 : if (err)
2828 : 3396 : goto reset_timer;
2829 : :
2830 [ + + ]: 714 : mptcp_for_each_subflow(msk, subflow) {
2831 [ - + + + ]: 474 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
2832 : 240 : u16 copied = 0;
2833 : :
2834 : 240 : mptcp_subflow_set_scheduled(subflow, false);
2835 : :
2836 : 240 : ssk = mptcp_subflow_tcp_sock(subflow);
2837 : :
2838 : 240 : lock_sock(ssk);
2839 : :
2840 : : /* limit retransmission to the bytes already sent on some subflows */
2841 : 240 : info.sent = 0;
2842 [ - + + + ]: 240 : info.limit = READ_ONCE(msk->csum_enabled) ? dfrag->data_len :
[ + + ]
2843 : : dfrag->already_sent;
2844 : :
2845 : : /*
2846 : : * make the whole retrans decision, xmit, disallow
2847 : : * fallback atomic, note that we can't retrans even
2848 : : * when an infinite fallback is in progress, i.e. new
2849 : : * subflows are disallowed.
2850 : : */
2851 : 240 : spin_lock_bh(&msk->fallback_lock);
2852 [ + - ]: 240 : if (__mptcp_check_fallback(msk) ||
2853 [ - + - + ]: 240 : !msk->allow_subflows) {
[ - + ]
2854 : 0 : spin_unlock_bh(&msk->fallback_lock);
2855 : 0 : release_sock(ssk);
2856 : 0 : goto clear_scheduled;
2857 : : }
2858 : :
2859 [ + + ]: 482 : while (info.sent < info.limit) {
2860 : 242 : ret = mptcp_sendmsg_frag(sk, ssk, dfrag, &info);
2861 [ + - ]: 242 : if (ret <= 0)
2862 : : break;
2863 : :
2864 [ + - ]: 242 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RETRANSSEGS);
2865 : 242 : copied += ret;
2866 : 242 : info.sent += ret;
2867 : : }
2868 [ + - ]: 240 : if (copied) {
2869 : 240 : len = max(copied, len);
2870 [ - + ]: 240 : tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
2871 : : info.size_goal);
2872 : 240 : msk->allow_infinite_fallback = false;
2873 : : }
2874 : 240 : spin_unlock_bh(&msk->fallback_lock);
2875 : :
2876 : 240 : release_sock(ssk);
2877 : : }
2878 : : }
2879 : :
2880 : 240 : msk->bytes_retrans += len;
2881 : 240 : dfrag->already_sent = max(dfrag->already_sent, len);
2882 : :
2883 : : /* With csum enabled retransmission can send new data. */
2884 [ + - ]: 240 : if (after64(dfrag->already_sent + dfrag->data_seq, msk->snd_nxt))
2885 : 0 : WRITE_ONCE(msk->snd_nxt, dfrag->already_sent + dfrag->data_seq);
2886 : :
2887 : 240 : reset_timer:
2888 : 5091 : mptcp_check_and_set_pending(sk);
2889 : :
2890 [ + + ]: 5091 : if (!mptcp_rtx_timer_pending(sk))
2891 : 89 : mptcp_reset_rtx_timer(sk);
2892 : :
2893 : 5002 : clear_scheduled:
2894 : : /* If no rtx data was available or in case of fallback, there
2895 : : * could be left-over scheduled subflows; clear them all
2896 : : * or later xmit could use bad ones
2897 : : */
2898 [ + + ]: 16112 : mptcp_for_each_subflow(msk, subflow)
2899 [ - + + + ]: 9356 : if (READ_ONCE(subflow->scheduled))
[ + + ]
2900 : 1988 : mptcp_subflow_set_scheduled(subflow, false);
2901 : 6756 : }
2902 : :
2903 : : /* schedule the timeout timer for the relevant event: either close timeout
2904 : : * or mp_fail timeout. The close timeout takes precedence on the mp_fail one
2905 : : */
2906 : 1422 : void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout)
2907 : : {
2908 : 1422 : struct sock *sk = (struct sock *)msk;
2909 : 1422 : unsigned long timeout, close_timeout;
2910 : :
2911 [ + + + - ]: 1422 : if (!fail_tout && !inet_csk(sk)->icsk_mtup.probe_timestamp)
2912 : : return;
2913 : :
2914 : 2844 : close_timeout = (unsigned long)inet_csk(sk)->icsk_mtup.probe_timestamp -
2915 : 1422 : tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
2916 : :
2917 : : /* the close timeout takes precedence on the fail one, and here at least one of
2918 : : * them is active
2919 : : */
2920 [ + + ]: 1422 : timeout = inet_csk(sk)->icsk_mtup.probe_timestamp ? close_timeout : fail_tout;
2921 : :
2922 : 1422 : sk_reset_timer(sk, &inet_csk(sk)->mptcp_tout_timer, timeout);
2923 : : }
2924 : :
2925 : 0 : static void mptcp_mp_fail_no_response(struct mptcp_sock *msk)
2926 : : {
2927 : 0 : struct sock *ssk = msk->first;
2928 : 0 : bool slow;
2929 : :
2930 [ # # ]: 0 : if (!ssk)
2931 : : return;
2932 : :
2933 [ # # # # ]: 0 : pr_debug("MP_FAIL doesn't respond, reset the subflow\n");
2934 : :
2935 : 0 : slow = lock_sock_fast(ssk);
2936 : 0 : mptcp_subflow_reset(ssk);
2937 : 0 : WRITE_ONCE(mptcp_subflow_ctx(ssk)->fail_tout, 0);
2938 : 0 : unlock_sock_fast(ssk, slow);
2939 : : }
2940 : :
2941 : 5624 : static void mptcp_backlog_purge(struct sock *sk)
2942 : : {
2943 [ - + ]: 5624 : struct mptcp_sock *msk = mptcp_sk(sk);
2944 : 5624 : struct sk_buff *tmp, *skb;
2945 : 5624 : LIST_HEAD(backlog);
2946 : :
2947 : 5624 : mptcp_data_lock(sk);
2948 [ - + ]: 5624 : list_splice_init(&msk->backlog_list, &backlog);
2949 : 5624 : msk->backlog_len = 0;
2950 : 5624 : mptcp_data_unlock(sk);
2951 : :
2952 [ - + ]: 5624 : list_for_each_entry_safe(skb, tmp, &backlog, list) {
2953 : 0 : mptcp_borrow_fwdmem(sk, skb);
2954 : 0 : kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
2955 : : }
2956 : 5624 : sk_mem_reclaim(sk);
2957 : 5624 : }
2958 : :
2959 : 545 : static void mptcp_do_fastclose(struct sock *sk)
2960 : : {
2961 : 545 : struct mptcp_subflow_context *subflow, *tmp;
2962 [ - + ]: 545 : struct mptcp_sock *msk = mptcp_sk(sk);
2963 : :
2964 : 545 : mptcp_set_state(sk, TCP_CLOSE);
2965 : 545 : mptcp_backlog_purge(sk);
2966 : 545 : msk->fastclosing = 1;
2967 : :
2968 : : /* Explicitly send the fastclose reset as need */
2969 [ + + ]: 545 : if (__mptcp_check_fallback(msk))
2970 : : return;
2971 : :
2972 [ + + ]: 1007 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2973 : 540 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2974 : :
2975 : 540 : lock_sock(ssk);
2976 : :
2977 : : /* Some subflow socket states don't allow/need a reset.*/
2978 [ - + + + ]: 540 : if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
[ + + ]
2979 : 90 : goto unlock;
2980 : :
2981 : 450 : subflow->send_fastclose = 1;
2982 : :
2983 : : /* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
2984 : : * issue in __tcp_select_window(), see tcp_disconnect().
2985 : : */
2986 : 450 : inet_csk(ssk)->icsk_ack.rcv_mss = TCP_MIN_MSS;
2987 : :
2988 : 450 : tcp_send_active_reset(ssk, ssk->sk_allocation,
2989 : : SK_RST_REASON_TCP_ABORT_ON_CLOSE);
2990 : 540 : unlock:
2991 : 540 : release_sock(ssk);
2992 : : }
2993 : : }
2994 : :
2995 : 13526 : static void mptcp_worker(struct work_struct *work)
2996 : : {
2997 : 13526 : struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work);
2998 : 13526 : struct sock *sk = (struct sock *)msk;
2999 : 13526 : unsigned long fail_tout;
3000 : 13526 : int state;
3001 : :
3002 : 13526 : lock_sock(sk);
3003 : 13526 : state = sk->sk_state;
3004 [ - + + + ]: 13526 : if (unlikely((1 << state) & (TCPF_CLOSE | TCPF_LISTEN)))
[ + + ]
3005 : 1012 : goto unlock;
3006 : :
3007 : 12514 : mptcp_check_fastclose(msk);
3008 : :
3009 : 12514 : mptcp_pm_worker(msk);
3010 : :
3011 : 12514 : mptcp_check_send_data_fin(sk);
3012 : 12514 : mptcp_check_data_fin_ack(sk);
3013 : 12514 : mptcp_check_data_fin(sk);
3014 : :
3015 [ + + ]: 19098 : if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
3016 : 1582 : __mptcp_close_subflow(sk);
3017 : :
3018 [ + + ]: 12514 : if (mptcp_close_tout_expired(sk)) {
3019 : 134 : struct mptcp_subflow_context *subflow, *tmp;
3020 : :
3021 : 134 : mptcp_do_fastclose(sk);
3022 [ + + ]: 290 : mptcp_for_each_subflow_safe(msk, subflow, tmp)
3023 : 156 : __mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
3024 : 134 : mptcp_close_wake_up(sk);
3025 : : }
3026 : :
3027 [ + + + + ]: 12514 : if (sock_flag(sk, SOCK_DEAD) && sk->sk_state == TCP_CLOSE) {
3028 : 1335 : __mptcp_destroy_sock(sk);
3029 : 1335 : goto unlock;
3030 : : }
3031 : :
3032 [ + + ]: 17081 : if (test_and_clear_bit(MPTCP_WORK_RTX, &msk->flags))
3033 : 5129 : __mptcp_retrans(sk);
3034 : :
3035 [ + - + - ]: 11179 : fail_tout = msk->first ? READ_ONCE(mptcp_subflow_ctx(msk->first)->fail_tout) : 0;
3036 [ + - - - ]: 11179 : if (fail_tout && time_after(jiffies, fail_tout))
3037 : 0 : mptcp_mp_fail_no_response(msk);
3038 : :
3039 : 0 : unlock:
3040 : 13526 : release_sock(sk);
3041 : 13526 : sock_put(sk);
3042 : 13526 : }
3043 : :
3044 : 5082 : static void __mptcp_init_sock(struct sock *sk)
3045 : : {
3046 [ - + ]: 5082 : struct mptcp_sock *msk = mptcp_sk(sk);
3047 : :
3048 : 5082 : INIT_LIST_HEAD(&msk->conn_list);
3049 : 5082 : INIT_LIST_HEAD(&msk->join_list);
3050 : 5082 : INIT_LIST_HEAD(&msk->rtx_queue);
3051 : 5082 : INIT_LIST_HEAD(&msk->backlog_list);
3052 : 5082 : INIT_WORK(&msk->work, mptcp_worker);
3053 : 5082 : msk->out_of_order_queue = RB_ROOT;
3054 : 5082 : msk->first_pending = NULL;
3055 : 5082 : msk->timer_ival = TCP_RTO_MIN;
3056 : 5082 : msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
3057 : 5082 : msk->backlog_len = 0;
3058 : 5082 : mptcp_init_rtt_est(msk);
3059 : :
3060 : 5082 : WRITE_ONCE(msk->first, NULL);
3061 : 5082 : inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
3062 : 5082 : WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
3063 : 5082 : msk->allow_infinite_fallback = true;
3064 : 5082 : msk->allow_subflows = true;
3065 : 5082 : msk->recovery = false;
3066 : 5082 : msk->subflow_id = 1;
3067 : 5082 : msk->last_data_sent = tcp_jiffies32;
3068 : 5082 : msk->last_data_recv = tcp_jiffies32;
3069 : 5082 : msk->last_ack_recv = tcp_jiffies32;
3070 : :
3071 : 5082 : mptcp_pm_data_init(msk);
3072 : 5082 : spin_lock_init(&msk->fallback_lock);
3073 : :
3074 : : /* re-use the csk retrans timer for MPTCP-level retrans */
3075 : 5082 : timer_setup(&sk->mptcp_retransmit_timer, mptcp_retransmit_timer, 0);
3076 : 5082 : timer_setup(&msk->sk.mptcp_tout_timer, mptcp_tout_timer, 0);
3077 : 5082 : }
3078 : :
3079 : 3556 : static void mptcp_ca_reset(struct sock *sk)
3080 : : {
3081 : 3556 : struct inet_connection_sock *icsk = inet_csk(sk);
3082 : :
3083 : 3556 : tcp_assign_congestion_control(sk);
3084 [ - + ]: 3556 : strscpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name,
3085 : : sizeof(mptcp_sk(sk)->ca_name));
3086 : :
3087 : : /* no need to keep a reference to the ops, the name will suffice */
3088 : 3556 : tcp_cleanup_congestion_control(sk);
3089 : 3556 : icsk->icsk_ca_ops = NULL;
3090 : 3556 : }
3091 : :
3092 : 3460 : static int mptcp_init_sock(struct sock *sk)
3093 : : {
3094 : 3460 : struct net *net = sock_net(sk);
3095 : 3460 : int ret;
3096 : :
3097 : 3460 : __mptcp_init_sock(sk);
3098 : :
3099 [ + + ]: 3460 : if (!mptcp_is_enabled(net))
3100 : : return -ENOPROTOOPT;
3101 : :
3102 [ + + + - ]: 3450 : if (unlikely(!net->mib.mptcp_statistics) && !mptcp_mib_alloc(net))
3103 : : return -ENOMEM;
3104 : :
3105 : 3450 : rcu_read_lock();
3106 [ - + ]: 3450 : ret = mptcp_init_sched(mptcp_sk(sk),
3107 : : mptcp_sched_find(mptcp_get_scheduler(net)));
3108 : 3450 : rcu_read_unlock();
3109 [ + - ]: 3450 : if (ret)
3110 : : return ret;
3111 : :
3112 : 3450 : set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
3113 : :
3114 : : /* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
3115 : : * propagate the correct value
3116 : : */
3117 : 3450 : mptcp_ca_reset(sk);
3118 : :
3119 : 3450 : sk_sockets_allocated_inc(sk);
3120 : 3450 : sk->sk_rcvbuf = READ_ONCE(net->ipv4.sysctl_tcp_rmem[1]);
3121 : 3450 : sk->sk_sndbuf = READ_ONCE(net->ipv4.sysctl_tcp_wmem[1]);
3122 : 3450 : sk->sk_write_space = sk_stream_write_space;
3123 : :
3124 : 3450 : return 0;
3125 : : }
3126 : :
3127 : 5079 : static void __mptcp_clear_xmit(struct sock *sk)
3128 : : {
3129 [ - + ]: 5079 : struct mptcp_sock *msk = mptcp_sk(sk);
3130 : 5079 : struct mptcp_data_frag *dtmp, *dfrag;
3131 : :
3132 : 5079 : msk->first_pending = NULL;
3133 [ + + ]: 5443 : list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list)
3134 : 364 : dfrag_clear(sk, dfrag);
3135 : 5079 : }
3136 : :
3137 : 3628 : void mptcp_cancel_work(struct sock *sk)
3138 : : {
3139 [ - + ]: 3628 : struct mptcp_sock *msk = mptcp_sk(sk);
3140 : :
3141 [ + + ]: 3628 : if (cancel_work_sync(&msk->work))
3142 : 43 : __sock_put(sk);
3143 : 3628 : }
3144 : :
3145 : 4068 : void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
3146 : : {
3147 : 4068 : lock_sock(ssk);
3148 : :
3149 [ - + + ]: 4068 : switch (ssk->sk_state) {
3150 : 0 : case TCP_LISTEN:
3151 [ # # ]: 0 : if (!(how & RCV_SHUTDOWN))
3152 : : break;
3153 : 18 : fallthrough;
3154 : : case TCP_SYN_SENT:
3155 [ - + ]: 18 : WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
3156 : : break;
3157 : 4050 : default:
3158 [ - + + + ]: 4050 : if (__mptcp_check_fallback(mptcp_sk(sk))) {
3159 [ - + - - ]: 177 : pr_debug("Fallback\n");
3160 : 177 : ssk->sk_shutdown |= how;
3161 : 177 : tcp_shutdown(ssk, how);
3162 : :
3163 : : /* simulate the data_fin ack reception to let the state
3164 : : * machine move forward
3165 : : */
3166 [ - + - + ]: 177 : WRITE_ONCE(mptcp_sk(sk)->snd_una, mptcp_sk(sk)->snd_nxt);
3167 : 177 : mptcp_schedule_work(sk);
3168 : : } else {
3169 [ - + - - ]: 3873 : pr_debug("Sending DATA_FIN on subflow %p\n", ssk);
3170 : 3873 : tcp_send_ack(ssk);
3171 [ + + ]: 3873 : if (!mptcp_rtx_timer_pending(sk))
3172 : 1880 : mptcp_reset_rtx_timer(sk);
3173 : : }
3174 : : break;
3175 : : }
3176 : :
3177 : 4068 : release_sock(ssk);
3178 : 4068 : }
3179 : :
3180 : 24423 : void mptcp_set_state(struct sock *sk, int state)
3181 : : {
3182 : 25409 : int oldstate = sk->sk_state;
3183 : :
3184 [ + + - ]: 24403 : switch (state) {
3185 : 3266 : case TCP_ESTABLISHED:
3186 [ + - ]: 3266 : if (oldstate != TCP_ESTABLISHED)
3187 [ + - ]: 3266 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
3188 : : break;
3189 : : case TCP_CLOSE_WAIT:
3190 : : /* Unlike TCP, MPTCP sk would not have the TCP_SYN_RECV state:
3191 : : * MPTCP "accepted" sockets will be created later on. So no
3192 : : * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
3193 : : */
3194 : : break;
3195 : 21137 : default:
3196 [ + + ]: 21137 : if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
3197 [ + - ]: 3266 : MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
3198 : : }
3199 : :
3200 : 25409 : inet_sk_state_store(sk, state);
3201 : 1006 : }
3202 : :
3203 : : static const unsigned char new_state[16] = {
3204 : : /* current state: new state: action: */
3205 : : [0 /* (Invalid) */] = TCP_CLOSE,
3206 : : [TCP_ESTABLISHED] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
3207 : : [TCP_SYN_SENT] = TCP_CLOSE,
3208 : : [TCP_SYN_RECV] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
3209 : : [TCP_FIN_WAIT1] = TCP_FIN_WAIT1,
3210 : : [TCP_FIN_WAIT2] = TCP_FIN_WAIT2,
3211 : : [TCP_TIME_WAIT] = TCP_CLOSE, /* should not happen ! */
3212 : : [TCP_CLOSE] = TCP_CLOSE,
3213 : : [TCP_CLOSE_WAIT] = TCP_LAST_ACK | TCP_ACTION_FIN,
3214 : : [TCP_LAST_ACK] = TCP_LAST_ACK,
3215 : : [TCP_LISTEN] = TCP_CLOSE,
3216 : : [TCP_CLOSING] = TCP_CLOSING,
3217 : : [TCP_NEW_SYN_RECV] = TCP_CLOSE, /* should not happen ! */
3218 : : };
3219 : :
3220 : 3472 : static int mptcp_close_state(struct sock *sk)
3221 : : {
3222 : 3472 : int next = (int)new_state[sk->sk_state];
3223 : 3472 : int ns = next & TCP_STATE_MASK;
3224 : :
3225 : 3472 : mptcp_set_state(sk, ns);
3226 : :
3227 : 3472 : return next & TCP_ACTION_FIN;
3228 : : }
3229 : :
3230 : 371050 : static void mptcp_check_send_data_fin(struct sock *sk)
3231 : : {
3232 : 371050 : struct mptcp_subflow_context *subflow;
3233 [ - + ]: 371050 : struct mptcp_sock *msk = mptcp_sk(sk);
3234 : :
3235 [ - + - - : 371050 : pr_debug("msk=%p snd_data_fin_enable=%d pending=%d snd_nxt=%llu write_seq=%llu\n",
- - ]
[ - + - - ]
3236 : : msk, msk->snd_data_fin_enable, !!mptcp_send_head(sk),
3237 : : msk->snd_nxt, msk->write_seq);
3238 : :
3239 : : /* we still need to enqueue subflows or not really shutting down,
3240 : : * skip this
3241 : : */
3242 [ - + + + : 374027 : if (!msk->snd_data_fin_enable || msk->snd_nxt + 1 != msk->write_seq ||
+ + - + ]
[ + + + +
- + ]
3243 : 2977 : mptcp_send_head(sk))
3244 : 368073 : return;
3245 : :
3246 : 2977 : WRITE_ONCE(msk->snd_nxt, msk->write_seq);
3247 : :
3248 [ + + ]: 6853 : mptcp_for_each_subflow(msk, subflow) {
3249 : 3876 : struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
3250 : :
3251 : 3876 : mptcp_subflow_shutdown(sk, tcp_sk, SEND_SHUTDOWN);
3252 : : }
3253 : : }
3254 : :
3255 : 2983 : static void __mptcp_wr_shutdown(struct sock *sk)
3256 : : {
3257 [ - + ]: 2983 : struct mptcp_sock *msk = mptcp_sk(sk);
3258 : :
3259 [ - + - - : 2983 : pr_debug("msk=%p snd_data_fin_enable=%d shutdown=%x state=%d pending=%d\n",
- - ]
[ - + - - ]
3260 : : msk, msk->snd_data_fin_enable, sk->sk_shutdown, sk->sk_state,
3261 : : !!mptcp_send_head(sk));
3262 : :
3263 : : /* will be ignored by fallback sockets */
3264 : 2983 : WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
3265 : 2983 : WRITE_ONCE(msk->snd_data_fin_enable, 1);
3266 : :
3267 : 2983 : mptcp_check_send_data_fin(sk);
3268 : 2983 : }
3269 : :
3270 : 4963 : static void __mptcp_destroy_sock(struct sock *sk)
3271 : : {
3272 [ - + ]: 4963 : struct mptcp_sock *msk = mptcp_sk(sk);
3273 : :
3274 [ - + - - ]: 4963 : pr_debug("msk=%p\n", msk);
3275 : :
3276 : 4963 : might_sleep();
3277 : :
3278 : 4963 : mptcp_stop_rtx_timer(sk);
3279 : 4963 : sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
3280 : 4963 : msk->pm.status = 0;
3281 : 4963 : mptcp_release_sched(msk);
3282 : :
3283 : 4963 : sk->sk_prot->destroy(sk);
3284 : :
3285 : 4963 : sk_stream_kill_queues(sk);
3286 : 4963 : xfrm_sk_free_policy(sk);
3287 : :
3288 : 4963 : sock_put(sk);
3289 : 4963 : }
3290 : :
3291 : 36 : void __mptcp_unaccepted_force_close(struct sock *sk)
3292 : : {
3293 : 36 : sock_set_flag(sk, SOCK_DEAD);
3294 : 36 : mptcp_do_fastclose(sk);
3295 : 36 : __mptcp_destroy_sock(sk);
3296 : 36 : }
3297 : :
3298 : 0 : static __poll_t mptcp_check_readable(struct sock *sk)
3299 : : {
3300 [ + + ]: 1356283 : return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
3301 : : }
3302 : :
3303 : 3351 : static void mptcp_check_listen_stop(struct sock *sk)
3304 : : {
3305 : 3351 : struct sock *ssk;
3306 : :
3307 [ + + ]: 3351 : if (inet_sk_state_load(sk) != TCP_LISTEN)
3308 : : return;
3309 : :
3310 : 1744 : sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
3311 [ - + ]: 1744 : ssk = mptcp_sk(sk)->first;
3312 [ + - - + ]: 3488 : if (WARN_ON_ONCE(!ssk || inet_sk_state_load(ssk) != TCP_LISTEN))
3313 : 0 : return;
3314 : :
3315 : 1744 : lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
3316 : 1744 : tcp_set_state(ssk, TCP_CLOSE);
3317 : 1744 : mptcp_subflow_queue_clean(sk, ssk);
3318 : 1744 : inet_csk_listen_stop(ssk);
3319 : 1744 : mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CLOSED);
3320 : 1744 : release_sock(ssk);
3321 : : }
3322 : :
3323 : 4986 : bool __mptcp_close(struct sock *sk, long timeout)
3324 : : {
3325 : 4986 : struct mptcp_subflow_context *subflow;
3326 [ - + ]: 4986 : struct mptcp_sock *msk = mptcp_sk(sk);
3327 : 4986 : bool do_cancel_work = false;
3328 : 4986 : int subflows_alive = 0;
3329 : :
3330 : 4986 : WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
3331 : :
3332 [ - + + + ]: 4986 : if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
[ + + ]
3333 : 3245 : mptcp_check_listen_stop(sk);
3334 : 3245 : mptcp_set_state(sk, TCP_CLOSE);
3335 : 3245 : goto cleanup;
3336 : : }
3337 : :
3338 [ + + + - : 3225 : if (mptcp_data_avail(msk) || timeout < 0 ||
+ + ]
3339 [ + - ]: 1496 : (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) {
3340 : : /* If the msk has read data, or the caller explicitly ask it,
3341 : : * do the MPTCP equivalent of TCP reset, aka MPTCP fastclose
3342 : : */
3343 : 269 : mptcp_do_fastclose(sk);
3344 : 269 : timeout = 0;
3345 [ + + ]: 1472 : } else if (mptcp_close_state(sk)) {
3346 : 1141 : __mptcp_wr_shutdown(sk);
3347 : : }
3348 : :
3349 : 1741 : sk_stream_wait_close(sk, timeout);
3350 : :
3351 : 4986 : cleanup:
3352 : : /* orphan all the subflows */
3353 [ + + ]: 10491 : mptcp_for_each_subflow(msk, subflow) {
3354 : 5505 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
3355 : 5505 : bool slow = lock_sock_fast_nested(ssk);
3356 : :
3357 : 5505 : subflows_alive += ssk->sk_state != TCP_CLOSE;
3358 : :
3359 : : /* since the close timeout takes precedence on the fail one,
3360 : : * cancel the latter
3361 : : */
3362 [ + + ]: 5505 : if (ssk == msk->first)
3363 : 4974 : subflow->fail_tout = 0;
3364 : :
3365 : : /* detach from the parent socket, but allow data_ready to
3366 : : * push incoming data into the mptcp stack, to properly ack it
3367 : : */
3368 : 5505 : ssk->sk_socket = NULL;
3369 : 5505 : ssk->sk_wq = NULL;
3370 : 5505 : unlock_sock_fast(ssk, slow);
3371 : : }
3372 : 4986 : sock_orphan(sk);
3373 : :
3374 : : /* all the subflows are closed, only timeout can change the msk
3375 : : * state, let's not keep resources busy for no reasons
3376 : : */
3377 [ + + ]: 4986 : if (subflows_alive == 0)
3378 : 2814 : mptcp_set_state(sk, TCP_CLOSE);
3379 : :
3380 : 4986 : sock_hold(sk);
3381 [ - + - - ]: 4986 : pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
3382 : 4986 : mptcp_pm_connection_closed(msk);
3383 : :
3384 [ + + ]: 4986 : if (sk->sk_state == TCP_CLOSE) {
3385 : 3592 : __mptcp_destroy_sock(sk);
3386 : 3592 : do_cancel_work = true;
3387 : : } else {
3388 : 1394 : mptcp_start_tout_timer(sk);
3389 : : }
3390 : :
3391 : 4986 : return do_cancel_work;
3392 : : }
3393 : :
3394 : 4986 : static void mptcp_close(struct sock *sk, long timeout)
3395 : : {
3396 : 4986 : bool do_cancel_work;
3397 : :
3398 : 4986 : lock_sock(sk);
3399 : :
3400 : 4986 : do_cancel_work = __mptcp_close(sk, timeout);
3401 : 4986 : release_sock(sk);
3402 [ + + ]: 4986 : if (do_cancel_work)
3403 : 3592 : mptcp_cancel_work(sk);
3404 : :
3405 : 4986 : sock_put(sk);
3406 : 4986 : }
3407 : :
3408 : 6816 : static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)
3409 : : {
3410 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3411 [ + - ]: 6816 : const struct ipv6_pinfo *ssk6 = inet6_sk(ssk);
3412 [ + - ]: 6816 : struct ipv6_pinfo *msk6 = inet6_sk(msk);
3413 : :
3414 : 6816 : msk->sk_v6_daddr = ssk->sk_v6_daddr;
3415 : 6816 : msk->sk_v6_rcv_saddr = ssk->sk_v6_rcv_saddr;
3416 : :
3417 [ + + ]: 6816 : if (msk6 && ssk6) {
3418 : 3054 : msk6->saddr = ssk6->saddr;
3419 : 3054 : msk6->flow_label = ssk6->flow_label;
3420 : : }
3421 : : #endif
3422 : :
3423 : 6816 : inet_sk(msk)->inet_num = inet_sk(ssk)->inet_num;
3424 : 6816 : inet_sk(msk)->inet_dport = inet_sk(ssk)->inet_dport;
3425 : 6816 : inet_sk(msk)->inet_sport = inet_sk(ssk)->inet_sport;
3426 : 6816 : inet_sk(msk)->inet_daddr = inet_sk(ssk)->inet_daddr;
3427 : 6816 : inet_sk(msk)->inet_saddr = inet_sk(ssk)->inet_saddr;
3428 : 6816 : inet_sk(msk)->inet_rcv_saddr = inet_sk(ssk)->inet_rcv_saddr;
3429 : 6816 : }
3430 : :
3431 : 5079 : static void mptcp_destroy_common(struct mptcp_sock *msk)
3432 : : {
3433 : 5079 : struct mptcp_subflow_context *subflow, *tmp;
3434 : 5079 : struct sock *sk = (struct sock *)msk;
3435 : :
3436 : 5079 : __mptcp_clear_xmit(sk);
3437 : 5079 : mptcp_backlog_purge(sk);
3438 : :
3439 : : /* join list will be eventually flushed (with rst) at sock lock release time */
3440 [ + + ]: 10547 : mptcp_for_each_subflow_safe(msk, subflow, tmp)
3441 : 5468 : __mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow), subflow, 0);
3442 : :
3443 : 5079 : __skb_queue_purge(&sk->sk_receive_queue);
3444 : 5079 : skb_rbtree_purge(&msk->out_of_order_queue);
3445 : :
3446 : : /* move all the rx fwd alloc into the sk_mem_reclaim_final in
3447 : : * inet_sock_destruct() will dispose it
3448 : : */
3449 : 5079 : mptcp_token_destroy(msk);
3450 : 5079 : mptcp_pm_destroy(msk);
3451 : 5079 : }
3452 : :
3453 : 106 : static int mptcp_disconnect(struct sock *sk, int flags)
3454 : : {
3455 [ - + ]: 106 : struct mptcp_sock *msk = mptcp_sk(sk);
3456 : :
3457 : : /* We are on the fastopen error path. We can't call straight into the
3458 : : * subflows cleanup code due to lock nesting (we are already under
3459 : : * msk->firstsocket lock).
3460 : : */
3461 [ + - ]: 106 : if (msk->fastopening)
3462 : : return -EBUSY;
3463 : :
3464 : 106 : mptcp_check_listen_stop(sk);
3465 : 106 : mptcp_set_state(sk, TCP_CLOSE);
3466 : :
3467 : 106 : mptcp_stop_rtx_timer(sk);
3468 : 106 : mptcp_stop_tout_timer(sk);
3469 : :
3470 : 106 : mptcp_pm_connection_closed(msk);
3471 : :
3472 : : /* msk->subflow is still intact, the following will not free the first
3473 : : * subflow
3474 : : */
3475 : 106 : mptcp_do_fastclose(sk);
3476 : 106 : mptcp_destroy_common(msk);
3477 : :
3478 : : /* The first subflow is already in TCP_CLOSE status, the following
3479 : : * can't overlap with a fallback anymore
3480 : : */
3481 : 106 : spin_lock_bh(&msk->fallback_lock);
3482 : 106 : msk->allow_subflows = true;
3483 : 106 : msk->allow_infinite_fallback = true;
3484 : 106 : WRITE_ONCE(msk->flags, 0);
3485 : 106 : spin_unlock_bh(&msk->fallback_lock);
3486 : :
3487 : 106 : msk->cb_flags = 0;
3488 : 106 : msk->recovery = false;
3489 : 106 : WRITE_ONCE(msk->can_ack, false);
3490 : 106 : WRITE_ONCE(msk->fully_established, false);
3491 : 106 : WRITE_ONCE(msk->rcv_data_fin, false);
3492 : 106 : WRITE_ONCE(msk->snd_data_fin_enable, false);
3493 : 106 : WRITE_ONCE(msk->rcv_fastclose, false);
3494 : 106 : WRITE_ONCE(msk->use_64bit_ack, false);
3495 : 106 : WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
3496 : 106 : mptcp_pm_data_reset(msk);
3497 : 106 : mptcp_ca_reset(sk);
3498 : 106 : msk->bytes_consumed = 0;
3499 : 106 : msk->bytes_acked = 0;
3500 : 106 : msk->bytes_received = 0;
3501 : 106 : msk->bytes_sent = 0;
3502 : 106 : msk->bytes_retrans = 0;
3503 : 106 : msk->rcvspace_init = 0;
3504 : 106 : msk->fastclosing = 0;
3505 : 106 : mptcp_init_rtt_est(msk);
3506 : :
3507 : : /* for fallback's sake */
3508 : 106 : WRITE_ONCE(msk->ack_seq, 0);
3509 : 106 : atomic64_set(&msk->rcv_wnd_sent, 0);
3510 : :
3511 : 106 : WRITE_ONCE(sk->sk_shutdown, 0);
3512 : 106 : sk_error_report(sk);
3513 : 106 : return 0;
3514 : : }
3515 : :
3516 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3517 : 780 : static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
3518 : : {
3519 [ - + ]: 780 : struct mptcp6_sock *msk6 = container_of(mptcp_sk(sk), struct mptcp6_sock, msk);
3520 : :
3521 : 780 : return &msk6->np;
3522 : : }
3523 : :
3524 : 780 : static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk)
3525 : : {
3526 [ + - ]: 780 : const struct ipv6_pinfo *np = inet6_sk(sk);
3527 : 780 : struct ipv6_txoptions *opt;
3528 : 780 : struct ipv6_pinfo *newnp;
3529 : :
3530 [ + - ]: 780 : newnp = inet6_sk(newsk);
3531 : :
3532 : 780 : rcu_read_lock();
3533 [ + - - + : 780 : opt = rcu_dereference(np->opt);
- - - - -
- ]
3534 [ + - ]: 780 : if (opt) {
3535 : 0 : opt = ipv6_dup_options(newsk, opt);
3536 [ # # ]: 0 : if (!opt)
3537 [ # # ]: 0 : net_warn_ratelimited("%s: Failed to copy ip6 options\n", __func__);
3538 : : }
3539 : 780 : RCU_INIT_POINTER(newnp->opt, opt);
3540 : 780 : rcu_read_unlock();
3541 : 780 : }
3542 : : #endif
3543 : :
3544 : 842 : static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk)
3545 : : {
3546 : 842 : struct ip_options_rcu *inet_opt, *newopt = NULL;
3547 : 842 : const struct inet_sock *inet = inet_sk(sk);
3548 : 842 : struct inet_sock *newinet;
3549 : :
3550 : 842 : newinet = inet_sk(newsk);
3551 : :
3552 : 842 : rcu_read_lock();
3553 [ + - - + : 842 : inet_opt = rcu_dereference(inet->inet_opt);
- - - - -
- ]
3554 [ + - ]: 842 : if (inet_opt) {
3555 : 0 : newopt = sock_kmemdup(newsk, inet_opt, sizeof(*inet_opt) +
3556 : 0 : inet_opt->opt.optlen, GFP_ATOMIC);
3557 [ # # ]: 0 : if (!newopt)
3558 [ # # ]: 0 : net_warn_ratelimited("%s: Failed to copy ip options\n", __func__);
3559 : : }
3560 : 842 : RCU_INIT_POINTER(newinet->inet_opt, newopt);
3561 : 842 : rcu_read_unlock();
3562 : 842 : }
3563 : :
3564 : 1622 : struct sock *mptcp_sk_clone_init(const struct sock *sk,
3565 : : const struct mptcp_options_received *mp_opt,
3566 : : struct sock *ssk,
3567 : : struct request_sock *req)
3568 : : {
3569 : 1622 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
3570 : 1622 : struct sock *nsk = sk_clone_lock(sk, GFP_ATOMIC);
3571 : 1622 : struct mptcp_subflow_context *subflow;
3572 : 1622 : struct mptcp_sock *msk;
3573 : :
3574 [ + - ]: 1622 : if (!nsk)
3575 : : return NULL;
3576 : :
3577 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3578 [ + + ]: 1622 : if (nsk->sk_family == AF_INET6)
3579 : 780 : inet_sk(nsk)->pinet6 = mptcp_inet6_sk(nsk);
3580 : : #endif
3581 : :
3582 : 1622 : __mptcp_init_sock(nsk);
3583 : :
3584 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3585 [ + + ]: 1622 : if (nsk->sk_family == AF_INET6)
3586 : 780 : mptcp_copy_ip6_options(nsk, sk);
3587 : : else
3588 : : #endif
3589 : 842 : mptcp_copy_ip_options(nsk, sk);
3590 : :
3591 [ - + ]: 1622 : msk = mptcp_sk(nsk);
3592 : 1622 : WRITE_ONCE(msk->local_key, subflow_req->local_key);
3593 : 1622 : WRITE_ONCE(msk->token, subflow_req->token);
3594 : 1622 : msk->in_accept_queue = 1;
3595 : 1622 : WRITE_ONCE(msk->fully_established, false);
3596 [ + + ]: 1622 : if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
3597 : 118 : WRITE_ONCE(msk->csum_enabled, true);
3598 : :
3599 : 1622 : WRITE_ONCE(msk->write_seq, subflow_req->idsn + 1);
3600 : 1622 : WRITE_ONCE(msk->snd_nxt, msk->write_seq);
3601 : 1622 : WRITE_ONCE(msk->snd_una, msk->write_seq);
3602 [ - + ]: 1622 : WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd);
3603 [ - + ]: 1622 : msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq;
3604 [ - + ]: 1622 : mptcp_init_sched(msk, mptcp_sk(sk)->sched);
3605 : :
3606 : : /* passive msk is created after the first/MPC subflow */
3607 : 1622 : msk->subflow_id = 2;
3608 : :
3609 : 1622 : sock_reset_flag(nsk, SOCK_RCU_FREE);
3610 : 1622 : security_inet_csk_clone(nsk, req);
3611 : :
3612 : : /* this can't race with mptcp_close(), as the msk is
3613 : : * not yet exposted to user-space
3614 : : */
3615 : 1622 : mptcp_set_state(nsk, TCP_ESTABLISHED);
3616 : :
3617 : : /* The msk maintain a ref to each subflow in the connections list */
3618 : 1622 : WRITE_ONCE(msk->first, ssk);
3619 : 1622 : subflow = mptcp_subflow_ctx(ssk);
3620 : 1622 : list_add(&subflow->node, &msk->conn_list);
3621 : 1622 : sock_hold(ssk);
3622 : :
3623 : : /* new mpc subflow takes ownership of the newly
3624 : : * created mptcp socket
3625 : : */
3626 : 1622 : mptcp_token_accept(subflow_req, msk);
3627 : :
3628 : : /* set msk addresses early to ensure mptcp_pm_get_local_id()
3629 : : * uses the correct data
3630 : : */
3631 : 1622 : mptcp_copy_inaddrs(nsk, ssk);
3632 : :
3633 : 1622 : mptcp_rcv_space_init(msk, ssk);
3634 : 1622 : msk->rcvq_space.time = mptcp_stamp();
3635 : :
3636 [ + + ]: 1622 : if (mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
3637 : 1566 : __mptcp_subflow_fully_established(msk, subflow, mp_opt);
3638 : 1622 : bh_unlock_sock(nsk);
3639 : :
3640 : : /* note: the newly allocated socket refcount is 2 now */
3641 : 1622 : return nsk;
3642 : : }
3643 : :
3644 : 4973 : static void mptcp_destroy(struct sock *sk)
3645 : : {
3646 [ - + ]: 4973 : struct mptcp_sock *msk = mptcp_sk(sk);
3647 : :
3648 : : /* allow the following to close even the initial subflow */
3649 : 4973 : msk->free_first = 1;
3650 : 4973 : mptcp_destroy_common(msk);
3651 : 4973 : sk_sockets_allocated_dec(sk);
3652 : 4973 : }
3653 : :
3654 : 604458 : void __mptcp_data_acked(struct sock *sk)
3655 : : {
3656 [ + + ]: 604458 : if (!sock_owned_by_user(sk))
3657 : 305329 : __mptcp_clean_una(sk);
3658 : : else
3659 [ - + ]: 299129 : __set_bit(MPTCP_CLEAN_UNA, &mptcp_sk(sk)->cb_flags);
3660 : 604458 : }
3661 : :
3662 : 1891876 : void __mptcp_check_push(struct sock *sk, struct sock *ssk)
3663 : : {
3664 [ + + ]: 1891876 : if (!sock_owned_by_user(sk))
3665 : 1408862 : __mptcp_subflow_push_pending(sk, ssk, false);
3666 : : else
3667 [ - + ]: 483014 : __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
3668 : 1891876 : }
3669 : :
3670 : : #define MPTCP_FLAGS_PROCESS_CTX_NEED (BIT(MPTCP_PUSH_PENDING) | \
3671 : : BIT(MPTCP_RETRANSMIT) | \
3672 : : BIT(MPTCP_FLUSH_JOIN_LIST))
3673 : :
3674 : : /* processes deferred events and flush wmem */
3675 : 1986267 : static void mptcp_release_cb(struct sock *sk)
3676 : : __must_hold(&sk->sk_lock.slock)
3677 : : {
3678 [ - + ]: 1986267 : struct mptcp_sock *msk = mptcp_sk(sk);
3679 : :
3680 : 288269 : for (;;) {
3681 : 2274536 : unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED);
3682 : 2274536 : struct list_head join_list, skbs;
3683 : 2274536 : bool spool_bl;
3684 : 2274536 : u32 moved;
3685 : :
3686 : 2274536 : spool_bl = mptcp_can_spool_backlog(sk, &skbs);
3687 [ + + ]: 2274536 : if (!flags && !spool_bl)
3688 : : break;
3689 : :
3690 [ + + ]: 288269 : INIT_LIST_HEAD(&join_list);
3691 [ + + ]: 288269 : list_splice_init(&msk->join_list, &join_list);
3692 : :
3693 : : /* the following actions acquire the subflow socket lock
3694 : : *
3695 : : * 1) can't be invoked in atomic scope
3696 : : * 2) must avoid ABBA deadlock with msk socket spinlock: the RX
3697 : : * datapath acquires the msk socket spinlock while helding
3698 : : * the subflow socket lock
3699 : : */
3700 : 288269 : msk->cb_flags &= ~flags;
3701 : 288269 : spin_unlock_bh(&sk->sk_lock.slock);
3702 : :
3703 [ + + ]: 288269 : if (flags & BIT(MPTCP_FLUSH_JOIN_LIST))
3704 : 6 : __mptcp_flush_join_list(sk, &join_list);
3705 [ + + ]: 288269 : if (flags & BIT(MPTCP_PUSH_PENDING))
3706 : 220603 : __mptcp_push_pending(sk, 0);
3707 [ + + ]: 288269 : if (flags & BIT(MPTCP_RETRANSMIT))
3708 : 1627 : __mptcp_retrans(sk);
3709 [ + + + + ]: 288269 : if (spool_bl && __mptcp_move_skbs(sk, &skbs, &moved)) {
3710 : : /* notify ack seq update */
3711 : 148405 : mptcp_cleanup_rbuf(msk, 0);
3712 : 148405 : sk->sk_data_ready(sk);
3713 : : }
3714 : :
3715 : 288269 : cond_resched();
3716 : 288269 : spin_lock_bh(&sk->sk_lock.slock);
3717 [ + + ]: 288269 : if (spool_bl)
3718 : 151307 : mptcp_backlog_spooled(sk, moved, &skbs);
3719 : : }
3720 : :
3721 [ - + - - : 3972025 : if (__test_and_clear_bit(MPTCP_CLEAN_UNA, &msk->cb_flags))
- - + + ]
3722 : 128498 : __mptcp_clean_una_wakeup(sk);
3723 [ + + ]: 1986267 : if (unlikely(msk->cb_flags)) {
3724 : : /* be sure to sync the msk state before taking actions
3725 : : * depending on sk_state (MPTCP_ERROR_REPORT)
3726 : : * On sk release avoid actions depending on the first subflow
3727 : : */
3728 [ - + - - : 9586 : if (__test_and_clear_bit(MPTCP_SYNC_STATE, &msk->cb_flags) && msk->first)
- - + + +
- ]
3729 : 1126 : __mptcp_sync_state(sk, msk->pending_state);
3730 [ - + - - : 9586 : if (__test_and_clear_bit(MPTCP_ERROR_REPORT, &msk->cb_flags))
- - + + ]
3731 : 583 : __mptcp_error_report(sk);
3732 [ - + - - : 9586 : if (__test_and_clear_bit(MPTCP_SYNC_SNDBUF, &msk->cb_flags))
- - + + ]
3733 : 3101 : __mptcp_sync_sndbuf(sk);
3734 : : }
3735 : 1986267 : }
3736 : :
3737 : : /* MP_JOIN client subflow must wait for 4th ack before sending any data:
3738 : : * TCP can't schedule delack timer before the subflow is fully established.
3739 : : * MPTCP uses the delack timer to do 3rd ack retransmissions
3740 : : */
3741 : 600 : static void schedule_3rdack_retransmission(struct sock *ssk)
3742 : : {
3743 : 600 : struct inet_connection_sock *icsk = inet_csk(ssk);
3744 [ - + ]: 600 : struct tcp_sock *tp = tcp_sk(ssk);
3745 : 600 : unsigned long timeout;
3746 : :
3747 [ - + + + ]: 600 : if (READ_ONCE(mptcp_subflow_ctx(ssk)->fully_established))
[ + + ]
3748 : : return;
3749 : :
3750 : : /* reschedule with a timeout above RTT, as we must look only for drop */
3751 [ + - ]: 96 : if (tp->srtt_us)
3752 [ - + ]: 96 : timeout = usecs_to_jiffies(tp->srtt_us >> (3 - 1));
3753 : : else
3754 : : timeout = TCP_TIMEOUT_INIT;
3755 : 96 : timeout += jiffies;
3756 : :
3757 [ - + ]: 96 : WARN_ON_ONCE(icsk->icsk_ack.pending & ICSK_ACK_TIMER);
3758 : 96 : smp_store_release(&icsk->icsk_ack.pending,
3759 : : icsk->icsk_ack.pending | ICSK_ACK_SCHED | ICSK_ACK_TIMER);
3760 : 96 : sk_reset_timer(ssk, &icsk->icsk_delack_timer, timeout);
3761 : : }
3762 : :
3763 : 34351 : void mptcp_subflow_process_delegated(struct sock *ssk, long status)
3764 : : {
3765 [ + + ]: 34351 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
3766 : 34351 : struct sock *sk = subflow->conn;
3767 : :
3768 [ + + ]: 34351 : if (status & BIT(MPTCP_DELEGATE_SEND)) {
3769 : 11040 : mptcp_data_lock(sk);
3770 [ + + ]: 11040 : if (!sock_owned_by_user(sk))
3771 : 9917 : __mptcp_subflow_push_pending(sk, ssk, true);
3772 : : else
3773 [ - + ]: 1123 : __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
3774 : 11040 : mptcp_data_unlock(sk);
3775 : : }
3776 [ + + ]: 34351 : if (status & BIT(MPTCP_DELEGATE_SNDBUF)) {
3777 : 20463 : mptcp_data_lock(sk);
3778 [ + + ]: 20463 : if (!sock_owned_by_user(sk))
3779 : 16227 : __mptcp_sync_sndbuf(sk);
3780 : : else
3781 [ - + ]: 4236 : __set_bit(MPTCP_SYNC_SNDBUF, &mptcp_sk(sk)->cb_flags);
3782 : 20463 : mptcp_data_unlock(sk);
3783 : : }
3784 [ + + ]: 34351 : if (status & BIT(MPTCP_DELEGATE_ACK))
3785 : 600 : schedule_3rdack_retransmission(ssk);
3786 : 34351 : }
3787 : :
3788 : 0 : static int mptcp_hash(struct sock *sk)
3789 : : {
3790 : : /* should never be called,
3791 : : * we hash the TCP subflows not the MPTCP socket
3792 : : */
3793 : 0 : WARN_ON_ONCE(1);
3794 : 0 : return 0;
3795 : : }
3796 : :
3797 : 10 : static void mptcp_unhash(struct sock *sk)
3798 : : {
3799 : : /* called from sk_common_release(), but nothing to do here */
3800 : 10 : }
3801 : :
3802 : 0 : static int mptcp_get_port(struct sock *sk, unsigned short snum)
3803 : : {
3804 [ # # ]: 0 : struct mptcp_sock *msk = mptcp_sk(sk);
3805 : :
3806 [ # # # # ]: 0 : pr_debug("msk=%p, ssk=%p\n", msk, msk->first);
3807 [ # # ]: 0 : if (WARN_ON_ONCE(!msk->first))
3808 : 0 : return -EINVAL;
3809 : :
3810 : 0 : return inet_csk_get_port(msk->first, snum);
3811 : : }
3812 : :
3813 : 1470 : void mptcp_finish_connect(struct sock *ssk)
3814 : : {
3815 : 1470 : struct mptcp_subflow_context *subflow;
3816 : 1470 : struct mptcp_sock *msk;
3817 : 1470 : struct sock *sk;
3818 : :
3819 [ - + ]: 1470 : subflow = mptcp_subflow_ctx(ssk);
3820 : 1470 : sk = subflow->conn;
3821 [ - + ]: 1470 : msk = mptcp_sk(sk);
3822 : :
3823 [ - + - - ]: 1470 : pr_debug("msk=%p, token=%u\n", sk, subflow->token);
3824 : :
3825 : 1470 : subflow->map_seq = subflow->iasn;
3826 : 1470 : subflow->map_subflow_seq = 1;
3827 : :
3828 : : /* the socket is not connected yet, no msk/subflow ops can access/race
3829 : : * accessing the field below
3830 : : */
3831 : 1470 : WRITE_ONCE(msk->local_key, subflow->local_key);
3832 : 1470 : WRITE_ONCE(msk->rcvq_space.time, mptcp_stamp());
3833 : :
3834 : 1470 : mptcp_pm_new_connection(msk, ssk, 0);
3835 : 1470 : }
3836 : :
3837 : 6272 : void mptcp_sock_graft(struct sock *sk, struct socket *parent)
3838 : : {
3839 : 6272 : write_lock_bh(&sk->sk_callback_lock);
3840 : 6272 : rcu_assign_pointer(sk->sk_wq, &parent->wq);
3841 [ + - ]: 6272 : sk_set_socket(sk, parent);
3842 : 6272 : write_unlock_bh(&sk->sk_callback_lock);
3843 : 6272 : }
3844 : :
3845 : : /* Can be called without holding the msk socket lock; use the callback lock
3846 : : * to avoid {READ_,WRITE_}ONCE annotations on sk_socket.
3847 : : */
3848 : 612 : static void mptcp_sock_check_graft(struct sock *sk, struct sock *ssk)
3849 : : {
3850 : 612 : struct socket *sock;
3851 : :
3852 : 612 : write_lock_bh(&sk->sk_callback_lock);
3853 : 612 : sock = sk->sk_socket;
3854 : 612 : write_unlock_bh(&sk->sk_callback_lock);
3855 [ + + ]: 612 : if (sock) {
3856 : 550 : mptcp_sock_graft(ssk, sock);
3857 : 550 : __mptcp_inherit_cgrp_data(sk, ssk);
3858 : 550 : __mptcp_inherit_memcg(sk, ssk, GFP_ATOMIC);
3859 : : }
3860 : 612 : }
3861 : :
3862 : 1200 : bool mptcp_finish_join(struct sock *ssk)
3863 : : {
3864 [ - + ]: 1200 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
3865 [ - + ]: 1200 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
3866 : 1200 : struct sock *parent = (void *)msk;
3867 : 1200 : bool ret = true;
3868 : :
3869 [ - + - - ]: 1200 : pr_debug("msk=%p, subflow=%p\n", msk, subflow);
3870 : :
3871 : : /* mptcp socket already closing? */
3872 [ - + ]: 1200 : if (!mptcp_is_fully_established(parent)) {
3873 : 0 : subflow->reset_reason = MPTCP_RST_EMPTCP;
3874 : 0 : return false;
3875 : : }
3876 : :
3877 : : /* Active subflow, already present inside the conn_list; is grafted
3878 : : * either by __mptcp_subflow_connect() or accept.
3879 : : */
3880 [ + + ]: 1200 : if (!list_empty(&subflow->node)) {
3881 : 588 : spin_lock_bh(&msk->fallback_lock);
3882 [ - + - + ]: 588 : if (!msk->allow_subflows) {
[ - + ]
3883 : 0 : spin_unlock_bh(&msk->fallback_lock);
3884 : 0 : return false;
3885 : : }
3886 : 588 : mptcp_subflow_joined(msk, ssk);
3887 : 588 : spin_unlock_bh(&msk->fallback_lock);
3888 : 588 : mptcp_propagate_sndbuf(parent, ssk);
3889 : 588 : return true;
3890 : : }
3891 : :
3892 [ - + ]: 612 : if (!mptcp_pm_allow_new_subflow(msk)) {
3893 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_JOINREJECTED);
3894 : 0 : goto err_prohibited;
3895 : : }
3896 : :
3897 : : /* If we can't acquire msk socket lock here, let the release callback
3898 : : * handle it
3899 : : */
3900 : 612 : mptcp_data_lock(parent);
3901 [ + + ]: 612 : if (!sock_owned_by_user(parent)) {
3902 : 606 : ret = __mptcp_finish_join(msk, ssk);
3903 [ + - ]: 606 : if (ret) {
3904 : 606 : sock_hold(ssk);
3905 : 606 : list_add_tail(&subflow->node, &msk->conn_list);
3906 : 606 : mptcp_sock_check_graft(parent, ssk);
3907 : : }
3908 : : } else {
3909 : 6 : sock_hold(ssk);
3910 [ - + ]: 6 : list_add_tail(&subflow->node, &msk->join_list);
3911 [ - + - - : 6 : __set_bit(MPTCP_FLUSH_JOIN_LIST, &msk->cb_flags);
- - ]
3912 : :
3913 : : /* In case of later failures, __mptcp_flush_join_list() will
3914 : : * properly orphan the ssk via mptcp_close_ssk().
3915 : : */
3916 : 6 : mptcp_sock_check_graft(parent, ssk);
3917 : : }
3918 : 612 : mptcp_data_unlock(parent);
3919 : :
3920 [ - + ]: 612 : if (!ret) {
3921 : 0 : mptcp_pm_close_subflow(msk);
3922 : 0 : err_prohibited:
3923 : 0 : subflow->reset_reason = MPTCP_RST_EPROHIBIT;
3924 : 0 : return false;
3925 : : }
3926 : :
3927 : : return true;
3928 : : }
3929 : :
3930 : 2000 : static void mptcp_shutdown(struct sock *sk, int how)
3931 : : {
3932 [ - + - - ]: 2000 : pr_debug("sk=%p, how=%d\n", sk, how);
3933 : :
3934 [ + - + + ]: 2000 : if ((how & SEND_SHUTDOWN) && mptcp_close_state(sk))
3935 : 1842 : __mptcp_wr_shutdown(sk);
3936 : 2000 : }
3937 : :
3938 : 16 : static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)
3939 : : {
3940 : 16 : const struct sock *sk = (void *)msk;
3941 : 16 : u64 delta;
3942 : :
3943 [ + - ]: 16 : if (sk->sk_state == TCP_LISTEN)
3944 : : return -EINVAL;
3945 : :
3946 [ - + + - ]: 16 : if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
[ + - ]
3947 : : return 0;
3948 : :
3949 : 16 : delta = msk->write_seq - v;
3950 [ + + + + ]: 16 : if (__mptcp_check_fallback(msk) && msk->first) {
3951 [ - + ]: 16 : struct tcp_sock *tp = tcp_sk(msk->first);
3952 : :
3953 : : /* the first subflow is disconnected after close - see
3954 : : * __mptcp_close_ssk(). tcp_disconnect() moves the write_seq
3955 : : * so ignore that status, too.
3956 : : */
3957 [ - + - + ]: 16 : if (!((1 << msk->first->sk_state) &
[ + - ]
3958 : : (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE)))
3959 : 16 : delta += READ_ONCE(tp->write_seq) - tp->snd_una;
3960 : : }
3961 : 16 : if (delta > INT_MAX)
3962 : : delta = INT_MAX;
3963 : :
3964 : 16 : return (int)delta;
3965 : : }
3966 : :
3967 : 16 : static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)
3968 : : {
3969 [ - + ]: 16 : struct mptcp_sock *msk = mptcp_sk(sk);
3970 : 16 : bool slow;
3971 : :
3972 [ - + + - ]: 16 : switch (cmd) {
3973 : 0 : case SIOCINQ:
3974 [ # # ]: 0 : if (sk->sk_state == TCP_LISTEN)
3975 : : return -EINVAL;
3976 : :
3977 : 0 : lock_sock(sk);
3978 [ # # ]: 0 : if (mptcp_move_skbs(sk))
3979 : 0 : mptcp_cleanup_rbuf(msk, 0);
3980 : 0 : *karg = mptcp_inq_hint(sk);
3981 : 0 : release_sock(sk);
3982 : 0 : break;
3983 : 4 : case SIOCOUTQ:
3984 : 8 : slow = lock_sock_fast(sk);
3985 : 8 : *karg = mptcp_ioctl_outq(msk, READ_ONCE(msk->snd_una));
3986 : 8 : unlock_sock_fast(sk, slow);
3987 : 8 : break;
3988 : 4 : case SIOCOUTQNSD:
3989 : 8 : slow = lock_sock_fast(sk);
3990 : 8 : *karg = mptcp_ioctl_outq(msk, msk->snd_nxt);
3991 : 8 : unlock_sock_fast(sk, slow);
3992 : 8 : break;
3993 : : default:
3994 : : return -ENOIOCTLCMD;
3995 : : }
3996 : :
3997 : : return 0;
3998 : : }
3999 : :
4000 : 1718 : static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
4001 : : int addr_len)
4002 : : {
4003 : 1718 : struct mptcp_subflow_context *subflow;
4004 [ - + ]: 1718 : struct mptcp_sock *msk = mptcp_sk(sk);
4005 : 1718 : int err = -EINVAL;
4006 : 1718 : struct sock *ssk;
4007 : :
4008 : 1718 : ssk = __mptcp_nmpc_sk(msk);
4009 [ - + ]: 1718 : if (IS_ERR(ssk))
4010 : 0 : return PTR_ERR(ssk);
4011 : :
4012 : 1718 : mptcp_set_state(sk, TCP_SYN_SENT);
4013 [ + - ]: 1718 : subflow = mptcp_subflow_ctx(ssk);
4014 : : #ifdef CONFIG_TCP_MD5SIG
4015 : : /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
4016 : : * TCP option space.
4017 : : */
4018 : : if (rcu_access_pointer(tcp_sk(ssk)->md5sig_info))
4019 : : mptcp_early_fallback(msk, subflow, MPTCP_MIB_MD5SIGFALLBACK);
4020 : : #endif
4021 [ + - ]: 1718 : if (subflow->request_mptcp) {
4022 [ + + ]: 1718 : if (mptcp_active_should_disable(sk))
4023 : 6 : mptcp_early_fallback(msk, subflow,
4024 : : MPTCP_MIB_MPCAPABLEACTIVEDISABLED);
4025 [ - + ]: 1712 : else if (mptcp_token_new_connect(ssk) < 0)
4026 : 0 : mptcp_early_fallback(msk, subflow,
4027 : : MPTCP_MIB_TOKENFALLBACKINIT);
4028 : : }
4029 : :
4030 : 1718 : WRITE_ONCE(msk->write_seq, subflow->idsn);
4031 : 1718 : WRITE_ONCE(msk->snd_nxt, subflow->idsn);
4032 : 1718 : WRITE_ONCE(msk->snd_una, subflow->idsn);
4033 [ + + ]: 1718 : if (likely(!__mptcp_check_fallback(msk)))
4034 [ + - ]: 1712 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVE);
4035 : :
4036 : : /* if reaching here via the fastopen/sendmsg path, the caller already
4037 : : * acquired the subflow socket lock, too.
4038 : : */
4039 [ + + ]: 1718 : if (!msk->fastopening)
4040 : 1648 : lock_sock(ssk);
4041 : :
4042 : : /* the following mirrors closely a very small chunk of code from
4043 : : * __inet_stream_connect()
4044 : : */
4045 [ - + ]: 1718 : if (ssk->sk_state != TCP_CLOSE)
4046 : 0 : goto out;
4047 : :
4048 [ + - - + : 1718 : if (BPF_CGROUP_PRE_CONNECT_ENABLED(ssk)) {
- - ]
4049 : 0 : err = ssk->sk_prot->pre_connect(ssk, uaddr, addr_len);
4050 [ - - ]: 0 : if (err)
4051 : 0 : goto out;
4052 : : }
4053 : :
4054 : 1718 : err = ssk->sk_prot->connect(ssk, uaddr, addr_len);
4055 [ - + ]: 1718 : if (err < 0)
4056 : 0 : goto out;
4057 : :
4058 [ + + ]: 1718 : inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
4059 : :
4060 : 1718 : out:
4061 [ + + ]: 1718 : if (!msk->fastopening)
4062 : 1648 : release_sock(ssk);
4063 : :
4064 : : /* on successful connect, the msk state will be moved to established by
4065 : : * subflow_finish_connect()
4066 : : */
4067 [ - + ]: 1718 : if (unlikely(err)) {
4068 : : /* avoid leaving a dangling token in an unconnected socket */
4069 : 0 : mptcp_token_destroy(msk);
4070 : 0 : mptcp_set_state(sk, TCP_CLOSE);
4071 : 0 : return err;
4072 : : }
4073 : :
4074 : 1718 : mptcp_copy_inaddrs(sk, ssk);
4075 : 1718 : return 0;
4076 : : }
4077 : :
4078 : : static struct proto mptcp_prot = {
4079 : : .name = "MPTCP",
4080 : : .owner = THIS_MODULE,
4081 : : .init = mptcp_init_sock,
4082 : : .connect = mptcp_connect,
4083 : : .disconnect = mptcp_disconnect,
4084 : : .close = mptcp_close,
4085 : : .setsockopt = mptcp_setsockopt,
4086 : : .getsockopt = mptcp_getsockopt,
4087 : : .shutdown = mptcp_shutdown,
4088 : : .destroy = mptcp_destroy,
4089 : : .sendmsg = mptcp_sendmsg,
4090 : : .ioctl = mptcp_ioctl,
4091 : : .recvmsg = mptcp_recvmsg,
4092 : : .release_cb = mptcp_release_cb,
4093 : : .hash = mptcp_hash,
4094 : : .unhash = mptcp_unhash,
4095 : : .get_port = mptcp_get_port,
4096 : : .stream_memory_free = mptcp_stream_memory_free,
4097 : : .sockets_allocated = &mptcp_sockets_allocated,
4098 : :
4099 : : .memory_allocated = &net_aligned_data.tcp_memory_allocated,
4100 : : .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc,
4101 : :
4102 : : .memory_pressure = &tcp_memory_pressure,
4103 : : .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_tcp_wmem),
4104 : : .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_tcp_rmem),
4105 : : .sysctl_mem = sysctl_tcp_mem,
4106 : : .obj_size = sizeof(struct mptcp_sock),
4107 : : .slab_flags = SLAB_TYPESAFE_BY_RCU,
4108 : : .no_autobind = true,
4109 : : };
4110 : :
4111 : 1744 : static int mptcp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len)
4112 : : {
4113 [ - + ]: 1744 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4114 : 1744 : struct sock *ssk, *sk = sock->sk;
4115 : 1744 : int err = -EINVAL;
4116 : :
4117 : 1744 : lock_sock(sk);
4118 : 1744 : ssk = __mptcp_nmpc_sk(msk);
4119 [ - + ]: 1744 : if (IS_ERR(ssk)) {
4120 : 0 : err = PTR_ERR(ssk);
4121 : 0 : goto unlock;
4122 : : }
4123 : :
4124 [ + + ]: 1744 : if (sk->sk_family == AF_INET)
4125 : 900 : err = inet_bind_sk(ssk, uaddr, addr_len);
4126 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
4127 [ + - ]: 844 : else if (sk->sk_family == AF_INET6)
4128 : 844 : err = inet6_bind_sk(ssk, uaddr, addr_len);
4129 : : #endif
4130 [ + + ]: 1744 : if (!err)
4131 : 1738 : mptcp_copy_inaddrs(sk, ssk);
4132 : :
4133 : 6 : unlock:
4134 : 1744 : release_sock(sk);
4135 : 1744 : return err;
4136 : : }
4137 : :
4138 : 1738 : static int mptcp_listen(struct socket *sock, int backlog)
4139 : : {
4140 [ - + ]: 1738 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4141 : 1738 : struct sock *sk = sock->sk;
4142 : 1738 : struct sock *ssk;
4143 : 1738 : int err;
4144 : :
4145 [ - + - - ]: 1738 : pr_debug("msk=%p\n", msk);
4146 : :
4147 : 1738 : lock_sock(sk);
4148 : :
4149 : 1738 : err = -EINVAL;
4150 [ + - - + ]: 1738 : if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
4151 : 0 : goto unlock;
4152 : :
4153 : 1738 : ssk = __mptcp_nmpc_sk(msk);
4154 [ - + ]: 1738 : if (IS_ERR(ssk)) {
4155 : 0 : err = PTR_ERR(ssk);
4156 : 0 : goto unlock;
4157 : : }
4158 : :
4159 : 1738 : mptcp_set_state(sk, TCP_LISTEN);
4160 : 1738 : sock_set_flag(sk, SOCK_RCU_FREE);
4161 : :
4162 : 1738 : lock_sock(ssk);
4163 : 1738 : err = __inet_listen_sk(ssk, backlog);
4164 : 1738 : release_sock(ssk);
4165 : 1738 : mptcp_set_state(sk, inet_sk_state_load(ssk));
4166 : :
4167 [ - + ]: 1738 : if (!err) {
4168 : 1738 : sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
4169 : 1738 : mptcp_copy_inaddrs(sk, ssk);
4170 : 1738 : mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
4171 : : }
4172 : :
4173 : 0 : unlock:
4174 : 1738 : release_sock(sk);
4175 : 1738 : return err;
4176 : : }
4177 : :
4178 : 1586 : static void mptcp_graft_subflows(struct sock *sk)
4179 : : {
4180 : 1586 : struct mptcp_subflow_context *subflow;
4181 [ - + ]: 1586 : struct mptcp_sock *msk = mptcp_sk(sk);
4182 : :
4183 [ + + ]: 1586 : if (mem_cgroup_sockets_enabled) {
4184 : 6 : LIST_HEAD(join_list);
4185 : :
4186 : : /* Subflows joining after __inet_accept() will get the
4187 : : * mem CG properly initialized at mptcp_finish_join() time,
4188 : : * but subflows pending in join_list need explicit
4189 : : * initialization before flushing `backlog_unaccounted`
4190 : : * or MPTCP can later unexpectedly observe unaccounted memory.
4191 : : */
4192 : 6 : mptcp_data_lock(sk);
4193 [ - + ]: 6 : list_splice_init(&msk->join_list, &join_list);
4194 : 6 : mptcp_data_unlock(sk);
4195 : :
4196 : 6 : __mptcp_flush_join_list(sk, &join_list);
4197 : : }
4198 : :
4199 [ + + ]: 3228 : mptcp_for_each_subflow(msk, subflow) {
4200 : 1642 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4201 : :
4202 : 1642 : lock_sock(ssk);
4203 : :
4204 : : /* Set ssk->sk_socket of accept()ed flows to mptcp socket.
4205 : : * This is needed so NOSPACE flag can be set from tcp stack.
4206 : : */
4207 [ + - ]: 1642 : if (!ssk->sk_socket)
4208 : 1642 : mptcp_sock_graft(ssk, sk->sk_socket);
4209 : :
4210 [ + + ]: 1642 : if (!mem_cgroup_sk_enabled(sk))
4211 : 1636 : goto unlock;
4212 : :
4213 : 6 : __mptcp_inherit_cgrp_data(sk, ssk);
4214 : 6 : __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
4215 : :
4216 : 1642 : unlock:
4217 : 1642 : release_sock(ssk);
4218 : : }
4219 : :
4220 [ + + ]: 1586 : if (mem_cgroup_sk_enabled(sk)) {
4221 : 6 : gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
4222 : 6 : int amt;
4223 : :
4224 : : /* Account the backlog memory; prior accept() is aware of
4225 : : * fwd and rmem only.
4226 : : */
4227 : 6 : mptcp_data_lock(sk);
4228 : 12 : amt = sk_mem_pages(sk->sk_forward_alloc +
4229 : 9 : msk->backlog_unaccounted +
4230 : 6 : atomic_read(&sk->sk_rmem_alloc)) -
4231 : 9 : sk_mem_pages(sk->sk_forward_alloc +
4232 : 6 : atomic_read(&sk->sk_rmem_alloc));
4233 : 6 : msk->backlog_unaccounted = 0;
4234 : 6 : mptcp_data_unlock(sk);
4235 : :
4236 [ - + ]: 6 : if (amt)
4237 : 0 : mem_cgroup_sk_charge(sk, amt, gfp);
4238 : : }
4239 : 1586 : }
4240 : :
4241 : 1770 : static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
4242 : : struct proto_accept_arg *arg)
4243 : : {
4244 [ - + ]: 1770 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4245 : 1770 : struct sock *ssk, *newsk;
4246 : :
4247 [ - + - - ]: 1770 : pr_debug("msk=%p\n", msk);
4248 : :
4249 : : /* Buggy applications can call accept on socket states other then LISTEN
4250 : : * but no need to allocate the first subflow just to error out.
4251 : : */
4252 : 1770 : ssk = READ_ONCE(msk->first);
4253 [ + - ]: 1770 : if (!ssk)
4254 : : return -EINVAL;
4255 : :
4256 [ - + - - ]: 1770 : pr_debug("ssk=%p, listener=%p\n", ssk, mptcp_subflow_ctx(ssk));
4257 : 1770 : newsk = inet_csk_accept(ssk, arg);
4258 [ + + ]: 1770 : if (!newsk)
4259 : 6 : return arg->err;
4260 : :
4261 [ - + - - : 1764 : pr_debug("newsk=%p, subflow is mptcp=%d\n", newsk, sk_is_mptcp(newsk));
- - ]
[ - + - - ]
4262 [ - + + + ]: 1764 : if (sk_is_mptcp(newsk)) {
[ + + ]
4263 : 1586 : struct mptcp_subflow_context *subflow;
4264 : 1586 : struct sock *new_mptcp_sock;
4265 : :
4266 [ - + ]: 1586 : subflow = mptcp_subflow_ctx(newsk);
4267 : 1586 : new_mptcp_sock = subflow->conn;
4268 : :
4269 : : /* is_mptcp should be false if subflow->conn is missing, see
4270 : : * subflow_syn_recv_sock()
4271 : : */
4272 [ - + ]: 1586 : if (WARN_ON_ONCE(!new_mptcp_sock)) {
4273 [ # # ]: 0 : tcp_sk(newsk)->is_mptcp = 0;
4274 : 0 : goto tcpfallback;
4275 : : }
4276 : :
4277 : 1586 : newsk = new_mptcp_sock;
4278 [ + - ]: 1586 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPCAPABLEPASSIVEACK);
4279 : :
4280 [ - + ]: 1586 : newsk->sk_kern_sock = arg->kern;
4281 : 1586 : lock_sock(newsk);
4282 : 1586 : __inet_accept(sock, newsock, newsk);
4283 : :
4284 : 1586 : set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
4285 [ - + ]: 1586 : msk = mptcp_sk(newsk);
4286 : 1586 : msk->in_accept_queue = 0;
4287 : :
4288 : 1586 : mptcp_graft_subflows(newsk);
4289 : 1586 : mptcp_rps_record_subflows(msk);
4290 [ + + ]: 1586 : __mptcp_propagate_sndbuf(newsk, mptcp_subflow_tcp_sock(subflow));
4291 : :
4292 : : /* Do late cleanup for the first subflow as necessary. Also
4293 : : * deal with bad peers not doing a complete shutdown.
4294 : : */
4295 [ + + ]: 1586 : if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
4296 [ + - ]: 6 : if (unlikely(list_is_singular(&msk->conn_list)))
4297 : 6 : mptcp_set_state(newsk, TCP_CLOSE);
4298 : 6 : mptcp_close_ssk(newsk, msk->first,
4299 : 6 : mptcp_subflow_ctx(msk->first));
4300 : : }
4301 : : } else {
4302 : 178 : tcpfallback:
4303 [ - + ]: 178 : newsk->sk_kern_sock = arg->kern;
4304 : 178 : lock_sock(newsk);
4305 : 178 : __inet_accept(sock, newsock, newsk);
4306 : : /* we are being invoked after accepting a non-mp-capable
4307 : : * flow: sk is a tcp_sk, not an mptcp one.
4308 : : *
4309 : : * Hand the socket over to tcp so all further socket ops
4310 : : * bypass mptcp.
4311 : : */
4312 : 178 : WRITE_ONCE(newsock->sk->sk_socket->ops,
4313 : : mptcp_fallback_tcp_ops(newsock->sk));
4314 : : }
4315 : 1764 : release_sock(newsk);
4316 : :
4317 : 1764 : return 0;
4318 : : }
4319 : :
4320 : 827518 : static __poll_t mptcp_check_writeable(struct mptcp_sock *msk)
4321 : : {
4322 : 827518 : struct sock *sk = (struct sock *)msk;
4323 : :
4324 [ + + ]: 827518 : if (__mptcp_stream_is_writeable(sk, 1))
4325 : : return EPOLLOUT | EPOLLWRNORM;
4326 : :
4327 : 349241 : set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
4328 : 349241 : smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */
4329 [ + + ]: 349241 : if (__mptcp_stream_is_writeable(sk, 1))
4330 : : return EPOLLOUT | EPOLLWRNORM;
4331 : :
4332 : : return 0;
4333 : : }
4334 : :
4335 : 1359047 : static __poll_t mptcp_poll(struct file *file, struct socket *sock,
4336 : : struct poll_table_struct *wait)
4337 : : {
4338 : 1359047 : struct sock *sk = sock->sk;
4339 : 1359047 : struct mptcp_sock *msk;
4340 : 1359047 : __poll_t mask = 0;
4341 : 1359047 : u8 shutdown;
4342 : 1359047 : int state;
4343 : :
4344 [ - + ]: 1359047 : msk = mptcp_sk(sk);
4345 : 1359047 : sock_poll_wait(file, sock, wait);
4346 : :
4347 : 1359047 : state = inet_sk_state_load(sk);
4348 [ - + - - ]: 1359047 : pr_debug("msk=%p state=%d flags=%lx\n", msk, state, msk->flags);
4349 [ + + ]: 1359047 : if (state == TCP_LISTEN) {
4350 : 2764 : struct sock *ssk = READ_ONCE(msk->first);
4351 : :
4352 [ - + ]: 2764 : if (WARN_ON_ONCE(!ssk))
4353 : 0 : return 0;
4354 : :
4355 [ + + ]: 4154 : return inet_csk_listen_poll(ssk);
4356 : : }
4357 : :
4358 : 1356283 : shutdown = READ_ONCE(sk->sk_shutdown);
4359 [ + + ]: 1356283 : if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
4360 : 3714 : mask |= EPOLLHUP;
4361 [ + + ]: 1356283 : if (shutdown & RCV_SHUTDOWN)
4362 : 203259 : mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
4363 : :
4364 [ + - ]: 1356283 : if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
4365 : 1356283 : mask |= mptcp_check_readable(sk);
4366 [ + + ]: 1356283 : if (shutdown & SEND_SHUTDOWN)
4367 : 528765 : mask |= EPOLLOUT | EPOLLWRNORM;
4368 : : else
4369 : 827518 : mask |= mptcp_check_writeable(msk);
4370 [ # # # # ]: 0 : } else if (state == TCP_SYN_SENT &&
[ # # ]
4371 [ # # ]: 0 : inet_test_bit(DEFER_CONNECT, sk)) {
4372 : : /* cf tcp_poll() note about TFO */
4373 : 0 : mask |= EPOLLOUT | EPOLLWRNORM;
4374 : : }
4375 : :
4376 : : /* This barrier is coupled with smp_wmb() in __mptcp_error_report() */
4377 : 1356283 : smp_rmb();
4378 [ + + ]: 1356283 : if (READ_ONCE(sk->sk_err))
4379 : 10 : mask |= EPOLLERR;
4380 : :
4381 : : return mask;
4382 : : }
4383 : :
4384 : 498583 : static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
4385 : : {
4386 [ - + ]: 498583 : struct mptcp_sock *msk = mptcp_sk(sk);
4387 : 498583 : struct sk_buff *skb;
4388 : 498583 : u32 offset;
4389 : :
4390 [ + + ]: 498583 : if (!list_empty(&msk->backlog_list))
4391 : 3131 : mptcp_move_skbs(sk);
4392 : :
4393 [ + + + - ]: 498583 : while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
4394 : 126988 : offset = MPTCP_SKB_CB(skb)->offset;
4395 [ + - ]: 126988 : if (offset < skb->len) {
4396 : 126988 : *off = offset;
4397 : 126988 : return skb;
4398 : : }
4399 : 0 : mptcp_eat_recv_skb(sk, skb);
4400 : : }
4401 : : return NULL;
4402 : : }
4403 : :
4404 : : /*
4405 : : * Note:
4406 : : * - It is assumed that the socket was locked by the caller.
4407 : : */
4408 : 270220 : static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
4409 : : sk_read_actor_t recv_actor, bool noack)
4410 : : {
4411 [ - + ]: 270220 : struct mptcp_sock *msk = mptcp_sk(sk);
4412 : 270220 : struct sk_buff *skb;
4413 : 270220 : int copied = 0;
4414 : 270220 : u32 offset;
4415 : :
4416 : 270220 : msk_owned_by_me(msk);
4417 : :
4418 [ + - ]: 270220 : if (sk->sk_state == TCP_LISTEN)
4419 : : return -ENOTCONN;
4420 [ + + ]: 385024 : while ((skb = mptcp_recv_skb(sk, &offset)) != NULL) {
4421 : 121595 : u32 data_len = skb->len - offset;
4422 : 121595 : int count;
4423 : 121595 : u32 size;
4424 : :
4425 : 121595 : size = min_t(size_t, data_len, INT_MAX);
4426 : 121595 : count = recv_actor(desc, skb, offset, size);
4427 [ + + ]: 121595 : if (count <= 0) {
4428 [ + + ]: 993 : if (!copied)
4429 : 945 : copied = count;
4430 : : break;
4431 : : }
4432 : :
4433 : 120602 : copied += count;
4434 : :
4435 : 120602 : msk->bytes_consumed += count;
4436 [ + + ]: 120602 : if (count < data_len) {
4437 : 3910 : MPTCP_SKB_CB(skb)->offset += count;
4438 : 3910 : MPTCP_SKB_CB(skb)->map_seq += count;
4439 : 3910 : break;
4440 : : }
4441 : :
4442 : 116692 : mptcp_eat_recv_skb(sk, skb);
4443 [ + + ]: 116692 : if (!desc->count)
4444 : : break;
4445 : : }
4446 : :
4447 [ - + ]: 270220 : if (noack)
4448 : 0 : goto out;
4449 : :
4450 : 270220 : mptcp_rcv_space_adjust(msk, copied);
4451 : :
4452 [ + + ]: 270220 : if (copied > 0) {
4453 : 113559 : mptcp_recv_skb(sk, &offset);
4454 : 113559 : mptcp_cleanup_rbuf(msk, copied);
4455 : : }
4456 : 156661 : out:
4457 : : return copied;
4458 : : }
4459 : :
4460 : 0 : static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
4461 : : sk_read_actor_t recv_actor)
4462 : : {
4463 : 0 : return __mptcp_read_sock(sk, desc, recv_actor, false);
4464 : : }
4465 : :
4466 : 270220 : static int __mptcp_splice_read(struct sock *sk, struct tcp_splice_state *tss)
4467 : : {
4468 : : /* Store TCP splice context information in read_descriptor_t. */
4469 : 270220 : read_descriptor_t rd_desc = {
4470 : : .arg.data = tss,
4471 : 270220 : .count = tss->len,
4472 : : };
4473 : :
4474 : 270220 : return mptcp_read_sock(sk, &rd_desc, tcp_splice_data_recv);
4475 : : }
4476 : :
4477 : : /**
4478 : : * mptcp_splice_read - splice data from MPTCP socket to a pipe
4479 : : * @sock: socket to splice from
4480 : : * @ppos: position (not valid)
4481 : : * @pipe: pipe to splice to
4482 : : * @len: number of bytes to splice
4483 : : * @flags: splice modifier flags
4484 : : *
4485 : : * Description:
4486 : : * Will read pages from given socket and fill them into a pipe.
4487 : : *
4488 : : * Return:
4489 : : * Amount of bytes that have been spliced.
4490 : : *
4491 : : **/
4492 : 100140 : static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
4493 : : struct pipe_inode_info *pipe, size_t len,
4494 : : unsigned int flags)
4495 : : {
4496 : 100140 : struct tcp_splice_state tss = {
4497 : : .pipe = pipe,
4498 : : .len = len,
4499 : : .flags = flags,
4500 : : };
4501 : 100140 : struct sock *sk = sock->sk;
4502 : 100140 : ssize_t spliced = 0;
4503 : 100140 : int ret = 0;
4504 : 100140 : long timeo;
4505 : :
4506 : : /*
4507 : : * We can't seek on a socket input
4508 : : */
4509 [ + - ]: 100140 : if (unlikely(*ppos))
4510 : : return -ESPIPE;
4511 : :
4512 : 100140 : lock_sock(sk);
4513 : :
4514 [ - + ]: 100140 : mptcp_rps_record_subflows(mptcp_sk(sk));
4515 : :
4516 [ + - ]: 100140 : timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
4517 [ + - ]: 270220 : while (tss.len) {
4518 : 270220 : ret = __mptcp_splice_read(sk, &tss);
4519 [ + + ]: 270220 : if (ret < 0) {
4520 : : break;
4521 [ + + ]: 269275 : } else if (!ret) {
4522 [ + + ]: 155716 : if (spliced)
4523 : : break;
4524 [ + - ]: 61958 : if (sock_flag(sk, SOCK_DONE))
4525 : : break;
4526 [ - + ]: 61958 : if (sk->sk_err) {
4527 : 0 : ret = sock_error(sk);
4528 : 0 : break;
4529 : : }
4530 [ + + ]: 61958 : if (sk->sk_shutdown & RCV_SHUTDOWN)
4531 : : break;
4532 [ + - ]: 61718 : if (sk->sk_state == TCP_CLOSE) {
4533 : : /*
4534 : : * This occurs when user tries to read
4535 : : * from never connected socket.
4536 : : */
4537 : : ret = -ENOTCONN;
4538 : : break;
4539 : : }
4540 [ + - ]: 61718 : if (!timeo) {
4541 : : ret = -EAGAIN;
4542 : : break;
4543 : : }
4544 : : /* if __mptcp_splice_read() got nothing while we have
4545 : : * an skb in receive queue, we do not want to loop.
4546 : : * This might happen with URG data.
4547 : : */
4548 [ + - ]: 61718 : if (!skb_queue_empty(&sk->sk_receive_queue))
4549 : : break;
4550 : 61718 : ret = sk_wait_data(sk, &timeo, NULL);
4551 [ + - ]: 61718 : if (ret < 0)
4552 : : break;
4553 [ - + ]: 61718 : if (signal_pending(current)) {
4554 [ # # ]: 0 : ret = sock_intr_errno(timeo);
4555 : : break;
4556 : : }
4557 : 61718 : continue;
4558 : : }
4559 : 113559 : tss.len -= ret;
4560 : 113559 : spliced += ret;
4561 : :
4562 [ + + - + ]: 113559 : if (!tss.len || !timeo)
4563 : : break;
4564 : 108625 : release_sock(sk);
4565 : 108625 : lock_sock(sk);
4566 : :
4567 [ + + ]: 108625 : if (tcp_recv_should_stop(sk))
4568 : : break;
4569 : : }
4570 : :
4571 : 100140 : release_sock(sk);
4572 : :
4573 [ + + ]: 100140 : if (spliced)
4574 : : return spliced;
4575 : :
4576 : 240 : return ret;
4577 : : }
4578 : :
4579 : : static const struct proto_ops mptcp_stream_ops = {
4580 : : .family = PF_INET,
4581 : : .owner = THIS_MODULE,
4582 : : .release = inet_release,
4583 : : .bind = mptcp_bind,
4584 : : .connect = inet_stream_connect,
4585 : : .socketpair = sock_no_socketpair,
4586 : : .accept = mptcp_stream_accept,
4587 : : .getname = inet_getname,
4588 : : .poll = mptcp_poll,
4589 : : .ioctl = inet_ioctl,
4590 : : .gettstamp = sock_gettstamp,
4591 : : .listen = mptcp_listen,
4592 : : .shutdown = inet_shutdown,
4593 : : .setsockopt = sock_common_setsockopt,
4594 : : .getsockopt = sock_common_getsockopt,
4595 : : .sendmsg = inet_sendmsg,
4596 : : .recvmsg = inet_recvmsg,
4597 : : .mmap = sock_no_mmap,
4598 : : .set_rcvlowat = mptcp_set_rcvlowat,
4599 : : .read_sock = mptcp_read_sock,
4600 : : .splice_read = mptcp_splice_read,
4601 : : };
4602 : :
4603 : : static struct inet_protosw mptcp_protosw = {
4604 : : .type = SOCK_STREAM,
4605 : : .protocol = IPPROTO_MPTCP,
4606 : : .prot = &mptcp_prot,
4607 : : .ops = &mptcp_stream_ops,
4608 : : .flags = INET_PROTOSW_ICSK,
4609 : : };
4610 : :
4611 : 64365 : static int mptcp_napi_poll(struct napi_struct *napi, int budget)
4612 : : {
4613 : 64365 : struct mptcp_delegated_action *delegated;
4614 : 64365 : struct mptcp_subflow_context *subflow;
4615 : 64365 : int work_done = 0;
4616 : :
4617 : 64365 : delegated = container_of(napi, struct mptcp_delegated_action, napi);
4618 [ + + ]: 130643 : while ((subflow = mptcp_subflow_delegated_next(delegated)) != NULL) {
4619 : 66278 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4620 : :
4621 : 66278 : bh_lock_sock_nested(ssk);
4622 [ + + ]: 66278 : if (!sock_owned_by_user(ssk)) {
4623 : 27603 : mptcp_subflow_process_delegated(ssk, xchg(&subflow->delegated_status, 0));
4624 : : } else {
4625 : : /* tcp_release_cb_override already processed
4626 : : * the action or will do at next release_sock().
4627 : : * In both case must dequeue the subflow here - on the same
4628 : : * CPU that scheduled it.
4629 : : */
4630 : 38675 : smp_wmb();
4631 : 38675 : clear_bit(MPTCP_DELEGATE_SCHEDULED, &subflow->delegated_status);
4632 : : }
4633 : 66278 : bh_unlock_sock(ssk);
4634 : 66278 : sock_put(ssk);
4635 : :
4636 [ + - ]: 66278 : if (++work_done == budget)
4637 : : return budget;
4638 : : }
4639 : :
4640 : : /* always provide a 0 'work_done' argument, so that napi_complete_done
4641 : : * will not try accessing the NULL napi->dev ptr
4642 : : */
4643 : 64365 : napi_complete_done(napi, 0);
4644 : 64365 : return work_done;
4645 : : }
4646 : :
4647 : 6 : void __init mptcp_proto_init(void)
4648 : : {
4649 : 6 : struct mptcp_delegated_action *delegated;
4650 : 6 : int cpu;
4651 : :
4652 : 6 : mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;
4653 : :
4654 [ - + ]: 6 : if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
4655 : 0 : panic("Failed to allocate MPTCP pcpu counter\n");
4656 : :
4657 : 6 : mptcp_napi_dev = alloc_netdev_dummy(0);
4658 [ - + ]: 6 : if (!mptcp_napi_dev)
4659 : 0 : panic("Failed to allocate MPTCP dummy netdev\n");
4660 [ + - + - ]: 54 : for_each_possible_cpu(cpu) {
4661 : 24 : delegated = per_cpu_ptr(&mptcp_delegated_actions, cpu);
4662 : 24 : INIT_LIST_HEAD(&delegated->head);
4663 : 24 : netif_napi_add_tx(mptcp_napi_dev, &delegated->napi,
4664 : : mptcp_napi_poll);
4665 : 24 : napi_enable(&delegated->napi);
4666 : : }
4667 : :
4668 : 6 : mptcp_subflow_init();
4669 : 6 : mptcp_pm_init();
4670 : 6 : mptcp_sched_init();
4671 : 6 : mptcp_token_init();
4672 : :
4673 [ - + ]: 6 : if (proto_register(&mptcp_prot, 1) != 0)
4674 : 0 : panic("Failed to register MPTCP proto.\n");
4675 : :
4676 : 6 : inet_register_protosw(&mptcp_protosw);
4677 : :
4678 : 6 : BUILD_BUG_ON(sizeof(struct mptcp_skb_cb) > sizeof_field(struct sk_buff, cb));
4679 : :
4680 : : /* struct mptcp_data_frag: 'overhead' corresponds to the alignment
4681 : : * (ALIGN(1, sizeof(long)) - 1, so 8-1) + the struct's size
4682 : : */
4683 : 6 : BUILD_BUG_ON(ALIGN(1, sizeof(long)) - 1 + sizeof(struct mptcp_data_frag)
4684 : : > U8_MAX);
4685 : 6 : }
4686 : :
4687 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
4688 : : static const struct proto_ops mptcp_v6_stream_ops = {
4689 : : .family = PF_INET6,
4690 : : .owner = THIS_MODULE,
4691 : : .release = inet6_release,
4692 : : .bind = mptcp_bind,
4693 : : .connect = inet_stream_connect,
4694 : : .socketpair = sock_no_socketpair,
4695 : : .accept = mptcp_stream_accept,
4696 : : .getname = inet6_getname,
4697 : : .poll = mptcp_poll,
4698 : : .ioctl = inet6_ioctl,
4699 : : .gettstamp = sock_gettstamp,
4700 : : .listen = mptcp_listen,
4701 : : .shutdown = inet_shutdown,
4702 : : .setsockopt = sock_common_setsockopt,
4703 : : .getsockopt = sock_common_getsockopt,
4704 : : .sendmsg = inet6_sendmsg,
4705 : : .recvmsg = inet6_recvmsg,
4706 : : .mmap = sock_no_mmap,
4707 : : #ifdef CONFIG_COMPAT
4708 : : .compat_ioctl = inet6_compat_ioctl,
4709 : : #endif
4710 : : .set_rcvlowat = mptcp_set_rcvlowat,
4711 : : .read_sock = mptcp_read_sock,
4712 : : .splice_read = mptcp_splice_read,
4713 : : };
4714 : :
4715 : : static struct proto mptcp_v6_prot;
4716 : :
4717 : : static struct inet_protosw mptcp_v6_protosw = {
4718 : : .type = SOCK_STREAM,
4719 : : .protocol = IPPROTO_MPTCP,
4720 : : .prot = &mptcp_v6_prot,
4721 : : .ops = &mptcp_v6_stream_ops,
4722 : : .flags = INET_PROTOSW_ICSK,
4723 : : };
4724 : :
4725 : 6 : int __init mptcp_proto_v6_init(void)
4726 : : {
4727 : 6 : int err;
4728 : :
4729 : 6 : mptcp_subflow_v6_init();
4730 : :
4731 : 6 : mptcp_v6_prot = mptcp_prot;
4732 : 6 : strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
4733 : 6 : mptcp_v6_prot.slab = NULL;
4734 : 6 : mptcp_v6_prot.obj_size = sizeof(struct mptcp6_sock);
4735 : 6 : mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock, np);
4736 : :
4737 : 6 : err = proto_register(&mptcp_v6_prot, 1);
4738 [ + - ]: 6 : if (err)
4739 : : return err;
4740 : :
4741 : 6 : err = inet6_register_protosw(&mptcp_v6_protosw);
4742 [ - + ]: 6 : if (err)
4743 : 0 : proto_unregister(&mptcp_v6_prot);
4744 : :
4745 : : return err;
4746 : : }
4747 : : #endif
|