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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 
  5 #ifndef WRITE_ONCE
  6 #define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val))
  7 #endif
  8 
  9 #ifndef NUMA_NO_NODE
 10 #define NUMA_NO_NODE    (-1)
 11 #endif
 12 
 13 #ifndef arena_container_of
 14 #define arena_container_of(ptr, type, member)                   \
 15         ({                                                      \
 16                 void __arena *__mptr = (void __arena *)(ptr);   \
 17                 ((type *)(__mptr - offsetof(type, member)));    \
 18         })
 19 #endif
 20 
 21 #ifdef __BPF__ /* when compiled as bpf program */
 22 
 23 #ifndef PAGE_SIZE
 24 #define PAGE_SIZE __PAGE_SIZE
 25 /*
 26  * for older kernels try sizeof(struct genradix_node)
 27  * or flexible:
 28  * static inline long __bpf_page_size(void) {
 29  *   return bpf_core_enum_value(enum page_size_enum___l, __PAGE_SIZE___l) ?: sizeof(struct genradix_node);
 30  * }
 31  * but generated code is not great.
 32  */
 33 #endif
 34 
 35 #if defined(__BPF_FEATURE_ADDR_SPACE_CAST) && !defined(BPF_ARENA_FORCE_ASM)
 36 #define __arena __attribute__((address_space(1)))
 37 #define __arena_global __attribute__((address_space(1)))
 38 #define cast_kern(ptr) /* nop for bpf prog. emitted by LLVM */
 39 #define cast_user(ptr) /* nop for bpf prog. emitted by LLVM */
 40 #else
 41 #define __arena
 42 #define __arena_global SEC(".addr_space.1")
 43 #define cast_kern(ptr) bpf_addr_space_cast(ptr, 0, 1)
 44 #define cast_user(ptr) bpf_addr_space_cast(ptr, 1, 0)
 45 #endif
 46 
 47 void __arena* bpf_arena_alloc_pages(void *map, void __arena *addr, __u32 page_cnt,
 48                                     int node_id, __u64 flags) __ksym __weak;
 49 void bpf_arena_free_pages(void *map, void __arena *ptr, __u32 page_cnt) __ksym __weak;
 50 
 51 #else /* when compiled as user space code */
 52 
 53 #define __arena
 54 #define __arg_arena
 55 #define cast_kern(ptr) /* nop for user space */
 56 #define cast_user(ptr) /* nop for user space */
 57 __weak char arena[1];
 58 
 59 #ifndef offsetof
 60 #define offsetof(type, member)  ((unsigned long)&((type *)0)->member)
 61 #endif
 62 
 63 static inline void __arena* bpf_arena_alloc_pages(void *map, void *addr, __u32 page_cnt,
 64                                                   int node_id, __u64 flags)
 65 {
 66         return NULL;
 67 }
 68 static inline void bpf_arena_free_pages(void *map, void __arena *ptr, __u32 page_cnt)
 69 {
 70 }
 71 
 72 #endif
 73 

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