All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Cong Wang <xiyou.wangcong@gmail.com>,
	John Fastabend <john.fastabend@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, Cong Wang <cong.wang@bytedance.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Sitnicki <jakub@cloudflare.com>,
	Lorenz Bauer <lmb@cloudflare.com>
Subject: Re: [Patch bpf] udp: fix a memory leak in udp_read_sock()
Date: Wed, 19 May 2021 12:06:30 -0700	[thread overview]
Message-ID: <60a561b63598a_22c462082f@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <CAM_iQpXkYsf=LF=g4aKLmas_9jHNqXGy-P2gi3R4eb65+ktz4A@mail.gmail.com>

Cong Wang wrote:
> On Tue, May 18, 2021 at 12:56 PM John Fastabend
> <john.fastabend@gmail.com> wrote:
> >
> > Cong Wang wrote:
> > > On Mon, May 17, 2021 at 10:36 PM John Fastabend
> > > <john.fastabend@gmail.com> wrote:
> > > >
> > > > Cong Wang wrote:
> > > > > From: Cong Wang <cong.wang@bytedance.com>
> > > > >
> > > > > sk_psock_verdict_recv() clones the skb and uses the clone
> > > > > afterward, so udp_read_sock() should free the original skb after
> > > > > done using it.
> > > >
> > > > The clone only happens if sk_psock_verdict_recv() returns >0.
> > >
> > > Sure, in case of error, no one uses the original skb either,
> > > so still need to free it.
> >
> > But the data is going to be dropped then. I'm questioning if this
> > is the best we can do or not. Its simplest sure, but could we
> > do a bit more work and peek those skbs or requeue them? Otherwise
> > if you cross memory limits for a bit your likely to drop these
> > unnecessarily.
> 
> What are the benefits of not dropping it? When sockmap takes
> over sk->sk_data_ready() it should have total control over the skb's
> in the receive queue. Otherwise user-space recvmsg() would race
> with sockmap when they try to read the first skb at the same time,
> therefore potentially user-space could get duplicated data (one via
> recvmsg(), one via sockmap). I don't see any benefits but races here.

The benefit of _not_ dropping it is the packet gets to the receiver
side. We've spent a bit of effort to get a packet across the network,
received on the stack, and then we drop it at the last point is not
so friendly.

About races is the socket is locked by the caller here? Or is this
not the case for UDP.

Its OK in the end to say "its UDP and lossy" but ideally we don't
make things worse by adding sockmap into the stack. We had these
problems already on TCP side, where they are much more severe
because sender believes retransmits will happen, and fixed them
by now. It would be nice if UDP side also didn't introduce
drops.

> 
> Thanks.



  reply	other threads:[~2021-05-19 19:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17  2:23 [Patch bpf] udp: fix a memory leak in udp_read_sock() Cong Wang
2021-05-17 16:22 ` Song Liu
2021-05-18  5:36 ` John Fastabend
2021-05-18 16:54   ` Cong Wang
2021-05-18 19:56     ` John Fastabend
2021-05-18 21:21       ` Cong Wang
2021-05-19 19:06         ` John Fastabend [this message]
2021-05-19 20:17           ` Cong Wang
2021-05-19 21:54             ` John Fastabend
2021-05-19 23:26               ` Cong Wang
2021-05-20 17:42                 ` John Fastabend
2021-05-20 20:14                   ` Cong Wang
2021-05-21 22:09                     ` John Fastabend
2021-05-21 23:39                       ` Cong Wang

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=60a561b63598a_22c462082f@john-XPS-13-9370.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=cong.wang@bytedance.com \
    --cc=daniel@iogearbox.net \
    --cc=jakub@cloudflare.com \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.