bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net,
	simon.horman@netronome.com, willemb@google.com,
	peterpenkov96@gmail.com, Stanislav Fomichev <sdf@google.com>
Subject: [RFC bpf-next v3 0/8] net: flow_dissector: trigger BPF hook when called from eth_get_headlen
Date: Fri, 22 Mar 2019 12:58:55 -0700	[thread overview]
Message-ID: <20190322195903.162516-1-sdf@google.com> (raw)

Currently, when eth_get_headlen calls flow dissector, it doesn't pass any
skb. Because we use passed skb to lookup associated networking namespace
to find whether we have a BPF program attached or not, we always use
C-based flow dissector in this case.

The goal of this patch series is to add new networking namespace argument
to the eth_get_headlen and make BPF flow dissector programs be able to
work in the skb-less case.

The series goes like this:
1. restrict access to a limited set of __sk_buff fields from flow
   dissector programs; in eth_get_headlen context, they don't
   make sense (for skb-context, they are also not relevant for
   flow dissector)
2. switch kernel context to new xdp_buff-like structure (struct
   bpf_flow_dissector) for flow dissector program
3. minor fix for nhoff clamping; doesn't affect anything besides tests
4. convert flow dissector BPF_PROG_TEST_RUN to skb-less mode to show that
   it works
5. add new optional network namespace argument to __skb_flow_dissect and
   plumb through the callers
6. handle __skb_flow_dissect with skb == NULL
7. add new net namespace argument to eth_get_headlen and adjust all users
8. add selftest that makes sure bpf_skb_load_bytes is prohibited in
   skb-less context

v3:
* new kernel xdp_buff-like context per Alexey suggestion
* drop skb_net helper
* properly clamp flow_keys->nhoff

v2:
* moved temporary skb from stack into percpu (avoids memset of ~200 bytes
  per packet)
* tightened down access to __sk_buff fields from flow dissector programs to
  avoid touching shinfo (whitelist only relevant fields)
* addressed suggestions from Willem

Stanislav Fomichev (8):
  flow_dissector: allow access only to a subset of __sk_buff fields
  flow_dissector: switch kernel context to struct bpf_flow_dissector
  flow_dissector: fix clamping of BPF flow_keys for non-zero nhoff
  bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode
  net: plumb network namespace into __skb_flow_dissect
  flow_dissector: handle no-skb use case
  net: pass net argument to the eth_get_headlen
  selftests/bpf: add flow dissector bpf_skb_load_bytes helper test

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c |   3 +-
 .../net/ethernet/hisilicon/hns3/hns3_enet.c   |   3 +-
 drivers/net/ethernet/intel/fm10k/fm10k_main.c |   2 +-
 drivers/net/ethernet/intel/i40e/i40e_txrx.c   |   3 +-
 drivers/net/ethernet/intel/iavf/iavf_txrx.c   |   3 +-
 drivers/net/ethernet/intel/ice/ice_txrx.c     |   2 +-
 drivers/net/ethernet/intel/igb/igb_main.c     |   3 +-
 drivers/net/ethernet/intel/igc/igc_main.c     |   3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |   2 +-
 .../net/ethernet/intel/ixgbevf/ixgbevf_main.c |   3 +-
 .../net/ethernet/mellanox/mlx5/core/en_tx.c   |   3 +-
 drivers/net/tun.c                             |   3 +-
 include/linux/etherdevice.h                   |   2 +-
 include/linux/skbuff.h                        |  23 ++-
 include/net/flow_dissector.h                  |  11 ++
 include/net/sch_generic.h                     |  11 +-
 net/bpf/test_run.c                            |  51 ++----
 net/core/filter.c                             | 151 +++++++++++++-----
 net/core/flow_dissector.c                     |  85 +++++-----
 net/ethernet/eth.c                            |   8 +-
 .../prog_tests/flow_dissector_load_bytes.c    |  48 ++++++
 22 files changed, 280 insertions(+), 145 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/flow_dissector_load_bytes.c

-- 
2.21.0.392.gf8f6787159e-goog

             reply	other threads:[~2019-03-22 19:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 19:58 Stanislav Fomichev [this message]
2019-03-22 19:58 ` [RFC bpf-next v3 1/8] flow_dissector: allow access only to a subset of __sk_buff fields Stanislav Fomichev
2019-03-22 19:58 ` [RFC bpf-next v3 2/8] flow_dissector: switch kernel context to struct bpf_flow_dissector Stanislav Fomichev
2019-03-22 19:58 ` [RFC bpf-next v3 3/8] flow_dissector: fix clamping of BPF flow_keys for non-zero nhoff Stanislav Fomichev
2019-03-22 19:58 ` [RFC bpf-next v3 4/8] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode Stanislav Fomichev
2019-03-22 19:59 ` [RFC bpf-next v3 5/8] net: plumb network namespace into __skb_flow_dissect Stanislav Fomichev
2019-03-22 19:59 ` [RFC bpf-next v3 6/8] flow_dissector: handle no-skb use case Stanislav Fomichev
2019-03-23  1:00   ` Alexei Starovoitov
2019-03-23  1:19     ` Stanislav Fomichev
2019-03-23  1:41       ` Alexei Starovoitov
2019-03-23 16:05         ` Stanislav Fomichev
2019-03-26  0:35           ` Alexei Starovoitov
2019-03-26 16:45             ` Stanislav Fomichev
2019-03-26 17:48               ` Alexei Starovoitov
2019-03-26 17:51                 ` Willem de Bruijn
2019-03-26 18:08                   ` Alexei Starovoitov
2019-03-26 18:17                     ` Stanislav Fomichev
2019-03-26 18:30                       ` Alexei Starovoitov
2019-03-26 18:54                         ` Stanislav Fomichev
2019-03-27  1:41                           ` Alexei Starovoitov
2019-03-27  2:44                             ` Stanislav Fomichev
2019-03-27 17:55                               ` Alexei Starovoitov
2019-03-27 19:58                                 ` Stanislav Fomichev
2019-03-28  1:26                                   ` Alexei Starovoitov
2019-03-28  3:14                                     ` Willem de Bruijn
2019-03-28  3:32                                       ` Alexei Starovoitov
2019-03-28  4:17                                         ` Stanislav Fomichev
2019-03-28 12:58                                           ` Willem de Bruijn
2019-04-01 16:30                                             ` Stanislav Fomichev
2019-03-22 19:59 ` [RFC bpf-next v3 7/8] net: pass net argument to the eth_get_headlen Stanislav Fomichev
2019-03-22 19:59 ` [RFC bpf-next v3 8/8] selftests/bpf: add flow dissector bpf_skb_load_bytes helper test 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=20190322195903.162516-1-sdf@google.com \
    --to=sdf@google.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=peterpenkov96@gmail.com \
    --cc=simon.horman@netronome.com \
    --cc=willemb@google.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).