提交 189c83bd 编写于 作者: J Jiri Olsa 提交者: Andrii Nakryiko

selftest/bpf: Switch recursion test to use htab_map_delete_elem

Currently the recursion test is hooking __htab_map_lookup_elem
function, which is invoked both from bpf_prog and bpf syscall.

But in our kernel build, the __htab_map_lookup_elem gets inlined
within the htab_map_lookup_elem, so it's not trigered and the
test fails.

Fixing this by using htab_map_delete_elem, which is not inlined
for bpf_prog calls (like htab_map_lookup_elem is) and is used
directly as pointer for map_delete_elem, so it won't disappear
by inlining.
Signed-off-by: NJiri Olsa <jolsa@kernel.org>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Acked-by: NSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/YVnfFTL/3T6jOwHI@krava
上级 929bef46
...@@ -20,18 +20,18 @@ void test_recursion(void) ...@@ -20,18 +20,18 @@ void test_recursion(void)
goto out; goto out;
ASSERT_EQ(skel->bss->pass1, 0, "pass1 == 0"); ASSERT_EQ(skel->bss->pass1, 0, "pass1 == 0");
bpf_map_lookup_elem(bpf_map__fd(skel->maps.hash1), &key, 0); bpf_map_delete_elem(bpf_map__fd(skel->maps.hash1), &key);
ASSERT_EQ(skel->bss->pass1, 1, "pass1 == 1"); ASSERT_EQ(skel->bss->pass1, 1, "pass1 == 1");
bpf_map_lookup_elem(bpf_map__fd(skel->maps.hash1), &key, 0); bpf_map_delete_elem(bpf_map__fd(skel->maps.hash1), &key);
ASSERT_EQ(skel->bss->pass1, 2, "pass1 == 2"); ASSERT_EQ(skel->bss->pass1, 2, "pass1 == 2");
ASSERT_EQ(skel->bss->pass2, 0, "pass2 == 0"); ASSERT_EQ(skel->bss->pass2, 0, "pass2 == 0");
bpf_map_lookup_elem(bpf_map__fd(skel->maps.hash2), &key, 0); bpf_map_delete_elem(bpf_map__fd(skel->maps.hash2), &key);
ASSERT_EQ(skel->bss->pass2, 1, "pass2 == 1"); ASSERT_EQ(skel->bss->pass2, 1, "pass2 == 1");
bpf_map_lookup_elem(bpf_map__fd(skel->maps.hash2), &key, 0); bpf_map_delete_elem(bpf_map__fd(skel->maps.hash2), &key);
ASSERT_EQ(skel->bss->pass2, 2, "pass2 == 2"); ASSERT_EQ(skel->bss->pass2, 2, "pass2 == 2");
err = bpf_obj_get_info_by_fd(bpf_program__fd(skel->progs.on_lookup), err = bpf_obj_get_info_by_fd(bpf_program__fd(skel->progs.on_delete),
&prog_info, &prog_info_len); &prog_info, &prog_info_len);
if (!ASSERT_OK(err, "get_prog_info")) if (!ASSERT_OK(err, "get_prog_info"))
goto out; goto out;
......
...@@ -24,8 +24,8 @@ struct { ...@@ -24,8 +24,8 @@ struct {
int pass1 = 0; int pass1 = 0;
int pass2 = 0; int pass2 = 0;
SEC("fentry/__htab_map_lookup_elem") SEC("fentry/htab_map_delete_elem")
int BPF_PROG(on_lookup, struct bpf_map *map) int BPF_PROG(on_delete, struct bpf_map *map)
{ {
int key = 0; int key = 0;
...@@ -35,10 +35,7 @@ int BPF_PROG(on_lookup, struct bpf_map *map) ...@@ -35,10 +35,7 @@ int BPF_PROG(on_lookup, struct bpf_map *map)
} }
if (map == (void *)&hash2) { if (map == (void *)&hash2) {
pass2++; pass2++;
/* htab_map_gen_lookup() will inline below call bpf_map_delete_elem(&hash2, &key);
* into direct call to __htab_map_lookup_elem()
*/
bpf_map_lookup_elem(&hash2, &key);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册