~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/timer_mim_reject.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (c) 2021 Facebook */
  3 #include <linux/bpf.h>
  4 #include <time.h>
  5 #include <errno.h>
  6 #include <bpf/bpf_helpers.h>
  7 #include <bpf/bpf_tracing.h>
  8 
  9 char _license[] SEC("license") = "GPL";
 10 struct hmap_elem {
 11         int pad; /* unused */
 12         struct bpf_timer timer;
 13 };
 14 
 15 struct inner_map {
 16         __uint(type, BPF_MAP_TYPE_HASH);
 17         __uint(max_entries, 1024);
 18         __type(key, int);
 19         __type(value, struct hmap_elem);
 20 } inner_htab SEC(".maps");
 21 
 22 #define ARRAY_KEY 1
 23 #define ARRAY_KEY2 2
 24 #define HASH_KEY 1234
 25 
 26 struct outer_arr {
 27         __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
 28         __uint(max_entries, 2);
 29         __uint(key_size, sizeof(int));
 30         __uint(value_size, sizeof(int));
 31         __array(values, struct inner_map);
 32 } outer_arr SEC(".maps") = {
 33         .values = { [ARRAY_KEY] = &inner_htab },
 34 };
 35 
 36 __u64 err;
 37 __u64 ok;
 38 __u64 cnt;
 39 
 40 /* callback for inner hash map */
 41 static int timer_cb(void *map, int *key, struct hmap_elem *val)
 42 {
 43         return 0;
 44 }
 45 
 46 SEC("fentry/bpf_fentry_test1")
 47 int BPF_PROG(test1, int a)
 48 {
 49         struct hmap_elem init = {};
 50         struct bpf_map *inner_map, *inner_map2;
 51         struct hmap_elem *val;
 52         int array_key = ARRAY_KEY;
 53         int array_key2 = ARRAY_KEY2;
 54         int hash_key = HASH_KEY;
 55 
 56         inner_map = bpf_map_lookup_elem(&outer_arr, &array_key);
 57         if (!inner_map)
 58                 return 0;
 59 
 60         inner_map2 = bpf_map_lookup_elem(&outer_arr, &array_key2);
 61         if (!inner_map2)
 62                 return 0;
 63         bpf_map_update_elem(inner_map, &hash_key, &init, 0);
 64         val = bpf_map_lookup_elem(inner_map, &hash_key);
 65         if (!val)
 66                 return 0;
 67 
 68         bpf_timer_init(&val->timer, inner_map2, CLOCK_MONOTONIC);
 69         if (bpf_timer_set_callback(&val->timer, timer_cb))
 70                 err |= 4;
 71         if (bpf_timer_start(&val->timer, 0, 0))
 72                 err |= 8;
 73         return 0;
 74 }
 75 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php