Subject: Re: [PATCH bpf-next] libbpf: remove explicit XSKMAP lookup from AF_XDP XDP program

From: Toke Høiland-Jørgensen <[email-masked]>
Date: Sun, 20 Oct 2019 21:53:19 +0200

Björn Töpel <[email-masked]> writes:

> From: Björn Töpel <[email-masked]>
>
> In commit 43e74c0267a3 ("bpf_xdp_redirect_map: Perform map lookup in
> eBPF helper") the bpf_redirect_map() helper learned to do map lookup,
> which means that the explicit lookup in the XDP program for AF_XDP is
> not needed.
>
> This commit removes the map lookup, which simplifies the BPF code and
> improves the performance for the "rx_drop" [1] scenario with ~4%.

Nice, 4% is pretty good!

I wonder if the program needs to be backwards-compatible (with pre-5.3
kernels), though?

You can do that by something like this:

ret = bpf_redirect_map(&xsks_map, index, XDP_PASS);
if (ret > 0)
  return ret;

if (bpf_map_lookup_elem(&xsks_map, &index))
   return bpf_redirect_map(&xsks_map, index, 0);
return XDP_PASS;

This works because bpf_redirect_map() prior to 43e74c0267a3 will return
XDP_ABORTED on a non-0 flags value.

-Toke