From: Cong Wang <xiyou.wangcong@gmail.com>
To: John Fastabend <john.fastabend@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
bpf <bpf@vger.kernel.org>,
duanxiongchun@bytedance.com,
Dongdong Wang <wangdongdong.6@bytedance.com>,
Jiang Wang <jiang.wang@bytedance.com>,
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-next v7 07/13] sock_map: introduce BPF_SK_SKB_VERDICT
Date: Mon, 29 Mar 2021 18:27:00 -0700 [thread overview]
Message-ID: <CAM_iQpUsCc18rxn7HBx9L7494Y5arpKAkPHtpUSOqitYevMypA@mail.gmail.com> (raw)
In-Reply-To: <60623417fe3b_401fb20857@john-XPS-13-9370.notmuch>
On Mon, Mar 29, 2021 at 1:10 PM John Fastabend <john.fastabend@gmail.com> wrote:
>
> Cong Wang wrote:
> > From: Cong Wang <cong.wang@bytedance.com>
> >
> > Reusing BPF_SK_SKB_STREAM_VERDICT is possible but its name is
> > confusing and more importantly we still want to distinguish them
> > from user-space. So we can just reuse the stream verdict code but
> > introduce a new type of eBPF program, skb_verdict. Users are not
> > allowed to set stream_verdict and skb_verdict at the same time.
> >
> > Cc: John Fastabend <john.fastabend@gmail.com>
> > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > Cc: Jakub Sitnicki <jakub@cloudflare.com>
> > Cc: Lorenz Bauer <lmb@cloudflare.com>
> > Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> > ---
>
> [...]
>
> > diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> > index 656eceab73bc..a045812d7c78 100644
> > --- a/net/core/skmsg.c
> > +++ b/net/core/skmsg.c
> > @@ -697,7 +697,7 @@ void sk_psock_drop(struct sock *sk, struct sk_psock *psock)
> > rcu_assign_sk_user_data(sk, NULL);
> > if (psock->progs.stream_parser)
> > sk_psock_stop_strp(sk, psock);
> > - else if (psock->progs.stream_verdict)
> > + else if (psock->progs.stream_verdict || psock->progs.skb_verdict)
> > sk_psock_stop_verdict(sk, psock);
> > write_unlock_bh(&sk->sk_callback_lock);
> >
> > @@ -1024,6 +1024,8 @@ static int sk_psock_verdict_recv(read_descriptor_t *desc, struct sk_buff *skb,
> > }
> > skb_set_owner_r(skb, sk);
> > prog = READ_ONCE(psock->progs.stream_verdict);
> > + if (!prog)
> > + prog = READ_ONCE(psock->progs.skb_verdict);
>
> Trying to think through this case. User attachs skb_verdict program
> to map, then updates map with a bunch of TCP sockets. The above
> code will run the skb_verdict program with the TCP socket as far as
> I can tell.
>
> This is OK because there really is no difference, other than by name,
> between a skb_verdict and a stream_verdict program? Do we want something
> to block adding TCP sockets to maps with stream_verdict programs? It
> feels a bit odd in its current state to me.
Yes, it should work too. skb_verdict only extends stream_verdict beyond
TCP, it does not prohibit TCP.
>
> > if (likely(prog)) {
> > skb_dst_drop(skb);
> > skb_bpf_redirect_clear(skb);
> > diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> > index e564fdeaada1..c46709786a49 100644
> > --- a/net/core/sock_map.c
> > +++ b/net/core/sock_map.c
> > @@ -155,6 +155,8 @@ static void sock_map_del_link(struct sock *sk,
> > strp_stop = true;
> > if (psock->saved_data_ready && stab->progs.stream_verdict)
> > verdict_stop = true;
> > + if (psock->saved_data_ready && stab->progs.skb_verdict)
> > + verdict_stop = true;
> > list_del(&link->list);
> > sk_psock_free_link(link);
> > }
> > @@ -227,7 +229,7 @@ static struct sk_psock *sock_map_psock_get_checked(struct sock *sk)
> > static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
> > struct sock *sk)
> > {
> > - struct bpf_prog *msg_parser, *stream_parser, *stream_verdict;
> > + struct bpf_prog *msg_parser, *stream_parser, *stream_verdict, *skb_verdict;
> > struct sk_psock *psock;
> > int ret;
> >
> > @@ -256,6 +258,15 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
> > }
> > }
> >
> > + skb_verdict = READ_ONCE(progs->skb_verdict);
> > + if (skb_verdict) {
> > + skb_verdict = bpf_prog_inc_not_zero(skb_verdict);
> > + if (IS_ERR(skb_verdict)) {
> > + ret = PTR_ERR(skb_verdict);
> > + goto out_put_msg_parser;
> > + }
> > + }
> > +
> > psock = sock_map_psock_get_checked(sk);
> > if (IS_ERR(psock)) {
> > ret = PTR_ERR(psock);
> > @@ -265,6 +276,7 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
> > if (psock) {
> > if ((msg_parser && READ_ONCE(psock->progs.msg_parser)) ||
> > (stream_parser && READ_ONCE(psock->progs.stream_parser)) ||
> > + (skb_verdict && READ_ONCE(psock->progs.skb_verdict)) ||
> > (stream_verdict && READ_ONCE(psock->progs.stream_verdict))) {
> > sk_psock_put(sk, psock);
> > ret = -EBUSY;
>
> Do we need another test here,
>
> (skb_verdict && READ_ONCE(psock->progs.stream_verdict)
>
> this way we return EBUSY and avoid having both stream_verdict and
> skb_verdict attached on the same map?
Yes, good catch, we do need a check here. And I will see if I can add a small
test case for this too.
Thanks.
next prev parent reply other threads:[~2021-03-30 1:27 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-28 20:20 [Patch bpf-next v7 00/13] sockmap: introduce BPF_SK_SKB_VERDICT and support UDP Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 01/13] skmsg: lock ingress_skb when purging Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 02/13] skmsg: introduce a spinlock to protect ingress_msg Cong Wang
2021-03-29 19:11 ` John Fastabend
2021-03-28 20:20 ` [Patch bpf-next v7 03/13] net: introduce skb_send_sock() for sock_map Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 04/13] skmsg: avoid lock_sock() in sk_psock_backlog() Cong Wang
2021-03-29 19:41 ` John Fastabend
2021-03-28 20:20 ` [Patch bpf-next v7 05/13] skmsg: use rcu work for destroying psock Cong Wang
2021-03-29 19:42 ` John Fastabend
2021-03-28 20:20 ` [Patch bpf-next v7 06/13] skmsg: use GFP_KERNEL in sk_psock_create_ingress_msg() Cong Wang
2021-03-29 19:44 ` John Fastabend
2021-03-28 20:20 ` [Patch bpf-next v7 07/13] sock_map: introduce BPF_SK_SKB_VERDICT Cong Wang
2021-03-29 20:09 ` John Fastabend
2021-03-30 1:27 ` Cong Wang [this message]
2021-03-28 20:20 ` [Patch bpf-next v7 08/13] sock: introduce sk->sk_prot->psock_update_sk_prot() Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 09/13] udp: implement ->read_sock() for sockmap Cong Wang
2021-03-29 20:54 ` John Fastabend
2021-03-30 5:39 ` Cong Wang
2021-03-30 6:23 ` John Fastabend
2021-03-30 6:36 ` Cong Wang
2021-03-30 6:45 ` John Fastabend
2021-03-28 20:20 ` [Patch bpf-next v7 10/13] skmsg: extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data() Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 11/13] udp: implement udp_bpf_recvmsg() for sockmap Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 12/13] sock_map: update sock type checks for UDP Cong Wang
2021-03-29 23:10 ` John Fastabend
2021-03-30 5:47 ` Cong Wang
2021-03-28 20:20 ` [Patch bpf-next v7 13/13] selftests/bpf: add a test case for udp sockmap Cong Wang
2021-03-28 23:27 ` [Patch bpf-next v7 00/13] sockmap: introduce BPF_SK_SKB_VERDICT and support UDP Alexei Starovoitov
2021-03-29 15:03 ` John Fastabend
2021-03-29 16:57 ` 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=CAM_iQpUsCc18rxn7HBx9L7494Y5arpKAkPHtpUSOqitYevMypA@mail.gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=duanxiongchun@bytedance.com \
--cc=jakub@cloudflare.com \
--cc=jiang.wang@bytedance.com \
--cc=john.fastabend@gmail.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=wangdongdong.6@bytedance.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 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).