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/* Copyright (c) 2020 Facebook */
3
4#include "vmlinux.h"
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
7#include <bpf/bpf_core_read.h>
8#include "../test_kmods/bpf_testmod.h"
9
10__u32 sz = 0;
11
12SEC("?raw_tp/bpf_testmod_test_read")
13int BPF_PROG(handle_raw_tp,
14 struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
15{
16 sz = BPF_CORE_READ(read_ctx, len);
17 return 0;
18}
19
20SEC("?raw_tp/bpf_testmod_test_write_bare_tp")
21int BPF_PROG(handle_raw_tp_bare,
22 struct task_struct *task, struct bpf_testmod_test_write_ctx *write_ctx)
23{
24 sz = BPF_CORE_READ(write_ctx, len);
25 return 0;
26}
27
28int raw_tp_writable_bare_in_val = 0;
29int raw_tp_writable_bare_early_ret = 0;
30int raw_tp_writable_bare_out_val = 0;
31
32SEC("?raw_tp.w/bpf_testmod_test_writable_bare_tp")
33int BPF_PROG(handle_raw_tp_writable_bare,
34 struct bpf_testmod_test_writable_ctx *writable)
35{
36 raw_tp_writable_bare_in_val = writable->val;
37 writable->early_ret = raw_tp_writable_bare_early_ret;
38 writable->val = raw_tp_writable_bare_out_val;
39 return 0;
40}
41
42SEC("?tp_btf/bpf_testmod_test_read")
43int BPF_PROG(handle_tp_btf,
44 struct task_struct *task, struct bpf_testmod_test_read_ctx *read_ctx)
45{
46 sz = read_ctx->len;
47 return 0;
48}
49
50SEC("?fentry/bpf_testmod_test_read")
51int BPF_PROG(handle_fentry,
52 struct file *file, struct kobject *kobj,
53 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
54{
55 sz = len;
56 return 0;
57}
58
59SEC("?fentry")
60int BPF_PROG(handle_fentry_manual,
61 struct file *file, struct kobject *kobj,
62 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
63{
64 sz = len;
65 return 0;
66}
67
68SEC("?fentry/bpf_testmod:bpf_testmod_test_read")
69int BPF_PROG(handle_fentry_explicit,
70 struct file *file, struct kobject *kobj,
71 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
72{
73 sz = len;
74 return 0;
75}
76
77
78SEC("?fentry")
79int BPF_PROG(handle_fentry_explicit_manual,
80 struct file *file, struct kobject *kobj,
81 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
82{
83 sz = len;
84 return 0;
85}
86
87int retval = 0;
88
89SEC("?fexit/bpf_testmod_test_read")
90int BPF_PROG(handle_fexit,
91 struct file *file, struct kobject *kobj,
92 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len,
93 int ret)
94{
95 sz = len;
96 retval = ret;
97 return 0;
98}
99
100SEC("?fexit/bpf_testmod_return_ptr")
101int BPF_PROG(handle_fexit_ret, int arg, struct file *ret)
102{
103 long buf = 0;
104
105 bpf_probe_read_kernel(&buf, 8, ret);
106 bpf_probe_read_kernel(&buf, 8, (char *)ret + 256);
107 *(volatile int *)ret;
108 *(volatile int *)&ret->f_mode;
109 return 0;
110}
111
112SEC("?fmod_ret/bpf_testmod_test_read")
113int BPF_PROG(handle_fmod_ret,
114 struct file *file, struct kobject *kobj,
115 struct bin_attribute *bin_attr, char *buf, loff_t off, size_t len)
116{
117 sz = len;
118 return 0; /* don't override the exit code */
119}
120
121SEC("?kprobe.multi/bpf_testmod_test_read")
122int BPF_PROG(kprobe_multi)
123{
124 return 0;
125}
126
127char _license[] SEC("license") = "GPL";