* [PATCH net-next] tcp: properly reset skb->truesize for tx recycling
@ 2019-04-19 23:02 Eric Dumazet
2019-04-19 23:11 ` Soheil Hassas Yeganeh
2019-04-19 23:42 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2019-04-19 23:02 UTC (permalink / raw)
To: David S . Miller
Cc: netdev, Eric Dumazet, Eric Dumazet, Soheil Hassas Yeganeh,
Willem de Bruijn
tcp sendmsg() and sendpage() normally advance skb->data_len
and skb->truesize by the payload added to an skb.
But sendmsg(fd, ..., MSG_ZEROCOPY) has to account for whole pages,
even if a single byte of payload is used in the page.
This means that we can not assume skb->truesize can be adjusted
by skb->data_len. We must instead overwrite its value.
Otherwise skb->truesize is too big and can hit socket sndbuf limit,
especially if the skb is recycled multiple times :/
Fixes: 472c2e07eef0 ("tcp: add one skb cache for tx")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Soheil Hassas Yeganeh <soheil@google.com>
Cc: Willem de Bruijn <willemb@google.com>
---
net/ipv4/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 603e770d59b3db96adca9602319d2f6970a56285..f7567a3698eb4d6c24dbe6a2f110413ce14d24a7 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -868,7 +868,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
if (likely(!size)) {
skb = sk->sk_tx_skb_cache;
if (skb && !skb_cloned(skb)) {
- skb->truesize -= skb->data_len;
+ skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
sk->sk_tx_skb_cache = NULL;
pskb_trim(skb, 0);
INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
--
2.21.0.593.g511ec345e18-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tcp: properly reset skb->truesize for tx recycling
2019-04-19 23:02 [PATCH net-next] tcp: properly reset skb->truesize for tx recycling Eric Dumazet
@ 2019-04-19 23:11 ` Soheil Hassas Yeganeh
2019-04-19 23:42 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Soheil Hassas Yeganeh @ 2019-04-19 23:11 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet, Willem de Bruijn
On Fri, Apr 19, 2019 at 7:02 PM Eric Dumazet <edumazet@google.com> wrote:
>
> tcp sendmsg() and sendpage() normally advance skb->data_len
> and skb->truesize by the payload added to an skb.
>
> But sendmsg(fd, ..., MSG_ZEROCOPY) has to account for whole pages,
> even if a single byte of payload is used in the page.
>
> This means that we can not assume skb->truesize can be adjusted
> by skb->data_len. We must instead overwrite its value.
>
> Otherwise skb->truesize is too big and can hit socket sndbuf limit,
> especially if the skb is recycled multiple times :/
>
> Fixes: 472c2e07eef0 ("tcp: add one skb cache for tx")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Soheil Hassas Yeganeh <soheil@google.com>
> Cc: Willem de Bruijn <willemb@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Nice catch! Thank you for the fix.
> ---
> net/ipv4/tcp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 603e770d59b3db96adca9602319d2f6970a56285..f7567a3698eb4d6c24dbe6a2f110413ce14d24a7 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -868,7 +868,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
> if (likely(!size)) {
> skb = sk->sk_tx_skb_cache;
> if (skb && !skb_cloned(skb)) {
> - skb->truesize -= skb->data_len;
> + skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
> sk->sk_tx_skb_cache = NULL;
> pskb_trim(skb, 0);
> INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
> --
> 2.21.0.593.g511ec345e18-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tcp: properly reset skb->truesize for tx recycling
2019-04-19 23:02 [PATCH net-next] tcp: properly reset skb->truesize for tx recycling Eric Dumazet
2019-04-19 23:11 ` Soheil Hassas Yeganeh
@ 2019-04-19 23:42 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-04-19 23:42 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, soheil, willemb
From: Eric Dumazet <edumazet@google.com>
Date: Fri, 19 Apr 2019 16:02:03 -0700
> tcp sendmsg() and sendpage() normally advance skb->data_len
> and skb->truesize by the payload added to an skb.
>
> But sendmsg(fd, ..., MSG_ZEROCOPY) has to account for whole pages,
> even if a single byte of payload is used in the page.
>
> This means that we can not assume skb->truesize can be adjusted
> by skb->data_len. We must instead overwrite its value.
>
> Otherwise skb->truesize is too big and can hit socket sndbuf limit,
> especially if the skb is recycled multiple times :/
>
> Fixes: 472c2e07eef0 ("tcp: add one skb cache for tx")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied, thanks Eric.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-19 23:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-19 23:02 [PATCH net-next] tcp: properly reset skb->truesize for tx recycling Eric Dumazet
2019-04-19 23:11 ` Soheil Hassas Yeganeh
2019-04-19 23:42 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).