[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <nsh73lyuoctjbeudj7o35jrkcygnfehhwj5dbf4u3hdvawx54v@nz6l2v5q2iin>
Date: Fri, 31 Jan 2025 10:33:38 +0100
From: Michal Koutný <mkoutny@...e.com>
To: Shakeel Butt <shakeel.butt@...ux.dev>
Cc: Tejun Heo <tj@...nel.org>, Johannes Weiner <hannes@...xchg.org>,
Christian Brauner <brauner@...nel.org>, cgroups@...r.kernel.org, linux-kernel@...r.kernel.org,
Meta kernel team <kernel-team@...a.com>
Subject: Re: [PATCH] cgroup: fix race between fork and cgroup.kill
On Thu, Jan 30, 2025 at 04:05:42PM -0800, Shakeel Butt <shakeel.butt@...ux.dev> wrote:
> @@ -6668,6 +6668,7 @@ void cgroup_post_fork(struct task_struct *child,
> struct kernel_clone_args *kargs)
> __releases(&cgroup_threadgroup_rwsem) __releases(&cgroup_mutex)
> {
> + unsigned int cgrp_kill_seq = 0;
This initialization is only needed for the extra "init tasks" branch
(the value should equal to whatever init_css_set.dfl_cgroup has, i.e.
0).
> unsigned long cgrp_flags = 0;
> bool kill = false;
> struct cgroup_subsys *ss;
> @@ -6681,10 +6682,13 @@ void cgroup_post_fork(struct task_struct *child,
>
> /* init tasks are special, only link regular threads */
> if (likely(child->pid)) {
> - if (kargs->cgrp)
> + if (kargs->cgrp) {
> cgrp_flags = kargs->cgrp->flags;
> - else
> + cgrp_kill_seq = kargs->cgrp->kill_seq;
> + } else {
This should not be strictly necessary thanks to cgroup_mutex during
cgroup_kill and CLONE_INTO_CGROUP.
> cgrp_flags = cset->dfl_cgrp->flags;
> + cgrp_kill_seq = cset->dfl_cgrp->kill_seq;
> + }
>
> WARN_ON_ONCE(!list_empty(&child->cg_list));
> cset->nr_tasks++;
> @@ -6719,7 +6723,7 @@ void cgroup_post_fork(struct task_struct *child,
> * child down right after we finished preparing it for
> * userspace.
> */
> - kill = test_bit(CGRP_KILL, &cgrp_flags);
> + kill = kargs->kill_seq != cgrp_kill_seq;
> }
>
> spin_unlock_irq(&css_set_lock);
The above are only notes for better understanding, I don't think the fix
needs changes in that regard. Thanks
Reviewed-by: Michal Koutný <mkoutny@...e.com>
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists