brintos

brintos / linux-shallow public Read only

0
0
Text · 1.7 KiB · 3a2ddca Raw
89 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */3#define BPF_NO_KFUNC_PROTOTYPES4#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 10struct {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_arm6415	__ulong(map_extra, 0x1ull << 32); /* start of mmap() region */16#else17	__ulong(map_extra, 0x1ull << 44); /* start of mmap() region */18#endif19} arena SEC(".maps");20 21#include "bpf_arena_alloc.h"22#include "bpf_arena_list.h"23 24struct elem {25	struct arena_list_node node;26	__u64 value;27};28 29struct arena_list_head __arena *list_head;30int list_sum;31int cnt;32bool skip = false;33 34#ifdef __BPF_FEATURE_ADDR_SPACE_CAST35long __arena arena_sum;36int __arena test_val = 1;37struct arena_list_head __arena global_head;38#else39long arena_sum SEC(".addr_space.1");40int test_val SEC(".addr_space.1");41#endif42 43int zero;44 45SEC("syscall")46int arena_list_add(void *ctx)47{48#ifdef __BPF_FEATURE_ADDR_SPACE_CAST49	__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#else62	skip = true;63#endif64	return 0;65}66 67SEC("syscall")68int arena_list_del(void *ctx)69{70#ifdef __BPF_FEATURE_ADDR_SPACE_CAST71	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#else83	skip = true;84#endif85	return 0;86}87 88char _license[] SEC("license") = "GPL";89