From: Prateek Sood <prsood@codeaurora.org>
To: Tejun Heo <tj@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
avagin@gmail.com, mingo@kernel.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, sramana@codeaurora.org
Subject: Re: [PATCH] cgroup/cpuset: fix circular locking dependency
Date: Wed, 13 Dec 2017 19:58:24 +0530 [thread overview]
Message-ID: <c54d904e-13bc-8e2b-c9c1-8bf9cb8a33a3@codeaurora.org> (raw)
In-Reply-To: <20171211153258.GI2421075@devbig577.frc2.facebook.com>
On 12/11/2017 09:02 PM, Tejun Heo wrote:
> Hello, Prateek.
>
> On Fri, Dec 08, 2017 at 05:15:55PM +0530, Prateek Sood wrote:
>> There is one deadlock issue during cgroup migration from cpu
>> hotplug path when a task T is being moved from source to
>> destination cgroup.
>>
>> kworker/0:0
>> cpuset_hotplug_workfn()
>> cpuset_hotplug_update_tasks()
>> hotplug_update_tasks_legacy()
>> remove_tasks_in_empty_cpuset()
>> cgroup_transfer_tasks() // stuck in iterator loop
>> cgroup_migrate()
>> cgroup_migrate_add_task()
>>
>> In cgroup_migrate_add_task() it checks for PF_EXITING flag of task T.
>> Task T will not migrate to destination cgroup. css_task_iter_start()
>> will keep pointing to task T in loop waiting for task T cg_list node
>> to be removed.
>
> Heh, that's a bug in cgroup_transfer_tasks() which happened because I
> forgot to update when we changed how we handle exiting tasks. The
> right thing to do here is making cgroup_transfer_tasks() repeat iff
> there were a valid migration target which didn't get transferred.
>
> Thanks.
>
Hi TJ,
Did you mean something like below. If not then could you
please share a patch for this problem in
cgroup_transfer_tasks().
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 473e0c0..41de618 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -143,6 +143,8 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset,
void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
struct css_task_iter *it);
+void css_task_migrate_iter_start(struct cgroup_subsys_state *css,
+ unsigned int flags, struct css_task_iter *it);
struct task_struct *css_task_iter_next(struct css_task_iter *it);
void css_task_iter_end(struct css_task_iter *it);
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index 024085d..12279ae 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -122,7 +122,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
* ->can_attach() fails.
*/
do {
- css_task_iter_start(&from->self, 0, &it);
+ css_task_migrate_iter_start(&from->self, 0, &it);
task = css_task_iter_next(&it);
if (task)
get_task_struct(task);
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 0b1ffe1..3c1d2d2 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4189,6 +4189,42 @@ void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
spin_unlock_irq(&css_set_lock);
}
+void css_task_migrate_iter_start(struct cgroup_subsys_state *css,
+ unsigned int flags, struct css_task_iter *it)
+{
+ struct task_struct *task = NULL;
+ /* no one should try to iterate before mounting cgroups */
+ WARN_ON_ONCE(!use_task_css_set_links);
+
+ memset(it, 0, sizeof(*it));
+
+ spin_lock_irq(&css_set_lock);
+
+ it->ss = css->ss;
+ it->flags = flags;
+
+ if (it->ss)
+ it->cset_pos = &css->cgroup->e_csets[css->ss->id];
+ else
+ it->cset_pos = &css->cgroup->cset_links;
+
+ it->cset_head = it->cset_pos;
+
+ css_task_iter_advance_css_set(it);
+
+ while (it->task_pos) {
+ task = list_entry(it->task_pos, struct task_struct,
+ cg_list);
+
+ if (likely(!(task->flags & PF_EXITING)))
+ break;
+
+ css_task_iter_advance(it);
+ }
+
+ spin_unlock_irq(&css_set_lock);
+}
+
/**
* css_task_iter_next - return the next task for the iterator
* @it: the task iterator being iterated
Thanks
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation
Center, Inc., is a member of Code Aurora Forum, a Linux Foundation
Collaborative Project
next prev parent reply other threads:[~2017-12-13 14:28 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CANaxB-zT+sz=z1FFk5npnwMySdfKCBZDkM+P+=JXDkCXbh=rCw@mail.gmail.com>
2017-11-28 11:35 ` Prateek Sood
2017-12-04 5:14 ` Prateek Sood
2017-12-04 20:22 ` Tejun Heo
2017-12-04 22:58 ` Tejun Heo
2017-12-04 23:01 ` Peter Zijlstra
2017-12-08 9:40 ` Prateek Sood
2017-12-08 11:45 ` Prateek Sood
2017-12-11 15:32 ` Tejun Heo
2017-12-13 14:28 ` Prateek Sood [this message]
2017-12-13 15:40 ` Tejun Heo
2017-12-15 8:54 ` Prateek Sood
2017-12-15 13:22 ` Tejun Heo
2017-12-15 19:06 ` Prateek Sood
2017-12-19 7:26 ` [PATCH] cgroup: Fix deadlock in cpu hotplug path Prateek Sood
2017-12-19 13:39 ` Tejun Heo
2017-12-11 15:20 ` [PATCH] cgroup/cpuset: fix circular locking dependency Tejun Heo
2017-12-13 7:50 ` Prateek Sood
2017-12-13 16:06 ` Tejun Heo
2017-12-15 19:04 ` Prateek Sood
2017-12-28 20:37 ` Prateek Sood
2018-01-02 16:16 ` Tejun Heo
2018-01-02 17:44 ` Paul E. McKenney
2018-01-02 18:01 ` Paul E. McKenney
2018-01-08 12:28 ` Tejun Heo
2018-01-08 13:47 ` [PATCH wq/for-4.16 1/2] workqueue: separate out init_rescuer() Tejun Heo
2018-01-08 13:47 ` [PATCH wq/for-4.16 2/2] workqueue: allow WQ_MEM_RECLAIM on early init workqueues Tejun Heo
2018-01-08 22:52 ` [PATCH] cgroup/cpuset: fix circular locking dependency Paul E. McKenney
2018-01-09 0:31 ` Paul E. McKenney
2018-01-09 3:42 ` Tejun Heo
2018-01-09 4:20 ` Paul E. McKenney
2018-01-09 13:44 ` Tejun Heo
2018-01-09 15:21 ` Paul E. McKenney
2018-01-09 15:37 ` Tejun Heo
2018-01-09 16:00 ` Paul E. McKenney
2018-01-10 20:08 ` Paul E. McKenney
2018-01-10 21:41 ` Tejun Heo
2018-01-10 22:10 ` Paul E. McKenney
2018-01-15 12:02 ` Prateek Sood
2018-01-16 16:27 ` 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=c54d904e-13bc-8e2b-c9c1-8bf9cb8a33a3@codeaurora.org \
--to=prsood@codeaurora.org \
--cc=avagin@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=sramana@codeaurora.org \
--cc=tj@kernel.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
all inboxes | Powered by JetHome®