Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp180551ioo; Fri, 20 May 2022 17:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfJ3/LmVtZxjkPvZA8im5L9jcblx29eZfg2Mc9fA+vM4rj2BFf416vB5tQplLPlhI23vYi X-Received: by 2002:a17:907:3f29:b0:6f4:cb04:a6f5 with SMTP id hq41-20020a1709073f2900b006f4cb04a6f5mr10886747ejc.115.1653094681970; Fri, 20 May 2022 17:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094681; cv=none; d=google.com; s=arc-20160816; b=YSoSqSIZIQ6HczruGEdlfX/pigfTbzbIPZrN6l69jx0+Vuj28ChUpsozEfZIHC2DeB 3cLLENBx6E0hu6AANnaDRvqqRw8JALgkqdVUL11vb+N6ddpZWLUsyl932G40QlZ2LGL2 uWCZynMS0gYtlhzQbFsnWC/7bC7IyU/2/Q/fANsfRU177isWFjKC0QlfS6DgAYHI839V RAL2HUjMDqyoUVckiEEVAOWPxAVdzx8T7wwVKB7ggzNqwfvV97MLCovmaKz+XFJ6IjEr ij3pPdHHH9eYixE32NH/73YHvMtHrbW01XdSNYDNhXAhQK8F8vXATuyIg5VgSXJYo17W 0Tjw== 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=rjHRlb1I3VbpwM5vlx4HP72yEGIAgQZNiDcXaK4IrWE=; b=IJXDI51rvooxRyjCGhox7/Ob2g5O6DTKQNJdTOgqO4AMf6zvt1pPxouuoWlddsDuUe ckIsV8XHegA2A3IlMZD039Cm3eDhHMUJEs5l0vBufIUhzhdzh9ElCCl/q1QFD2/rfOGg QJP1YzwWgCVTQJJRHCau3PnTgtKE9F8A1OnRKH3qXSh7w+TnLu22vt6+bsq/gaJD1blr ju284h1d5sot4PXQ4bbebnP6hwtglcJKyqdey/VQcby3TzUBTGiyUZ963dgc4ZL21FmK X+NJeKziO4cohCWLEQ2ZhBTDqXpMmb7J/0dtd+Dw1U/F/vTp4WlLahnLz8ODvaVcNEMV 5brw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CqWaIRBY; 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 q10-20020a056402518a00b0042afe90eb86si7239923edd.498.2022.05.20.17.57.35; Fri, 20 May 2022 17:58:01 -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=CqWaIRBY; 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 S236727AbiETWh1 (ORCPT + 99 others); Fri, 20 May 2022 18:37:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243679AbiETWh0 (ORCPT ); Fri, 20 May 2022 18:37:26 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 656A3185C9C for ; Fri, 20 May 2022 15:37:24 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id k30so13219693wrd.5 for ; Fri, 20 May 2022 15:37:24 -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=rjHRlb1I3VbpwM5vlx4HP72yEGIAgQZNiDcXaK4IrWE=; b=CqWaIRBYO4RMPakxBtGQr0gF0h+doHGHgL6p8/uY/2bT1FSn5s8z8EPF3lDt9rHVYn 5itjBBvHeFp2Vo1o45+HjsRWft6V3cBTf5aRQI4gxDIoCJ+CfcA90Ir0c7oNRAloniK1 1YxLAnp74KeRbPRxZxm8rr9oSTbEUR5wTuxgh1Kc4peUuKD2q70w//S4s5rdx9mdkq8z lEHEdSjqR540R7Ak9Rtm+TwYGHdLqdEiAK1p52r+Zl82Ri960sciviRPXFw93JTz39Dp zZpJ44VH6SOPhSaFZAGCztGyQ/4jt7oyJpC4KD463XIDqi89CL5o476rYfInHk4PdGNz MWRQ== 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=rjHRlb1I3VbpwM5vlx4HP72yEGIAgQZNiDcXaK4IrWE=; b=zfJxWuyd9w5YEPMPqoJr8kV0X3JoVyM52FYkZZ11dEkMEuYsQP7oU6DXcxg6k44OEA SCjiVxusTJK2woEexEmOwTNlHLVUJhWZ3KxkGrp+66gDe4tMDgUCfqnrx07W7BFLiTOk me/IUpvY1w0BpGukr6/z5wuxD90qlkK5oSNFuxfV6KcDPrSbbQIkuqpCJwxpg0R27orc yng8mnbYk8NHGsGQlcaypjUvyRR3j5lMk/5TcK4WpmxI/PcyIvRjcKK1X7g/db1Att3Q EQr3RIIGiOlIwql0vICx+0YQ6k993se4p9veifDihi4IporvNiQPmpAWYMqfAXq4FCNF Nvtw== X-Gm-Message-State: AOAM531B0ZxoxvaVedsa6NcW8LOQlJo7uM/Z5pCMA28ywMIcSD5/vG5C a1zat0iSkFDM1cRAAljA3SsqPNoHg7N8cDRki0Gf9g== X-Received: by 2002:a05:6000:154a:b0:20c:7e65:c79e with SMTP id 10-20020a056000154a00b0020c7e65c79emr10148218wry.582.1653086242817; Fri, 20 May 2022 15:37:22 -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> In-Reply-To: <20220520221919.jnqgv52k4ajlgzcl@MBP-98dd607d3435.dhcp.thefacebook.com> From: Yosry Ahmed Date: Fri, 20 May 2022 15:36:46 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 3/5] bpf: Introduce cgroup iter To: Alexei Starovoitov Cc: Hao Luo , Tejun Heo , Yonghong Song , 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=unavailable 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 Fri, May 20, 2022 at 3:19 PM Alexei Starovoitov wrote: > > On Fri, May 20, 2022 at 02:18:42PM -0700, Yosry Ahmed wrote: > > > > > > The userspace needs to specify the identity of the cgroup, when > > > creating bpf_iter. This identity could be cgroup id or fd. This > > > identity needs to be converted to cgroup object somewhere before > > > passing into bpf program to use. > > > > > > Let's sum up the discussion here, I feel like we are losing track of > > the main problem. IIUC the main concern is that cgroup_iter is not > > effectively an iterator, it rather dumps information for one cgroup. I > > like the suggestion to make it iterate cgroups by default, and an > > optional cgroup_id parameter to make it only "iterate" this one > > cgroup. > > 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? So basically extend the current patch so that cgroup_id (or cgroup_fd) is optional, and it specifies where the iteration starts. If not provided, then we start at root. For our use case where we want the iterator to only be invoked for one cgroup we make it return 1 to stop after the first iteration. I assume an order parameter is also needed to specify "pre" for our use case to make sure we are starting iteration at the top cgroup (the one whose cgroup_id is the parameter of the iterator). Is my understanding correct? If yes, then this sounds very good. It is generic enough, actually iterates cgroups, and works for our use case.