From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Björn Töpel" <bjorn.topel@gmail.com>,
magnus.karlsson@intel.com, alexander.h.duyck@intel.com,
alexander.duyck@gmail.com, john.fastabend@gmail.com, ast@fb.com,
brouer@redhat.com, willemdebruijn.kernel@gmail.com,
daniel@iogearbox.net, mst@redhat.com, netdev@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
michael.lundkvist@ericsson.com, jesse.brandeburg@intel.com,
anjali.singhai@intel.com, qi.z.zhang@intel.com
Subject: Re: [PATCH bpf-next v3 07/15] bpf: introduce new bpf AF_XDP map type BPF_MAP_TYPE_XSKMAP
Date: Mon, 8 Oct 2018 08:31:50 -0700 [thread overview]
Message-ID: <ac8d2c20-f0fc-725c-a0a9-bee0b1620af1@gmail.com> (raw)
In-Reply-To: <20180502110136.3738-8-bjorn.topel@gmail.com>
On 05/02/2018 04:01 AM, Björn Töpel wrote:
> From: Björn Töpel <bjorn.topel@intel.com>
>
> The xskmap is yet another BPF map, very much inspired by
> dev/cpu/sockmap, and is a holder of AF_XDP sockets. A user application
> adds AF_XDP sockets into the map, and by using the bpf_redirect_map
> helper, an XDP program can redirect XDP frames to an AF_XDP socket.
>
> Note that a socket that is bound to certain ifindex/queue index will
> *only* accept XDP frames from that netdev/queue index. If an XDP
> program tries to redirect from a netdev/queue index other than what
> the socket is bound to, the frame will not be received on the socket.
>
> A socket can reside in multiple maps.
>
> v3: Fixed race and simplified code.
> v2: Removed one indirection in map lookup.
>
> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
> ---
> include/linux/bpf.h | 25 +++++
> include/linux/bpf_types.h | 3 +
> include/net/xdp_sock.h | 7 ++
> include/uapi/linux/bpf.h | 1 +
> kernel/bpf/Makefile | 3 +
> kernel/bpf/verifier.c | 8 +-
> kernel/bpf/xskmap.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++
> net/xdp/xsk.c | 5 +
> 8 files changed, 289 insertions(+), 2 deletions(-)
> create mode 100644 kernel/bpf/xskmap.c
>
This function is called under rcu_read_lock() , from map_update_elem()
> +
> +static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,
> + u64 map_flags)
> +{
> + struct xsk_map *m = container_of(map, struct xsk_map, map);
> + u32 i = *(u32 *)key, fd = *(u32 *)value;
> + struct xdp_sock *xs, *old_xs;
> + struct socket *sock;
> + int err;
> +
> + if (unlikely(map_flags > BPF_EXIST))
> + return -EINVAL;
> + if (unlikely(i >= m->map.max_entries))
> + return -E2BIG;
> + if (unlikely(map_flags == BPF_NOEXIST))
> + return -EEXIST;
> +
> + sock = sockfd_lookup(fd, &err);
> + if (!sock)
> + return err;
> +
> + if (sock->sk->sk_family != PF_XDP) {
> + sockfd_put(sock);
> + return -EOPNOTSUPP;
> + }
> +
> + xs = (struct xdp_sock *)sock->sk;
> +
> + if (!xsk_is_setup_for_bpf_map(xs)) {
> + sockfd_put(sock);
> + return -EOPNOTSUPP;
> + }
> +
> + sock_hold(sock->sk);
> +
> + old_xs = xchg(&m->xsk_map[i], xs);
> + if (old_xs) {
> + /* Make sure we've flushed everything. */
So it is illegal to call synchronize_net(), since it is a reschedule point.
> + synchronize_net();
> + sock_put((struct sock *)old_xs);
> + }
> +
> + sockfd_put(sock);
> + return 0;
> +}
>
next prev parent reply other threads:[~2018-10-08 22:44 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 11:01 [PATCH bpf-next v3 00/15] Introducing AF_XDP support Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 01/15] net: initial AF_XDP skeleton Björn Töpel
2018-05-23 22:50 ` Stephen Hemminger
2018-05-24 6:38 ` Björn Töpel
2018-05-24 17:57 ` Alexei Starovoitov
2018-05-02 11:01 ` [PATCH bpf-next v3 02/15] xsk: add user memory registration support sockopt Björn Töpel
2018-05-04 12:34 ` Daniel Borkmann
2018-05-02 11:01 ` [PATCH bpf-next v3 03/15] xsk: add umem fill queue support and mmap Björn Töpel
2018-05-04 12:49 ` Daniel Borkmann
2018-05-02 11:01 ` [PATCH bpf-next v3 04/15] xsk: add Rx queue setup and mmap support Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 05/15] xsk: add support for bind for Rx Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 06/15] xsk: add Rx receive functions and poll support Björn Töpel
2018-05-04 12:59 ` Daniel Borkmann
2018-05-22 7:42 ` Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 07/15] bpf: introduce new bpf AF_XDP map type BPF_MAP_TYPE_XSKMAP Björn Töpel
2018-10-08 15:31 ` Eric Dumazet [this message]
2018-10-08 16:05 ` Björn Töpel
2018-10-08 16:52 ` Björn Töpel
2018-10-08 16:55 ` Eric Dumazet
2018-10-08 17:04 ` Björn Töpel
2018-10-08 17:40 ` [PATCH bpf] xsk: do not call synchronize_net() under RCU read lock Björn Töpel
2018-10-09 0:30 ` Song Liu
2018-10-11 8:22 ` Daniel Borkmann
2018-05-02 11:01 ` [PATCH bpf-next v3 08/15] xsk: wire up XDP_DRV side of AF_XDP Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 09/15] xsk: wire up XDP_SKB " Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 10/15] xsk: add umem completion queue support and mmap Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 11/15] xsk: add Tx queue setup and mmap support Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 12/15] dev: packet: make packet_direct_xmit a common function Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 13/15] xsk: support for Tx Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 14/15] xsk: statistics support Björn Töpel
2018-05-02 11:01 ` [PATCH bpf-next v3 15/15] samples/bpf: sample application and documentation for AF_XDP sockets Björn Töpel
2018-05-02 20:59 ` Jesper Dangaard Brouer
2018-05-03 13:55 ` [PATCH bpf-next v3 00/15] Introducing AF_XDP support Willem de Bruijn
2018-05-03 15:07 ` David Miller
2018-05-03 22:49 ` Daniel Borkmann
2018-05-03 23:38 ` Alexei Starovoitov
2018-05-04 11:22 ` Magnus Karlsson
2018-05-05 0:34 ` Alexei Starovoitov
2018-05-07 9:13 ` Magnus Karlsson
2018-05-07 13:09 ` Jesper Dangaard Brouer
2018-05-07 19:47 ` Björn Töpel
2018-05-17 6:46 ` Björn Töpel
2018-05-18 3:38 ` Alexei Starovoitov
2018-05-18 13:43 ` Daniel Borkmann
2018-05-18 15:18 ` Björn Töpel
2018-05-18 16:17 ` Daniel Borkmann
2018-05-18 16:32 ` Björn Töpel
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=ac8d2c20-f0fc-725c-a0a9-bee0b1620af1@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=alexander.duyck@gmail.com \
--cc=alexander.h.duyck@intel.com \
--cc=anjali.singhai@intel.com \
--cc=ast@fb.com \
--cc=bjorn.topel@gmail.com \
--cc=bjorn.topel@intel.com \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=jesse.brandeburg@intel.com \
--cc=john.fastabend@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=michael.lundkvist@ericsson.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=qi.z.zhang@intel.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).