Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp577963rdg; Tue, 10 Oct 2023 21:44:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHj2hOGEYG3HqSPnOBteHPe0IwLtktuFkgcGmmr+hDFewM29cJy4YKUYi8s/kdsnL64XAQ2 X-Received: by 2002:a05:6a00:1d89:b0:68f:c6f8:144a with SMTP id z9-20020a056a001d8900b0068fc6f8144amr16836036pfw.22.1696999495585; Tue, 10 Oct 2023 21:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696999495; cv=none; d=google.com; s=arc-20160816; b=XGu5H7uEpSpoOX0oA5ham+NADj+Oa/yJ7n/Ne57ro+X9mCXxAvIbC0nCv/aknZoneP HwaVSsS41bpmVquZLboniOk45VXUtc4Dbb+EwkP4vKwUPlCIWWtsduRKTCCoddYODth+ PnuL8Nsn3WKbbExR/SNeC4UN4xjTVmrtElcAIwsA0k5zYrCXV2zecGi+urGJy7yoD+Fi i/M4ccrY+SYx0HZfx6YXMgtyVp2pwcjGpuxEBiPCoOy7MyZ+PgjUsY8b6yOzjQAEys16 p1fAxSpH1uAJYZ2gkGYa5ew6L19bRgZO/w75tNvlXr82fzVkCFngZXB/iZOkrDdXZMIM cZuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=lP4b4JzgevJDuqoo7Rpr4koADp7QjWQ1TVT0IwKQygg=; fh=6znqg4o/0ePbhzd3XMQuWkYBxffIkmGaamo/34Njcb8=; b=tOh7U1jKg9+XeZ9BkOytexEZig1z4ajdU+DbtDmbKD2SV4fspdKc8OnfwhJDNTGC3P DTkyLVgEvfjq1fu4dvnJ/7jbekSQgkUwtGDvvO/YjysAbT+qizvqMpf3AZCypjjf8Lhd BaifnmECW7leayamTtcbOawlFJZT4ZBpU/xVfTfZaO4oF1wSEIxQuwWszzWEabqsPJ+u b6vc5tBv0C8f4ptqlpNK1aL8fq2bYknTo/WwAwLYgBY3ixxZweDTZD7gZa3tLnnRBElk 38PEN26UtfbjknZMzVeB3ompEn1pCUpZxvLRojhTo0tj/rqu9ZJXotb5bVHpu/H5cLDJ kR0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=WcOV32Ny; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a26-20020a63705a000000b0053074c54c3fsi14181648pgn.868.2023.10.10.21.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 21:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=WcOV32Ny; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id F0B81801B928; Tue, 10 Oct 2023 21:44:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345147AbjJKEol (ORCPT + 99 others); Wed, 11 Oct 2023 00:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345026AbjJKEok (ORCPT ); Wed, 11 Oct 2023 00:44:40 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 292A594 for ; Tue, 10 Oct 2023 21:44:14 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-58d26cfe863so1678754a12.2 for ; Tue, 10 Oct 2023 21:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1696999453; x=1697604253; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=lP4b4JzgevJDuqoo7Rpr4koADp7QjWQ1TVT0IwKQygg=; b=WcOV32Nyerab2jwd1tzTWYqzurnKYm7stBEkyzT7rIJ/kOE5nvUTTF4iG91uVVfreO hhlHyLK2LENjx2YMuBzV+CcJKTV4khMAe3ydL7VMkzmv48oFBNXqtkbLCfzlw56UVzow W+cDL/VjwZzdG9AMYLEB8Wy/+MjXjm0wuNMvdrI6sZL2W5Cugzv4HHwzozrcnONpfdzJ xpf4SpRe/VYwagZon80+FutnxmXpAnjZLOD8iKPwZQNKULNVuK/kb0TDKKI9h+FL9UMR 39N2+bi7EoJj1rmWWK3i5opdbePGc+t3sBudHg/8jARPkY3lDX8LovujNx+94GXeRxxF N9rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696999453; x=1697604253; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lP4b4JzgevJDuqoo7Rpr4koADp7QjWQ1TVT0IwKQygg=; b=CQoKdqsC3Tr6QXLQrFoWepL2/8lfz308AV0SdCg2MlsJZlIW/W0RbndmEVWiRdniy7 b4JLIHqQSDxE9TYKNC4E7A4+KEfVU2mr+QR4az5aknRlgiqbPjdjlH3arm9qPjQDcr/1 cJOq5OZPwnwHcMJZXCIb3NCiRv2fRHU3OVRql6xhyw7zQ0jUIzlZDg50ju8wSMlzZ8wU JnAIxXYTiSXWWAIT6LdM9gkrw/544RbubyAtYisk9GTm+NEyOtbq/oMnH0Gyzzrd+3wY uTo4/0CVfUu4Qp4xLcr/gnIQCH0rI2a7LhfeI6vi96W6F0W3aJQWe1S1GRDFwSKzoh8z rQ8g== X-Gm-Message-State: AOJu0YzVZskqUUsVifcZzc1ghFLbEoPDqLjmqrOcPTAfwi+7EuowXMf8 wf40WUFY3Tt/5yQAxWuLNO+FfA== X-Received: by 2002:a05:6a21:33a8:b0:16b:8bcf:9e27 with SMTP id yy40-20020a056a2133a800b0016b8bcf9e27mr14605437pzb.20.1696999453635; Tue, 10 Oct 2023 21:44:13 -0700 (PDT) Received: from [10.84.141.101] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id m8-20020a17090a4d8800b00263f41a655esm10595328pjh.43.2023.10.10.21.44.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Oct 2023 21:44:12 -0700 (PDT) Message-ID: Date: Wed, 11 Oct 2023 12:44:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next v4 4/8] bpf: Introduce css open-coded iterator kfuncs To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org References: <20231007124522.34834-1-zhouchuyi@bytedance.com> <20231007124522.34834-5-zhouchuyi@bytedance.com> From: Chuyi Zhou In-Reply-To: <20231007124522.34834-5-zhouchuyi@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 10 Oct 2023 21:44:50 -0700 (PDT) X-Spam-Level: ** 在 2023/10/7 20:45, Chuyi Zhou 写道: > This Patch adds kfuncs bpf_iter_css_{new,next,destroy} which allow > creation and manipulation of struct bpf_iter_css in open-coded iterator > style. These kfuncs actually wrapps css_next_descendant_{pre, post}. > css_iter can be used to: > > 1) iterating a sepcific cgroup tree with pre/post/up order > > 2) iterating cgroup_subsystem in BPF Prog, like > for_each_mem_cgroup_tree/cpuset_for_each_descendant_pre in kernel. > > The API design is consistent with cgroup_iter. bpf_iter_css_new accepts > parameters defining iteration order and starting css. Here we also reuse > BPF_CGROUP_ITER_DESCENDANTS_PRE, BPF_CGROUP_ITER_DESCENDANTS_POST, > BPF_CGROUP_ITER_ANCESTORS_UP enums. > > Signed-off-by: Chuyi Zhou > Acked-by: Tejun Heo > --- > kernel/bpf/cgroup_iter.c | 59 +++++++++++++++++++ > kernel/bpf/helpers.c | 3 + > .../testing/selftests/bpf/bpf_experimental.h | 6 ++ > 3 files changed, 68 insertions(+) > > diff --git a/kernel/bpf/cgroup_iter.c b/kernel/bpf/cgroup_iter.c > index 810378f04fbc..9c6ad892ae82 100644 > --- a/kernel/bpf/cgroup_iter.c > +++ b/kernel/bpf/cgroup_iter.c > @@ -294,3 +294,62 @@ static int __init bpf_cgroup_iter_init(void) > } > > late_initcall(bpf_cgroup_iter_init); > + > +struct bpf_iter_css { > + __u64 __opaque[3]; > +} __attribute__((aligned(8))); > + > +struct bpf_iter_css_kern { > + struct cgroup_subsys_state *start; > + struct cgroup_subsys_state *pos; > + unsigned int flags; > +} __attribute__((aligned(8))); > + > +__bpf_kfunc int bpf_iter_css_new(struct bpf_iter_css *it, > + struct cgroup_subsys_state *start, unsigned int flags) > +{ > + struct bpf_iter_css_kern *kit = (void *)it; > + > + BUILD_BUG_ON(sizeof(struct bpf_iter_css_kern) != sizeof(struct bpf_iter_css)); > + BUILD_BUG_ON(__alignof__(struct bpf_iter_css_kern) != __alignof__(struct bpf_iter_css)); > + This would cause the fail of netdev/build_32bit CI (https://netdev.bots.linux.dev/static/nipa/790929/13412333/build_32bit/stderr): tools/testing/selftests/kvm/settings: warning: ignored by one of the .gitignore files ../kernel/bpf/cgroup_iter.c:308:17: warning: no previous prototype for ‘bpf_iter_css_new’ [-Wmissing-prototypes] 308 | __bpf_kfunc int bpf_iter_css_new(struct bpf_iter_css *it, | ^~~~~~~~~~~~~~~~ ../kernel/bpf/cgroup_iter.c:332:41: warning: no previous prototype for ‘bpf_iter_css_next’ [-Wmissing-prototypes] 332 | __bpf_kfunc struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *it) | ^~~~~~~~~~~~~~~~~ ../kernel/bpf/cgroup_iter.c:353:18: warning: no previous prototype for ‘bpf_iter_css_destroy’ [-Wmissing-prototypes] 353 | __bpf_kfunc void bpf_iter_css_destroy(struct bpf_iter_css *it) | ^~~~~~~~~~~~~~~~~~~~ In file included from : ../kernel/bpf/cgroup_iter.c: In function ‘bpf_iter_css_new’: ./../include/linux/compiler_types.h:425:45: error: call to ‘__compiletime_assert_322’ declared with attribute error: BUILD_BUG_ON failed: sizeof(struct bpf_iter_css_kern) != sizeof(struct bpf_iter_css) 425 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^ ./../include/linux/compiler_types.h:406:25: note: in definition of macro ‘__compiletime_assert’ 406 | prefix ## suffix(); \ | ^~~~~~ ./../include/linux/compiler_types.h:425:9: note: in expansion of macro ‘_compiletime_assert’ 425 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’ 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ../include/linux/build_bug.h:50:9: note: in expansion of macro ‘BUILD_BUG_ON_MSG’ 50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) | ^~~~~~~~~~~~~~~~ ../kernel/bpf/cgroup_iter.c:313:9: note: in expansion of macro ‘BUILD_BUG_ON’ 313 | BUILD_BUG_ON(sizeof(struct bpf_iter_css_kern) != sizeof(struct bpf_iter_css)); The reason seems on 32-bit machine, sizeof(struct bpf_iter_css) is 24 and sizeof(struct bpf_iter_css_kern) is 16. I was wondering whether the BUILD_BUG_ON check is necessary. Looking at the struct bpf_list_node and struct bpf_list_node_kern wich are very similay to bpf_iter_css, I didn't see the BUILD_BUG_ON check when convert from (struct bpf_list_node *) to (struct bpf_list_node_kern *) /* Non-opaque version of bpf_list_node in uapi/linux/bpf.h */ struct bpf_list_node_kern { struct list_head list_head; void *owner; } __attribute__((aligned(8))); struct bpf_list_node { __u64 :64; __u64 :64; __u64 :64; } __attribute__((aligned(8))); __bpf_kfunc int bpf_list_push_back_impl(struct bpf_list_head *head, struct bpf_list_node *node, void *meta__ign, u64 off) { struct bpf_list_node_kern *n = (void *)node; }