Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp254160rwn; Thu, 8 Sep 2022 00:40:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR7aQgCCPUoUa/gZnyDwlUgP2SGqmQiBD6YEgzqLeIJkxj4ZZQT15Rf9hAVvBXFQ8Cw6bk4W X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr5185334ejt.4.1662622815510; Thu, 08 Sep 2022 00:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662622815; cv=none; d=google.com; s=arc-20160816; b=i3KntD330TuTHf6XGJ3o0XNO3j7UY5pWFS2WaML1v+CU6y5s5Qrx+cqqIUPpC7HziK Z5Iq0fmWNZZHtXASdi81tF5QTMr+0OUc7mmh95dwlhyVv2HPxdSERNceD91sativxeKc arXESl8ReGkCGrvW0+S9meSS4jxMf4gdYqHbE4xjgmsqyMJKzA2AiMcVKH2lwYWG3D0i YUwvnkZUCgyfc65bQ30f2l0HcLFnYSBv0V0F5XTkuTX3OPdnUoRd3jsaIiEbNorVFxYZ UudCqyOHJjyqelk9VsUGKWkWBbda7hH831CIlRByQICAXoCv8Mo1DKcWSbxxWcsva2n4 Ni3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=I1aFbtsi2lH5YoJkyorkSeEZiiynebuxeU5WY++V9pQ=; b=lgtWtrbFZvwCFKnV6aSZA4vAJbQlWb7ZDx07za5pLgc3ZqSfScUOzCwERJ23y0ycyb g2UMfyEIxnEA2LjImFEzSjartJ7yRR44cSuWFcQhkeoAbyMQVVEs2HZS2CYNtOg6TYLh jOHjD4J7rN3fuSLyvX1qnHEcxUJN7/kRyelsvs1kMHrfVZ8NUbuphkcrBT2SYd+YQT4R uTOs573jETYadqu+S/Rr8C/11yTL0925byJabRQh+gGiXNZSyjXK5n5iFhfNWDIqVezi JtGxMVZsGX1M/F6S8sKrjbKlYuAn5FB9wN10pM1zCIAS2u5/aSX6bLEPFhIlqLXco5og bOmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a05640205cc00b0044900e60983si16364399edx.541.2022.09.08.00.39.46; Thu, 08 Sep 2022 00:40:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbiIHGvm (ORCPT + 99 others); Thu, 8 Sep 2022 02:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230506AbiIHGv3 (ORCPT ); Thu, 8 Sep 2022 02:51:29 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF49918385; Wed, 7 Sep 2022 23:51:27 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MNV9H2LBYz6S32d; Thu, 8 Sep 2022 14:49:39 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP2 (Coremail) with SMTP id Syh0CgBXqHHskBljwcslAg--.10754S4; Thu, 08 Sep 2022 14:51:26 +0800 (CST) From: Pu Lehui To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Pu Lehui Subject: [PATCH bpf-next v2 2/2] bpftool: Fix cgroup attach flags being assigned to effective progs Date: Thu, 8 Sep 2022 14:53:04 +0000 Message-Id: <20220908145304.3436139-3-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220908145304.3436139-1-pulehui@huaweicloud.com> References: <20220908145304.3436139-1-pulehui@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgBXqHHskBljwcslAg--.10754S4 X-Coremail-Antispam: 1UD129KBjvJXoW7WFWkWF1xKw1DGFy3JFW5Wrg_yoW8Zr48pr ykZa4UG3Wrur98XFWfK34YqFWrGw4xAryjyas8Jw45uF17GryvvrW2ka4kCr15WFW7Cw4x ZF1Y9FyUWa1UtaUanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x0262 8vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02 F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GF ylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r 1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07js vtZUUUUU= X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pu Lehui 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 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; } -- 2.25.1