netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@fomichev.me>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Stanislav Fomichev <sdf@google.com>,
	Network Development <netdev@vger.kernel.org>,
	David Miller <davem@davemloft.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	simon.horman@netronome.com, Willem de Bruijn <willemb@google.com>
Subject: Re: [RFC bpf-next 4/7] net: flow_dissector: handle no-skb use case
Date: Tue, 5 Feb 2019 12:45:31 -0800	[thread overview]
Message-ID: <20190205204531.GE10769@mini-arch> (raw)
In-Reply-To: <CAF=yD-JaWQG=5mA3bBU1+as9hkTNT=+3aJB1uwN_U4qFz44btQ@mail.gmail.com>

On 02/05, Willem de Bruijn wrote:
> On Tue, Feb 5, 2019 at 12:57 PM Stanislav Fomichev <sdf@google.com> wrote:
> >
> > When flow_dissector is called without skb (with only data and hlen),
> > construct on-stack skb (which has a linear chunk of data passed
> > to the flow dissector). This should let us handle eth_get_headlen
> > case where only data is provided and we don't want to (yet) allocate
> > an skb.
> >
> > Since this on-stack skb doesn't allocate its own data, we can't
> > add shinfo and need to be careful to avoid any code paths that use
> > it. Flow dissector BPF programs can only call bpf_skb_load_bytes helper,
> > which doesn't touch shinfo in our case (skb->len is the length of the
> > linear header so it exits early).
> >
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> >  include/linux/skbuff.h    |  5 +++
> >  net/core/flow_dissector.c | 95 +++++++++++++++++++++++++++++----------
> >  2 files changed, 76 insertions(+), 24 deletions(-)
> >
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index aa9a9983de80..5f1c085cb34c 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -1227,6 +1227,11 @@ bool __skb_flow_bpf_dissect(struct bpf_prog *prog,
> >                             const struct sk_buff *skb,
> >                             struct flow_dissector *flow_dissector,
> >                             struct bpf_flow_keys *flow_keys);
> > +bool __flow_bpf_dissect(struct bpf_prog *prog,
> > +                       void *data, __be16 proto,
> > +                       int nhoff, int hlen,
> > +                       struct flow_dissector *flow_dissector,
> > +                       struct bpf_flow_keys *flow_keys);
> 
> nit: please use more descriptive name. Perhaps bpf_flow_dissect_raw
> and rename __skb_flow_bpf_dissect to bpf_flow_dissect_skb.
Agreed.

> > +bool __flow_bpf_dissect(struct bpf_prog *prog,
> > +                       void *data, __be16 proto,
> > +                       int nhoff, int hlen,
> > +                       struct flow_dissector *flow_dissector,
> > +                       struct bpf_flow_keys *flow_keys)
> > +{
> > +       struct bpf_skb_data_end *cb;
> > +       struct sk_buff skb;
> > +       u32 result;
> > +
> > +       __init_skb(&skb, data, hlen);
> > +       skb_put(&skb, hlen);
> > +       skb.protocol = proto;
> > +
> > +       init_flow_keys(flow_keys, &skb, nhoff);
> > +
> > +       cb = (struct bpf_skb_data_end *)skb.cb;
> > +       cb->data_meta = skb.data;
> > +       cb->data_end  = skb.data + skb_headlen(&skb);
> > +
> > +       result = BPF_PROG_RUN(prog, &skb);
> > +
> > +       clamp_flow_keys(flow_keys, hlen);
> >
> >         return result == BPF_OK;
> >  }
> 
> Can__flow_bpf_dissect just construct an skb and then call
> __skb_flow_bpf_dissect?
__skb_flow_bpf_dissect calls bpf_compute_data_pointers which calls
skb_metadata_len which touches shinfo. And I don't think I have a
clever way to handle that.

> 
> It will unnecessarily save and restore the control block, but that is
> a relatively small cost (compared to, say, zeroing the entire skb).

  reply	other threads:[~2019-02-05 20:45 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 17:36 [RFC bpf-next 0/7] net: flow_dissector: trigger BPF hook when called from eth_get_headlen Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 1/7] net: introduce __init_skb and __init_skb_shinfo helpers Stanislav Fomichev
2019-02-05 20:18   ` Willem de Bruijn
2019-02-05 17:36 ` [RFC bpf-next 2/7] net: introduce skb_net helper Stanislav Fomichev
2019-02-05 20:19   ` Willem de Bruijn
2019-02-05 20:42     ` Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 3/7] net: plumb network namespace into __skb_flow_dissect Stanislav Fomichev
2019-02-05 20:19   ` Willem de Bruijn
2019-02-05 20:40     ` Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 4/7] net: flow_dissector: handle no-skb use case Stanislav Fomichev
2019-02-05 20:19   ` Willem de Bruijn
2019-02-05 20:45     ` Stanislav Fomichev [this message]
2019-02-05 17:36 ` [RFC bpf-next 5/7] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode Stanislav Fomichev
2019-02-05 20:19   ` Willem de Bruijn
2019-02-05 17:36 ` [RFC bpf-next 6/7] selftests/bpf: add flow dissector bpf_skb_load_bytes helper test Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 7/7] net: flow_dissector: pass net argument to the eth_get_headlen Stanislav Fomichev
2019-02-05 20:18 ` [RFC bpf-next 0/7] net: flow_dissector: trigger BPF hook when called from eth_get_headlen Willem de Bruijn
2019-02-05 20:40   ` Stanislav Fomichev
2019-02-06  0:47     ` Alexei Starovoitov
2019-02-06  0:59       ` Stanislav Fomichev
2019-02-06  3:12         ` Alexei Starovoitov
2019-02-06  3:56           ` Stanislav Fomichev
2019-02-06  4:11             ` Alexei Starovoitov
2019-02-06  5:49               ` Stanislav Fomichev
2019-02-12 17:02                 ` Stanislav Fomichev
2019-02-14  4:39                   ` Alexei Starovoitov
2019-02-14  5:57                     ` Stanislav Fomichev
2019-02-14  6:38                       ` Alexei Starovoitov
2019-02-14 17:35                         ` Stanislav Fomichev
2019-02-25 20:33                           ` Stanislav Fomichev

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=20190205204531.GE10769@mini-arch \
    --to=sdf@fomichev.me \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --cc=simon.horman@netronome.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@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 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).