Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp593222rdg; Tue, 10 Oct 2023 22:32:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8YpPokRnPCf43Bcf1g4vIgJGlZ/1Uy6Tjwd1pnEP5tw48LTpSNVIV/HIU5WxTdwR/hx34 X-Received: by 2002:a05:6830:6b44:b0:6b7:4af2:492d with SMTP id dc4-20020a0568306b4400b006b74af2492dmr19430047otb.38.1697002373203; Tue, 10 Oct 2023 22:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697002373; cv=none; d=google.com; s=arc-20160816; b=0MsOftq8EZb3qdGpyQoItbFvlfWrTFdVWZAbZLh/RzMnmCz/iegGQs7LFNPCQ3fTvY 4lH66fsHCUt9ynCFeJeGpQLyY6LCeD7s4Sc13MwjvzPTpH+F+lIWQiun6ne3NsGum9BR jevoS0agH/+heu3HYntmsQCuMZFYvjBfg8jbJ4N/yvOzBSnMdCD7WjMkQ8QAkjg7Gnry eQpqJXjHwZE161zXetpGOD0X15teIbC3cokjGlAsePvgHsA2TV3R3muf9wkgUjY4YbMs q87z3j20Ifd8HMPiDDv9KcQJMCFKkYo7q1p/K86z0PN7RFQAJaGrc/3JebuH4KUTcuQc fCXg== 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:references :cc:to:from:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=yH3kcRER/tjzkTTrrhG07aFLmDQ323Q0KUD/SfU15Ok=; fh=6znqg4o/0ePbhzd3XMQuWkYBxffIkmGaamo/34Njcb8=; b=V/+8jqUkuJw5HlHLUAcN5a+TgOGpPtX4J/RdbALIj+ezJcE8Qm/3H37ZGt08SHw9C+ mk582LV9GR3NTTkZWHC6mSppoU9UzJ3Vhpzg5TIDYp/0YkjV/xpSQamhbHcTCf7f+R3v brjtpAouj3hkKyDfVN/gNKdYN5uG3JrZfVkBKddJumAiXo3Qux/HAZ+mMFmjuQHpVi06 Xb2rNm7pwxlKkTvFarsdKqUI1T5ud/t1y6MOoKeuk0TkbHaC3WHO/kIZsg+y2e9tR+95 JrkQqCkcF04/XiRgHf5UAvf5lqeLkH4Q6hxrKaH/pfiWu6OKU4UgZrpa0K7W1HO/7PeW 5pdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="WpUpzUt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id eg24-20020a056a00801800b0068780155ddbsi11216907pfb.131.2023.10.10.22.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 22:32:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="WpUpzUt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 332598025DDC; Tue, 10 Oct 2023 22:32:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjJKFcc (ORCPT + 99 others); Wed, 11 Oct 2023 01:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjJKFcb (ORCPT ); Wed, 11 Oct 2023 01:32:31 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 622748E for ; Tue, 10 Oct 2023 22:32:07 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-27d087c4276so95810a91.0 for ; Tue, 10 Oct 2023 22:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697002327; x=1697607127; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=yH3kcRER/tjzkTTrrhG07aFLmDQ323Q0KUD/SfU15Ok=; b=WpUpzUt/rMjn8ldj33jojoHFxIznpVZL1N3cphgS+yw6i6bP+lrqgdDO78jUO3JQko 58DEPIY99o2m9mH/E9Wgfbg9wUm4N/ztJ+uyxX7nZ4gyRp2TDjdSnVIdeJBMX4TpjF5Z mL/lWlTXwWMQpOxrfQa8x7RJBqVbDdmspSgcHh+pNXsrItqpSOe09PjYgRqKaFtKT6fI 0pD0MBTdiCJKCyZhOOEZhH1dwNtUwVosNJLAG5IDHjN/ZGcXbwrV3jJVQW0d6KIcvz8P MPfHjZ64Nc/upEPBSm5XZRplu7scbE9bWTjY5pXJnlIdpXChZPKVNcRF+3eEabWCmSc9 K1VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697002327; x=1697607127; h=content-transfer-encoding:in-reply-to:references:cc:to:from:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=yH3kcRER/tjzkTTrrhG07aFLmDQ323Q0KUD/SfU15Ok=; b=eh1vebyr2Kihybnev+7ggC1iplLGbKLSNrU8wrqAycTpC/wU8k30SvM8X7v4DCUYBz GTQDKBL5mYXfFf75RuPebq5+aNEnb6NfwM0W3Y1C8RcHP3ybaTGuDwJG7ZI0Ga4H+OtK eVwMO4/wj5VjtE8v258Q6uMwW3V4IPhqcfk2LNf4fhccZnOgp6TpEuKuMHaVq1IOnO+1 9n6y+0gO1YcSmO7TGcOkE//pYhcVZDAIHr2WWKtjbCHSHHncCWBN/PA9CUTAVEcqbw+k pzHglvaMNPoXBsZK42VzjiLbdKv62VLJxoBDR4gam2F/5E/qbvTvBX8acI+bLM0oWbQV Ffvw== X-Gm-Message-State: AOJu0YwY9foPn1Q2pRBK06i02NAqxKuoq4dRqhqQh1HCu2Uv9fS2y2qX BZSskwE9ccHjGdt7BxRYWbjobcgEpg6ByZZQVPw= X-Received: by 2002:a17:90b:8d1:b0:27c:ed8e:1840 with SMTP id ds17-20020a17090b08d100b0027ced8e1840mr3302538pjb.10.1697002326788; Tue, 10 Oct 2023 22:32:06 -0700 (PDT) Received: from [10.84.141.101] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id y14-20020a17090a134e00b00277560ecd5dsm12812284pjf.46.2023.10.10.22.32.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Oct 2023 22:32:06 -0700 (PDT) Message-ID: <1ea32c1c-babf-452d-8097-c23777e8018b@bytedance.com> Date: Wed, 11 Oct 2023 13:32:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next v4 4/8] bpf: Introduce css open-coded iterator kfuncs From: Chuyi Zhou 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> In-Reply-To: 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 10 Oct 2023 22:32:50 -0700 (PDT) X-Spam-Level: ** 在 2023/10/11 12:44, Chuyi Zhou 写道: > > > 在 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; > > } > or we can change the BUILD_BUG_ON check, like bpf_timer_kern in bpf_timer_init: --- a/kernel/bpf/cgroup_iter.c +++ b/kernel/bpf/cgroup_iter.c @@ -310,7 +310,7 @@ __bpf_kfunc int bpf_iter_css_new(struct bpf_iter_css *it, { 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(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)); kit->start = NULL; diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index 773be9a221f5..0772545568f1 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -877,7 +877,7 @@ __bpf_kfunc int bpf_iter_task_new(struct bpf_iter_task *it, { struct bpf_iter_task_kern *kit = (void *)it; - BUILD_BUG_ON(sizeof(struct bpf_iter_task_kern) != sizeof(struct bpf_iter_task)); + BUILD_BUG_ON(sizeof(struct bpf_iter_task_kern) > sizeof(struct bpf_iter_task)); BUILD_BUG_ON(__alignof__(struct bpf_iter_task_kern) != __alignof__(struct bpf_iter_task));