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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/bpf_arena_list.h

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-only OR BSD-2-Clause) */
  2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
  3 #pragma once
  4 #include "bpf_arena_common.h"
  5 
  6 struct arena_list_node;
  7 
  8 typedef struct arena_list_node __arena arena_list_node_t;
  9 
 10 struct arena_list_node {
 11         arena_list_node_t *next;
 12         arena_list_node_t * __arena *pprev;
 13 };
 14 
 15 struct arena_list_head {
 16         struct arena_list_node __arena *first;
 17 };
 18 typedef struct arena_list_head __arena arena_list_head_t;
 19 
 20 #define list_entry(ptr, type, member) arena_container_of(ptr, type, member)
 21 
 22 #define list_entry_safe(ptr, type, member) \
 23         ({ typeof(*ptr) * ___ptr = (ptr); \
 24          ___ptr ? ({ cast_kern(___ptr); list_entry(___ptr, type, member); }) : NULL; \
 25          })
 26 
 27 #ifndef __BPF__
 28 static inline void *bpf_iter_num_new(struct bpf_iter_num *it, int i, int j) { return NULL; }
 29 static inline void bpf_iter_num_destroy(struct bpf_iter_num *it) {}
 30 static inline bool bpf_iter_num_next(struct bpf_iter_num *it) { return true; }
 31 #define cond_break ({})
 32 #define can_loop true
 33 #endif
 34 
 35 /* Safely walk link list elements. Deletion of elements is allowed. */
 36 #define list_for_each_entry(pos, head, member)                                  \
 37         for (void * ___tmp = (pos = list_entry_safe((head)->first,              \
 38                                                     typeof(*(pos)), member),    \
 39                               (void *)0);                                       \
 40              pos && ({ ___tmp = (void *)pos->member.next; 1; }) && can_loop;    \
 41              pos = list_entry_safe((void __arena *)___tmp, typeof(*(pos)), member))
 42 
 43 static inline void list_add_head(arena_list_node_t *n, arena_list_head_t *h)
 44 {
 45         arena_list_node_t *first = h->first, * __arena *tmp;
 46 
 47         cast_user(first);
 48         cast_kern(n);
 49         WRITE_ONCE(n->next, first);
 50         cast_kern(first);
 51         if (first) {
 52                 tmp = &n->next;
 53                 cast_user(tmp);
 54                 WRITE_ONCE(first->pprev, tmp);
 55         }
 56         cast_user(n);
 57         WRITE_ONCE(h->first, n);
 58 
 59         tmp = &h->first;
 60         cast_user(tmp);
 61         cast_kern(n);
 62         WRITE_ONCE(n->pprev, tmp);
 63 }
 64 
 65 static inline void __list_del(arena_list_node_t *n)
 66 {
 67         arena_list_node_t *next = n->next, *tmp;
 68         arena_list_node_t * __arena *pprev = n->pprev;
 69 
 70         cast_user(next);
 71         cast_kern(pprev);
 72         tmp = *pprev;
 73         cast_kern(tmp);
 74         WRITE_ONCE(tmp, next);
 75         if (next) {
 76                 cast_user(pprev);
 77                 cast_kern(next);
 78                 WRITE_ONCE(next->pprev, pprev);
 79         }
 80 }
 81 
 82 #define POISON_POINTER_DELTA 0
 83 
 84 #define LIST_POISON1  ((void __arena *) 0x100 + POISON_POINTER_DELTA)
 85 #define LIST_POISON2  ((void __arena *) 0x122 + POISON_POINTER_DELTA)
 86 
 87 static inline void list_del(arena_list_node_t *n)
 88 {
 89         __list_del(n);
 90         n->next = LIST_POISON1;
 91         n->pprev = LIST_POISON2;
 92 }
 93 

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