Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp464803pxb; Wed, 8 Sep 2021 05:24:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHdENA8mpxCZh9C9uGB01Nff+n4w1fRwF2DXs6Q52ISirlZ2YsAFu/cZYW0NzVgYj4GFOJ X-Received: by 2002:a92:db0c:: with SMTP id b12mr2612418iln.171.1631103899035; Wed, 08 Sep 2021 05:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631103899; cv=none; d=google.com; s=arc-20160816; b=sIihzQ21TrNcTCjQQV1FP13oMlCFjI1GqQl9o+aVHh5COasD8AAbfPy3aMz9dCRvQu Bmvd8YGxYym5X5ZHgTVhpJSr0L/tAlOisAHFk4uqeIDsRAlEd1E0lK4PuaAqOh0MDUIa S2w1uvfA5qoUHK+4FCbvmsCtbSxBVyRZNKURLtqZN5SMloA1lwXOeuzQorW/S9p6lj1H WBEm6OcX1V5iD7ofdIK2oBlYX3ucsAGHKJ47mqZGArGWVWH6KR/prc2YCHF6xklcb0J+ Hh7aYGeec9CPY4NRXYm/jRjcwsKT+q0L+lSQ3oohiP0cVcyCegbeR+ZSUI8IZQ1lBBzu xoWg== 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:references:cc:to :subject; bh=u2ImlLsDQw1vB5ELyUbLmNVuSp4rEExvDmh06KZiilw=; b=M57kv+AmWxYAQDpuW9UosVtu7OMtuclHqN6KPpfRoFOsPAqfhuPaW8qHCQ6N3c+OIA 3Oida55r8aPiLDv85LFbMM+zR+EtufaJyCbJpWUX6NSIgKRPnwvJYKcpQTrohnYPI7Q7 6K9xeRRT0FHeBNmqRfavaIKymWjyz8MtiLoU9R3O6fP2fpusqa1VTkiYgQMuHzflXiEV UHOIsKeVO7lpsof/yjoHE4QvFIfFifGv5coRCaq4SLTyURbEa476t2mNGxYiRX/lLA6T dxYPqa3QiaFoI4ZmcK64ZEGsfAA8lSz80uk+aR6+dU3m79YsLLMQ8FdNXwlZGob1N21h zoIg== 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 a2si1897974ilf.15.2021.09.08.05.24.37; Wed, 08 Sep 2021 05:24:59 -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 S1348337AbhIHLdX (ORCPT + 99 others); Wed, 8 Sep 2021 07:33:23 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:15394 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbhIHLdQ (ORCPT ); Wed, 8 Sep 2021 07:33:16 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H4Kd20KKczQmXZ; Wed, 8 Sep 2021 19:28:06 +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.2308.8; Wed, 8 Sep 2021 19:32:06 +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.2308.8; Wed, 8 Sep 2021 19:32:06 +0800 Subject: Re: [PATCH] kernel/sched: Fix sched_fork() access an invalid sched_task_group To: Tejun Heo CC: , , , , References: <20210826112635.7404-1-zhangqiao22@huawei.com> <1f0cd867-9c6d-4e22-cadd-06af9f852f7a@huawei.com> <128d52ab-b4ee-65f8-e0a3-2796ef43a98b@huawei.com> <3df62791-d123-db9b-ec9c-092c47a941cc@huawei.com> From: Zhang Qiao In-Reply-To: Message-ID: Date: Wed, 8 Sep 2021 19:32:06 +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 On 2021/9/8 1:01, Tejun Heo wrote: > Hello, > > On Thu, Sep 02, 2021 at 03:42:15PM +0800, Zhang Qiao wrote: >> I checked the code again. >> I don't quite understand what you said, if the child be moved between >> cgroup_post_fork() and sched_post_sched(), what problems might it cause? > > cgroup_post_fork() is where the child's creation is committed from cgroup's > POV, so it'd be migrating cgroups before the initial creation is finished. >>From glancing, looks like it'll break css_set task counts to begin with. > This violates the basic assumptions and can cause critical failures in > subtle ways. The would replace one subtle race with a possibly worse one. Hello, I will update this patch by following the steps below: 1)rename cgroup_subsys->fork() to cgroup_subsys->post_fork(); 2)add cgroup_subsys->fork() and the cpu_cgroup_fork() callback like this: void cpu_cgroup_fork(struct task_struct *task) { .... p->sched_task_group = task_group(current); __set_task_cpu(p, smp_processor_id()); if (p->sched_class->task_fork) p->sched_class->task_fork(p); .... 3)call cgroup_subsys->fork() after cgroup_can_fork(). Do you have any suggestion? thanks. Zhang Qiao > > Thanks. >