Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4969913rdb; Fri, 15 Sep 2023 19:50:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhwiaH7m+JuOZooq870zw99uQWGX40BIEl2PnREtAWkqOrzusSQQrzxiJXU+W6/UBPqtcP X-Received: by 2002:a05:6870:64a7:b0:1d5:aa83:c225 with SMTP id cz39-20020a05687064a700b001d5aa83c225mr4223783oab.21.1694832630619; Fri, 15 Sep 2023 19:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694832630; cv=none; d=google.com; s=arc-20160816; b=RLKNijLReELspQ2kJPr7q4lW61UjtDr97ls1U0Cj6tMStt/RoDrBh6ueh59r+MeNXx gz6BTMwUoYZlHkK8yTuyFNxCiSESug30QeKrYOzZReykvKzpO7a0SirAYMAPbkMlvTvW wzvmRvuz+g86adrx7oD+USBq4BGtc38mFSE4BFT8Y2Wf+DAzG5w2x8v//O1GHaC9LSMU RUEiW0Aj/3eYM2UqlGpna4y3IRiGych3rZYUrqMTWp5c8NQ5HlsG+ki9o0oIi0EWPHic KXPD9gQZb3Y1uV4B/ULWXy+ocHhHZ0pOCD7tOuPkfp3kXOFQYnjB1fO6yr7GitMXMTQI hwaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=cIpYKgze7l+4kxt1H4ShRKX1dLLu6xyjGygZfgTzVnI=; fh=luN1T+TZmJdWrv2MwLqOcKf0btUR/zj1LntAQkciNa8=; b=ny4YGTx6o7cSD8MUT2XU4qwDbAPLqSSG70XCOzKa1rW2LX9BcCdjDFNtmfSeh3FSPx n3LQ0eDY5+OPKJjRp8xtrfzStmnwKywM1yVGRzvKjEAsjaZ0PbORyqPF2Kkrxj4zhc68 92XfHvCBnSWzSc+GWBSOaERd+lN7quGN6NmBUOcS24PTMlhkIsoRvNbkDIc+OOwvY7Mo bd0TFuSbjscnCLwPoZTzwnjovIlW8yvkmcHkJaNxHy0p85HOkwYjKMhTJOrJ76BaDF4d tY6rylq8HNV3HkFP+bznFk2LWumzb6EJzoju9DrJNi9uuZiKONKI6jWKOHChxR1P4izR 2e5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=icqbDhBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 6-20020a630a06000000b00577f67a0614si4026531pgk.879.2023.09.15.19.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 19:50:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=icqbDhBr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3ED9C81B4AE3; Fri, 15 Sep 2023 13:26:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234228AbjIOUZu (ORCPT + 99 others); Fri, 15 Sep 2023 16:25:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237481AbjIOUZk (ORCPT ); Fri, 15 Sep 2023 16:25:40 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C3F32703; Fri, 15 Sep 2023 13:25:31 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-403012f27e1so26789435e9.1; Fri, 15 Sep 2023 13:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694809530; x=1695414330; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cIpYKgze7l+4kxt1H4ShRKX1dLLu6xyjGygZfgTzVnI=; b=icqbDhBrxpoXaDTB9GXlyDfU7To5JzmT/Ju285ozn1a7hb8zvUXbfaWaUYaXsZTgGU ys9xSEU8uDGvej9UXTbhlU6jVuIpk72zKT9k28vRpG4f7CBuqlDAVSLl5qbA0hOxv9PQ z6oYAjAuyfHVH1wJo5mTr9rBPH3Y0Lbol3c4C3AdCO8BGslmK45ATfnHsC8we+nOSg7c LPMCs5e7DAmrEG9CrsbNtJvFDP8UFsN5xRacVyYZFkEZp6q5RgUXv6mtyHZXXVxBn0TT c+Bi7Wx99JUH/HNSLm0SL9W/L6PM7yGIePjQD0w5FC4wC42JtZffHTMCFjjwv3p4WRhU mX3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694809530; x=1695414330; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cIpYKgze7l+4kxt1H4ShRKX1dLLu6xyjGygZfgTzVnI=; b=jk6O0RydNyeYGKWKDs2prkoi3W0TsPrNfLni9i+t8dVTXW/Vselq89bLpAzpSrZelh 4yTc/KjcohlFV15/k240rz4j4GJyahborUrybeCoJsRX5+B4lCPN91pgtDzq4lFqvLap eP9pNFY6CALhWFfBH8M4HJrKZaxwJp7B4Cl1Apgqc2YX+GSFKRqm1L/YH204UGAHQvKO /ptrSSy2qJpAI63XWVPLHrE3uTbEmMEB55+jS1CEzvaSLZKIBokdBRGxB9XSbO6bKuSX 2FHnkS65eyGFhf2g4D+9Gde9yLIk5bMl/lrdmZgkl5g5n0UggnwRCSNSx0AaLxznatOF 5w/Q== X-Gm-Message-State: AOJu0Yy7tidOKhfVcnF1+5dtweR9jfqPE3wkuiGmhMq6HKE7ZCrtK89k Uk4Q/ScSYsjl/+UOfuUSS2DEBuwg26BYjiPl3ely+QYJmdQ= X-Received: by 2002:adf:fb08:0:b0:31f:e534:2d6f with SMTP id c8-20020adffb08000000b0031fe5342d6fmr1961692wrr.11.1694809529639; Fri, 15 Sep 2023 13:25:29 -0700 (PDT) MIME-Version: 1.0 References: <20230912070149.969939-1-zhouchuyi@bytedance.com> <20230912070149.969939-5-zhouchuyi@bytedance.com> <8f27e07e-e23c-af80-90eb-b1123e1f68cd@bytedance.com> In-Reply-To: <8f27e07e-e23c-af80-90eb-b1123e1f68cd@bytedance.com> From: Andrii Nakryiko Date: Fri, 15 Sep 2023 13:25:18 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 4/6] bpf: Introduce css_descendant open-coded iterator kfuncs To: Chuyi Zhou Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, tj@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 13:26:30 -0700 (PDT) On Fri, Sep 15, 2023 at 4:57=E2=80=AFAM Chuyi Zhou wrote: > > Hello. > > =E5=9C=A8 2023/9/15 07:26, Andrii Nakryiko =E5=86=99=E9=81=93: > > On Tue, Sep 12, 2023 at 12:02=E2=80=AFAM Chuyi Zhou wrote: > >> > >> This Patch adds kfuncs bpf_iter_css_{pre,post}_{new,next,destroy} whic= h > >> allow creation and manipulation of struct bpf_iter_css in open-coded > >> iterator style. These kfuncs actually wrapps css_next_descendant_{pre, > >> post}. BPF programs can use these kfuncs through bpf_for_each macro fo= r > >> iteration of all descendant css under a root css. > >> > >> Signed-off-by: Chuyi Zhou > >> --- > >> include/uapi/linux/bpf.h | 8 +++++ > >> kernel/bpf/helpers.c | 6 ++++ > >> kernel/bpf/task_iter.c | 53 ++++++++++++++++++++++++++++++++= ++ > >> tools/include/uapi/linux/bpf.h | 8 +++++ > >> tools/lib/bpf/bpf_helpers.h | 12 ++++++++ > >> 5 files changed, 87 insertions(+) > >> > >> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > >> index befa55b52e29..57760afc13d0 100644 > >> --- a/include/uapi/linux/bpf.h > >> +++ b/include/uapi/linux/bpf.h > >> @@ -7326,4 +7326,12 @@ struct bpf_iter_process { > >> __u64 __opaque[1]; > >> } __attribute__((aligned(8))); > >> > >> +struct bpf_iter_css_pre { > >> + __u64 __opaque[2]; > >> +} __attribute__((aligned(8))); > >> + > >> +struct bpf_iter_css_post { > >> + __u64 __opaque[2]; > >> +} __attribute__((aligned(8))); > >> + > >> #endif /* _UAPI__LINUX_BPF_H__ */ > >> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > >> index 9b7d2c6f99d1..ca1f6404af9e 100644 > >> --- a/kernel/bpf/helpers.c > >> +++ b/kernel/bpf/helpers.c > >> @@ -2510,6 +2510,12 @@ BTF_ID_FLAGS(func, bpf_iter_css_task_destroy, K= F_ITER_DESTROY) > >> BTF_ID_FLAGS(func, bpf_iter_process_new, KF_ITER_NEW) > >> BTF_ID_FLAGS(func, bpf_iter_process_next, KF_ITER_NEXT | KF_RET_NULL= ) > >> BTF_ID_FLAGS(func, bpf_iter_process_destroy, KF_ITER_DESTROY) > >> +BTF_ID_FLAGS(func, bpf_iter_css_pre_new, KF_ITER_NEW) > >> +BTF_ID_FLAGS(func, bpf_iter_css_pre_next, KF_ITER_NEXT | KF_RET_NULL) > >> +BTF_ID_FLAGS(func, bpf_iter_css_pre_destroy, KF_ITER_DESTROY) > >> +BTF_ID_FLAGS(func, bpf_iter_css_post_new, KF_ITER_NEW) > >> +BTF_ID_FLAGS(func, bpf_iter_css_post_next, KF_ITER_NEXT | KF_RET_NULL= ) > >> +BTF_ID_FLAGS(func, bpf_iter_css_post_destroy, KF_ITER_DESTROY) > >> BTF_ID_FLAGS(func, bpf_dynptr_adjust) > >> BTF_ID_FLAGS(func, bpf_dynptr_is_null) > >> BTF_ID_FLAGS(func, bpf_dynptr_is_rdonly) > >> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c > >> index 9d1927dc3a06..8963fc779b87 100644 > >> --- a/kernel/bpf/task_iter.c > >> +++ b/kernel/bpf/task_iter.c > >> @@ -880,6 +880,59 @@ __bpf_kfunc void bpf_iter_process_destroy(struct = bpf_iter_process *it) > >> { > >> } > >> > >> +struct bpf_iter_css_kern { > >> + struct cgroup_subsys_state *root; > >> + struct cgroup_subsys_state *pos; > >> +} __attribute__((aligned(8))); > >> + > >> +__bpf_kfunc int bpf_iter_css_pre_new(struct bpf_iter_css_pre *it, > >> + struct cgroup_subsys_state *root) > > > > similar to my comment on previous patches, please see > > kernel/bpf/cgroup_iter.c for iter/cgroup iterator program. Let's stay > > consistent. We have one iterator that accepts parameters defining > > iteration order and starting cgroup. Unless there are some technical > > reasons we can't follow similar approach with this open-coded iter, > > let's use the same approach. We can even reuse > > BPF_CGROUP_ITER_DESCENDANTS_PRE, BPF_CGROUP_ITER_DESCENDANTS_POST, > > BPF_CGROUP_ITER_ANCESTORS_UP enums. > > > > I know your concern. It would be nice if we keep consistent with > kernel/bpf/cgroup_iter.c > > But this patch actually want to support iterating css > (cgroup_subsys_state) not cgroup (css is more low lever). > With css_iter we can do something like > "for_each_mem_cgroup_tree/cpuset_for_each_descendant_pre" > in BPF Progs which is hard for cgroup_iter. In the future we can use > this iterator to plug some customizable policy in other resource control > system. That's fine if it's not exactly cgroup iter and returns a different kernel object. But let's at least consistently use BPF_CGROUP_ITER_DESCENDANTS_PRE/BPF_CGROUP_ITER_DESCENDANTS_POST/BPF_CGROUP= _ITER_ANCESTORS_UP approach as a way to specify iteration order? > > BTW, what I did in RFC actually very similar with the approach of > cgroup_iter. > (https://lore.kernel.org/all/20230827072057.1591929-4-zhouchuyi@bytedance= .com/). > > Thanks.