Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp961638rwe; Thu, 25 Aug 2022 12:25:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Tdu0CZqM50sV3AE7hsoYU+g2KqmM2HaI9UkMlFYfaHyYwMiLyF0LWGW/pD+HsFlmMwBMn X-Received: by 2002:a05:6402:274e:b0:447:4e9d:69e8 with SMTP id z14-20020a056402274e00b004474e9d69e8mr4310779edd.295.1661455504824; Thu, 25 Aug 2022 12:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661455504; cv=none; d=google.com; s=arc-20160816; b=YxV9GLvJYPZ1kI3r3zFsoska3f1t0iutO4gkm6/sB1xgk8mK+XRFQSphCrcMELrlJ2 C26PzjjuPDYEUZ9Vuq/N2GQQ/D3rMMbhTkJ6O4Py99sPtpKZ1ARXT42R3m2HeGSfYZMc +lzIXbVsCsSBZgGKzBfq/rja6HcO9PzWU6C2mezCrGMdOhoFWwM3T1CSdRbdht6aT+UX yzqbluTBq/ZZ9KoQ/j/f87SeOpKE++9yuYvsuYTMyUJNX9V7xZ4gXJROj4bkdeUURP+i ghjk7CNoxJgssH2eeMSYPF7eYPKEozOimUCMLBKM7BX3nWu2nQhDXh8twAWz0DSJvXg6 oVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EDk7Jt2uZRRncSr/gTEg0S0FNgT/gNpLO3FmZsA//fA=; b=mn63LctLiLvU0A8WGzImuHt1rzF6ExosqV6vX2CpkZXnBWH2qR9Pe2f6q7T4bIdxse lMdNBx9pN2gcDcOlIBurFm5YUODZ8Vc0ZYaS8wLrpD23mWJMHvVcbnBal+XEMSszVYUl CNAiGZD5xAgKTwgAotPmkIjmOpzpbGNTjeFgXwcFsuuQCOqfdVbAwxlAABSJdcqjAo8R QIEPZr8zMu6a0FlG7oOktWlm8y6EZt9dVK16LM+pmpFubdBa8nrixJHZlTq/8roRCEOm nhXW/PxODE4k1lVZKTqcTo6HhTYa+ex2oV67gRfViCn3r3oJUjAiJK0d0P6QYEI5Bmef THLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lggwvEUA; 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 b22-20020aa7df96000000b00446b9a31a1fsi165136edy.199.2022.08.25.12.24.39; Thu, 25 Aug 2022 12:25:04 -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=lggwvEUA; 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 S243536AbiHYS41 (ORCPT + 99 others); Thu, 25 Aug 2022 14:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243531AbiHYS4Z (ORCPT ); Thu, 25 Aug 2022 14:56:25 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F2B4B9582 for ; Thu, 25 Aug 2022 11:56:23 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id a4so15964921qto.10 for ; Thu, 25 Aug 2022 11:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=EDk7Jt2uZRRncSr/gTEg0S0FNgT/gNpLO3FmZsA//fA=; b=lggwvEUATyTifL2BFcwYTuCjX5Xws2W1lUnfZWPbjeca+/WyDPPV48Q9AMavRDlRD9 0ZfjTxVKSp297twRIc8IuHWBcdk5R7sgvfeMxzwFJwK3BFQzl/bxwh2wGzgZbwW4Tjh5 v40GvDvWOSY9HKic0GWE+CLddsJooRKsz83kSnXyyqefqUn7nTemz1NS9gtLsqxvKUFt TS3pPtuFDCDj1o+PH7uQefAL0PefDqidAwV+pxmQO4KUdiCxhFGA/C7HXWygEt4uTiK+ kVXRP2ku+pcRRt/7gUL4c8JkJN3YWi4lLZgYvrFRcHFTLcukfc+dkH30KcZFYOAHb/TQ GzEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=EDk7Jt2uZRRncSr/gTEg0S0FNgT/gNpLO3FmZsA//fA=; b=Ck638VXAgCpKzK4Cm2tIEyuraOgJbtMMfMPJuLjlwRZ/hWmeQlcjH0pacAgM3vsOwC 5nJWe9KI1VFgbAjL2MPzs0/39GfqsOLPHFcXXg6LG+Q+dRa/T9ogchbjzmfCMpxei+0O /EPK5naUM3RtPUl3vHGyE6RRS4OWkBLod7VuDe3jUvh1BHEjfZ1CUOEq8xAtamIFkq4G W4qQlrKTx5WQSm2YqUJ5dcMOYdiFPCJ5HrdqksOmKLcLy7ON+W+OzVbjk2iaBjcoq0Au UtN3pQ2lVwuL47WqEQf7xXyjflC40oHnp2tRIcclknEp/6gWKcfjXJeu4HNiAjq6tiSD 6Yzg== X-Gm-Message-State: ACgBeo0f55INgkrK3/N89ykuyPr233U5b+2VxQxpECRav/oaQE0dFyud Sr32L27y+SddGuzAfjJf+Mm1MY3MDn2mpPQ4nHoszg== X-Received: by 2002:ac8:57d3:0:b0:344:51fd:6b36 with SMTP id w19-20020ac857d3000000b0034451fd6b36mr4830086qta.299.1661453782442; Thu, 25 Aug 2022 11:56:22 -0700 (PDT) MIME-Version: 1.0 References: <20220824030031.1013441-1-haoluo@google.com> <20220824030031.1013441-2-haoluo@google.com> <20220825152455.GA29058@blackbody.suse.cz> In-Reply-To: <20220825152455.GA29058@blackbody.suse.cz> From: Hao Luo Date: Thu, 25 Aug 2022 11:56:11 -0700 Message-ID: Subject: Re: [PATCH bpf-next v9 1/5] bpf: Introduce cgroup iter To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: 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 , John Fastabend , Jiri Olsa , Roman Gushchin , David Rientjes , Stanislav Fomichev , Shakeel Butt , Yosry Ahmed Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Thu, Aug 25, 2022 at 8:24 AM Michal Koutn=C3=BD wrote= : > > Hello. > > On Tue, Aug 23, 2022 at 08:00:27PM -0700, Hao Luo wro= te: > > +static int bpf_iter_attach_cgroup(struct bpf_prog *prog, > > + union bpf_iter_link_info *linfo, > > + struct bpf_iter_aux_info *aux) > > +{ > > + int fd =3D linfo->cgroup.cgroup_fd; > > + u64 id =3D linfo->cgroup.cgroup_id; > > + int order =3D linfo->cgroup.order; > > + struct cgroup *cgrp; > > + > > + if (order !=3D BPF_ITER_DESCENDANTS_PRE && > > + order !=3D BPF_ITER_DESCENDANTS_POST && > > + order !=3D BPF_ITER_ANCESTORS_UP && > > + order !=3D BPF_ITER_SELF_ONLY) > > + return -EINVAL; > > + > > + if (fd && id) > > + return -EINVAL; > > + > > + if (fd) > > + cgrp =3D cgroup_get_from_fd(fd); > > + else if (id) > > + cgrp =3D cgroup_get_from_id(id); > > + else /* walk the entire hierarchy by default. */ > > + cgrp =3D cgroup_get_from_path("/"); > > + > > + if (IS_ERR(cgrp)) > > + return PTR_ERR(cgrp); > > This section caught my eye. > > Perhaps the simpler way for the default hierachy fallback would be > > cgrp =3D &cgrp_dfl_root.cgrp; > cgroup_get(cgroup) > > But maybe it's not what is the intention if cgroup NS should be taken > into account and cgroup_get_from_path() is buggy in this regard. > > Would it make sense to prepend the patch below to your series? Michal, this patch series has merged. Do you need me to send your patch on your behalf, or you want to do it yourself? > ----8<---- > From 1098e60e89d4d901b7eef04e531f2c889309a91b Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Michal=3D20Koutn=3DC3=3DBD?=3D > Date: Thu, 25 Aug 2022 15:19:04 +0200 > Subject: [PATCH] cgroup: Honor caller's cgroup NS when resolving path > MIME-Version: 1.0 > Content-Type: text/plain; charset=3DUTF-8 > Content-Transfer-Encoding: 8bit > > cgroup_get_from_path() is not widely used function. Its callers presume > the path is resolved under cgroup namespace. (There is one caller > currently and resolving in init NS won't make harm (netfilter). However, > future users may be subject to different effects when resolving > globally.) > Since, there's currently no use for the global resolution, modify the > existing function to take cgroup NS into account. > > Fixes: a79a908fd2b0 ("cgroup: introduce cgroup namespaces") > Signed-off-by: Michal Koutn=C3=BD > --- > kernel/cgroup/cgroup.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c > index ffaccd6373f1..9280f4b41d8b 100644 > --- a/kernel/cgroup/cgroup.c > +++ b/kernel/cgroup/cgroup.c > @@ -6603,8 +6603,12 @@ struct cgroup *cgroup_get_from_path(const char *pa= th) > { > struct kernfs_node *kn; > struct cgroup *cgrp =3D ERR_PTR(-ENOENT); > + struct cgroup *root_cgrp; > > - kn =3D kernfs_walk_and_get(cgrp_dfl_root.cgrp.kn, path); > + spin_lock_irq(&css_set_lock); > + root_cgrp =3D current_cgns_cgroup_from_root(&cgrp_dfl_root); > + kn =3D kernfs_walk_and_get(root_cgrp->kn, path); > + spin_unlock_irq(&css_set_lock); > if (!kn) > goto out; > > > base-commit: 3cc40a443a04d52b0c95255dce264068b01e9bfe > -- > 2.37.0 >