Received: by 2002:ab3:5012:0:b0:1d7:b7fe:f8b7 with SMTP id y18csp3090061ltb; Tue, 9 Aug 2022 12:27:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR48UJ11wWHoLvhMwa+N3EzVQAhAy7UtyXSHnyukTn0GaCvAtgl0mEWQLcag1lu3PlprDqHf X-Received: by 2002:a17:90b:4a82:b0:1f5:832f:bfc with SMTP id lp2-20020a17090b4a8200b001f5832f0bfcmr7259pjb.213.1660073252062; Tue, 09 Aug 2022 12:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660073252; cv=none; d=google.com; s=arc-20160816; b=i5q9xMfTvshdro+TwGjFeYkfp44HnJLQ6hLGeKPMWfyD76qh08TiCgCh4hracikPYj lPHonqydCgiSoHIwh/x+KiDZ69pbXGvgyfdp6dAJpT4ohA+KhUdq0Np3djOJmEP3J43a YHItf19FwyOulqSSxM+Sdl6yVOzD3509MtYhLG5Ngs+lpkTf00Esuy5E0S9wwlrzSe51 DwXaTpbv4OTv81iislixm7LC7yUwy0mD568AvU+8sH0YyUzkNwFbVNv7xsIUwNJz0c4V lVuck8S6tWv8zNPCfrujz3bteMAutxvo9Zk4Vm4SnQMy+VsVirQDPNILaioJmNVjhgbE Xq7Q== 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=W39UTjuGL/i3nw+dgDx0+fMLYroO0xsXKyyQ9sO3qfs=; b=FXOc1CKnUdPcpcKTbSiTKt6DE6uNBE38V3EmiUsiRLsw5UBcemJkprRyoWAT/m2WAI Qf3mwT8xAb3gdqPlBas+V3Q//ZJaV7711b8KyueYYXu2zB8v6r6EZVwtWlgcn0rgDuK9 go0m3OgfC/hfmjA1VjQ5OgJ2ftVF586B6raU+TiWHFPMbIkIazBYjksJF42ubt2mGshn WQVWn/G331rircL4tWzUNdiuFp+zkhWVEFscUNWt7n11z+4dfWurSBGFsJgp0jEXry95 qJxKTbKWzzAJof7MWl77M5kIYFlcgygLdTYR3Mgqd39UkoouJy2e/ZgAPP0wVnnQmCEZ Qe0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Fm5fnpQk; 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 k203-20020a6284d4000000b005251b8f85ecsi481037pfd.61.2022.08.09.12.27.18; Tue, 09 Aug 2022 12:27:32 -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=Fm5fnpQk; 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 S245435AbiHITEi (ORCPT + 99 others); Tue, 9 Aug 2022 15:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344141AbiHITDV (ORCPT ); Tue, 9 Aug 2022 15:03:21 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 391992BB16 for ; Tue, 9 Aug 2022 11:38:44 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id v14so3851677qkf.4 for ; Tue, 09 Aug 2022 11:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=W39UTjuGL/i3nw+dgDx0+fMLYroO0xsXKyyQ9sO3qfs=; b=Fm5fnpQkRBDixj266mJEDjoI5meQ1E60sTmfOsHyY4gHXSPI47WK21mPv188hkdsBc 1D4TqzxCqwoLkifQFTRkJW0CYED+uXT5c8xuxNC1L52e+xaIjanzU9IqE0lbAHCb7J2/ c4D622uQsla/OWEOaDBGBLVELPWHUKcAbfKsBMFVJzYbc7DdCkDcN30dU/x0nBfoZZqP qOpFVPntPIQ140a5/hXtOFv0p1SE86EJi+UCbpZPFjopffVvfr9bwa1vVrgkZXSCpQqF zy8+xUOGIBZuCbUaq9a9ce80kCe0wK5TguviBzveJ9mxc7tNKCMigHVnDp9JUlUoYPkh sAHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=W39UTjuGL/i3nw+dgDx0+fMLYroO0xsXKyyQ9sO3qfs=; b=FQ710PQHgH5rZd9iVVo0d5srJcyI/yP0qCHYr9rbRAO3V3pfawJmsuH+dgks1hNh0x SfuMD5aRH2cxLx0tXqraX9A2T/JZQc7Ljl6jlrvkv6SRFL6XrZ5ZitFbqtKTVh4j74Wt XiTJ5CVvx+W+X5BK0AOAsailoBvU0AFkOL/WCHBofPGCKx80zhtoOc5EefV/Y6tATRFv yEMmWt7LHhT8F0omkTxGODGgCwWRw6GAPrA2CsGje6RElClr6p06uhOCEnexhuhq/NU1 qDtu+q3uVZil7KHEaT2zldYJD46RkwDb+SXjoLEgbjtvbawW0I2yOKhVwzGPWoiwzIFd PcwQ== X-Gm-Message-State: ACgBeo0Rn+nELN1uymrASFrMvu6bcIgNLQEGHITn8oL5IjeToS3N1Ash eh9C1bj1vWxIifYrTquNNAAV1+RVHZkXTp8gA651dg== X-Received: by 2002:a05:620a:8:b0:6b9:58ea:be83 with SMTP id j8-20020a05620a000800b006b958eabe83mr6879567qki.221.1660070323122; Tue, 09 Aug 2022 11:38:43 -0700 (PDT) MIME-Version: 1.0 References: <20220805214821.1058337-1-haoluo@google.com> <20220805214821.1058337-5-haoluo@google.com> <20220809162325.hwgvys5n3rivuz7a@MacBook-Pro-3.local.dhcp.thefacebook.com> In-Reply-To: <20220809162325.hwgvys5n3rivuz7a@MacBook-Pro-3.local.dhcp.thefacebook.com> From: Hao Luo Date: Tue, 9 Aug 2022 11:38:32 -0700 Message-ID: Subject: Re: [PATCH bpf-next v7 4/8] bpf: Introduce cgroup iter To: Alexei Starovoitov Cc: Andrii Nakryiko , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org, netdev@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Tejun Heo , Zefan Li , KP Singh , Johannes Weiner , Michal Hocko , Benjamin Tissoires , John Fastabend , Michal Koutny , Roman Gushchin , David Rientjes , Stanislav Fomichev , Shakeel Butt , Yosry Ahmed 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 Tue, Aug 9, 2022 at 9:23 AM Alexei Starovoitov wrote: > > On Mon, Aug 08, 2022 at 05:56:57PM -0700, Hao Luo wrote: > > On Mon, Aug 8, 2022 at 5:19 PM Andrii Nakryiko > > wrote: > > > > > > On Fri, Aug 5, 2022 at 2:49 PM Hao Luo wrote: > > > > > > > > Cgroup_iter is a type of bpf_iter. It walks over cgroups in four modes: > > > > > > > > - walking a cgroup's descendants in pre-order. > > > > - walking a cgroup's descendants in post-order. > > > > - walking a cgroup's ancestors. > > > > - process only the given cgroup. > > > > [...] > > > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > > > > index 59a217ca2dfd..4d758b2e70d6 100644 > > > > --- a/include/uapi/linux/bpf.h > > > > +++ b/include/uapi/linux/bpf.h > > > > @@ -87,10 +87,37 @@ struct bpf_cgroup_storage_key { > > > > __u32 attach_type; /* program attach type (enum bpf_attach_type) */ > > > > }; > > > > > > > > +enum bpf_iter_order { > > > > + BPF_ITER_ORDER_DEFAULT = 0, /* default order. */ > > > > > > why is this default order necessary? It just adds confusion (I had to > > > look up source code to know what is default order). I might have > > > missed some discussion, so if there is some very good reason, then > > > please document this in commit message. But I'd rather not do some > > > magical default order instead. We can set 0 to mean invalid and error > > > out, or just do SELF as the very first value (and if user forgot to > > > specify more fancy mode, they hopefully will quickly discover this in > > > their testing). > > > > > > > PRE/POST/UP are tree-specific orders. SELF applies on all iters and > > yields only a single object. How does task_iter express a non-self > > order? By non-self, I mean something like "I don't care about the > > order, just scan _all_ the objects". And this "don't care" order, IMO, > > may be the common case. I don't think everyone cares about walking > > order for tasks. The DEFAULT is intentionally put at the first value, > > so that if users don't care about order, they don't have to specify > > this field. > > > > If that sounds valid, maybe using "UNSPEC" instead of "DEFAULT" is better? > > I agree with Andrii. > This: > + if (order == BPF_ITER_ORDER_DEFAULT) > + order = BPF_ITER_DESCENDANTS_PRE; > > looks like an arbitrary choice. > imo > BPF_ITER_DESCENDANTS_PRE = 0, > would have been more obvious. No need to dig into definition of "default". > > UNSPEC = 0 > is fine too if we want user to always be conscious about the order > and the kernel will error if that field is not initialized. > That would be my preference, since it will match the rest of uapi/bpf.h > Sounds good. In the next version, will use enum bpf_iter_order { BPF_ITER_ORDER_UNSPEC = 0, BPF_ITER_SELF_ONLY, /* process only a single object. */ BPF_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */ BPF_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */ BPF_ITER_ANCESTORS_UP, /* walk ancestors upward. */ }; and explicitly list the values acceptable by cgroup_iter, error out if UNSPEC is detected. Also, following Andrii's comments, will change BPF_ITER_SELF to BPF_ITER_SELF_ONLY, which does seem a little bit explicit in comparison. > I applied the first 3 patches to ease respin. Thanks! This helps! > Thanks!