[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87bluaqoim.fsf@toke.dk>
Date: Mon, 21 Oct 2019 14:19:45 +0200
From: Toke Høiland-Jørgensen <toke@...hat.com>
To: Björn Töpel <bjorn.topel@...il.com>
Cc: Netdev <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Björn Töpel <bjorn.topel@...el.com>,
bpf <bpf@...r.kernel.org>,
Magnus Karlsson <magnus.karlsson@...il.com>,
"Karlsson\, Magnus" <magnus.karlsson@...el.com>,
"Samudrala\, Sridhar" <sridhar.samudrala@...el.com>
Subject: Re: [PATCH bpf-next v2] libbpf: use implicit XSKMAP lookup from AF_XDP XDP program
Björn Töpel <bjorn.topel@...il.com> writes:
> On Mon, 21 Oct 2019 at 13:50, Toke Høiland-Jørgensen <toke@...hat.com> wrote:
>>
>> Björn Töpel <bjorn.topel@...il.com> writes:
>>
>> > From: Björn Töpel <bjorn.topel@...el.com>
>> >
>> > 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 for post-5.3 kernels.
>> >
>> > This commit adds the implicit map lookup with default action, which
>> > improves the performance for the "rx_drop" [1] scenario with ~4%.
>> >
>> > For pre-5.3 kernels, the bpf_redirect_map() returns XDP_ABORTED, and a
>> > fallback path for backward compatibility is entered, where explicit
>> > lookup is still performed. This means a slight regression for older
>> > kernels (an additional bpf_redirect_map() call), but I consider that a
>> > fair punishment for users not upgrading their kernels. ;-)
>> >
>> > v1->v2: Backward compatibility (Toke) [2]
>> >
>> > [1] # xdpsock -i eth0 -z -r
>> > [2] https://lore.kernel.org/bpf/87pnirb3dc.fsf@toke.dk/
>> >
>> > Suggested-by: Toke Høiland-Jørgensen <toke@...hat.com>
>> > Signed-off-by: Björn Töpel <bjorn.topel@...el.com>
>> > ---
>> > tools/lib/bpf/xsk.c | 45 +++++++++++++++++++++++++++++++++++----------
>> > 1 file changed, 35 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
>> > index b0f532544c91..391a126b3fd8 100644
>> > --- a/tools/lib/bpf/xsk.c
>> > +++ b/tools/lib/bpf/xsk.c
>> > @@ -274,33 +274,58 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
>> > /* This is the C-program:
>> > * SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
>> > * {
>> > - * int index = ctx->rx_queue_index;
>> > + * int ret, index = ctx->rx_queue_index;
>> > *
>> > * // A set entry here means that the correspnding queue_id
>> > * // has an active AF_XDP socket bound to it.
>> > + * ret = bpf_redirect_map(&xsks_map, index, XDP_PASS);
>> > + * ret &= XDP_PASS | XDP_REDIRECT;
>>
>> Why the masking? Looks a bit weird (XDP return codes are not defined as
>> bitmask values), and it's not really needed, is it?
>>
>
> bpf_redirect_map() returns a 32-bit signed int, so the upper 32-bit
> will need to be cleared. Having an explicit AND is one instruction
> less than two shifts. So, it's an optimization (every instruction is
> sacred).
OIC. Well, a comment explaining that might be nice (since you're doing
per-instruction comments anyway)? :)
-Toke
Powered by blists - more mailing lists