xref: /linux/tools/testing/selftests/bpf/progs/struct_ops_id_ops_mapping2.c (revision 4f38da1f027ea2c9f01bb71daa7a299c191b6940)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <vmlinux.h>
4 #include <bpf/bpf_tracing.h>
5 #include "bpf_misc.h"
6 #include "../test_kmods/bpf_testmod.h"
7 #include "../test_kmods/bpf_testmod_kfunc.h"
8 
9 char _license[] SEC("license") = "GPL";
10 
11 #define bpf_kfunc_multi_st_ops_test_1(args) bpf_kfunc_multi_st_ops_test_1(args, st_ops_id)
12 int st_ops_id;
13 
14 int test_pid;
15 int test_err;
16 
17 #define MAP2_MAGIC 4567
18 
19 SEC("struct_ops")
20 int BPF_PROG(test_1, struct st_ops_args *args)
21 {
22 	return MAP2_MAGIC;
23 }
24 
25 SEC("tp_btf/sys_enter")
26 int BPF_PROG(sys_enter, struct pt_regs *regs, long id)
27 {
28 	struct st_ops_args args = {};
29 	struct task_struct *task;
30 	int ret;
31 
32 	task = bpf_get_current_task_btf();
33 	if (!test_pid || task->pid != test_pid)
34 		return 0;
35 
36 	ret = bpf_kfunc_multi_st_ops_test_1(&args);
37 	if (ret != MAP2_MAGIC)
38 		test_err++;
39 
40 	return 0;
41 }
42 
43 SEC("syscall")
44 int syscall_prog(void *ctx)
45 {
46 	struct st_ops_args args = {};
47 	int ret;
48 
49 	ret = bpf_kfunc_multi_st_ops_test_1(&args);
50 	if (ret != MAP2_MAGIC)
51 		test_err++;
52 
53 	return 0;
54 }
55 
56 SEC(".struct_ops.link")
57 struct bpf_testmod_multi_st_ops st_ops_map = {
58 	.test_1 = (void *)test_1,
59 };
60