From: Eduard Zingerman <eddyz87@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Yonghong Song <yonghong.song@linux.dev>,
Amery Hung <ameryhung@gmail.com>,
kernel-team@meta.com
Subject: Re: [RFC PATCH bpf-next 5/6] bpf: Allow pro/epilogue to call kfunc
Date: Wed, 14 Aug 2024 15:17:43 -0700 [thread overview]
Message-ID: <3066ed3d157d391e67858e44da8b0d7865df2ad9.camel@gmail.com> (raw)
In-Reply-To: <20240813184943.3759630-6-martin.lau@linux.dev>
On Tue, 2024-08-13 at 11:49 -0700, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> The existing prologue has been able to call bpf helper but not a kfunc.
> This patch allows the prologue/epilogue to call the kfunc.
[...]
> Once the insn->off is determined (either reuse an existing one
> or an unused one is found), it will call the existing add_kfunc_call()
> and everything else should fall through.
>
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
> ---
fwiw, don't see any obvious problems with this patch.
Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
> kernel/bpf/verifier.c | 116 ++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 113 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 5e995b7884fb..2873e1083402 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2787,6 +2787,61 @@ static struct btf *find_kfunc_desc_btf(struct bpf_verifier_env *env, s16 offset)
> return btf_vmlinux ?: ERR_PTR(-ENOENT);
> }
>
> +static int find_kfunc_desc_btf_offset(struct bpf_verifier_env *env, struct btf *btf,
> + struct module *module, s16 *offset)
> +{
> + struct bpf_kfunc_btf_tab *tab;
> + struct bpf_kfunc_btf *b;
> + s16 new_offset = S16_MAX;
> + u32 i;
> +
> + if (btf_is_vmlinux(btf)) {
> + *offset = 0;
> + return 0;
> + }
> +
> + tab = env->prog->aux->kfunc_btf_tab;
> + if (!tab) {
> + tab = kzalloc(sizeof(*tab), GFP_KERNEL);
> + if (!tab)
> + return -ENOMEM;
> + env->prog->aux->kfunc_btf_tab = tab;
> + }
> +
> + b = tab->descs;
> + for (i = tab->nr_descs; i > 0; i--) {
Question: why iterating in reverse here?
> + if (b[i - 1].btf == btf) {
> + *offset = b[i - 1].offset;
> + return 0;
> + }
> + /* Search new_offset from backward S16_MAX, S16_MAX-1, ...
> + * tab->nr_descs max out at MAX_KFUNC_BTFS which is
> + * smaller than S16_MAX, so it will be able to find
> + * a non-zero new_offset to use.
> + */
> + if (new_offset == b[i - 1].offset)
> + new_offset--;
> + }
> +
> + if (tab->nr_descs == MAX_KFUNC_BTFS) {
> + verbose(env, "too many different module BTFs\n");
> + return -E2BIG;
> + }
> +
> + if (!try_module_get(module))
> + return -ENXIO;
> +
> + b = &tab->descs[tab->nr_descs++];
> + btf_get(btf);
> + b->btf = btf;
> + b->module = module;
> + b->offset = new_offset;
> + *offset = new_offset;
> + sort(tab->descs, tab->nr_descs, sizeof(tab->descs[0]),
> + kfunc_btf_cmp_by_off, NULL);
> + return 0;
> +}
> +
> static int add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, s16 offset)
> {
> const struct btf_type *func, *func_proto;
[...]
next prev parent reply other threads:[~2024-08-14 22:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 18:49 [RFC PATCH bpf-next 0/6] bpf: Add gen_epilogue and allow kfunc call in pro/epilogue Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 1/6] bpf: Add gen_epilogue to bpf_verifier_ops Martin KaFai Lau
2024-08-14 20:56 ` Eduard Zingerman
2024-08-15 22:14 ` Martin KaFai Lau
2024-08-17 22:25 ` Amery Hung
2024-08-13 18:49 ` [RFC PATCH bpf-next 2/6] bpf: Export bpf_base_func_proto Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 3/6] selftests/test: test gen_prologue and gen_epilogue Martin KaFai Lau
2024-08-14 20:48 ` Eduard Zingerman
2024-08-15 23:41 ` Martin KaFai Lau
2024-08-16 0:23 ` Eduard Zingerman
2024-08-16 1:50 ` Eduard Zingerman
2024-08-16 17:27 ` Martin KaFai Lau
2024-08-16 20:27 ` Eduard Zingerman
2024-08-19 22:30 ` Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 4/6] bpf: Add module parameter to " Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 5/6] bpf: Allow pro/epilogue to call kfunc Martin KaFai Lau
2024-08-14 22:17 ` Eduard Zingerman [this message]
2024-08-15 23:47 ` Martin KaFai Lau
2024-08-13 18:49 ` [RFC PATCH bpf-next 6/6] selftests/bpf: Add kfunc call test in gen_prologue and gen_epilogue Martin KaFai Lau
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=3066ed3d157d391e67858e44da8b0d7865df2ad9.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@linux.dev \
--cc=yonghong.song@linux.dev \
/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