mbox series

[bpf-next,v2,0/6] sockmap/sk_skb program memory acct fixes

Message ID 160226618411.4390.8167055952618723738.stgit@john-Precision-5820-Tower
Headers show
Series sockmap/sk_skb program memory acct fixes | expand

Message

John Fastabend Oct. 9, 2020, 5:57 p.m. UTC
Users of sockmap and skmsg trying to build proxys and other tools
have pointed out to me the error handling can be problematic. If
the proxy is under-provisioned and/or the BPF admin does not have
the ability to update/modify memory provisions on the sockets
its possible data may be dropped. For some things we have retries
so everything works out OK, but for most things this is likely
not great. And things go bad.

The original design dropped memory accounting on the receive
socket as earlyy as possible. We did this early in sk_skb
handling and then charged it to the redirect socket immediately
after running the BPF program.

But, this design caused a fundamental problem. Namely, what should we do
if we redirect to a socket that has already reached its socket memory
limits. For proxy use cases the network admin can tune memory limits.
But, in general we punted on this problem and told folks to simply make
your memory limits high enough to handle your workload. This is not a
really good answer. When deploying into environments where we expect this
to be transparent its no longer the case because we need to tune params.
In fact its really only viable in cases where we have fine grained
control over the application. For example a proxy redirecting from an
ingress socket to an egress socket. The result is I get bug
reports because its surprising for one, but more importantly also breaks
some use cases. So lets fix it.

This series cleans up the different cases so that in many common
modes, such as passing packet up to receive socket, we can simply
use the underlying assumption that the TCP stack already has done
memory accounting.

Next instead of trying to do memory accounting against the socket
we plan to redirect into we keep memory accounting on the receive
socket until the skb can be put on the redirect socket. This means
if we do an egress redirect to a socket and sock_writable() returns
EAGAIN we can requeue the skb on the workqueue and try again. The
same scenario plays out for ingress. If the skb can not be put on
the receive queue of the redirect socket than we simply requeue and
retry. In both cases memory is still accounted for against the
receiving socket.

This also handles head of line blocking. With the above scheme the
skb is on a queue associated with the socket it will be sent/recv'd
on, but the memory accounting is against the received socket. This
means the receive socket can advance to the next skb and avoid head
of line blocking. At least until its receive memory on the socket
runs out. This will put some maximum size on the amount of data any
socket can enqueue giving us bounds on the skb lists so they can't grow
indefinately.

Overall I think this is a win. Tested with test_sockmap from selftsts
and running netperf in a small k8s cluster.

These are fixes, but I tagged it for bpf-next considering we are
at -rc8.

v1->v2: Fix uninitialized/unused variables (kernel test robot)

---

John Fastabend (6):
      bpf, sockmap: skb verdict SK_PASS to self already checked rmem limits
      bpf, sockmap: On receive programs try to fast track SK_PASS ingress
      bpf, sockmap: remove skb_set_owner_w wmem will be taken later from sendpage
      bpf, sockmap: remove dropped data on errors in redirect case
      bpf, sockmap: Remove skb_orphan and let normal skb_kfree do cleanup
      bpf, sockmap: Add memory accounting so skbs on ingress lists are visible


 net/core/skmsg.c |   83 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 45 insertions(+), 38 deletions(-)

--
Signature

Comments

John Fastabend Oct. 9, 2020, 6:04 p.m. UTC | #1
John Fastabend wrote:
> Users of sockmap and skmsg trying to build proxys and other tools
> have pointed out to me the error handling can be problematic. If

Will need a v3 to fix a typo, should be ready after fix, rebuild
and retest.

> v1->v2: Fix uninitialized/unused variables (kernel test robot)
> 

v2->v3: patch2: err = 0 needs to be err = -EIO to use workqueue

> ---
> 
> John Fastabend (6):
>       bpf, sockmap: skb verdict SK_PASS to self already checked rmem limits
>       bpf, sockmap: On receive programs try to fast track SK_PASS ingress
>       bpf, sockmap: remove skb_set_owner_w wmem will be taken later from sendpage
>       bpf, sockmap: remove dropped data on errors in redirect case
>       bpf, sockmap: Remove skb_orphan and let normal skb_kfree do cleanup
>       bpf, sockmap: Add memory accounting so skbs on ingress lists are visible
> 
> 
>  net/core/skmsg.c |   83 +++++++++++++++++++++++++++++-------------------------
>  1 file changed, 45 insertions(+), 38 deletions(-)
> 
> --
> Signature