summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/verifier_arena_globals2.c
blob: e6bd7b61f9f13e37ad4435d87371a10ae3eca72a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */

#define BPF_NO_KFUNC_PROTOTYPES
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
#include "bpf_experimental.h"
#include "bpf_arena_common.h"

#define ARENA_PAGES (32)

struct {
	__uint(type, BPF_MAP_TYPE_ARENA);
	__uint(map_flags, BPF_F_MMAPABLE);
	__uint(max_entries, ARENA_PAGES);
#ifdef __TARGET_ARCH_arm64
	__ulong(map_extra, (1ull << 32) | (~0u - __PAGE_SIZE * ARENA_PAGES + 1));
#else
	__ulong(map_extra, (1ull << 44) | (~0u - __PAGE_SIZE * ARENA_PAGES + 1));
#endif
} arena SEC(".maps");

/*
 * Fill the entire arena with global data.
 * The offset into the arena should be 0.
 */
char __arena global_data[ARENA_PAGES][PAGE_SIZE];

SEC("syscall")
__success __retval(0)
int check_reserve2(void *ctx)
{
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
	void __arena *guard;
	int ret;

	guard = (void __arena *)arena_base(&arena);

	/* Make sure the data at offset 0 case is properly handled. */
	ret = bpf_arena_reserve_pages(&arena, guard, 1);
	if (!ret)
		return 1;
#endif
	return 0;
}

char _license[] SEC("license") = "GPL";