Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Eric Dumazet <edumazet@google.com>
Cc: netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: let skb_orphan_partial wake-up waiters.
Date: Tue, 30 Mar 2021 17:18:21 +0200	[thread overview]
Message-ID: <99736955c48b19366a2a06f43ea4a0d507454dbc.camel@redhat.com> (raw)
In-Reply-To: <CANn89iJkXuhMdU0==ZV3s8z75p1hrhjY3reR_MWUh1i-gJVeCg@mail.gmail.com>

On Tue, 2021-03-30 at 16:40 +0200, Eric Dumazet wrote:
> On Tue, Mar 30, 2021 at 4:39 PM Eric Dumazet <edumazet@google.com> wrote:
> > On Tue, Mar 30, 2021 at 4:25 PM Paolo Abeni <pabeni@redhat.com> wrote:
> > > Currently the mentioned helper can end-up freeing the socket wmem
> > > without waking-up any processes waiting for more write memory.
> > > 
> > > If the partially orphaned skb is attached to an UDP (or raw) socket,
> > > the lack of wake-up can hang the user-space.
> > > 
> > > Address the issue invoking the write_space callback after
> > > releasing the memory, if the old skb destructor requires that.
> > > 
> > > Fixes: f6ba8d33cfbb ("netem: fix skb_orphan_partial()")
> > > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > > ---
> > >  net/core/sock.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > > 
> > > diff --git a/net/core/sock.c b/net/core/sock.c
> > > index 0ed98f20448a2..7a38332d748e7 100644
> > > --- a/net/core/sock.c
> > > +++ b/net/core/sock.c
> > > @@ -2137,6 +2137,8 @@ void skb_orphan_partial(struct sk_buff *skb)
> > > 
> > >                 if (refcount_inc_not_zero(&sk->sk_refcnt)) {
> > >                         WARN_ON(refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc));
> > > +                       if (skb->destructor == sock_wfree)
> > > +                               sk->sk_write_space(sk);
> > 
> > Interesting.
> > 
> > Why TCP is not a problem here ?

AFAICS, tcp_wfree() does not call sk->sk_write_space(). Processes
waiting for wmem are woken by ack processing.

> > I would rather replace WARN_ON(refcount_sub_and_test(skb->truesize,
> > &sk->sk_wmem_alloc)) by :
> >                         skb_orphan(skb);
> 
> And of course re-add
>                         skb->sk = sk;

Double checking to be sure. The patched slice of skb_orphan_partial()
will then look like:

	if (can_skb_orphan_partial(skb)) {
		struct sock *sk = skb->sk;
		
		if (refcount_inc_not_zero(&sk->sk_refcnt)) {
			skb_orphan(skb);
			skb->sk = sk;
			skb->destructor = sock_efree;
		}
	} // ...

Am I correct?

Thanks!

Paolo


  reply	other threads:[~2021-03-30 15:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 14:24 [PATCH net] net: let skb_orphan_partial wake-up waiters Paolo Abeni
2021-03-30 14:39 ` Eric Dumazet
2021-03-30 14:40   ` Eric Dumazet
2021-03-30 15:18     ` Paolo Abeni [this message]
2021-03-30 15:29       ` Eric Dumazet
2021-03-30 15:32       ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99736955c48b19366a2a06f43ea4a0d507454dbc.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox