Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2461135ioo; Mon, 23 May 2022 20:30:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEEvFxDWi6Fh5mJWvDQaxV6KIKmtU8v9klp/rpmFpJTsAAqTKYm9cdil0fVZeCMAktQSIM X-Received: by 2002:a17:902:db04:b0:161:9fb0:b85d with SMTP id m4-20020a170902db0400b001619fb0b85dmr25491354plx.143.1653363016602; Mon, 23 May 2022 20:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653363016; cv=none; d=google.com; s=arc-20160816; b=sFrEPsuZxHuToO1aL0/ayZM4gsgEljFmXDGezs0eXn9YL2SVOP55QLbS7DCi2m6JF1 TzDkZVNualHFkMlGRX860c3AzMqVfxvtfpo9AcZdsU1rvR0Z0g1XKWq5iGUDkcvR6NlD b53e1T7QDlT6qqNfaoDPqFGUoxOFz2F25um9l6H34UuQICwkgZ3pKLWCQ5ktbr2V4sAp 5MfXdt0yORvWmnToNAmUdx+fFqqJ9DMTI7K3A6VR8nYNQJnDfY+dBqvJY/SA5tzSA8xp m2d8BJL4XM0TTBCBeo1yRbvJMuHqpMNA1nvgJ51w6cmrZ/odeo7doebvPqGGic7aSTaq Z8Wg== 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=WWmcSlMLXyPAtUCAvd6HT22Q24cwWlGO+SKtL9DeqKU=; b=deRbSIQoHwUBHQvI39nviJBDuu9iFHHLykGHfD1D0T5APo2FtPIuVq/fplg/uSrYoy ZR1+WcKMTmh7Lt1Je6mHGtN4GqohVcszQWph8F0lpaZ0tgkUEu+elncSlBfyP/8Z8GXr qJ8iw1iegmo5nOKnmkwIAiY2Bet3+DD+uXdmIlyrXNaj6EFmdv4JGUpGUrXH5eFpiO2E aYM+EVfWdqU3GbCf9+V5toc0JoLA2aU4+k8Mrgf91HV14i9/RKs7QH5qCDHlPQMKyVUO Ad74VhMAGrDFLQY3apTW7SaektRx4ziiPIETwvXAoOE6WYbH6gjolJf3s/Y+e5n3ocCM ekxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g2y1NFt4; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a63580d000000b003f5d5bbf0b1si1469681pgb.245.2022.05.23.20.30.04; Mon, 23 May 2022 20:30:16 -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=@gmail.com header.s=20210112 header.b=g2y1NFt4; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232676AbiEXBaf (ORCPT + 99 others); Mon, 23 May 2022 21:30:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbiEXBac (ORCPT ); Mon, 23 May 2022 21:30:32 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DA106FD01; Mon, 23 May 2022 18:30:31 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id a10so17026542ioe.9; Mon, 23 May 2022 18:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WWmcSlMLXyPAtUCAvd6HT22Q24cwWlGO+SKtL9DeqKU=; b=g2y1NFt4Sseyx742KMl6xBdUityeBuD37EEwViwqBrkw+a2f6FepgoHeNqAcHs4pnS 0d1Nacm02K76ckrC3k60Cc4C8TIqbozizgZCpdm9jM366ElB583C3x0+qMEiKbQa79DU YHDMuqpINrn+W61mvf7NC/5707+lHWwF+Tx1zT+xJQt83X08GyKfcGSLHmDD3wcDUyir po18oBXtV7uTSIYeNHC59VElipZiBC9rlK0g45oJrdVu0oHLfbAF5/b+3h665gFYveW/ UjseAlbhaDpLGIt8CVLkZtoWQnBcZcOnoemVbm/5tZaLqXOTTdnmZXZGuhjPdA4Nr1ff j5mA== 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=WWmcSlMLXyPAtUCAvd6HT22Q24cwWlGO+SKtL9DeqKU=; b=ANCSUm8y4iPMs/k1ZgOeYd9zz5DtxYtFR11Ky0uYDfp6lOT9DPn63VA4o+Fos2UsKZ x8thq+MWlYGvKMQh+E9ZKYoJU0m+r0vAywNdDlmCW1n4QlVMi6T1JQ3sZfBd/vPJaZ4A JRTT4F0RM52fkMhSIHmThfswutA1OoF/N/yG/yjHkzKGOqe+ooZIGE5YL9ql6BdJ65G3 nIHzzeaRmUg8L7Sp9OGGWsCbzChBklpu2WFLYXfqxem7pZBCbXbDd8pOXRXQyGYmMpyh 7rRUQKPHeTgnP4Bb+Ltcduw83ynwpByJBuOANJ1LbhP0sFF9iMGedFmr8dwCBiVDJYYp zkTQ== X-Gm-Message-State: AOAM5327Qs8gNlxvjDEtZ++tX+3qPGxVtCMwPJF+nZul+dfLxFZqwAlx 13UQGZcrFppArHfmhXDqwPHSuwA0QS7aSZJFXlA= X-Received: by 2002:a05:6638:2393:b0:32e:319d:c7cc with SMTP id q19-20020a056638239300b0032e319dc7ccmr12749526jat.103.1653355831019; Mon, 23 May 2022 18:30:31 -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: Andrii Nakryiko Date: Mon, 23 May 2022 18:30:20 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 3/5] bpf: Introduce cgroup iter To: Hao Luo 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 5:53 PM Hao Luo wrote: > > 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, Probably something more like BPF_CG_WALK_DESCENDANT_PRE and so on? > }; > > In bpf_iter's seq_next(), change the algorithm to yield the parent of > the current cgroup.