Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2488309ioo; Mon, 23 May 2022 21:33:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP/RPCFkY6sXU/vv9JcPiGsYI166/K08PQyUoEdI5aLlIG/EuViLZkWYJhDB8s9xxAnVMW X-Received: by 2002:a63:d743:0:b0:3f5:f77a:a516 with SMTP id w3-20020a63d743000000b003f5f77aa516mr22489019pgi.210.1653366827944; Mon, 23 May 2022 21:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653366827; cv=none; d=google.com; s=arc-20160816; b=TGTLZ+LeNfXon5wh52bsCQRMzR2GYyanNhcrh7jytNR1Gn6PKIdR9spUEN6xIvAG0x zMt1ZUo6EHoA0ZacuwI7nK+FOiK0ZC8cmD/pcY8X7jUaIUG+MIh/mTq8BBUQrOxEOV2b +99p1sJj74sYs3Nu+vF32sU+bxqo6wpeqoNavPHZ5g9YcpXozVDpAF3KYBxRhJSvokEQ +xg83zAoKPEid3FVX1ThCKH/EmFwoR7whfuYvZHPESv+I/o+YBPxJ0JwRIG1m1ECCR5/ qRha6JPgyidmBWxtuGauRD/1lfc3fZgiUz/ceK3dyyDMnjjUPuCVJPD3RpI2D7QsalGG rt/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=x4jbl/h/9IkQPtvCa68VGCFyvxT/KOdRev2otsqHtfM=; b=KLnRCxHYHc9CRS7x8htkFDennIZ1EFA8I7w8I9RP9DJRTH2oCyRliw3UXwRGIIUR75 rUSRnCPqMHsDqLM+YEMIUbYITBS3+tsg2VcLEomqnZS7JSeNQfxaQ89QhRgNzM/+kU8J AXblST8MGQFoQ4IcAnnDXfsy6aL2cDdra51nmQIgzbUsIe66lLsDYciCCy+X780hzVtl 9MmOk1tktQgajnt3cwXCh4zwu06bvRW5RhQliIDaemKDd5JCfb3bx2k21Zj9d7UTD2Da PyBP68gTpdn2fjSHAqftb03YPTHbKYN19+C09hx11+OST3x5fWlaOmKyAAbtRddorBKu idRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CLD8Vfeh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t75-20020a635f4e000000b003c23c6b393bsi10628676pgb.652.2022.05.23.21.33.35; Mon, 23 May 2022 21:33:47 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=CLD8Vfeh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231983AbiEXAxT (ORCPT + 99 others); Mon, 23 May 2022 20:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbiEXAxO (ORCPT ); Mon, 23 May 2022 20:53:14 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2826A8217D for ; Mon, 23 May 2022 17:53:13 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id f35so1154760qtb.11 for ; Mon, 23 May 2022 17:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x4jbl/h/9IkQPtvCa68VGCFyvxT/KOdRev2otsqHtfM=; b=CLD8VfehPsBJZKAJX5SPjbU2o9Q0pXOcAnEDp/JCvbkisTN6aYTXXFyQR9tQD56GBx aRURvpzT0qMlj0TBitxFWqDDvCT7U90MMnkPOH7LbK07zbOfHREkSn8Li4gc75TrIKyc 4uuiItRFMVlt6QQAOggQDGe1AiKerD3SvjRiu1ENyYtAh/rfWdUH/ZJsQT2ThcD8PAv6 MpBn3JnnKsqLEd+RT++NjvLR95c5HM9CWQ14xRsasQpZu9B/Kr/L3k4fd7DFsj3y950S k2CC+P/CT3/lw9ZSnEFMFi9WjEGj+g0wqyyOnP98XBItvA/gQpr2iamhbFL0JA0bVPw5 pL+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x4jbl/h/9IkQPtvCa68VGCFyvxT/KOdRev2otsqHtfM=; b=u/9TThafvyCAzeJvUPVckQvm0yx4zNzT/BKqABchxGyShT6rS06fY5k83ZZkrjQiFH Zg0kBhiLMcU8v81Wclq5tqB6ersuGHLxLfm9TT4xsIClps3pRLMmf7eEkV0CcMFprlVw aN+8bAe2eyz1OYFHe+ci1gNjmjdzvbpJOIJoNoUSrsLGYoqfPd168PE2BcWWiJCI4tJW PYLAxdAihNYmnNt/trGIKzWZTSFOCtCtEhEp4rIJeceHXAlpZORuhS7gjZ9WHkeNN1Vf LMp2+KwLo/8DSmSSz32rdj+9ks36nQ49jjcI+5s3YZ2oe3RyQxSyV7dV0Dru1nP6eIWE r4NA== X-Gm-Message-State: AOAM530p5TAx4dS/82CLv33ssTwBKwxNKrkR+VPGCCPF2pzwTKK350hH 0f3k3wAAotpcGFr73XapM10SYrHxgdPbUrmmVhofvg== X-Received: by 2002:ac8:7d86:0:b0:2f3:c523:19a2 with SMTP id c6-20020ac87d86000000b002f3c52319a2mr18366810qtd.566.1653353592069; Mon, 23 May 2022 17:53:12 -0700 (PDT) MIME-Version: 1.0 References: <20220520012133.1217211-1-yosryahmed@google.com> <20220520012133.1217211-4-yosryahmed@google.com> <73fd9853-5dab-8b59-24a0-74c0a6cae88e@fb.com> <20220520221919.jnqgv52k4ajlgzcl@MBP-98dd607d3435.dhcp.thefacebook.com> <5b301151-0a65-df43-3a3a-6d57e10cfc2d@fb.com> In-Reply-To: From: Hao Luo Date: Mon, 23 May 2022 17:53:00 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 3/5] bpf: Introduce cgroup iter To: Andrii Nakryiko Cc: Yonghong Song , Tejun Heo , Alexei Starovoitov , Yosry Ahmed , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Zefan Li , Johannes Weiner , Shuah Khan , Roman Gushchin , Michal Hocko , Stanislav Fomichev , David Rientjes , Greg Thelen , Shakeel Butt , Linux Kernel Mailing List , Networking , bpf , Cgroups Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Mon, May 23, 2022 at 4:58 PM Andrii Nakryiko wrote: > > On Fri, May 20, 2022 at 7:35 PM Hao Luo wrote: > > > > On Fri, May 20, 2022 at 5:59 PM Yonghong Song wrote: > > > On 5/20/22 3:57 PM, Tejun Heo wrote: > > > > Hello, > > > > > > > > On Fri, May 20, 2022 at 03:19:19PM -0700, Alexei Starovoitov wrote: > > > >> We have bpf_map iterator that walks all bpf maps. > > > >> When map iterator is parametrized with map_fd the iterator walks > > > >> all elements of that map. > > > >> cgroup iterator should have similar semantics. > > > >> When non-parameterized it will walk all cgroups and their descendent > > > >> depth first way. I believe that's what Yonghong is proposing. > > > >> When parametrized it will start from that particular cgroup and > > > >> walk all descendant of that cgroup only. > > > >> The bpf prog can stop the iteration right away with ret 1. > > > >> Maybe we can add two parameters. One -> cgroup_fd to use and another -> > > > >> the order of iteration css_for_each_descendant_pre vs _post. > > > >> wdyt? > > > > > > > > Sounds perfectly reasonable to me. > > > > > > This works for me too. Thanks! > > > > > > > This sounds good to me. Thanks. Let's try to do it in the next iteration. > > Can we, in addition to descendant_pre and descendant_post walk > algorithms also add the one that does ascendants walk (i.e., start > from specified cgroup and walk up to the root cgroup)? I don't have > specific example, but it seems natural to include it for "cgroup > iterator" in general. Hopefully it won't add much code to the > implementation. Yep. Sounds reasonable and doable. It's just adding a flag to specify traversal order, like: { WALK_DESCENDANT_PRE, WALK_DESCENDANT_POST, WALK_PARENT_UP, }; In bpf_iter's seq_next(), change the algorithm to yield the parent of the current cgroup.