Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4282490pxb; Tue, 31 Aug 2021 01:00:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyT7Ss6SLJsFtqwKK9YOlKgSn+RbHc1HsQ8e3EGm9QWU9rFUyglb3VGIWrPPd5rPIY3KjbH X-Received: by 2002:a05:6e02:e42:: with SMTP id l2mr19341207ilk.285.1630396850740; Tue, 31 Aug 2021 01:00:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630396850; cv=none; d=google.com; s=arc-20160816; b=cdhvA3mIgJlPyOYeopVLtJOqHkdO+dwZqBjj2oTfqy0dL6V6n13ZaOq5/spEegb1FK pUMOerNPJgAp7ddlSsgc7GRomT/mponAWuDyjhoqnEBMgiRf6nSZwZqCe9XxRW4Ne3Oi aSBRz5037k8sCKAF/Dt0h5jajJB3/IkgmLlB9F5MYj3LFNhHWCEFwzwaAoQpcH4GdUq6 XkmDRrpR8b8xYWUlqHBK0fhD7NbwtAMQ7Us3aA7QtPsOMFB1x0teaHlkubGOxc8l8YIx d/x8IAXDYAb8Uxbuf/SGuJnHojcgPkjgBOJG5P8q7lBPSrR2mdYIps+OwhPWZp33FvcF xqtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:message-id:in-reply-to:from:cc:references:to :subject; bh=zvKWweN0fABz52gAbM3QEk8nSahHjeObxgUdKZfAHg0=; b=hUK0K4z9kTQY6PKPYhTb8eOnfFsyQU+HvL510um8RqOF/u13SfXma4X/So0RU0FCEG gI466vIFiyoyeX9EclSeCxkTRl1ALtRnn2gkKRCoemIOteXxINwpsM9oQdiZ/UdnwJH/ +MMlzzVk9RJ6y4O8CV2gpMncIlGsL+vXkF9VWHRQa29LiUpAKLijBbEqtgnQT2vi9ji5 10AibQqI/XsXOvSZ8JDVGoTPwbXG27gMTREl93M8P1+j32n++eqcAm3R42EM3EzxbANg o6HzVaXeoSOFz8MWMF2e6iSNX6aYJdujD7/mH5tXUpfJysK6fTLQ77dkbm5ctO9hsEcq Ynaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si13254892jac.2.2021.08.31.01.00.38; Tue, 31 Aug 2021 01:00:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240115AbhHaIAB (ORCPT + 99 others); Tue, 31 Aug 2021 04:00:01 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:14439 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240072AbhHaH7p (ORCPT ); Tue, 31 Aug 2021 03:59:45 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GzKGc31y1zbft8; Tue, 31 Aug 2021 15:54:48 +0800 (CST) Received: from dggpeml500018.china.huawei.com (7.185.36.186) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 31 Aug 2021 15:58:43 +0800 Received: from [10.67.101.251] (10.67.101.251) by dggpeml500018.china.huawei.com (7.185.36.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 31 Aug 2021 15:58:42 +0800 Subject: Re: [PATCH] kernel/sched: Fix sched_fork() access an invalid sched_task_group To: Tejun Heo , References: <20210826112635.7404-1-zhangqiao22@huawei.com> CC: , , , From: Zhang Qiao In-Reply-To: Message-ID: <1f0cd867-9c6d-4e22-cadd-06af9f852f7a@huawei.com> Date: Tue, 31 Aug 2021 15:58:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.101.251] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500018.china.huawei.com (7.185.36.186) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >> >> 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.