Message ID | 20220920154233.1494352-1-pulehui@huaweicloud.com (mailing list archive) |
---|---|
Headers | show |
Series | Fix wrong cgroup attach flags being assigned to effective progs | expand |
On 2022/9/20 23:42, Pu Lehui wrote: > From: Pu Lehui <pulehui@huawei.com> > > When root-cgroup attach multi progs and sub-cgroup attach a > override prog, bpftool will display incorrectly for the attach > flags of the sub-cgroup’s effective progs: > > $ bpftool cgroup tree /sys/fs/cgroup effective > CgroupPath > ID AttachType AttachFlags Name > /sys/fs/cgroup > 6 cgroup_sysctl multi sysctl_tcp_mem > 13 cgroup_sysctl multi sysctl_tcp_mem > /sys/fs/cgroup/cg1 > 20 cgroup_sysctl override sysctl_tcp_mem > 6 cgroup_sysctl override sysctl_tcp_mem <- wrong > 13 cgroup_sysctl override sysctl_tcp_mem <- wrong > /sys/fs/cgroup/cg1/cg2 > 20 cgroup_sysctl sysctl_tcp_mem > 6 cgroup_sysctl sysctl_tcp_mem > 13 cgroup_sysctl sysctl_tcp_mem > > For cg1, obviously, the attach flags of prog6 and prog13 can not be > OVERRIDE. And for query with EFFECTIVE flags, exporting attach flags > does not make sense. So let's remove the AttachFlags field and the > associated logic. After these patches, the above effective cgroup > tree will show as bellow: > > # bpftool cgroup tree /sys/fs/cgroup effective > CgroupPath > ID AttachType Name > /sys/fs/cgroup > 6 cgroup_sysctl sysctl_tcp_mem > 13 cgroup_sysctl sysctl_tcp_mem > /sys/fs/cgroup/cg1 > 20 cgroup_sysctl sysctl_tcp_mem > 6 cgroup_sysctl sysctl_tcp_mem > 13 cgroup_sysctl sysctl_tcp_mem > /sys/fs/cgroup/cg1/cg2 > 20 cgroup_sysctl sysctl_tcp_mem > 6 cgroup_sysctl sysctl_tcp_mem > 13 cgroup_sysctl sysctl_tcp_mem > > v4: > - Reject prog_attach_flags array when effective query. (Martin) > - Target to bpf tree. (Martin) > > v3: > https://lore.kernel.org/bpf/20220914161742.3180731-1-pulehui@huaweicloud.com > - Don't show attach flags when effective query. (John, sdf, Martin) > > v2: > https://lore.kernel.org/bpf/20220908145304.3436139-1-pulehui@huaweicloud.com > - Limit prog_cnt to avoid overflow. (John) > - Add more detail message. > > v1: > https://lore.kernel.org/bpf/20220820120234.2121044-1-pulehui@huawei.com > > Pu Lehui (2): > bpf, cgroup: Reject prog_attach_flags array when effective query > bpftool: Fix wrong cgroup attach flags being assigned to effective > progs > > include/uapi/linux/bpf.h | 7 +++-- > kernel/bpf/cgroup.c | 28 +++++++++++------- > tools/bpf/bpftool/cgroup.c | 54 ++++++++++++++++++++++++++++++---- > tools/include/uapi/linux/bpf.h | 7 +++-- > 4 files changed, 77 insertions(+), 19 deletions(-) > selftest no pass, sorry, will fix. https://github.com/kernel-patches/bpf/actions/runs/3088351905/jobs/4995009382
From: Pu Lehui <pulehui@huawei.com> When root-cgroup attach multi progs and sub-cgroup attach a override prog, bpftool will display incorrectly for the attach flags of the sub-cgroup’s effective progs: $ bpftool cgroup tree /sys/fs/cgroup effective CgroupPath ID AttachType AttachFlags Name /sys/fs/cgroup 6 cgroup_sysctl multi sysctl_tcp_mem 13 cgroup_sysctl multi sysctl_tcp_mem /sys/fs/cgroup/cg1 20 cgroup_sysctl override sysctl_tcp_mem 6 cgroup_sysctl override sysctl_tcp_mem <- wrong 13 cgroup_sysctl override sysctl_tcp_mem <- wrong /sys/fs/cgroup/cg1/cg2 20 cgroup_sysctl sysctl_tcp_mem 6 cgroup_sysctl sysctl_tcp_mem 13 cgroup_sysctl sysctl_tcp_mem For cg1, obviously, the attach flags of prog6 and prog13 can not be OVERRIDE. And for query with EFFECTIVE flags, exporting attach flags does not make sense. So let's remove the AttachFlags field and the associated logic. After these patches, the above effective cgroup tree will show as bellow: # bpftool cgroup tree /sys/fs/cgroup effective CgroupPath ID AttachType Name /sys/fs/cgroup 6 cgroup_sysctl sysctl_tcp_mem 13 cgroup_sysctl sysctl_tcp_mem /sys/fs/cgroup/cg1 20 cgroup_sysctl sysctl_tcp_mem 6 cgroup_sysctl sysctl_tcp_mem 13 cgroup_sysctl sysctl_tcp_mem /sys/fs/cgroup/cg1/cg2 20 cgroup_sysctl sysctl_tcp_mem 6 cgroup_sysctl sysctl_tcp_mem 13 cgroup_sysctl sysctl_tcp_mem v4: - Reject prog_attach_flags array when effective query. (Martin) - Target to bpf tree. (Martin) v3: https://lore.kernel.org/bpf/20220914161742.3180731-1-pulehui@huaweicloud.com - Don't show attach flags when effective query. (John, sdf, Martin) v2: https://lore.kernel.org/bpf/20220908145304.3436139-1-pulehui@huaweicloud.com - Limit prog_cnt to avoid overflow. (John) - Add more detail message. v1: https://lore.kernel.org/bpf/20220820120234.2121044-1-pulehui@huawei.com Pu Lehui (2): bpf, cgroup: Reject prog_attach_flags array when effective query bpftool: Fix wrong cgroup attach flags being assigned to effective progs include/uapi/linux/bpf.h | 7 +++-- kernel/bpf/cgroup.c | 28 +++++++++++------- tools/bpf/bpftool/cgroup.c | 54 ++++++++++++++++++++++++++++++---- tools/include/uapi/linux/bpf.h | 7 +++-- 4 files changed, 77 insertions(+), 19 deletions(-)