All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	 Kernel Team <kernel-team@meta.com>, Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH v3 bpf-next 7/9] libbpf: implement __arg_ctx fallback logic
Date: Wed, 3 Jan 2024 21:39:29 -0800	[thread overview]
Message-ID: <CAADnVQJn0+fvvbOVnfPFQm=1j+=oFsjy65T2-QY8Ps0pL4nh_A@mail.gmail.com> (raw)
In-Reply-To: <20240104013847.3875810-8-andrii@kernel.org>

On Wed, Jan 3, 2024 at 5:39 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> This limitation was the reason to add btf_decl_tag("arg:ctx"), making
> the actual argument type not important, so that user can just define
> "generic" signature:
>
>   __noinline int global_subprog(void *ctx __arg_ctx) { ... }

I still think that this __arg_ctx only makes sense with 'void *'.
Blind rewrite of ctx is a foot gun.

I've tried the following:

diff --git a/tools/testing/selftests/bpf/progs/test_global_func_ctx_args.c
b/tools/testing/selftests/bpf/progs/test_global_func_ctx_args.c
index 9a06e5eb1fbe..0e5f5205d4a8 100644
--- a/tools/testing/selftests/bpf/progs/test_global_func_ctx_args.c
+++ b/tools/testing/selftests/bpf/progs/test_global_func_ctx_args.c
@@ -106,9 +106,9 @@ int perf_event_ctx(void *ctx)
 /* this global subprog can be now called from many types of entry progs, each
  * with different context type
  */
-__weak int subprog_ctx_tag(void *ctx __arg_ctx)
+__weak int subprog_ctx_tag(long ctx __arg_ctx)
 {
-       return bpf_get_stack(ctx, stack, sizeof(stack), 0);
+       return bpf_get_stack((void *)ctx, stack, sizeof(stack), 0);
 }

 struct my_struct { int x; };
@@ -131,7 +131,7 @@ int arg_tag_ctx_raw_tp(void *ctx)
 {
        struct my_struct x = { .x = 123 };

-       return subprog_ctx_tag(ctx) + subprog_multi_ctx_tags(ctx, &x, ctx);
+       return subprog_ctx_tag((long)ctx) +
subprog_multi_ctx_tags(ctx, &x, ctx);
 }

and it "works".

Both kernel and libbpf should really limit it to 'void *'.

In the other email I suggested to allow types that match expected
based on prog type, but even that is probably a danger zone as well.
The correct type would already be detected by the verifier,
so extra __arg_ctx is pointless.
It makes sense only for such polymorphic functions and those
better use 'void *' and don't dereference it.

I think this can be a follow up.

  reply	other threads:[~2024-01-04  5:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04  1:38 [PATCH v3 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 1/9] libbpf: make uniform use of btf__fd() accessor inside libbpf Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 2/9] libbpf: use explicit map reuse flag to skip map creation steps Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 3/9] libbpf: don't rely on map->fd as an indicator of map being created Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 4/9] libbpf: use stable map placeholder FDs Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 5/9] libbpf: move exception callbacks assignment logic into relocation step Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 6/9] libbpf: move BTF loading step after " Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 7/9] libbpf: implement __arg_ctx fallback logic Andrii Nakryiko
2024-01-04  5:39   ` Alexei Starovoitov [this message]
2024-01-04 18:37     ` Andrii Nakryiko
2024-01-04 18:52       ` Alexei Starovoitov
2024-01-04 20:58         ` Andrii Nakryiko
2024-01-05  1:33           ` Alexei Starovoitov
2024-01-05  3:57             ` Andrii Nakryiko
2024-01-05  5:42               ` Alexei Starovoitov
2024-01-08 23:45                 ` Andrii Nakryiko
2024-01-09  1:49                   ` Alexei Starovoitov
2024-01-09 17:17                     ` Andrii Nakryiko
2024-01-10  1:58                       ` Alexei Starovoitov
2024-01-10 19:02                         ` Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 8/9] selftests/bpf: add arg:ctx cases to test_global_funcs tests Andrii Nakryiko
2024-01-04  1:38 ` [PATCH v3 bpf-next 9/9] selftests/bpf: add __arg_ctx BTF rewrite test Andrii Nakryiko
2024-01-04  2:33 ` [PATCH v3 bpf-next 0/9] Libbpf-side __arg_ctx fallback support Eduard Zingerman
2024-01-04  8:13 ` patchwork-bot+netdevbpf

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='CAADnVQJn0+fvvbOVnfPFQm=1j+=oFsjy65T2-QY8Ps0pL4nh_A@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.