Merge tag 'perf-urgent-2020-08-23' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / tools / testing / selftests / bpf / progs / modify_return.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright 2020 Google LLC.
5  */
6
7 #include <linux/bpf.h>
8 #include <bpf/bpf_helpers.h>
9 #include <bpf/bpf_tracing.h>
10
11 char _license[] SEC("license") = "GPL";
12
13 static int sequence = 0;
14 __s32 input_retval = 0;
15
16 __u64 fentry_result = 0;
17 SEC("fentry/bpf_modify_return_test")
18 int BPF_PROG(fentry_test, int a, __u64 b)
19 {
20         sequence++;
21         fentry_result = (sequence == 1);
22         return 0;
23 }
24
25 __u64 fmod_ret_result = 0;
26 SEC("fmod_ret/bpf_modify_return_test")
27 int BPF_PROG(fmod_ret_test, int a, int *b, int ret)
28 {
29         sequence++;
30         /* This is the first fmod_ret program, the ret passed should be 0 */
31         fmod_ret_result = (sequence == 2 && ret == 0);
32         return input_retval;
33 }
34
35 __u64 fexit_result = 0;
36 SEC("fexit/bpf_modify_return_test")
37 int BPF_PROG(fexit_test, int a, __u64 b, int ret)
38 {
39         sequence++;
40         /* If the input_reval is non-zero a successful modification should have
41          * occurred.
42          */
43         if (input_retval)
44                 fexit_result = (sequence == 3 && ret == input_retval);
45         else
46                 fexit_result = (sequence == 3 && ret == 4);
47
48         return 0;
49 }