Skip to content

Commit 358ed62

Browse files
Talal Ahmaddavem330
authored andcommitted
tcp: call sk_wmem_schedule before sk_mem_charge in zerocopy path
sk_wmem_schedule makes sure that sk_forward_alloc has enough bytes for charging that is going to be done by sk_mem_charge. In the transmit zerocopy path, there is sk_mem_charge but there was no call to sk_wmem_schedule. This change adds that call. Without this call to sk_wmem_schedule, sk_forward_alloc can go negetive which is a bug because sk_forward_alloc is a per-socket space that has been forward charged so this can't be negative. Fixes: f214f91 ("tcp: enable MSG_ZEROCOPY") Signed-off-by: Talal Ahmad <talalahmad@google.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Wei Wang <weiwan@google.com> Reviewed-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 43b90bf commit 358ed62

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/ipv4/tcp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,9 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
13751375
}
13761376
pfrag->offset += copy;
13771377
} else {
1378+
if (!sk_wmem_schedule(sk, copy))
1379+
goto wait_for_space;
1380+
13781381
err = skb_zerocopy_iter_stream(sk, skb, msg, copy, uarg);
13791382
if (err == -EMSGSIZE || err == -EEXIST) {
13801383
tcp_mark_push(tp, skb);

0 commit comments

Comments
 (0)