bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	ast@kernel.org, jakub@cloudflare.com
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [bpf PATCH 3/5] bpf, sockmap: Avoid returning unneeded EAGAIN when redirecting to self
Date: Thu, 12 Nov 2020 11:52:39 -0800	[thread overview]
Message-ID: <5fad928748443_2a6120855@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <a49096e0-6cc7-7741-a283-27c8629da80f@iogearbox.net>

Daniel Borkmann wrote:
> On 11/7/20 8:38 PM, John Fastabend wrote:
> > If a socket redirects to itself and it is under memory pressure it is
> > possible to get a socket stuck so that recv() returns EAGAIN and the
> > socket can not advance for some time. This happens because when
> > redirecting a skb to the same socket we received the skb on we first
> > check if it is OK to enqueue the skb on the receiving socket by checking
> > memory limits. But, if the skb is itself the object holding the memory
> > needed to enqueue the skb we will keep retrying from kernel side
> > and always fail with EAGAIN. Then userspace will get a recv() EAGAIN
> > error if there are no skbs in the psock ingress queue. This will continue
> > until either some skbs get kfree'd causing the memory pressure to
> > reduce far enough that we can enqueue the pending packet or the
> > socket is destroyed. In some cases its possible to get a socket
> > stuck for a noticable amount of time if the socket is only receiving
> > skbs from sk_skb verdict programs. To reproduce I make the socket
> > memory limits ridiculously low so sockets are always under memory
> > pressure. More often though if under memory pressure it looks like
> > a spurious EAGAIN error on user space side causing userspace to retry
> > and typically enough has moved on the memory side that it works.
> > 
> > To fix skip memory checks and skb_orphan if receiving on the same
> > sock as already assigned.
> > 
> > For SK_PASS cases this is easy, its always the same socket so we
> > can just omit the orphan/set_owner pair.
> > 
> > For backlog cases we need to check skb->sk and decide if the orphan
> > and set_owner pair are needed.
> > 
> > Fixes: 51199405f9672 ("bpf: skb_verdict, support SK_PASS on RX BPF path")
> > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > ---
> >   net/core/skmsg.c |   72 ++++++++++++++++++++++++++++++++++++++++--------------
> >   1 file changed, 53 insertions(+), 19 deletions(-)
> > 
> > diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> > index fe44280c033e..580252e532da 100644
> > --- a/net/core/skmsg.c
> > +++ b/net/core/skmsg.c
> > @@ -399,38 +399,38 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from,
> >   }
> >   EXPORT_SYMBOL_GPL(sk_msg_memcopy_from_iter);
> >   
> > -static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
> > +static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,
> > +						  struct sk_buff *skb)
> >   {
> > -	struct sock *sk = psock->sk;
> > -	int copied = 0, num_sge;
> >   	struct sk_msg *msg;
> >   
> >   	if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf)
> > -		return -EAGAIN;
> > +		return NULL;
> > +
> > +	if (!sk_rmem_schedule(sk, skb, skb->len))
> 
> Isn't accounting always truesize based, thus we should fix & convert all skb->len
> to skb->truesize ?

Right good catch, will fix in v2.

  reply	other threads:[~2020-11-12 19:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-07 19:37 [bpf PATCH 0/5] sockmap fixes John Fastabend
2020-11-07 19:37 ` [bpf PATCH 1/5] bpf, sockmap: fix partial copy_page_to_iter so progress can still be made John Fastabend
2020-11-12  0:19   ` Daniel Borkmann
2020-11-12 19:56     ` John Fastabend
2020-11-07 19:38 ` [bpf PATCH 2/5] bpf, sockmap: Ensure SO_RCVBUF memory is observed on ingress redirect John Fastabend
2020-11-07 19:38 ` [bpf PATCH 3/5] bpf, sockmap: Avoid returning unneeded EAGAIN when redirecting to self John Fastabend
2020-11-12  0:22   ` Daniel Borkmann
2020-11-12 19:52     ` John Fastabend [this message]
2020-11-07 19:38 ` [bpf PATCH 4/5] bpf, sockmap: Handle memory acct if skb_verdict prog redirects " John Fastabend
2020-11-07 19:39 ` [bpf PATCH 5/5] bpf, sockmap: Avoid failures from skb_to_sgvec when skb has frag_list John Fastabend

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=5fad928748443_2a6120855@john-XPS-13-9370.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jakub@cloudflare.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;
as well as URLs for NNTP newsgroup(s).