selftests/bpf: Ensure sleepable program is rejected by hash map iter

Add a test to ensure sleepable program is rejected by hash map iterator.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220810080538.1845898-10-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Hou Tao 2022-08-10 16:05:38 +08:00 committed by Alexei Starovoitov
parent 939a1a946d
commit c5c0981fd8
2 changed files with 15 additions and 0 deletions

View File

@ -679,6 +679,12 @@ static void test_bpf_hash_map(void)
goto out;
}
/* Sleepable program is prohibited for hash map iterator */
linfo.map.map_fd = map_fd;
link = bpf_program__attach_iter(skel->progs.sleepable_dummy_dump, &opts);
if (!ASSERT_ERR_PTR(link, "attach_sleepable_prog_to_iter"))
goto out;
linfo.map.map_fd = map_fd;
link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts);
if (!ASSERT_OK_PTR(link, "attach_iter"))

View File

@ -112,3 +112,12 @@ int dump_bpf_hash_map(struct bpf_iter__bpf_map_elem *ctx)
return 0;
}
SEC("iter.s/bpf_map_elem")
int sleepable_dummy_dump(struct bpf_iter__bpf_map_elem *ctx)
{
if (ctx->meta->seq_num == 0)
BPF_SEQ_PRINTF(ctx->meta->seq, "map dump starts\n");
return 0;
}