Message ID | 20220614171734.1103875-2-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | tcp: final (?) round of mem pressure fixes | expand |
On Tue, Jun 14, 2022 at 1:17 PM Eric Dumazet <eric.dumazet@gmail.com> wrote: > > From: Eric Dumazet <edumazet@google.com> > > sk_forced_mem_schedule() has a bug similar to ones fixed > in commit 7c80b038d23e ("net: fix sk_wmem_schedule() and > sk_rmem_schedule() errors") > > While this bug has little chance to trigger in old kernels, > we need to fix it before the following patch. > > Fixes: d83769a580f1 ("tcp: fix possible deadlock in tcp_send_fin()") > Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> > --- > net/ipv4/tcp_output.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > index 8ab98e1aca6797a51eaaf8886680d2001a616948..18c913a2347a984ae8cf2793bb8991e59e5e94ab 100644 > --- a/net/ipv4/tcp_output.c > +++ b/net/ipv4/tcp_output.c > @@ -3362,11 +3362,12 @@ void tcp_xmit_retransmit_queue(struct sock *sk) > */ > void sk_forced_mem_schedule(struct sock *sk, int size) > { > - int amt; > + int delta, amt; > > - if (size <= sk->sk_forward_alloc) > + delta = size - sk->sk_forward_alloc; > + if (delta <= 0) > return; > - amt = sk_mem_pages(size); > + amt = sk_mem_pages(delta); > sk->sk_forward_alloc += amt << PAGE_SHIFT; > sk_memory_allocated_add(sk, amt); > > -- > 2.36.1.476.g0c4daa206d-goog >
On Tue, Jun 14, 2022 at 10:17:33AM -0700, Eric Dumazet wrote: > From: Eric Dumazet <edumazet@google.com> > > sk_forced_mem_schedule() has a bug similar to ones fixed > in commit 7c80b038d23e ("net: fix sk_wmem_schedule() and > sk_rmem_schedule() errors") > > While this bug has little chance to trigger in old kernels, > we need to fix it before the following patch. > > Fixes: d83769a580f1 ("tcp: fix possible deadlock in tcp_send_fin()") > Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com>
On Tue, Jun 14, 2022 at 10:41 AM Soheil Hassas Yeganeh <soheil@google.com> wrote: > > On Tue, Jun 14, 2022 at 1:17 PM Eric Dumazet <eric.dumazet@gmail.com> wrote: > > > > From: Eric Dumazet <edumazet@google.com> > > > > sk_forced_mem_schedule() has a bug similar to ones fixed > > in commit 7c80b038d23e ("net: fix sk_wmem_schedule() and > > sk_rmem_schedule() errors") > > > > While this bug has little chance to trigger in old kernels, > > we need to fix it before the following patch. > > > > Fixes: d83769a580f1 ("tcp: fix possible deadlock in tcp_send_fin()") > > Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Wei Wang <weiwan@google.com> > > Acked-by: Soheil Hassas Yeganeh <soheil@google.com> > > > --- > > net/ipv4/tcp_output.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > > index 8ab98e1aca6797a51eaaf8886680d2001a616948..18c913a2347a984ae8cf2793bb8991e59e5e94ab 100644 > > --- a/net/ipv4/tcp_output.c > > +++ b/net/ipv4/tcp_output.c > > @@ -3362,11 +3362,12 @@ void tcp_xmit_retransmit_queue(struct sock *sk) > > */ > > void sk_forced_mem_schedule(struct sock *sk, int size) > > { > > - int amt; > > + int delta, amt; > > > > - if (size <= sk->sk_forward_alloc) > > + delta = size - sk->sk_forward_alloc; > > + if (delta <= 0) > > return; > > - amt = sk_mem_pages(size); > > + amt = sk_mem_pages(delta); > > sk->sk_forward_alloc += amt << PAGE_SHIFT; > > sk_memory_allocated_add(sk, amt); > > > > -- > > 2.36.1.476.g0c4daa206d-goog > >
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 8ab98e1aca6797a51eaaf8886680d2001a616948..18c913a2347a984ae8cf2793bb8991e59e5e94ab 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3362,11 +3362,12 @@ void tcp_xmit_retransmit_queue(struct sock *sk) */ void sk_forced_mem_schedule(struct sock *sk, int size) { - int amt; + int delta, amt; - if (size <= sk->sk_forward_alloc) + delta = size - sk->sk_forward_alloc; + if (delta <= 0) return; - amt = sk_mem_pages(size); + amt = sk_mem_pages(delta); sk->sk_forward_alloc += amt << PAGE_SHIFT; sk_memory_allocated_add(sk, amt);