Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp612753imn; Thu, 28 Jul 2022 10:23:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/PhnIe5cYzuMBYhxtb7lgpdTnvrLYIg0DJoh2lOV20nGMP4FPzzuelwT7OZJLzaBGd+20 X-Received: by 2002:a17:90b:4c87:b0:1f2:cf1d:c906 with SMTP id my7-20020a17090b4c8700b001f2cf1dc906mr405005pjb.119.1659029015555; Thu, 28 Jul 2022 10:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659029015; cv=none; d=google.com; s=arc-20160816; b=TCTl+RaxTqVuzY/jY9u6rTwAw4HvDLCbKPv0DKnCEaAD0nskCIUtyhYLvHwrv2Cr1k afKZwqreXQ4P1RPXCbNKtPquFOP86iVQ3ku6HZOxHo3mBXbFSSbIsKlfcIoXQzXL0oRC SGkiyMaQzXBbtqab2FEiK6NwpN99VktFBWS3DkjiiR9coWXHSGS4H+dGbsq74jbatqqe CxRNT7mupyYhFJji1SlkD6rpsVnGRIJXhwwqQRvCXfgVDyU2bsJQMEfIa8TO9SRhb7wS p1q5tBZ74sZGnfogTlecVjSPel+hn79ktuYDlmLNI/r4FI6RAvNw+o58GGWpTmwpZW4x QAVg== 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=VW7oYK4RqwqbJsASlxdjRV3NEVCTNvlDrSDTg61QkOg=; b=cuIfZ2RsLa3ujz4zB4gqmI+3SQZz4fdmBcjqOKvIiZi3sBcph4N7mYQslOVyKtzWDH Hu2HcM1koUYm5vl9B87l8cMvE3o2VU/MWjRrOKAAtAoL8K597rPZx/ls+cxFqO8fTO+s r3fPj4C6xvR8v5/+SMsAREmtvsCxYxyKc+3IjKVNS/kQhg9GD2ssdWZ64iE8gjCK5/et lkzQn5NDcp5zTNTsBB9n+ouZZa8NOYqjbMWFwesj60p66ksaGIUXDAKVqX4pzt0dYaAf Z8Qu+TSoZoh+3CvYLY8I96oNS0UN/p9EWKg1K6t/Rh1qfXtC4pa+o/9ZjdG7oKNyxOFm sOCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=h8FxtRKK; 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 v3-20020a631503000000b00415ed5db5absi1490025pgl.772.2022.07.28.10.23.20; Thu, 28 Jul 2022 10:23:35 -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=h8FxtRKK; 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 S232355AbiG1RVJ (ORCPT + 99 others); Thu, 28 Jul 2022 13:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231487AbiG1RU7 (ORCPT ); Thu, 28 Jul 2022 13:20:59 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC545F111 for ; Thu, 28 Jul 2022 10:20:58 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id g1so1908650qki.7 for ; Thu, 28 Jul 2022 10:20:58 -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=VW7oYK4RqwqbJsASlxdjRV3NEVCTNvlDrSDTg61QkOg=; b=h8FxtRKKQHF4SZtxhuJuCSHn3CxIjnLxoANRs2Qd79XyLUdqOiqvCZ0nf/TljQOJoz 7Uyovrfff5RQt4y3dHNonwXKvY7FZUnDtoRHS7lWjuK8E6idQMKrJMS4QFSzUEZF4m66 TzgFuIxGVMtfqQ0hB1NxW5AKLb+TvhCtZrfm9cueT8LxtqQg9su+cN3ghlP+T2lVpLdI ORveshtJMkLA+6KRzWshwGMkPKwKHyh+tpsCEeMexuP4mlBxfIufMDal02TfyaOgJefJ /BB58eusHQOE/4dQDk/11j96eQxmE3KTRG8BmpQQQX33x3W6J0jhBI98b3UHF00rtHXj TKrg== 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=VW7oYK4RqwqbJsASlxdjRV3NEVCTNvlDrSDTg61QkOg=; b=W/0TtLMibZnT+pOCAmVlKQNJDxZ+UnQgNG9SdfqANEpLvPeRv3bnQxJnR5SUvUUeII qg0/YzHhQ/fXkxjWCHcPGhb0e2BqN+ZY88PRFhZPJ80i4y7N3RI3qRYxP8idrMyxay5g k5oXPBPyf7M23fj2KbgObkIpDqtiGi6gagYHVLv4RbPh68sRsmZyV01BFEZADTLGyP1h JPzDlJDZp6mhIPz9xOsr06feHz8uCiBA8ohgK2pIAqlfuepPm0j8BzJT/A5n+dU0CVt2 hBfj5wwek/61UzbfvfOBN1ZJU6fxn24VKqW0DFYtw1qIV40Q8L9m4yxFHQxnZVFwIcqe TTsA== X-Gm-Message-State: AJIora+PPChuRGs0rx2XMu4ke91gG8YvZfKMzdskHNcB/WWB5rj/TS18 Ar7ymTHP/8Z6nmTuxnMU3yJg1CWD73yvuPg0YYh1iw== X-Received: by 2002:a05:620a:4105:b0:6b6:116b:2265 with SMTP id j5-20020a05620a410500b006b6116b2265mr20807430qko.583.1659028857346; Thu, 28 Jul 2022 10:20:57 -0700 (PDT) MIME-Version: 1.0 References: <20220722174829.3422466-1-yosryahmed@google.com> <20220722174829.3422466-5-yosryahmed@google.com> In-Reply-To: From: Hao Luo Date: Thu, 28 Jul 2022 10:20:46 -0700 Message-ID: Subject: Re: [PATCH bpf-next v5 4/8] bpf: Introduce cgroup iter To: Tejun Heo Cc: Yosry Ahmed , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , Zefan Li , Johannes Weiner , Shuah Khan , Michal Hocko , KP Singh , Benjamin Tissoires , John Fastabend , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Roman Gushchin , David Rientjes , Stanislav Fomichev , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org 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, 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 Hi Tejun, On Thu, Jul 28, 2022 at 9:51 AM Tejun Heo wrote: > > Hello, > > On Fri, Jul 22, 2022 at 05:48:25PM +0000, Yosry Ahmed wrote: > > + > > + /* cgroup_iter walks either the live descendants of a cgroup subtree, or the > > + * ancestors of a given cgroup. > > + */ > > + struct { > > + /* Cgroup file descriptor. This is root of the subtree if walking > > + * descendants; it's the starting cgroup if walking the ancestors. > > + * If it is left 0, the traversal starts from the default cgroup v2 > > + * root. For walking v1 hierarchy, one should always explicitly > > + * specify the cgroup_fd. > > + */ > > + __u32 cgroup_fd; > > So, we're identifying the starting point with an fd. > > > + __u32 traversal_order; > > + } cgroup; > > }; > > > > /* BPF syscall commands, see bpf(2) man-page for more details. */ > > @@ -6136,6 +6156,16 @@ struct bpf_link_info { > > __u32 map_id; > > } map; > > }; > > + union { > > + struct { > > + __u64 cgroup_id; > > + __u32 traversal_order; > > + } cgroup; > > but iterating the IDs. IDs are the better choice for cgroup2 as there's > nothing specific to the calling program or the fds it has, but I guess this > is because you want to use it for cgroup1, right? Oh well, that's okay I > guess. > Yes, we are identifying the starting point with FD. The cgroup_id here is the information reported from kernel to userspace for identifying the cgroup. We use FD because it is a convention in BPF. Compatibility of cgroup1 is a good feature of this convention. My thoughts: It seems that ID may be better, for two reasons. First, because ID is stateless, the userspace doesn't have to remember closing the FD. Second, using different identifications in two directions (userspace specifies cgroup using FD, while kernel reports cgroup using ID) introduces a little complexity when connecting them together. Hao > Acked-by: Tejun Heo > > Thanks. > > -- > tejun