BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<martin.lau@kernel.org>
Cc: <andrii@kernel.org>, <kernel-team@meta.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: [PATCH v3 bpf-next 8/9] selftests/bpf: add arg:ctx cases to test_global_funcs tests
Date: Wed, 3 Jan 2024 17:38:46 -0800	[thread overview]
Message-ID: <20240104013847.3875810-9-andrii@kernel.org> (raw)
In-Reply-To: <20240104013847.3875810-1-andrii@kernel.org>

Add a few extra cases of global funcs with context arguments. This time
rely on "arg:ctx" decl_tag (__arg_ctx macro), but put it next to
"classic" cases where context argument has to be of an exact type that
BPF verifier expects (e.g., bpf_user_pt_regs_t for kprobe/uprobe).

Colocating all these cases separately from other global func args that
rely on arg:xxx decl tags (in verifier_global_subprogs.c) allows for
simpler backwards compatibility testing on old kernels. All the cases in
test_global_func_ctx_args.c are supposed to work on older kernels, which
was manually validated during development.

Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 .../bpf/progs/test_global_func_ctx_args.c     | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)

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 7faa8eef0598..9a06e5eb1fbe 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
@@ -102,3 +102,52 @@ int perf_event_ctx(void *ctx)
 {
 	return perf_event_ctx_subprog(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)
+{
+	return bpf_get_stack(ctx, stack, sizeof(stack), 0);
+}
+
+struct my_struct { int x; };
+
+__weak int subprog_multi_ctx_tags(void *ctx1 __arg_ctx,
+				  struct my_struct *mem,
+				  void *ctx2 __arg_ctx)
+{
+	if (!mem)
+		return 0;
+
+	return bpf_get_stack(ctx1, stack, sizeof(stack), 0) +
+	       mem->x +
+	       bpf_get_stack(ctx2, stack, sizeof(stack), 0);
+}
+
+SEC("?raw_tp")
+__success __log_level(2)
+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);
+}
+
+SEC("?perf_event")
+__success __log_level(2)
+int arg_tag_ctx_perf(void *ctx)
+{
+	struct my_struct x = { .x = 123 };
+
+	return subprog_ctx_tag(ctx) + subprog_multi_ctx_tags(ctx, &x, ctx);
+}
+
+SEC("?kprobe")
+__success __log_level(2)
+int arg_tag_ctx_kprobe(void *ctx)
+{
+	struct my_struct x = { .x = 123 };
+
+	return subprog_ctx_tag(ctx) + subprog_multi_ctx_tags(ctx, &x, ctx);
+}
-- 
2.34.1


  parent reply	other threads:[~2024-01-04  1:41 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
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 ` Andrii Nakryiko [this message]
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=20240104013847.3875810-9-andrii@kernel.org \
    --to=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox