linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Qiao <zhangqiao22@huawei.com>
To: Tejun Heo <tj@kernel.org>, <peterz@infradead.org>
Cc: <juri.lelli@redhat.com>, <linux-kernel@vger.kernel.org>,
	<mingo@redhat.com>, <vincent.guittot@linaro.org>
Subject: Re: [PATCH] kernel/sched: Fix sched_fork() access an invalid sched_task_group
Date: Tue, 31 Aug 2021 15:58:42 +0800	[thread overview]
Message-ID: <1f0cd867-9c6d-4e22-cadd-06af9f852f7a@huawei.com> (raw)
In-Reply-To: <YS0WF0sxr0ysb6Za@mtj.duckdns.org>


hi, thanks for your reviews.

On 2021/8/31 1:32, Tejun Heo wrote:
> Hello,
> 
> On Mon, Aug 30, 2021 at 04:39:54PM +0200, Peter Zijlstra wrote:
>>> When a new process is forked, cgroup_post_fork() associates it
>>> with the cgroup of its parent. Therefore this commit move the
>>> __set_task_cpu() and task_fork() that access some cgroup-related
>>> fields(sched_task_group and cfs_rq) to sched_post_fork() and
>>> call sched_post_fork() after cgroup_post_fork().
> 
> I think this would allow cgroup migrations to take place before
> sched_post_fork() is run, which likely will break stuff. The right
> thing to do likely is taking sched_task_group (and whatever other
> fields) after cgroup_can_fork(), which fixates the cgroup memberships,
But it still seems possible that it accessed an invalid sched_task_group?
because the child process does not update its sched_task_group util
cgroup_post_fork().
> is run. For other controllers, operations like this would be performed
> from cgroup_subsys->fork() callback but it's tricky for sched due to
> autogroup.
> 
>>> Fixes: 8323f26ce342 ("sched: Fix race in task_group")
>>> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
>>
>> Hmm, I think you're right. Did something recently chagne in cgroup land
>> to make this more visible? This code hasn't changed in like 9 years.
I think this problem has always existed. I've reproduced it in multiple versions,
including 3.10 and 5.14-rc3.

> 
> I can't think of any remotely recent change either. I guess ppl just
> don't try to migrate the parent while fork is in progress.
> 
> Thanks.
> 

thandks.

  reply	other threads:[~2021-08-31  7:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 11:26 [PATCH] kernel/sched: Fix sched_fork() access an invalid sched_task_group Zhang Qiao
2021-08-30 11:49 ` Zhang Qiao
2021-08-30 14:39 ` Peter Zijlstra
2021-08-30 17:32   ` Tejun Heo
2021-08-31  7:58     ` Zhang Qiao [this message]
2021-08-31 22:59       ` Tejun Heo
2021-09-01  7:43         ` Zhang Qiao
2021-09-01 16:45           ` Tejun Heo
2021-09-02  7:42             ` Zhang Qiao
2021-09-07 17:01               ` Tejun Heo
2021-09-08 11:32                 ` Zhang Qiao
2021-09-08 16:29                   ` Tejun Heo
2021-09-09  9:45                     ` Zhang Qiao

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=1f0cd867-9c6d-4e22-cadd-06af9f852f7a@huawei.com \
    --to=zhangqiao22@huawei.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    /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).