Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Adapt cgroup effective query uapi change

The attach flags is meaningless for effective query and
its value will always be set as 0 during effective query.
Root cg's effective progs is always its attached progs,
so we use non-effective query to get its progs count and
attach flags. And we don't need the remain attach flags
check.

Fixes: b79c9fc9551b ("bpf: implement BPF_PROG_QUERY for BPF_LSM_CGROUP")
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Link: https://lore.kernel.org/r/20220921104604.2340580-4-pulehui@huaweicloud.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Pu Lehui and committed by
Martin KaFai Lau
d2aa993b bdcee1b0

+4 -7
+4 -7
tools/testing/selftests/bpf/prog_tests/cgroup_link.c
··· 71 71 72 72 ping_and_check(cg_nr, 0); 73 73 74 - /* query the number of effective progs and attach flags in root cg */ 74 + /* query the number of attached progs and attach flags in root cg */ 75 75 err = bpf_prog_query(cgs[0].fd, BPF_CGROUP_INET_EGRESS, 76 - BPF_F_QUERY_EFFECTIVE, &attach_flags, NULL, 77 - &prog_cnt); 76 + 0, &attach_flags, NULL, &prog_cnt); 78 77 CHECK_FAIL(err); 79 78 CHECK_FAIL(attach_flags != BPF_F_ALLOW_MULTI); 80 79 if (CHECK(prog_cnt != 1, "effect_cnt", "exp %d, got %d\n", 1, prog_cnt)) ··· 84 85 BPF_F_QUERY_EFFECTIVE, NULL, NULL, 85 86 &prog_cnt); 86 87 CHECK_FAIL(err); 87 - CHECK_FAIL(attach_flags != BPF_F_ALLOW_MULTI); 88 88 if (CHECK(prog_cnt != cg_nr, "effect_cnt", "exp %d, got %d\n", 89 89 cg_nr, prog_cnt)) 90 90 goto cleanup; 91 91 92 92 /* query the effective prog IDs in last cg */ 93 93 err = bpf_prog_query(cgs[last_cg].fd, BPF_CGROUP_INET_EGRESS, 94 - BPF_F_QUERY_EFFECTIVE, &attach_flags, 95 - prog_ids, &prog_cnt); 94 + BPF_F_QUERY_EFFECTIVE, NULL, prog_ids, 95 + &prog_cnt); 96 96 CHECK_FAIL(err); 97 - CHECK_FAIL(attach_flags != BPF_F_ALLOW_MULTI); 98 97 if (CHECK(prog_cnt != cg_nr, "effect_cnt", "exp %d, got %d\n", 99 98 cg_nr, prog_cnt)) 100 99 goto cleanup;