From: Jakub Sitnicki <jakub@cloudflare.com>
To: Lorenz Bauer <lmb@cloudflare.com>
Cc: john.fastabend@gmail.com, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@cloudflare.com, netdev@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 0/9] bpf: sockmap, sockhash: support storing UDP sockets
Date: Sun, 01 Mar 2020 22:26:40 +0100 [thread overview]
Message-ID: <875zfndawf.fsf@cloudflare.com> (raw)
In-Reply-To: <20200228115344.17742-1-lmb@cloudflare.com>
On Fri, Feb 28, 2020 at 12:53 PM CET, Lorenz Bauer wrote:
> Thanks for all the reviews so far! I've fixed the identified bug and addressed
> feedback as much as possible.
>
> I've not taken up Jakub's suggestion to get rid of sk_psock_hooks_init. My
> intention is to encapsulate initializing both v4 and v6 protos. Really, it's
> down to personal preference, and I'm happy to remove it if others prefer
> Jakub's approach. I'm also still eager for a solution that requires less
> machinery.
I was going to do expenses but this seemed more fun. Challenge accepted.
I think we can massage tcp_bpf to extract sk_prot initialization bits
out of it into skmsg, and have skmsg call back into tcp/udp_bpf.
3 callbacks from skmsg back to tcp/udp_bpf would be needed to get there:
- assert_proto_ops
- check_v6_needs_rebuild
- get_proto (akin to choose_proto in this series)
With that in place we could go for a direct dispatch based on sock type:
#define sk_psock_assert_proto_ops(sk, ops) \
(sk->sk_type == SOCK_STREAM \
? tcp_bpf_assert_proto_ops(ops) \
: udp_bpf_assert_proto_ops(ops))
The steps to get there would be:
1. extract tcp_bpf_get_proto
2. fold tcp_bpf_update_sk_prot
3. move tcp_bpf_init -> sk_psock_init_proto
4. fold tcp_bpf_reinit_sk_prot
5. move tcp_bpf_reinit -> sk_psock_reinit_proto
6. add macros for callbacks into tcp_bpf
7. add udp_bpf
... which I've given a shot at, mixing it into your patches:
https://github.com/jsitnicki/linux/commits/extract-sk-psock-proto
Note, I didn't make an effort to share the code for rebuilding v6 proto
between tcp_bpf and udp_bpf. This construct seems hard to read already
as is without making it generic.
Final thought, I would probably place the bits common between tcp_bpf
and udp_bpf in skmsg under sk_psock_* namespace, instead of sockmap.
It is just my interpretation, but I think that was the idea outlined in
commit 604326b41a6f ("bpf, sockmap: convert to generic sk_msg
interface"):
The code itself has been split and refactored into three bigger
pieces: i) the generic sk_msg API which deals with managing the
scatter gather ring, providing helpers for walking and mangling,
transferring application data from user space into it, and preparing
it for BPF pre/post-processing, ii) the plain sock map itself
where sockets can be attached to or detached from; these bits
are independent of i) which can now be used also without sock
map, and iii) the integration with plain TCP as one protocol
to be used for processing L7 application data (later this could
e.g. also be extended to other protocols like UDP).
As skmsg already hosts some sk_psock_* functions used by tcp_bpf, and
they share the same build toggle NET_SK_MSG, that seems natural.
>
> Changes since v1:
> - Check newsk->sk_prot in tcp_bpf_clone
> - Fix compilation with BPF_STREAM_PARSER disabled
> - Use spin_lock_init instead of static initializer
> - Elaborate on TCPF_SYN_RECV
> - Cosmetic changes to TEST macros, and more tests
> - Add Jakub and me as maintainers
>
> Lorenz Bauer (9):
> bpf: sockmap: only check ULP for TCP sockets
> bpf: tcp: guard declarations with CONFIG_NET_SOCK_MSG
> bpf: sockmap: move generic sockmap hooks from BPF TCP
> skmsg: introduce sk_psock_hooks
> bpf: sockmap: allow UDP sockets
> selftests: bpf: don't listen() on UDP sockets
> selftests: bpf: add tests for UDP sockets in sockmap
> selftests: bpf: enable UDP sockmap reuseport tests
> bpf, doc: update maintainers for L7 BPF
>
> MAINTAINERS | 3 +
> include/linux/bpf.h | 4 +-
> include/linux/skmsg.h | 72 +++----
> include/linux/udp.h | 4 +
> include/net/tcp.h | 18 +-
> net/core/skmsg.c | 55 +++++
> net/core/sock_map.c | 160 ++++++++++----
> net/ipv4/Makefile | 1 +
> net/ipv4/tcp_bpf.c | 169 +++------------
> net/ipv4/udp_bpf.c | 53 +++++
> .../bpf/prog_tests/select_reuseport.c | 6 -
> .../selftests/bpf/prog_tests/sockmap_listen.c | 204 +++++++++++++-----
> 12 files changed, 465 insertions(+), 284 deletions(-)
> create mode 100644 net/ipv4/udp_bpf.c
prev parent reply other threads:[~2020-03-01 21:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-28 11:53 [PATCH bpf-next v2 0/9] bpf: sockmap, sockhash: support storing UDP sockets Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 1/9] bpf: sockmap: only check ULP for TCP sockets Lorenz Bauer
2020-03-03 17:35 ` John Fastabend
2020-03-04 8:39 ` Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 2/9] bpf: tcp: guard declarations with CONFIG_NET_SOCK_MSG Lorenz Bauer
2020-03-03 17:46 ` John Fastabend
2020-02-28 11:53 ` [PATCH bpf-next v2 3/9] bpf: sockmap: move generic sockmap hooks from BPF TCP Lorenz Bauer
2020-03-03 17:50 ` Martin KaFai Lau
2020-03-04 8:44 ` Lorenz Bauer
2020-03-03 17:52 ` John Fastabend
2020-02-28 11:53 ` [PATCH bpf-next v2 4/9] skmsg: introduce sk_psock_hooks Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 5/9] bpf: sockmap: allow UDP sockets Lorenz Bauer
2020-03-03 17:56 ` Martin KaFai Lau
2020-02-28 11:53 ` [PATCH bpf-next v2 6/9] selftests: bpf: don't listen() on " Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 7/9] selftests: bpf: add tests for UDP sockets in sockmap Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 8/9] selftests: bpf: enable UDP sockmap reuseport tests Lorenz Bauer
2020-02-28 11:53 ` [PATCH bpf-next v2 9/9] bpf, doc: update maintainers for L7 BPF Lorenz Bauer
2020-03-03 19:45 ` John Fastabend
2020-02-28 11:57 ` [PATCH bpf-next v2 0/9] bpf: sockmap, sockhash: support storing UDP sockets Lorenz Bauer
2020-03-01 21:26 ` Jakub Sitnicki [this message]
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=875zfndawf.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@cloudflare.com \
--cc=lmb@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).