[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJ+HfNjQpzdubbZL+4Yty6oQ+or9rHK_BAuc=CFMD-j3taEznQ@mail.gmail.com>
Date: Sun, 24 Nov 2019 07:56:49 +0100
From: Björn Töpel <bjorn.topel@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...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>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Edward Cree <ecree@...arflare.com>,
Toke Høiland-Jørgensen <thoiland@...hat.com>,
Andrii Nakryiko <andrii.nakryiko@...il.com>,
Tariq Toukan <tariqt@...lanox.com>,
Saeed Mahameed <saeedm@...lanox.com>,
Maxim Mikityanskiy <maximmi@...lanox.com>
Subject: Re: [PATCH bpf-next v2 2/6] xdp: introduce xdp_call
On Sun, 24 Nov 2019 at 02:59, Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> On Sat, Nov 23, 2019 at 08:12:21AM +0100, Björn Töpel wrote:
> > From: Björn Töpel <bjorn.topel@...el.com>
> >
> > The xdp_call.h header wraps a more user-friendly API around the BPF
> > dispatcher. A user adds a trampoline/XDP caller using the
> > DEFINE_XDP_CALL macro, and updates the BPF dispatcher via
> > xdp_call_update(). The actual dispatch is done via xdp_call().
> >
> > Note that xdp_call() is only supported for builtin drivers. Module
> > builds will fallback to bpf_prog_run_xdp().
> >
> > The next patch will show-case how the i40e driver uses xdp_call.
> >
> > Signed-off-by: Björn Töpel <bjorn.topel@...el.com>
> > ---
> > include/linux/xdp_call.h | 66 ++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 66 insertions(+)
> > create mode 100644 include/linux/xdp_call.h
> >
> > diff --git a/include/linux/xdp_call.h b/include/linux/xdp_call.h
> > new file mode 100644
> > index 000000000000..69b2d325a787
> > --- /dev/null
> > +++ b/include/linux/xdp_call.h
> > @@ -0,0 +1,66 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +/* Copyright(c) 2019 Intel Corporation. */
> > +#ifndef _LINUX_XDP_CALL_H
> > +#define _LINUX_XDP_CALL_H
> > +
> > +#include <linux/filter.h>
> > +
> > +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_RETPOLINE) && !defined(MODULE)
> > +
> > +void bpf_dispatcher_change_prog(void *func, struct bpf_prog *from,
> > + struct bpf_prog *to);
> > +
> > +#define XDP_CALL_TRAMP(name) ____xdp_call_##name##_tramp
> > +
> > +#define DEFINE_XDP_CALL(name) \
> > + unsigned int XDP_CALL_TRAMP(name)( \
> > + const void *xdp_ctx, \
> > + const struct bpf_insn *insnsi, \
> > + unsigned int (*bpf_func)(const void *, \
> > + const struct bpf_insn *)) \
> > + { \
> > + return bpf_func(xdp_ctx, insnsi); \
> > + }
> > +
> > +#define DECLARE_XDP_CALL(name) \
> > + unsigned int XDP_CALL_TRAMP(name)( \
> > + const void *xdp_ctx, \
> > + const struct bpf_insn *insnsi, \
> > + unsigned int (*bpf_func)(const void *, \
> > + const struct bpf_insn *))
> > +
> > +#define xdp_call_run(name, prog, ctx) ({ \
> > + u32 ret; \
> > + cant_sleep(); \
> > + if (static_branch_unlikely(&bpf_stats_enabled_key)) { \
> > + struct bpf_prog_stats *stats; \
> > + u64 start = sched_clock(); \
> > + ret = XDP_CALL_TRAMP(name)(ctx, \
> > + (prog)->insnsi, \
> > + (prog)->bpf_func); \
> > + stats = this_cpu_ptr((prog)->aux->stats); \
> > + u64_stats_update_begin(&stats->syncp); \
> > + stats->cnt++; \
> > + stats->nsecs += sched_clock() - start; \
> > + u64_stats_update_end(&stats->syncp); \
> > + } else { \
> > + ret = XDP_CALL_TRAMP(name)(ctx, \
> > + (prog)->insnsi, \
> > + (prog)->bpf_func); \
> > + } \
> > + ret; })
>
> I cannot help but wonder whether it's possible to avoid copy-paste from
> BPF_PROG_RUN().
> At least could you place this new macro right next to BPF_PROG_RUN?
> If it's in a different file eventually they may diverge.
>
Yeah, I'll take a stab at that!
Thanks,
Björn
Powered by blists - more mailing lists