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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/arena_list.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) 2024 Meta Platforms, Inc. and affiliates. */
  3 #define BPF_NO_KFUNC_PROTOTYPES
  4 #include <vmlinux.h>
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_tracing.h>
  7 #include <bpf/bpf_core_read.h>
  8 #include "bpf_experimental.h"
  9 
 10 struct {
 11         __uint(type, BPF_MAP_TYPE_ARENA);
 12         __uint(map_flags, BPF_F_MMAPABLE);
 13         __uint(max_entries, 100); /* number of pages */
 14 #ifdef __TARGET_ARCH_arm64
 15         __ulong(map_extra, 0x1ull << 32); /* start of mmap() region */
 16 #else
 17         __ulong(map_extra, 0x1ull << 44); /* start of mmap() region */
 18 #endif
 19 } arena SEC(".maps");
 20 
 21 #include "bpf_arena_alloc.h"
 22 #include "bpf_arena_list.h"
 23 
 24 struct elem {
 25         struct arena_list_node node;
 26         __u64 value;
 27 };
 28 
 29 struct arena_list_head __arena *list_head;
 30 int list_sum;
 31 int cnt;
 32 bool skip = false;
 33 
 34 #ifdef __BPF_FEATURE_ADDR_SPACE_CAST
 35 long __arena arena_sum;
 36 int __arena test_val = 1;
 37 struct arena_list_head __arena global_head;
 38 #else
 39 long arena_sum SEC(".addr_space.1");
 40 int test_val SEC(".addr_space.1");
 41 #endif
 42 
 43 int zero;
 44 
 45 SEC("syscall")
 46 int arena_list_add(void *ctx)
 47 {
 48 #ifdef __BPF_FEATURE_ADDR_SPACE_CAST
 49         __u64 i;
 50 
 51         list_head = &global_head;
 52 
 53         for (i = zero; i < cnt && can_loop; i++) {
 54                 struct elem __arena *n = bpf_alloc(sizeof(*n));
 55 
 56                 test_val++;
 57                 n->value = i;
 58                 arena_sum += i;
 59                 list_add_head(&n->node, list_head);
 60         }
 61 #else
 62         skip = true;
 63 #endif
 64         return 0;
 65 }
 66 
 67 SEC("syscall")
 68 int arena_list_del(void *ctx)
 69 {
 70 #ifdef __BPF_FEATURE_ADDR_SPACE_CAST
 71         struct elem __arena *n;
 72         int sum = 0;
 73 
 74         arena_sum = 0;
 75         list_for_each_entry(n, list_head, node) {
 76                 sum += n->value;
 77                 arena_sum += n->value;
 78                 list_del(&n->node);
 79                 bpf_free(n);
 80         }
 81         list_sum = sum;
 82 #else
 83         skip = true;
 84 #endif
 85         return 0;
 86 }
 87 
 88 char _license[] SEC("license") = "GPL";
 89 

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