Skip to content

Commit 7943c0f

Browse files
Alexei Starovoitovdavem330
Alexei Starovoitov
authored andcommittedNov 18, 2014
bpf: remove test map scaffolding and user proper types
proper types and function helpers are ready. Use them in verifier testsuite. Remove temporary stubs Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d0003ec commit 7943c0f

File tree

2 files changed

+16
-54
lines changed

2 files changed

+16
-54
lines changed
 

‎kernel/bpf/test_stub.c

+9-47
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,18 @@ struct bpf_context {
1818
u64 arg2;
1919
};
2020

21-
static u64 test_func(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
22-
{
23-
return 0;
24-
}
25-
26-
static struct bpf_func_proto test_funcs[] = {
27-
[BPF_FUNC_unspec] = {
28-
.func = test_func,
29-
.gpl_only = true,
30-
.ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL,
31-
.arg1_type = ARG_CONST_MAP_PTR,
32-
.arg2_type = ARG_PTR_TO_MAP_KEY,
33-
},
34-
};
35-
3621
static const struct bpf_func_proto *test_func_proto(enum bpf_func_id func_id)
3722
{
38-
if (func_id < 0 || func_id >= ARRAY_SIZE(test_funcs))
23+
switch (func_id) {
24+
case BPF_FUNC_map_lookup_elem:
25+
return &bpf_map_lookup_elem_proto;
26+
case BPF_FUNC_map_update_elem:
27+
return &bpf_map_update_elem_proto;
28+
case BPF_FUNC_map_delete_elem:
29+
return &bpf_map_delete_elem_proto;
30+
default:
3931
return NULL;
40-
return &test_funcs[func_id];
32+
}
4133
}
4234

4335
static const struct bpf_context_access {
@@ -78,38 +70,8 @@ static struct bpf_prog_type_list tl_prog = {
7870
.type = BPF_PROG_TYPE_UNSPEC,
7971
};
8072

81-
static struct bpf_map *test_map_alloc(union bpf_attr *attr)
82-
{
83-
struct bpf_map *map;
84-
85-
map = kzalloc(sizeof(*map), GFP_USER);
86-
if (!map)
87-
return ERR_PTR(-ENOMEM);
88-
89-
map->key_size = attr->key_size;
90-
map->value_size = attr->value_size;
91-
map->max_entries = attr->max_entries;
92-
return map;
93-
}
94-
95-
static void test_map_free(struct bpf_map *map)
96-
{
97-
kfree(map);
98-
}
99-
100-
static struct bpf_map_ops test_map_ops = {
101-
.map_alloc = test_map_alloc,
102-
.map_free = test_map_free,
103-
};
104-
105-
static struct bpf_map_type_list tl_map = {
106-
.ops = &test_map_ops,
107-
.type = BPF_MAP_TYPE_UNSPEC,
108-
};
109-
11073
static int __init register_test_ops(void)
11174
{
112-
bpf_register_map_type(&tl_map);
11375
bpf_register_prog_type(&tl_prog);
11476
return 0;
11577
}

‎samples/bpf/test_verifier.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static struct bpf_test tests[] = {
261261
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
262262
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
263263
BPF_LD_MAP_FD(BPF_REG_1, 0),
264-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
264+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
265265
BPF_EXIT_INSN(),
266266
},
267267
.fixup = {2},
@@ -417,7 +417,7 @@ static struct bpf_test tests[] = {
417417
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_10),
418418
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
419419
BPF_LD_MAP_FD(BPF_REG_1, 0),
420-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
420+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_delete_elem),
421421
BPF_EXIT_INSN(),
422422
},
423423
.errstr = "fd 0 is not pointing to valid bpf_map",
@@ -430,7 +430,7 @@ static struct bpf_test tests[] = {
430430
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
431431
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
432432
BPF_LD_MAP_FD(BPF_REG_1, 0),
433-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
433+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
434434
BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
435435
BPF_EXIT_INSN(),
436436
},
@@ -445,7 +445,7 @@ static struct bpf_test tests[] = {
445445
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
446446
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
447447
BPF_LD_MAP_FD(BPF_REG_1, 0),
448-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
448+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
449449
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),
450450
BPF_ST_MEM(BPF_DW, BPF_REG_0, 4, 0),
451451
BPF_EXIT_INSN(),
@@ -461,7 +461,7 @@ static struct bpf_test tests[] = {
461461
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
462462
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
463463
BPF_LD_MAP_FD(BPF_REG_1, 0),
464-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
464+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
465465
BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),
466466
BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 0),
467467
BPF_EXIT_INSN(),
@@ -548,7 +548,7 @@ static struct bpf_test tests[] = {
548548
BPF_ST_MEM(BPF_DW, BPF_REG_2, -56, 0),
549549
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -56),
550550
BPF_LD_MAP_FD(BPF_REG_1, 0),
551-
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_unspec),
551+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_delete_elem),
552552
BPF_EXIT_INSN(),
553553
},
554554
.fixup = {24},
@@ -659,7 +659,7 @@ static int create_map(void)
659659
long long key, value = 0;
660660
int map_fd;
661661

662-
map_fd = bpf_create_map(BPF_MAP_TYPE_UNSPEC, sizeof(key), sizeof(value), 1024);
662+
map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), 1024);
663663
if (map_fd < 0) {
664664
printf("failed to create map '%s'\n", strerror(errno));
665665
}

0 commit comments

Comments
 (0)
Please sign in to comment.