netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn.topel@gmail.com>
To: bjorn.topel@gmail.com, magnus.karlsson@intel.com,
	magnus.karlsson@gmail.com, ast@kernel.org, daniel@iogearbox.net,
	netdev@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
	brouer@redhat.com, u9012063@gmail.com, qi.z.zhang@intel.com,
	jakub.kicinski@netronome.com, andrew@lunn.ch
Subject: [PATCH bpf-next v2 0/7] Add support for XDP_ATTACH
Date: Mon, 17 Dec 2018 11:24:54 +0100	[thread overview]
Message-ID: <20181217102501.22019-1-bjorn.topel@gmail.com> (raw)

From: Björn Töpel <bjorn.topel@intel.com>

Hi!

This patch set adds support for a new XDP socket bind option,
XDP_ATTACH.

XDP_ATTACH associates an XDP socket to a specific netdev Rx queue. To
redirect a packet to an attached socket from XDP, the bpf_xsk_redirect
helper is used. The bpf_xsk_redirect helper is also introduced in this
series.

Many XDP socket users just need a simple way of creating/binding a
socket and receiving frames right away without a complicated XDP
program. "Attached" XDP sockets removes the need for the XSKMAP, and
allows for a trivial XDP program, e.g.:

  SEC("xdp")
  int xdp_prog(struct xdp_md *ctx)
  {
        return bpf_xsk_redirect(ctx);
  }

An attached XDP socket also has better performance than the XSKMAP
based sockets (performance numbers below).

The first three patches of the series add support for the XDP_ATTACH
flag and the BPF helper.

Since the trivial XDP program above will be a very common way of using
AF_XDP sockets, it makes sense to bundle that XDP program to libbpf. 

We call BPF programs that are bundled with libbpf a "builtin
program". To access the bpf_object/bpf_program of a builtin program
the following libbpf API are introduced:

      LIBBPF_API struct bpf_object *bpf_object__open_builtin(
                      enum bpf_prog_type prog_type);
    
      LIBBPF_API struct bpf_program *
      bpf_object__find_xdp_builtin_program(
                    struct bpf_object* obj,
                      enum libbpf_builtin_xdp_prog prog);
    
The first function is used to get a handle to the bpf_object
containing all builtin programs for a certain program type. The latter
is used to access a certain builtin program from the bpf_object. Note
that currenty only XDP is supported. When other program types are
supported, additional bpf_object__find_PROG_TYPE_builtin_program
function are required.
    
Patch 4 and 5 introduce the "builtin" program to libbpf.

The last two patches adds XDP_ATTACH support and the "builtin" libbpf
support to the sample application.

Some questions:

* If the only builtin programs in libbpf will be XDP programs, the
  libbpf API in this series might be a bit over-engineered. Thoughts?

* Is the idea that users of libbpf should use the IS_ERR*
  functionality for checking pointers (e.g. __open), or is that just
  library internal convenience?

Finally, the performance numbers for rxdrop (Intel(R) Xeon(R) Gold
6154 CPU @ 3.00GHz):

XDP_SKB:
XSKMAP:     2.8 Mpps
XDP_ATTACH: 2.9 Mpps

XDP_DRV - copy:
XSKMAP:     8.5 Mpps
XDP_ATTACH: 9.3 Mpps

XDP_DRV - zero-copy:
XSKMAP:     15.1 Mpps
XDP_ATTACH: 17.3 Mpps

Thanks!
Björn

v1->v2: Reworked the "builtin program" concept. The v1 had the builtin
        program as part of the kernel, which simply added too much
        complexity. In v2, the "builtin" was moved to libbpf
        instead. Alexei suggested that XDP_ATTACH was renamed to to
        XDP_BUILTIN_ATTACH, but given that the "builtin" functionality
        was removed, the old name stuck.


Björn Töpel (7):
  xsk: simplify AF_XDP socket teardown
  xsk: add XDP_ATTACH bind() flag
  bpf: add bpf_xsk_redirect function
  tools/bpf: sync kernel uapi bpf.h to tools directory
  libbpf: initial support for builtin BPF programs
  samples: bpf: simplify/cleanup xdpsock
  samples: bpf: add support for XDP_ATTACH to xdpsock

 include/linux/filter.h         |   4 +
 include/linux/netdevice.h      |   1 +
 include/net/xdp_sock.h         |   3 +
 include/trace/events/xdp.h     |  61 ++++++++++++++
 include/uapi/linux/bpf.h       |  14 +++-
 include/uapi/linux/if_xdp.h    |   1 +
 net/core/filter.c              | 100 +++++++++++++++++++++++
 net/xdp/xsk.c                  |  67 +++++++++------
 samples/bpf/xdpsock_user.c     | 145 +++++++++++++++++++++++----------
 tools/include/uapi/linux/bpf.h |  14 +++-
 tools/lib/bpf/libbpf.c         |  85 +++++++++++++++++++
 tools/lib/bpf/libbpf.h         |  14 ++++
 tools/lib/bpf/libbpf.map       |   2 +
 13 files changed, 441 insertions(+), 70 deletions(-)

-- 
2.19.1

             reply	other threads:[~2018-12-17 10:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-17 10:24 Björn Töpel [this message]
2018-12-17 10:24 ` [PATCH bpf-next v2 1/7] xsk: simplify AF_XDP socket teardown Björn Töpel
2018-12-17 10:24 ` [PATCH bpf-next v2 2/7] xsk: add XDP_ATTACH bind() flag Björn Töpel
2018-12-17 10:24 ` [PATCH bpf-next v2 3/7] bpf: add bpf_xsk_redirect function Björn Töpel
2018-12-17 10:24 ` [PATCH bpf-next v2 4/7] tools/bpf: sync kernel uapi bpf.h to tools directory Björn Töpel
2018-12-17 10:24 ` [PATCH bpf-next v2 5/7] libbpf: initial support for builtin BPF programs Björn Töpel
2018-12-17 10:25 ` [PATCH bpf-next v2 6/7] samples: bpf: simplify/cleanup xdpsock Björn Töpel
2018-12-17 10:25 ` [PATCH bpf-next v2 7/7] samples: bpf: add support for XDP_ATTACH to xdpsock Björn Töpel
2018-12-17 12:50 ` [PATCH bpf-next v2 0/7] Add support for XDP_ATTACH Jesper Dangaard Brouer
2018-12-17 13:39   ` Björn Töpel
2018-12-17 14:10     ` Jesper Dangaard Brouer
2018-12-17 14:55       ` Magnus Karlsson
2018-12-17 15:30         ` Björn Töpel
2018-12-18 23:04           ` Alexei Starovoitov
2018-12-19  9:34             ` Björn Töpel
2018-12-19 16:23               ` Jesper Dangaard Brouer
2018-12-20  0:48               ` Alexei Starovoitov
2018-12-18  2:36     ` Jakub Kicinski
2018-12-18  8:59       ` Björn Töpel
2018-12-18 18:18         ` Jakub Kicinski

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=20181217102501.22019-1-bjorn.topel@gmail.com \
    --to=bjorn.topel@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=magnus.karlsson@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=qi.z.zhang@intel.com \
    --cc=u9012063@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).