cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

test_ksyms_btf.c (1408B)


      1// SPDX-License-Identifier: GPL-2.0
      2/* Copyright (c) 2020 Google */
      3
      4#include "vmlinux.h"
      5
      6#include <bpf/bpf_helpers.h>
      7
      8__u64 out__runqueues_addr = -1;
      9__u64 out__bpf_prog_active_addr = -1;
     10
     11__u32 out__rq_cpu = -1; /* percpu struct fields */
     12int out__bpf_prog_active = -1; /* percpu int */
     13
     14__u32 out__this_rq_cpu = -1;
     15int out__this_bpf_prog_active = -1;
     16
     17__u32 out__cpu_0_rq_cpu = -1; /* cpu_rq(0)->cpu */
     18
     19extern const struct rq runqueues __ksym; /* struct type global var. */
     20extern const int bpf_prog_active __ksym; /* int type global var. */
     21
     22SEC("raw_tp/sys_enter")
     23int handler(const void *ctx)
     24{
     25	struct rq *rq;
     26	int *active;
     27	__u32 cpu;
     28
     29	out__runqueues_addr = (__u64)&runqueues;
     30	out__bpf_prog_active_addr = (__u64)&bpf_prog_active;
     31
     32	cpu = bpf_get_smp_processor_id();
     33
     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;
     41
     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;
     45
     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;
     51
     52	return 0;
     53}
     54
     55char _license[] SEC("license") = "GPL";