Skip to content

Commit 0c58607

Browse files
joestringerborkmann
authored andcommitted
selftests/bpf: Generalize dummy program types
Don't hardcode the dummy program types to SOCKET_FILTER type, as this prevents testing bpf_tail_call in conjunction with other program types. Instead, use the program type specified in the test case. Signed-off-by: Joe Stringer <joe@wand.net.nz> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 6acc9b4 commit 0c58607

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12652,18 +12652,18 @@ static int create_map(uint32_t type, uint32_t size_key,
1265212652
return fd;
1265312653
}
1265412654

12655-
static int create_prog_dummy1(void)
12655+
static int create_prog_dummy1(enum bpf_map_type prog_type)
1265612656
{
1265712657
struct bpf_insn prog[] = {
1265812658
BPF_MOV64_IMM(BPF_REG_0, 42),
1265912659
BPF_EXIT_INSN(),
1266012660
};
1266112661

12662-
return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog,
12662+
return bpf_load_program(prog_type, prog,
1266312663
ARRAY_SIZE(prog), "GPL", 0, NULL, 0);
1266412664
}
1266512665

12666-
static int create_prog_dummy2(int mfd, int idx)
12666+
static int create_prog_dummy2(enum bpf_map_type prog_type, int mfd, int idx)
1266712667
{
1266812668
struct bpf_insn prog[] = {
1266912669
BPF_MOV64_IMM(BPF_REG_3, idx),
@@ -12674,11 +12674,12 @@ static int create_prog_dummy2(int mfd, int idx)
1267412674
BPF_EXIT_INSN(),
1267512675
};
1267612676

12677-
return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog,
12677+
return bpf_load_program(prog_type, prog,
1267812678
ARRAY_SIZE(prog), "GPL", 0, NULL, 0);
1267912679
}
1268012680

12681-
static int create_prog_array(uint32_t max_elem, int p1key)
12681+
static int create_prog_array(enum bpf_map_type prog_type, uint32_t max_elem,
12682+
int p1key)
1268212683
{
1268312684
int p2key = 1;
1268412685
int mfd, p1fd, p2fd;
@@ -12690,8 +12691,8 @@ static int create_prog_array(uint32_t max_elem, int p1key)
1269012691
return -1;
1269112692
}
1269212693

12693-
p1fd = create_prog_dummy1();
12694-
p2fd = create_prog_dummy2(mfd, p2key);
12694+
p1fd = create_prog_dummy1(prog_type);
12695+
p2fd = create_prog_dummy2(prog_type, mfd, p2key);
1269512696
if (p1fd < 0 || p2fd < 0)
1269612697
goto out;
1269712698
if (bpf_map_update_elem(mfd, &p1key, &p1fd, BPF_ANY) < 0)
@@ -12748,8 +12749,8 @@ static int create_cgroup_storage(bool percpu)
1274812749

1274912750
static char bpf_vlog[UINT_MAX >> 8];
1275012751

12751-
static void do_test_fixup(struct bpf_test *test, struct bpf_insn *prog,
12752-
int *map_fds)
12752+
static void do_test_fixup(struct bpf_test *test, enum bpf_map_type prog_type,
12753+
struct bpf_insn *prog, int *map_fds)
1275312754
{
1275412755
int *fixup_map1 = test->fixup_map1;
1275512756
int *fixup_map2 = test->fixup_map2;
@@ -12805,15 +12806,15 @@ static void do_test_fixup(struct bpf_test *test, struct bpf_insn *prog,
1280512806
}
1280612807

1280712808
if (*fixup_prog1) {
12808-
map_fds[4] = create_prog_array(4, 0);
12809+
map_fds[4] = create_prog_array(prog_type, 4, 0);
1280912810
do {
1281012811
prog[*fixup_prog1].imm = map_fds[4];
1281112812
fixup_prog1++;
1281212813
} while (*fixup_prog1);
1281312814
}
1281412815

1281512816
if (*fixup_prog2) {
12816-
map_fds[5] = create_prog_array(8, 7);
12817+
map_fds[5] = create_prog_array(prog_type, 8, 7);
1281712818
do {
1281812819
prog[*fixup_prog2].imm = map_fds[5];
1281912820
fixup_prog2++;
@@ -12859,11 +12860,13 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
1285912860
for (i = 0; i < MAX_NR_MAPS; i++)
1286012861
map_fds[i] = -1;
1286112862

12862-
do_test_fixup(test, prog, map_fds);
12863+
if (!prog_type)
12864+
prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
12865+
do_test_fixup(test, prog_type, prog, map_fds);
1286312866
prog_len = probe_filter_length(prog);
1286412867

12865-
fd_prog = bpf_verify_program(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER,
12866-
prog, prog_len, test->flags & F_LOAD_WITH_STRICT_ALIGNMENT,
12868+
fd_prog = bpf_verify_program(prog_type, prog, prog_len,
12869+
test->flags & F_LOAD_WITH_STRICT_ALIGNMENT,
1286712870
"GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
1286812871

1286912872
expected_ret = unpriv && test->result_unpriv != UNDEF ?

0 commit comments

Comments
 (0)