diff mbox series

[bpf-next,1/2] bpf/selftests: coverage for calling kfuncs within tracepoint

Message ID 20240814235800.15253-2-inwardvessel@gmail.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series allow calling kfuncs in normal tracepoint programs | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 42 this patch: 42
netdev/build_tools success Errors and warnings before: 1 this patch: 1
netdev/cc_maintainers warning 12 maintainers not CCed: mykolal@fb.com sdf@fomichev.me haoluo@google.com shuah@kernel.org jolsa@kernel.org daniel@iogearbox.net linux-kselftest@vger.kernel.org song@kernel.org yonghong.song@linux.dev kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 44 this patch: 44
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 49 this patch: 49
netdev/checkpatch warning CHECK: No space is necessary after a cast WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? WARNING: externs should be avoided in .c files
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18

Commit Message

JP Kobryn Aug. 14, 2024, 11:57 p.m. UTC
This test exposes the issue of being unable to call kfuncs within a
normal tracepoint program. The program will be rejected by the verifier
as not allowed.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
---
 .../selftests/bpf/prog_tests/kfunc_in_tp.c    | 34 ++++++++++++++++++
 .../selftests/bpf/progs/test_kfunc_in_tp.c    | 35 +++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c

Comments

Eduard Zingerman Aug. 15, 2024, 12:10 a.m. UTC | #1
On Wed, 2024-08-14 at 16:57 -0700, JP Kobryn wrote:
> This test exposes the issue of being unable to call kfuncs within a
> normal tracepoint program. The program will be rejected by the verifier
> as not allowed.
> 
> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
> ---

I have no opinion regarding the gist of this patch-set,
just a few technical nits.

Please swap places for patches 1 and 2, such that at any point in
commit history selftests are passing. This should help with any
potential bisect.

>  .../selftests/bpf/prog_tests/kfunc_in_tp.c    | 34 ++++++++++++++++++
>  .../selftests/bpf/progs/test_kfunc_in_tp.c    | 35 +++++++++++++++++++
>  2 files changed, 69 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
> new file mode 100644
> index 000000000000..bef1d192fc00
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
> @@ -0,0 +1,34 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
> +
> +#include <errno.h>
> +#include <sys/syscall.h>
> +#include <unistd.h>
> +
> +#include "test_kfunc_in_tp.skel.h"
> +#include "test_progs.h"
> +
> +static void run_tp(void)
> +{
> +	(void)syscall(__NR_getpid);
> +}
> +
> +void test_kfunc_in_tp(void)

Could you please consider use of test_loader framework for these tests?
This would make 'kfunc_in_tp.c' unnecessary.
Example of tests using this framework:

    tools/testing/selftests/bpf/progs/cpumask_failure.c

(but please, integrate with tools/testing/selftests/bpf/prog_tests/verifier.c
 to avoid creation of unnecessary files).

> +{
> +	struct test_kfunc_in_tp *skel;
> +	int err;
> +
> +	skel = test_kfunc_in_tp__open();
> +	ASSERT_OK_PTR(skel, "test_kfunc_in_tp__open");
> +
> +	err = test_kfunc_in_tp__load(skel);
> +	ASSERT_OK(err, "test_kfunc_in_tp__load");
> +
> +	err = test_kfunc_in_tp__attach(skel);
> +	ASSERT_OK(err, "test_kfunc_in_tp__attach");
> +
> +	run_tp();
> +	ASSERT_OK(skel->data->result, "complete");
> +
> +	test_kfunc_in_tp__destroy(skel);
> +}

[...]
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
new file mode 100644
index 000000000000..bef1d192fc00
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/kfunc_in_tp.c
@@ -0,0 +1,34 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#include "test_kfunc_in_tp.skel.h"
+#include "test_progs.h"
+
+static void run_tp(void)
+{
+	(void)syscall(__NR_getpid);
+}
+
+void test_kfunc_in_tp(void)
+{
+	struct test_kfunc_in_tp *skel;
+	int err;
+
+	skel = test_kfunc_in_tp__open();
+	ASSERT_OK_PTR(skel, "test_kfunc_in_tp__open");
+
+	err = test_kfunc_in_tp__load(skel);
+	ASSERT_OK(err, "test_kfunc_in_tp__load");
+
+	err = test_kfunc_in_tp__attach(skel);
+	ASSERT_OK(err, "test_kfunc_in_tp__attach");
+
+	run_tp();
+	ASSERT_OK(skel->data->result, "complete");
+
+	test_kfunc_in_tp__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c b/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c
new file mode 100644
index 000000000000..5a3f1ff930af
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_kfunc_in_tp.c
@@ -0,0 +1,35 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+char _license[] SEC("license") = "GPL";
+
+extern struct bpf_cpumask *bpf_cpumask_create(void) __ksym;
+extern void bpf_cpumask_set_cpu(u32 cpu, struct bpf_cpumask *cpumask) __ksym;
+extern bool bpf_cpumask_test_cpu(u32 cpu, const struct cpumask *cpumask) __ksym;
+extern void bpf_cpumask_release(struct bpf_cpumask *cpumask) __ksym;
+
+int result = -1;
+
+/* call arbitrary kfuncs within a tracepoint program */
+SEC("tp/syscalls/sys_enter_getpid")
+int handle_tp(struct trace_event_raw_ipi_send_cpumask *ctx)
+{
+	struct bpf_cpumask *cpumask;
+	const u32 cpu = bpf_get_smp_processor_id();
+
+	cpumask = bpf_cpumask_create();
+	if (!cpumask)
+		return 0;
+
+	bpf_cpumask_set_cpu(cpu, cpumask);
+	if (bpf_cpumask_test_cpu(cpu, (struct cpumask *)cpumask))
+		bpf_printk("match\n");
+
+	bpf_cpumask_release(cpumask);
+	result = 0;
+
+	return 0;
+}