WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_ksyms_btf.c
blobbb8ea9270f29cc4cf09e93872395b8950840f102
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Google */
4 #include "vmlinux.h"
6 #include <bpf/bpf_helpers.h>
8 __u64 out__runqueues_addr = -1;
9 __u64 out__bpf_prog_active_addr = -1;
11 __u32 out__rq_cpu = -1; /* percpu struct fields */
12 int out__bpf_prog_active = -1; /* percpu int */
14 __u32 out__this_rq_cpu = -1;
15 int out__this_bpf_prog_active = -1;
17 __u32 out__cpu_0_rq_cpu = -1; /* cpu_rq(0)->cpu */
19 extern const struct rq runqueues __ksym; /* struct type global var. */
20 extern const int bpf_prog_active __ksym; /* int type global var. */
22 SEC("raw_tp/sys_enter")
23 int handler(const void *ctx)
25 struct rq *rq;
26 int *active;
27 __u32 cpu;
29 out__runqueues_addr = (__u64)&runqueues;
30 out__bpf_prog_active_addr = (__u64)&bpf_prog_active;
32 cpu = bpf_get_smp_processor_id();
34 /* test bpf_per_cpu_ptr() */
35 rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, cpu);
36 if (rq)
37 out__rq_cpu = rq->cpu;
38 active = (int *)bpf_per_cpu_ptr(&bpf_prog_active, cpu);
39 if (active)
40 out__bpf_prog_active = *active;
42 rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 0);
43 if (rq) /* should always be valid, but we can't spare the check. */
44 out__cpu_0_rq_cpu = rq->cpu;
46 /* test bpf_this_cpu_ptr */
47 rq = (struct rq *)bpf_this_cpu_ptr(&runqueues);
48 out__this_rq_cpu = rq->cpu;
49 active = (int *)bpf_this_cpu_ptr(&bpf_prog_active);
50 out__this_bpf_prog_active = *active;
52 return 0;
55 char _license[] SEC("license") = "GPL";