From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB2EAC433F5 for ; Fri, 21 Jan 2022 12:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380438AbiAUMnV (ORCPT ); Fri, 21 Jan 2022 07:43:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35627 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350560AbiAUMnT (ORCPT ); Fri, 21 Jan 2022 07:43:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642768999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4npqjtp4XyHuyXZdSlqBznaQ1OqDTHRAdb5cB+lM/zc=; b=DeUOPTRcJGu4oId4TxPl9t9gIWoEnKTzJPHYddcmE7c2pf5DA1yQnSlKCpeEHTWaqOZYMY GvPSZHJCWACePgv9gf3D3H0yycASLCqojWHARO8YSgxgw1p2350u+ckanQgretEh9F3ufF BIShVDKWuJZ3dEO9Zqvxeti6rdBRXVY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-1ueiQlrZOEm5vfO2ZKx8Qg-1; Fri, 21 Jan 2022 07:43:13 -0500 X-MC-Unique: 1ueiQlrZOEm5vfO2ZKx8Qg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B8C91006AA5; Fri, 21 Jan 2022 12:43:11 +0000 (UTC) Received: from [10.22.16.178] (unknown [10.22.16.178]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D6697AB75; Fri, 21 Jan 2022 12:43:09 +0000 (UTC) Message-ID: Date: Fri, 21 Jan 2022 07:43:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug Content-Language: en-US To: Zhang Qiao , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Cc: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org, matthltc@us.ibm.com, bblum@google.com, menage@google.com, akpm@linux-foundation.org, mkoutny@suse.com, zhaogongyi@huawei.com References: <20220121101210.84926-1-zhangqiao22@huawei.com> From: Waiman Long In-Reply-To: <20220121101210.84926-1-zhangqiao22@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/21/22 05:12, Zhang Qiao wrote: > As previously discussed(https://lkml.org/lkml/2022/1/20/51), > cpuset_attach() is affected with similar cpu hotplug race, > as follow scenario: > > cpuset_attach() cpu hotplug > --------------------------- ---------------------- > down_write(cpuset_rwsem) > guarantee_online_cpus() // (load cpus_attach) > sched_cpu_deactivate > set_cpu_active() > // will change cpu_active_mask > set_cpus_allowed_ptr(cpus_attach) > __set_cpus_allowed_ptr_locked() > // (if the intersection of cpus_attach and > cpu_active_mask is empty, will return -EINVAL) > up_write(cpuset_rwsem) > > To avoid races such as described above, protect cpuset_attach() call > with cpu_hotplug_lock. > > Fixes: be367d099270 ("cgroups: let ss->can_attach and ss->attach do whole threadgroups at a time") > Reported-by: Zhao Gongyi > Signed-off-by: Zhang Qiao > --- > kernel/cgroup/cpuset.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index dc653ab26e50..0af5725cc1df 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -2252,6 +2252,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) > cgroup_taskset_first(tset, &css); > cs = css_cs(css); > > + cpus_read_lock(); > percpu_down_write(&cpuset_rwsem); > > guarantee_online_mems(cs, &cpuset_attach_nodemask_to); > @@ -2305,6 +2306,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) > wake_up(&cpuset_attach_wq); > > percpu_up_write(&cpuset_rwsem); > + cpus_read_unlock(); > } > > /* The various types of files and directories in a cpuset file system */ > -- > 2.18.0 The locking sequence looks right. Acked-by: Waiman Long