2018-04-24 18:56 GMT+02:00 Willem de Bruijn <willemdebruijn.ker...@gmail.com>: > On Mon, Apr 23, 2018 at 9:56 AM, Björn Töpel <bjorn.to...@gmail.com> wrote: >> From: Björn Töpel <bjorn.to...@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. >> >> Signed-off-by: Björn Töpel <bjorn.to...@intel.com> > >> +struct xsk_map_entry { >> + struct xdp_sock *xs; >> + struct rcu_head rcu; >> +}; > >> +struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map, u32 key) >> +{ >> + struct xsk_map *m = container_of(map, struct xsk_map, map); >> + struct xsk_map_entry *entry; >> + >> + if (key >= map->max_entries) >> + return NULL; >> + >> + entry = READ_ONCE(m->xsk_map[key]); >> + return entry ? entry->xs : NULL; >> +} > > This dynamically allocated structure adds an extra cacheline lookup. If > xdp_sock gets an rcu_head, it can be linked into the map directly.
Nice one! I'll try this out!