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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_map_lock.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) 2019 Facebook
  3 #include <linux/bpf.h>
  4 #include <linux/version.h>
  5 #include <bpf/bpf_helpers.h>
  6 
  7 #define VAR_NUM 16
  8 
  9 struct hmap_elem {
 10         struct bpf_spin_lock lock;
 11         int var[VAR_NUM];
 12 };
 13 
 14 struct {
 15         __uint(type, BPF_MAP_TYPE_HASH);
 16         __uint(max_entries, 1);
 17         __type(key, __u32);
 18         __type(value, struct hmap_elem);
 19 } hash_map SEC(".maps");
 20 
 21 struct array_elem {
 22         struct bpf_spin_lock lock;
 23         int var[VAR_NUM];
 24 };
 25 
 26 struct {
 27         __uint(type, BPF_MAP_TYPE_ARRAY);
 28         __uint(max_entries, 1);
 29         __type(key, int);
 30         __type(value, struct array_elem);
 31 } array_map SEC(".maps");
 32 
 33 SEC("cgroup/skb")
 34 int bpf_map_lock_test(struct __sk_buff *skb)
 35 {
 36         struct hmap_elem *val;
 37         int rnd = bpf_get_prandom_u32();
 38         int key = 0, err = 1, i;
 39         struct array_elem *q;
 40 
 41         val = bpf_map_lookup_elem(&hash_map, &key);
 42         if (!val)
 43                 goto err;
 44         /* spin_lock in hash map */
 45         bpf_spin_lock(&val->lock);
 46         for (i = 0; i < VAR_NUM; i++)
 47                 val->var[i] = rnd;
 48         bpf_spin_unlock(&val->lock);
 49 
 50         /* spin_lock in array */
 51         q = bpf_map_lookup_elem(&array_map, &key);
 52         if (!q)
 53                 goto err;
 54         bpf_spin_lock(&q->lock);
 55         for (i = 0; i < VAR_NUM; i++)
 56                 q->var[i] = rnd;
 57         bpf_spin_unlock(&q->lock);
 58         err = 0;
 59 err:
 60         return err;
 61 }
 62 char _license[] SEC("license") = "GPL";
 63 

~ [ 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