1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
3#include <vmlinux.h>
4#include <bpf/bpf_tracing.h>
5#include <bpf/bpf_helpers.h>
6#include "bpf_misc.h"
7#include "bpf_arena_spin_lock.h"
8
9struct {
10 __uint(type, BPF_MAP_TYPE_ARENA);
11 __uint(map_flags, BPF_F_MMAPABLE);
12 __uint(max_entries, 100); /* number of pages */
13#ifdef __TARGET_ARCH_arm64
14 __ulong(map_extra, 0x1ull << 32); /* start of mmap() region */
15#else
16 __ulong(map_extra, 0x1ull << 44); /* start of mmap() region */
17#endif
18} arena SEC(".maps");
19
20int cs_count;
21
22#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
23arena_spinlock_t __arena lock;
24int test_skip = 1;
25#else
26int test_skip = 2;
27#endif
28
29int counter;
30int limit;
31
32SEC("tc")
33int prog(void *ctx)
34{
35 int ret = -2;
36
37#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
38 unsigned long flags;
39
40 if ((ret = arena_spin_lock_irqsave(&lock, flags)))
41 return ret;
42 if (counter != limit)
43 counter++;
44 bpf_repeat(cs_count);
45 ret = 0;
46 arena_spin_unlock_irqrestore(&lock, flags);
47#endif
48 return ret;
49}
50
51char _license[] SEC("license") = "GPL";
52

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of linux/tools/testing/selftests/bpf/progs/arena_spin_lock.c