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_btf_newkv.c (1309B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2/* Copyright (c) 2018 Facebook */
      3#include <linux/bpf.h>
      4#include <bpf/bpf_helpers.h>
      5#include "bpf_legacy.h"
      6
      7struct ipv_counts {
      8	unsigned int v4;
      9	unsigned int v6;
     10};
     11
     12#pragma GCC diagnostic push
     13#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     14/* just to validate we can handle maps in multiple sections */
     15struct bpf_map_def SEC("maps") btf_map_legacy = {
     16	.type = BPF_MAP_TYPE_ARRAY,
     17	.key_size = sizeof(int),
     18	.value_size = sizeof(long long),
     19	.max_entries = 4,
     20};
     21#pragma GCC diagnostic pop
     22
     23BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
     24
     25struct {
     26	__uint(type, BPF_MAP_TYPE_ARRAY);
     27	__uint(max_entries, 4);
     28	__type(key, int);
     29	__type(value, struct ipv_counts);
     30} btf_map SEC(".maps");
     31
     32__attribute__((noinline))
     33int test_long_fname_2(void)
     34{
     35	struct ipv_counts *counts;
     36	int key = 0;
     37
     38	counts = bpf_map_lookup_elem(&btf_map, &key);
     39	if (!counts)
     40		return 0;
     41
     42	counts->v6++;
     43
     44	/* just verify we can reference both maps */
     45	counts = bpf_map_lookup_elem(&btf_map_legacy, &key);
     46	if (!counts)
     47		return 0;
     48
     49	return 0;
     50}
     51
     52__attribute__((noinline))
     53int test_long_fname_1(void)
     54{
     55	return test_long_fname_2();
     56}
     57
     58SEC("dummy_tracepoint")
     59int _dummy_tracepoint(void *arg)
     60{
     61	return test_long_fname_1();
     62}
     63
     64char _license[] SEC("license") = "GPL";