Skip to content

Commit 479f554

Browse files
edumazetkuba-moo
authored andcommitted
tcp: fix mem under-charging with zerocopy sendmsg()
We got reports of following warning in inet_sock_destruct() WARN_ON(sk_forward_alloc_get(sk)); Whenever we add a non zero-copy fragment to a pure zerocopy skb, we have to anticipate that whole skb->truesize will be uncharged when skb is finally freed. skb->data_len is the payload length. But the memory truesize estimated by __zerocopy_sg_from_iter() is page aligned. Fixes: 9b65b17 ("net: avoid double accounting for pure zerocopy skbs") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Talal Ahmad <talalahmad@google.com> Cc: Arjun Roy <arjunroy@google.com> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Link: https://lore.kernel.org/r/20220201065254.680532-1-eric.dumazet@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e42e70a commit 479f554

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

net/ipv4/tcp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,13 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
13221322

13231323
/* skb changing from pure zc to mixed, must charge zc */
13241324
if (unlikely(skb_zcopy_pure(skb))) {
1325-
if (!sk_wmem_schedule(sk, skb->data_len))
1325+
u32 extra = skb->truesize -
1326+
SKB_TRUESIZE(skb_end_offset(skb));
1327+
1328+
if (!sk_wmem_schedule(sk, extra))
13261329
goto wait_for_space;
13271330

1328-
sk_mem_charge(sk, skb->data_len);
1331+
sk_mem_charge(sk, extra);
13291332
skb_shinfo(skb)->flags &= ~SKBFL_PURE_ZEROCOPY;
13301333
}
13311334

0 commit comments

Comments
 (0)