linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Qiao <zhangqiao22@huawei.com>
To: Waiman Long <longman@redhat.com>, <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>
Subject: Re: [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug
Date: Sat, 22 Jan 2022 15:54:09 +0800	[thread overview]
Message-ID: <12975f48-0419-9c34-8751-c3d3fca4f7b3@huawei.com> (raw)
In-Reply-To: <a166a39f-aa9f-95af-3f3f-f4e17e7c3305@redhat.com>



在 2022/1/21 20:43, Waiman Long 写道:
> 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 <zhaogongyi@huawei.com>
>> Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com>
>> ---
>>   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 <longman@redhat.com>
> 
Thanks for your review!

Regards,
Qiao
.

> .

  reply	other threads:[~2022-01-22  7:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 10:12 [PATCH] cgroup/cpuset: Fix a race between cpuset_attach() and cpu hotplug Zhang Qiao
2022-01-21 12:43 ` Waiman Long
2022-01-22  7:54   ` Zhang Qiao [this message]
2022-01-21 15:57 ` Michal Koutný
2022-01-22  7:37   ` Zhang Qiao
2022-02-07  6:17 ` Zhang Qiao
2022-02-14 19:50 ` Tejun Heo

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=12975f48-0419-9c34-8751-c3d3fca4f7b3@huawei.com \
    --to=zhangqiao22@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=bblum@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=longman@redhat.com \
    --cc=matthltc@us.ibm.com \
    --cc=menage@google.com \
    --cc=mkoutny@suse.com \
    --cc=tj@kernel.org \
    --cc=zhaogongyi@huawei.com \
    /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).