bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
	 andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	 yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com,
	 haoluo@google.com, jolsa@kernel.org, tj@kernel.org,
	lizefan.x@bytedance.com,  hannes@cmpxchg.org,
	yosryahmed@google.com, sinquersw@gmail.com,
	 cgroups@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 1/8] cgroup: Don't have to hold cgroup_mutex in task_cgroup_from_root()
Date: Tue, 10 Oct 2023 11:58:14 +0800	[thread overview]
Message-ID: <CALOAHbC4_0990_HD4=mg8gfU51juk8fs07zYrr6VL9fPOuLOng@mail.gmail.com> (raw)
In-Reply-To: <sdw6rnzbvmktajcxb4svj2kzvttftae2i5nd2lnlxnm3llub37@2q2rlubjzb5a>

On Mon, Oct 9, 2023 at 10:45 PM Michal Koutný <mkoutny@suse.com> wrote:
>
> On Sat, Oct 07, 2023 at 02:02:57PM +0000, Yafang Shao <laoar.shao@gmail.com> wrote:
> > The task cannot modify cgroups if we have already acquired the
> > css_set_lock, thus eliminating the need to hold the cgroup_mutex. Following
> > this change, task_cgroup_from_root() can be employed in non-sleepable contexts.
>
> IIRC, cset_cgroup_from_root() needs cgroup_mutex to make sure the `root`
> doesn't disappear under hands (synchronization with
> cgroup_destroy_root().

current_cgns_cgroup_from_root() doesn't hold the cgroup_mutext as
well. Could this potentially lead to issues, such as triggering the
BUG_ON() in __cset_cgroup_from_root(), if the root has already been
destroyed?

> However, as I look at it now, cgroup_mutex won't synchronize against
> cgroup_kill_sb(), it may worked by accident(?) nowadays (i.e. callers
> pinned the root implicitly in another way).
>
> Still, it'd be good to have an annotation that ensures, the root is around
> when using it. (RCU read lock might be fine but you'd need
> cgroup_get_live() if passing it out of the RCU read section.)
>
> Basically, the code must be made safe against cgroup v1 unmounts.

What we aim to protect against is changes to the `root_list`, which
occur exclusively during cgroup setup and destroy paths. Would it be
beneficial to introduce a dedicated root_list_lock specifically for
this purpose? This approach could potentially reduce the need for the
broader cgroup_mutex in other scenarios.

--
Regards
Yafang

  reply	other threads:[~2023-10-10  3:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-07 14:02 [RFC PATCH bpf-next 0/8] bpf, cgroup: Add BPF support for cgroup1 hierarchy Yafang Shao
2023-10-07 14:02 ` [RFC PATCH bpf-next 1/8] cgroup: Don't have to hold cgroup_mutex in task_cgroup_from_root() Yafang Shao
2023-10-07 15:50   ` Tejun Heo
2023-10-08  2:32     ` Yafang Shao
2023-10-09 14:45   ` Michal Koutný
2023-10-10  3:58     ` Yafang Shao [this message]
2023-10-10  8:29       ` Michal Koutný
2023-10-10 11:58         ` Yafang Shao
2023-10-07 14:02 ` [RFC PATCH bpf-next 2/8] cgroup: Add new helpers for cgroup1 hierarchy Yafang Shao
2023-10-07 15:55   ` Tejun Heo
2023-10-08  2:36     ` Yafang Shao
2023-10-09 11:32   ` Michal Koutný
2023-10-09 13:10     ` Yafang Shao
2023-10-09 14:48       ` Michal Koutný
2023-10-10  3:59         ` Yafang Shao
2023-10-07 14:02 ` [RFC PATCH bpf-next 3/8] bpf: Add kfuncs " Yafang Shao
2023-10-07 15:57   ` Tejun Heo
2023-10-08  2:37     ` Yafang Shao
2023-10-07 14:03 ` [RFC PATCH bpf-next 4/8] selftests/bpf: Fix issues in setup_classid_environment() Yafang Shao
2023-10-07 14:03 ` [RFC PATCH bpf-next 5/8] selftests/bpf: Add parallel support for classid Yafang Shao
2023-10-07 14:03 ` [RFC PATCH bpf-next 6/8] selftests/bpf: Add a new cgroup helper get_classid_cgroup_id() Yafang Shao
2023-10-07 14:03 ` [RFC PATCH bpf-next 7/8] selftests/bpf: Add a new cgroup helper get_cgroup_hierarchy_id() Yafang Shao
2023-10-07 14:03 ` [RFC PATCH bpf-next 8/8] selftests/bpf: Add selftests for cgroup1 hierarchy Yafang Shao
2023-10-09 11:46 ` [RFC PATCH bpf-next 0/8] bpf, cgroup: Add BPF support " Michal Koutný
2023-10-09 13:11   ` Yafang Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALOAHbC4_0990_HD4=mg8gfU51juk8fs07zYrr6VL9fPOuLOng@mail.gmail.com' \
    --to=laoar.shao@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hannes@cmpxchg.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=martin.lau@linux.dev \
    --cc=mkoutny@suse.com \
    --cc=sdf@google.com \
    --cc=sinquersw@gmail.com \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=yonghong.song@linux.dev \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).