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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/preempted_bpf_ma_op.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) 2023. Huawei Technologies Co., Ltd */
  3 #include <vmlinux.h>
  4 #include <bpf/bpf_tracing.h>
  5 #include <bpf/bpf_helpers.h>
  6 
  7 #include "bpf_experimental.h"
  8 
  9 struct bin_data {
 10         char data[256];
 11         struct bpf_spin_lock lock;
 12 };
 13 
 14 struct map_value {
 15         struct bin_data __kptr * data;
 16 };
 17 
 18 struct {
 19         __uint(type, BPF_MAP_TYPE_ARRAY);
 20         __type(key, int);
 21         __type(value, struct map_value);
 22         __uint(max_entries, 2048);
 23 } array SEC(".maps");
 24 
 25 char _license[] SEC("license") = "GPL";
 26 
 27 bool nomem_err = false;
 28 
 29 static int del_array(unsigned int i, int *from)
 30 {
 31         struct map_value *value;
 32         struct bin_data *old;
 33 
 34         value = bpf_map_lookup_elem(&array, from);
 35         if (!value)
 36                 return 1;
 37 
 38         old = bpf_kptr_xchg(&value->data, NULL);
 39         if (old)
 40                 bpf_obj_drop(old);
 41 
 42         (*from)++;
 43         return 0;
 44 }
 45 
 46 static int add_array(unsigned int i, int *from)
 47 {
 48         struct bin_data *old, *new;
 49         struct map_value *value;
 50 
 51         value = bpf_map_lookup_elem(&array, from);
 52         if (!value)
 53                 return 1;
 54 
 55         new = bpf_obj_new(typeof(*new));
 56         if (!new) {
 57                 nomem_err = true;
 58                 return 1;
 59         }
 60 
 61         old = bpf_kptr_xchg(&value->data, new);
 62         if (old)
 63                 bpf_obj_drop(old);
 64 
 65         (*from)++;
 66         return 0;
 67 }
 68 
 69 static void del_then_add_array(int from)
 70 {
 71         int i;
 72 
 73         i = from;
 74         bpf_loop(512, del_array, &i, 0);
 75 
 76         i = from;
 77         bpf_loop(512, add_array, &i, 0);
 78 }
 79 
 80 SEC("fentry/bpf_fentry_test1")
 81 int BPF_PROG2(test0, int, a)
 82 {
 83         del_then_add_array(0);
 84         return 0;
 85 }
 86 
 87 SEC("fentry/bpf_fentry_test2")
 88 int BPF_PROG2(test1, int, a, u64, b)
 89 {
 90         del_then_add_array(512);
 91         return 0;
 92 }
 93 
 94 SEC("fentry/bpf_fentry_test3")
 95 int BPF_PROG2(test2, char, a, int, b, u64, c)
 96 {
 97         del_then_add_array(1024);
 98         return 0;
 99 }
100 
101 SEC("fentry/bpf_fentry_test4")
102 int BPF_PROG2(test3, void *, a, char, b, int, c, u64, d)
103 {
104         del_then_add_array(1536);
105         return 0;
106 }
107 

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