cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly
authorWaiman Long <longman@redhat.com>
Tue, 11 Apr 2023 13:35:58 +0000 (09:35 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 12 Apr 2023 18:23:58 +0000 (08:23 -1000)
commit42a11bf5c5436e91b040aeb04063be1710bb9f9c
treeff02e5249b0b5f2e8f16c820c57c0339fd2e5217
parentba9182a89626d5f83c2ee4594f55cb9c1e60f0e2
cgroup/cpuset: Make cpuset_fork() handle CLONE_INTO_CGROUP properly

By default, the clone(2) syscall spawn a child process into the same
cgroup as its parent. With the use of the CLONE_INTO_CGROUP flag
introduced by commit ef2c41cf38a7 ("clone3: allow spawning processes
into cgroups"), the child will be spawned into a different cgroup which
is somewhat similar to writing the child's tid into "cgroup.threads".

The current cpuset_fork() method does not properly handle the
CLONE_INTO_CGROUP case where the cpuset of the child may be different
from that of its parent.  Update the cpuset_fork() method to treat the
CLONE_INTO_CGROUP case similar to cpuset_attach().

Since the newly cloned task has not been running yet, its actual
memory usage isn't known. So it is not necessary to make change to mm
in cpuset_fork().

Fixes: ef2c41cf38a7 ("clone3: allow spawning processes into cgroups")
Reported-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c