Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
9char _license[] SEC("license") = "GPL";
10
11int test_pid;
12
13/* Programs associated with st_ops_map_a */
14
15#define MAP_A_MAGIC 1234
16int test_err_a;
17
18SEC("struct_ops")
19int BPF_PROG(test_1_a, struct st_ops_args *args)
20{
21 return MAP_A_MAGIC;
22}
23
24SEC("tp_btf/sys_enter")
25int BPF_PROG(sys_enter_prog_a, struct pt_regs *regs, long id)
26{
27 struct st_ops_args args = {};
28 struct task_struct *task;
29 int ret;
30
31 task = bpf_get_current_task_btf();
32 if (!test_pid || task->pid != test_pid)
33 return 0;
34
35 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
36 if (ret != MAP_A_MAGIC)
37 test_err_a++;
38
39 return 0;
40}
41
42SEC("syscall")
43int syscall_prog_a(void *ctx)
44{
45 struct st_ops_args args = {};
46 int ret;
47
48 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
49 if (ret != MAP_A_MAGIC)
50 test_err_a++;
51
52 return 0;
53}
54
55SEC(".struct_ops.link")
56struct bpf_testmod_multi_st_ops st_ops_map_a = {
57 .test_1 = (void *)test_1_a,
58};
59
60/* Programs associated with st_ops_map_b */
61
62#define MAP_B_MAGIC 5678
63int test_err_b;
64
65SEC("struct_ops")
66int BPF_PROG(test_1_b, struct st_ops_args *args)
67{
68 return MAP_B_MAGIC;
69}
70
71SEC("tp_btf/sys_enter")
72int BPF_PROG(sys_enter_prog_b, struct pt_regs *regs, long id)
73{
74 struct st_ops_args args = {};
75 struct task_struct *task;
76 int ret;
77
78 task = bpf_get_current_task_btf();
79 if (!test_pid || task->pid != test_pid)
80 return 0;
81
82 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
83 if (ret != MAP_B_MAGIC)
84 test_err_b++;
85
86 return 0;
87}
88
89SEC("syscall")
90int syscall_prog_b(void *ctx)
91{
92 struct st_ops_args args = {};
93 int ret;
94
95 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
96 if (ret != MAP_B_MAGIC)
97 test_err_b++;
98
99 return 0;
100}
101
102SEC(".struct_ops.link")
103struct bpf_testmod_multi_st_ops st_ops_map_b = {
104 .test_1 = (void *)test_1_b,
105};