From: Pu Lehui <pulehui@huawei.com>
To: <bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Quentin Monnet <quentin@isovalent.com>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
"Jean-Philippe Brucker" <jean-philippe@linaro.org>,
Stanislav Fomichev <sdf@google.com>,
"Hao Luo" <haoluo@goddogle.com>, Jiri Olsa <jolsa@kernel.org>,
Pu Lehui <pulehui@huawei.com>
Subject: [PATCH bpf-next 2/2] bpftool: Fix cgroup attach flags being assigned to effective progs
Date: Sat, 20 Aug 2022 20:02:34 +0800 [thread overview]
Message-ID: <20220820120234.2121044-3-pulehui@huawei.com> (raw)
In-Reply-To: <20220820120234.2121044-1-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 c t /sys/fs/cgroup effective
CgroupPath
ID AttachType AttachFlags Name
/sys/fs/cgroup
6 sysctl multi sysctl_tcp_mem
13 sysctl multi sysctl_tcp_mem
/sys/fs/cgroup/cg1
20 sysctl override sysctl_tcp_mem
6 sysctl override sysctl_tcp_mem
13 sysctl override sysctl_tcp_mem
Attach flags is only valid for attached progs of this layer
cgroup, but not for effective progs. Since prog_attach_flags
array is already bypass the effective progs, so we can just
use it.
Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
tools/bpf/bpftool/cgroup.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/tools/bpf/bpftool/cgroup.c b/tools/bpf/bpftool/cgroup.c
index cced668fb2a3..fa3eef0ff860 100644
--- a/tools/bpf/bpftool/cgroup.c
+++ b/tools/bpf/bpftool/cgroup.c
@@ -219,11 +219,7 @@ static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
return 0;
for (iter = 0; iter < p.prog_cnt; iter++) {
- __u32 attach_flags;
-
- attach_flags = prog_attach_flags[iter] ?: p.attach_flags;
-
- switch (attach_flags) {
+ switch (prog_attach_flags[iter]) {
case BPF_F_ALLOW_MULTI:
attach_flags_str = "multi";
break;
@@ -234,7 +230,8 @@ static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
attach_flags_str = "";
break;
default:
- snprintf(buf, sizeof(buf), "unknown(%x)", attach_flags);
+ snprintf(buf, sizeof(buf), "unknown(%x)",
+ prog_attach_flags[iter]);
attach_flags_str = buf;
}
--
2.25.1
prev parent reply other threads:[~2022-08-20 11:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-20 12:02 [PATCH bpf-next 0/2] Fix cgroup attach flags being assigned to effective progs Pu Lehui
2022-08-20 12:02 ` [PATCH bpf-next 1/2] bpf, cgroup: Fix " Pu Lehui
2022-08-23 21:22 ` John Fastabend
2022-09-08 3:07 ` Pu Lehui
2022-09-08 3:23 ` Pu Lehui
2022-08-20 12:02 ` Pu Lehui [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220820120234.2121044-3-pulehui@huawei.com \
--to=pulehui@huawei.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@goddogle.com \
--cc=jean-philippe@linaro.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox