summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/bad_struct_ops.c
diff options
context:
space:
mode:
authorEduard Zingerman <eddyz87@gmail.com>2024-03-06 12:45:20 +0200
committerAndrii Nakryiko <andrii@kernel.org>2024-03-06 15:18:15 -0800
commitc1b93c07b3ac3204c6a42a7f7b6217e36f44df4f (patch)
treebc5013bfc1d6b5f26f1a7cf9796c0f11b7639022 /tools/testing/selftests/bpf/progs/bad_struct_ops.c
parentc8617e8bcf8d1ef357fadf5c96bd86b9952fb93f (diff)
selftests/bpf: Bad_struct_ops test
When loading struct_ops programs kernel requires BTF id of the struct_ops type and member index for attachment point inside that type. This makes impossible to use same BPF program in several struct_ops maps that have different struct_ops type. Check if libbpf rejects such BPF objects files. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240306104529.6453-7-eddyz87@gmail.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/bad_struct_ops.c')
-rw-r--r--tools/testing/selftests/bpf/progs/bad_struct_ops.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/bad_struct_ops.c b/tools/testing/selftests/bpf/progs/bad_struct_ops.c
new file mode 100644
index 000000000000..b7e175cd0af0
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bad_struct_ops.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include "../bpf_testmod/bpf_testmod.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("struct_ops/test_1")
+int BPF_PROG(test_1) { return 0; }
+
+SEC("struct_ops/test_2")
+int BPF_PROG(test_2) { return 0; }
+
+SEC(".struct_ops.link")
+struct bpf_testmod_ops testmod_1 = {
+ .test_1 = (void *)test_1,
+ .test_2 = (void *)test_2
+};
+
+SEC(".struct_ops.link")
+struct bpf_testmod_ops2 testmod_2 = {
+ .test_1 = (void *)test_1
+};