From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH v2 bpf-next 06/10] bpf: support 'arg:xxx' btf_decl_tag-based hints for global subprog args
Date: Wed, 13 Dec 2023 21:33:21 +0200 [thread overview]
Message-ID: <fe6ecc7ca2cf4516f9658609c53796670c05adf5.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzYMkTouSBADH8x6Xx8DRYRtkFUOxG6cmGEa4rpi2xUZAg@mail.gmail.com>
On Wed, 2023-12-13 at 11:18 -0800, Andrii Nakryiko wrote:
[...]
> > > @@ -6846,7 +6846,35 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
[...]
> > > + if (tag) {
> > > + /* disallow arg tags in static subprogs */
> > > + if (!is_global) {
> > > + bpf_log(log, "arg#%d type tag is not supported in static functions\n", i);
> > > + return -EOPNOTSUPP;
> > > + }
> > > + if (strcmp(tag, "ctx") == 0) {
> > > + sub->args[i].arg_type = ARG_PTR_TO_CTX;
> > > + continue;
> >
> > Nit: personally, I'd keep tags parsing and processing logically separate:
> > - at this point set a flag 'is_ctx'
> > - and modify the check below as follows:
> >
> > if (is_ctx || (btf_type_is_ptr(t) && btf_get_prog_ctx_type(log, btf, t, prog_type, i))) {
> > sub->args[i].arg_type = ARG_PTR_TO_CTX;
> > continue;
> > }
> >
> > So that there is only one place where ARG_PTR_TO_CTX is assigned.
> > Feel free to ignore.
>
> I think it's actually more convoluted and error-prone with the is_ctx
> flag. Tag is overriding whatever BTF type information we have. But if
> we delay ARG_PTR_TO_CTX setting to later, we need to make sure that
> post-tag BTF processing is aware of is_ctx (and potentially other)
> flags and doesn't freak out. We might add more BTF processing before
> ARG_PTR_TO_CTX, etc. Having to worry about not overriding tag-based
> decisions seems very error-prone.
>
> Also, btf_prepare_func_args() really simplifies the "definition" of an
> argument to one enum (and in some cases maybe an extra argument like
> memory size). It should be fine to just set this enum in two places
> separately, doesn't seem like a hindrance for maintainability.
Well, I disagree a bit, but that does not matter.
You are right that after extracting btf_prepare_func_args()
the code is easy enough to follow.
next prev parent reply other threads:[~2023-12-13 19:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 23:25 [PATCH v2 bpf-next 00/10] Enhance BPF global subprogs with argument tags Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 01/10] bpf: abstract away global subprog arg preparation logic from reg state setup Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 02/10] bpf: reuse btf_prepare_func_args() check for main program BTF validation Andrii Nakryiko
2023-12-13 17:43 ` Eduard Zingerman
2023-12-13 18:06 ` Andrii Nakryiko
2023-12-13 18:14 ` Eduard Zingerman
2023-12-13 18:23 ` Andrii Nakryiko
2023-12-13 18:29 ` Eduard Zingerman
2023-12-12 23:25 ` [PATCH v2 bpf-next 03/10] bpf: prepare btf_prepare_func_args() for handling static subprogs Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 04/10] bpf: move subprog call logic back to verifier.c Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 05/10] bpf: reuse subprog argument parsing logic for subprog call checks Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 06/10] bpf: support 'arg:xxx' btf_decl_tag-based hints for global subprog args Andrii Nakryiko
2023-12-13 17:43 ` Eduard Zingerman
2023-12-13 19:18 ` Andrii Nakryiko
2023-12-13 19:33 ` Eduard Zingerman [this message]
2023-12-12 23:25 ` [PATCH v2 bpf-next 07/10] bpf: add support for passing dynptr pointer to global subprog Andrii Nakryiko
2023-12-13 17:43 ` Eduard Zingerman
2023-12-12 23:25 ` [PATCH v2 bpf-next 08/10] libbpf: add __arg_xxx macros for annotating global func args Andrii Nakryiko
2023-12-13 17:43 ` Eduard Zingerman
2023-12-12 23:25 ` [PATCH v2 bpf-next 09/10] selftests/bpf: add global subprog annotation tests Andrii Nakryiko
2023-12-12 23:25 ` [PATCH v2 bpf-next 10/10] selftests/bpf: add freplace of BTF-unreliable main prog test Andrii Nakryiko
2023-12-13 17:44 ` Eduard Zingerman
2023-12-13 19:25 ` Andrii Nakryiko
2023-12-13 20:39 ` Eduard Zingerman
2023-12-13 22:48 ` Andrii Nakryiko
2023-12-14 0:14 ` Eduard Zingerman
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=fe6ecc7ca2cf4516f9658609c53796670c05adf5.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@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@kernel.org \
/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