Skip to content

Commit 675d149

Browse files
committed
selftests/bpf: Factor out arena test from compute_live_registers
Prior commit [0] bundled multiple tests for compute_live_registers(), with only one being arena-specific. Since kernel arena code is compiled-in only if supported, this results in run-time failure of *all* otherwise portable tests, e.g. on armhf 32-bit: run_subtest:PASS:obj_open_mem 0 nsec libbpf: map 'arena': failed to create: -EINVAL run_subtest:FAIL:unexpected_load_failure unexpected error: -22 (errno 22) torvalds#68/1 compute_live_registers/assign_chain:FAIL Previous arena test code was mainly added as separate source files [1], allowing either their temporary removal as a workaround or, ultimately, exclusion via Makefile to build successfully. Follow the prior approach by separating out arena-specific test source. 0: ("selftests/bpf: test cases for compute_live_registers()") 1: arena_spin_lock.c, arena_atomics.c, arena_htab.c, arena_htab_asm.c, arena_list.c, verifier_arena.c, verifier_arena_large.c Signed-off-by: Tony Ambardar <[email protected]>
1 parent b17d149 commit 675d149

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "compute_live_registers_arena.skel.h"
4+
#include "test_progs.h"
5+
6+
void test_compute_live_registers_arena(void)
7+
{
8+
RUN_TESTS(compute_live_registers_arena);
9+
}
10+

tools/testing/selftests/bpf/progs/compute_live_registers.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <linux/bpf.h>
44
#include <bpf/bpf_helpers.h>
55
#include "../../../include/linux/filter.h"
6-
#include "bpf_arena_common.h"
76
#include "bpf_misc.h"
87

98
struct {
@@ -13,12 +12,6 @@ struct {
1312
__type(value, __u64);
1413
} test_map SEC(".maps");
1514

16-
struct {
17-
__uint(type, BPF_MAP_TYPE_ARENA);
18-
__uint(map_flags, BPF_F_MMAPABLE);
19-
__uint(max_entries, 1);
20-
} arena SEC(".maps");
21-
2215
SEC("socket")
2316
__log_level(2)
2417
__msg(" 0: .......... (b7) r0 = 42")
@@ -370,33 +363,6 @@ __naked void ldabs(void)
370363
}
371364

372365

373-
#ifdef __BPF_FEATURE_ADDR_SPACE_CAST
374-
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
375-
__log_level(2)
376-
__msg(" 6: .12345.... (85) call bpf_arena_alloc_pages")
377-
__msg(" 7: 0......... (bf) r1 = addr_space_cast(r0, 0, 1)")
378-
__msg(" 8: .1........ (b7) r2 = 42")
379-
__naked void addr_space_cast(void)
380-
{
381-
asm volatile (
382-
"r1 = %[arena] ll;"
383-
"r2 = 0;"
384-
"r3 = 1;"
385-
"r4 = 0;"
386-
"r5 = 0;"
387-
"call %[bpf_arena_alloc_pages];"
388-
"r1 = addr_space_cast(r0, 0, 1);"
389-
"r2 = 42;"
390-
"*(u64 *)(r1 +0) = r2;"
391-
"r0 = 0;"
392-
"exit;"
393-
:
394-
: __imm(bpf_arena_alloc_pages),
395-
__imm_addr(arena)
396-
: __clobber_all);
397-
}
398-
#endif
399-
400366
static __used __naked int aux1(void)
401367
{
402368
asm volatile (
@@ -431,10 +397,4 @@ __naked void subprog1(void)
431397
::: __clobber_all);
432398
}
433399

434-
/* to retain debug info for BTF generation */
435-
void kfunc_root(void)
436-
{
437-
bpf_arena_alloc_pages(0, 0, 0, 0, 0);
438-
}
439-
440400
char _license[] SEC("license") = "GPL";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/bpf.h>
4+
#include <bpf/bpf_helpers.h>
5+
#include "bpf_arena_common.h"
6+
#include "bpf_misc.h"
7+
8+
struct {
9+
__uint(type, BPF_MAP_TYPE_ARENA);
10+
__uint(map_flags, BPF_F_MMAPABLE);
11+
__uint(max_entries, 1);
12+
} arena SEC(".maps");
13+
14+
#ifdef __BPF_FEATURE_ADDR_SPACE_CAST
15+
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
16+
__log_level(2)
17+
__msg(" 6: .12345.... (85) call bpf_arena_alloc_pages")
18+
__msg(" 7: 0......... (bf) r1 = addr_space_cast(r0, 0, 1)")
19+
__msg(" 8: .1........ (b7) r2 = 42")
20+
__naked void addr_space_cast(void)
21+
{
22+
asm volatile (
23+
"r1 = %[arena] ll;"
24+
"r2 = 0;"
25+
"r3 = 1;"
26+
"r4 = 0;"
27+
"r5 = 0;"
28+
"call %[bpf_arena_alloc_pages];"
29+
"r1 = addr_space_cast(r0, 0, 1);"
30+
"r2 = 42;"
31+
"*(u64 *)(r1 +0) = r2;"
32+
"r0 = 0;"
33+
"exit;"
34+
:
35+
: __imm(bpf_arena_alloc_pages),
36+
__imm_addr(arena)
37+
: __clobber_all);
38+
}
39+
#endif
40+
41+
/* to retain debug info for BTF generation */
42+
void kfunc_root(void)
43+
{
44+
bpf_arena_alloc_pages(0, 0, 0, 0, 0);
45+
}
46+
47+
char _license[] SEC("license") = "GPL";
48+

0 commit comments

Comments
 (0)