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
11struct elem {
12 struct bpf_timer timer;
13};
14
15struct {
16 __uint(type, BPF_MAP_TYPE_ARRAY);
17 __uint(max_entries, 1);
18 __type(key, int);
19 __type(value, struct elem);
20} array_map SEC(".maps");
21
22#define MAP_MAGIC 1234
23int recur;
24int test_err;
25int timer_ns;
26int timer_test_1_ret;
27int timer_cb_run;
28
29__noinline static int timer_cb(void *map, int *key, struct bpf_timer *timer)
30{
31 struct st_ops_args args = {};
32
33 recur++;
34 timer_test_1_ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
35 recur--;
36
37 timer_cb_run++;
38
39 return 0;
40}
41
42SEC("struct_ops")
43int BPF_PROG(test_1, struct st_ops_args *args)
44{
45 struct bpf_timer *timer;
46 int key = 0;
47
48 if (!recur) {
49 timer = bpf_map_lookup_elem(&array_map, &key);
50 if (!timer)
51 return 0;
52
53 bpf_timer_init(timer, &array_map, 1);
54 bpf_timer_set_callback(timer, timer_cb);
55 bpf_timer_start(timer, timer_ns, 0);
56 }
57
58 return MAP_MAGIC;
59}
60
61SEC("syscall")
62int syscall_prog(void *ctx)
63{
64 struct st_ops_args args = {};
65 int ret;
66
67 ret = bpf_kfunc_multi_st_ops_test_1_assoc(&args);
68 if (ret != MAP_MAGIC)
69 test_err++;
70
71 return 0;
72}
73
74SEC(".struct_ops.link")
75struct bpf_testmod_multi_st_ops st_ops_map = {
76 .test_1 = (void *)test_1,
77};