From patchwork Sat Aug 20 12:02:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pu Lehui X-Patchwork-Id: 12949628 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B44C7C32774 for ; Sat, 20 Aug 2022 11:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345239AbiHTLdU (ORCPT ); Sat, 20 Aug 2022 07:33:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345157AbiHTLdS (ORCPT ); Sat, 20 Aug 2022 07:33:18 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694E010C0; Sat, 20 Aug 2022 04:33:12 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M8xHZ1y3YzlWLb; Sat, 20 Aug 2022 19:30:02 +0800 (CST) Received: from dggpemm500019.china.huawei.com (7.185.36.180) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 20 Aug 2022 19:33:10 +0800 Received: from k04.huawei.com (10.67.174.115) by dggpemm500019.china.huawei.com (7.185.36.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 20 Aug 2022 19:33:10 +0800 From: Pu Lehui To: , CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "Jean-Philippe Brucker" , Stanislav Fomichev , "Hao Luo" , Jiri Olsa , Pu Lehui 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 Message-ID: <20220820120234.2121044-3-pulehui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220820120234.2121044-1-pulehui@huawei.com> References: <20220820120234.2121044-1-pulehui@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.115] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500019.china.huawei.com (7.185.36.180) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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 --- 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; }