From: Daniel Borkmann <daniel@iogearbox.net>
To: "Björn Töpel" <bjorn.topel@gmail.com>,
ast@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
maciej.fijalkowski@intel.com, hawk@kernel.org, toke@redhat.com,
magnus.karlsson@intel.com, john.fastabend@gmail.com,
kuba@kernel.org, davem@davemloft.net
Subject: Re: [PATCH bpf-next v4 1/2] bpf, xdp: make bpf_redirect_map() a map operation
Date: Fri, 26 Feb 2021 22:48:35 +0100 [thread overview]
Message-ID: <c36e681a-673d-d0d2-816a-e8f2c8ef5df7@iogearbox.net> (raw)
In-Reply-To: <20210226112322.144927-2-bjorn.topel@gmail.com>
On 2/26/21 12:23 PM, Björn Töpel wrote:
> From: Björn Töpel <bjorn.topel@intel.com>
>
> Currently the bpf_redirect_map() implementation dispatches to the
> correct map-lookup function via a switch-statement. To avoid the
> dispatching, this change adds bpf_redirect_map() as a map
> operation. Each map provides its bpf_redirect_map() version, and
> correct function is automatically selected by the BPF verifier.
>
> A nice side-effect of the code movement is that the map lookup
> functions are now local to the map implementation files, which removes
> one additional function call.
>
> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
> ---
> include/linux/bpf.h | 26 ++++++--------------------
> include/linux/filter.h | 27 +++++++++++++++++++++++++++
> include/net/xdp_sock.h | 19 -------------------
> kernel/bpf/cpumap.c | 8 +++++++-
> kernel/bpf/devmap.c | 16 ++++++++++++++--
> kernel/bpf/verifier.c | 11 +++++++++--
> net/core/filter.c | 39 +--------------------------------------
> net/xdp/xskmap.c | 18 ++++++++++++++++++
> 8 files changed, 82 insertions(+), 82 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index cccaef1088ea..a44ba904ca37 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -117,6 +117,9 @@ struct bpf_map_ops {
> void *owner, u32 size);
> struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(void *owner);
>
> + /* XDP helpers.*/
> + int (*xdp_redirect_map)(struct bpf_map *map, u32 ifindex, u64 flags);
> +
> /* map_meta_equal must be implemented for maps that can be
> * used as an inner map. It is a runtime check to ensure
> * an inner map can be inserted to an outer map.
[...]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 1dda9d81f12c..96705a49225e 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5409,7 +5409,8 @@ record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
> func_id != BPF_FUNC_map_delete_elem &&
> func_id != BPF_FUNC_map_push_elem &&
> func_id != BPF_FUNC_map_pop_elem &&
> - func_id != BPF_FUNC_map_peek_elem)
> + func_id != BPF_FUNC_map_peek_elem &&
> + func_id != BPF_FUNC_redirect_map)
> return 0;
>
> if (map == NULL) {
> @@ -11762,7 +11763,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
> insn->imm == BPF_FUNC_map_delete_elem ||
> insn->imm == BPF_FUNC_map_push_elem ||
> insn->imm == BPF_FUNC_map_pop_elem ||
> - insn->imm == BPF_FUNC_map_peek_elem)) {
> + insn->imm == BPF_FUNC_map_peek_elem ||
> + insn->imm == BPF_FUNC_redirect_map)) {
> aux = &env->insn_aux_data[i + delta];
> if (bpf_map_ptr_poisoned(aux))
> goto patch_call_imm;
> @@ -11804,6 +11806,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
> (int (*)(struct bpf_map *map, void *value))NULL));
> BUILD_BUG_ON(!__same_type(ops->map_peek_elem,
> (int (*)(struct bpf_map *map, void *value))NULL));
> + BUILD_BUG_ON(!__same_type(ops->xdp_redirect_map,
> + (int (*)(struct bpf_map *map, u32 ifindex, u64 flags))NULL));
> patch_map_ops_generic:
> switch (insn->imm) {
> case BPF_FUNC_map_lookup_elem:
> @@ -11830,6 +11834,9 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
> insn->imm = BPF_CAST_CALL(ops->map_peek_elem) -
> __bpf_call_base;
> continue;
> + case BPF_FUNC_redirect_map:
> + insn->imm = BPF_CAST_CALL(ops->xdp_redirect_map) - __bpf_call_base;
Small nit: I would name the generic callback ops->map_redirect so that this is in line with
the general naming convention for the map ops. Otherwise this looks much better, thx!
> + continue;
> }
>
> goto patch_call_imm;
next prev parent reply other threads:[~2021-02-26 21:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-26 11:23 [PATCH bpf-next v4 0/2] Optimize bpf_redirect_map()/xdp_do_redirect() Björn Töpel
2021-02-26 11:23 ` [PATCH bpf-next v4 1/2] bpf, xdp: make bpf_redirect_map() a map operation Björn Töpel
2021-02-26 11:37 ` Toke Høiland-Jørgensen
2021-02-26 11:40 ` Björn Töpel
2021-02-26 12:04 ` Björn Töpel
2021-02-26 12:26 ` Toke Høiland-Jørgensen
2021-02-26 14:28 ` Jesper Dangaard Brouer
2021-02-26 14:27 ` Jesper Dangaard Brouer
2021-02-26 14:29 ` Jesper Dangaard Brouer
2021-02-26 15:23 ` kernel test robot
2021-02-26 21:48 ` Daniel Borkmann [this message]
2021-02-27 9:04 ` Björn Töpel
2021-02-27 10:22 ` Daniel Borkmann
2021-02-26 11:23 ` [PATCH bpf-next v4 2/2] bpf, xdp: restructure redirect actions Björn Töpel
2021-02-26 11:35 ` [PATCH bpf-next v4 0/2] Optimize bpf_redirect_map()/xdp_do_redirect() Toke Høiland-Jørgensen
2021-02-26 11:38 ` Björn Töpel
2021-02-26 11:43 ` Toke Høiland-Jørgensen
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=c36e681a-673d-d0d2-816a-e8f2c8ef5df7@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=ast@kernel.org \
--cc=bjorn.topel@gmail.com \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=toke@redhat.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).