]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests/bpf: Ensure sleepable program is rejected by hash map iter
authorHou Tao <houtao1@huawei.com>
Wed, 10 Aug 2022 08:05:38 +0000 (16:05 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Aug 2022 17:12:48 +0000 (10:12 -0700)
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>
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
tools/testing/selftests/bpf/progs/bpf_iter_bpf_hash_map.c

index 1571a6586b3b1657f077390dac6fe6e48ae91475..e89685bd587ccfb6f8a9ef4985d45cdce33273e6 100644 (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"))
index 0aa3cd34cbe37ddf16f342fb05b284cf7482a675..d7a69217fb688f21802831f53a387a6197fdbb2c 100644 (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;
+}