cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm()
@ 2014-02-27 10:19 Li Zefan
  2014-02-27 10:19 ` [PATCH 2/2] cpuset: fix a race condition in __cpuset_node_allowed_softwall() Li Zefan
       [not found] ` <530F1117.1020605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Li Zefan @ 2014-02-27 10:19 UTC (permalink / raw)
  To: Tejun Heo; +Cc: LKML, Cgroups

I can trigger a lockdep warning:

  # mount -t cgroup -o cpuset xxx /cgroup
  # mkdir /cgroup/cpuset
  # mkdir /cgroup/tmp
  # echo 0 > /cgroup/tmp/cpuset.cpus
  # echo 0 > /cgroup/tmp/cpuset.mems
  # echo 1 > /cgroup/tmp/cpuset.memory_migrate
  # echo $$ > /cgroup/tmp/tasks
  # echo 1 > /cgruop/tmp/cpuset.mems

  ===============================
  [ INFO: suspicious RCU usage. ]
  3.14.0-rc1-0.1-default+ #32 Not tainted
  -------------------------------
  include/linux/cgroup.h:682 suspicious rcu_dereference_check() usage!
  ...
    [<ffffffff81582174>] dump_stack+0x72/0x86
    [<ffffffff810b8f01>] lockdep_rcu_suspicious+0x101/0x140
    [<ffffffff81105ba1>] cpuset_migrate_mm+0xb1/0xe0
  ...

We used to hold cgroup_mutex when calling cpuset_migrate_mm(), but now
we hold cpuset_mutex, which causes task_css() to complain.

This is not a false-positive but a real issue.

Holding cpuset_mutex won't prevent a task's cpuset from changing, and
it won't prevent the original task->cgroup from destroying during this
change.

Fixes: 5d21cc2db040 (cpuset: replace cgroup_mutex locking with cpuset internal locking)
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> # 3.9+
Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 kernel/cpuset.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index d8bec21..5f50ec6 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -948,12 +948,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
  *    Temporarilly set tasks mems_allowed to target nodes of migration,
  *    so that the migration code can allocate pages on these nodes.
  *
- *    Call holding cpuset_mutex, so current's cpuset won't change
- *    during this call, as manage_mutex holds off any cpuset_attach()
- *    calls.  Therefore we don't need to take task_lock around the
- *    call to guarantee_online_mems(), as we know no one is changing
- *    our task's cpuset.
- *
  *    While the mm_struct we are migrating is typically from some
  *    other task, the task_struct mems_allowed that we are hacking
  *    is for our current task, which must allocate new pages for that
@@ -970,8 +964,10 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
 
 	do_migrate_pages(mm, from, to, MPOL_MF_MOVE_ALL);
 
+	rcu_read_lock();
 	mems_cs = effective_nodemask_cpuset(task_cs(tsk));
 	guarantee_online_mems(mems_cs, &tsk->mems_allowed);
+	rcu_read_unlock();
 }
 
 /*
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] cpuset: fix a race condition in __cpuset_node_allowed_softwall()
  2014-02-27 10:19 [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm() Li Zefan
@ 2014-02-27 10:19 ` Li Zefan
       [not found]   ` <530F1138.2090903-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
       [not found] ` <530F1117.1020605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Li Zefan @ 2014-02-27 10:19 UTC (permalink / raw)
  To: Tejun Heo; +Cc: LKML, Cgroups

It's not safe to access task's cpuset after releasing task_lock().
Holding callback_mutex won't help.

Cc: <stable@vger.kernel.org>
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
 kernel/cpuset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 5f50ec6..c63a0d9 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -2412,9 +2412,9 @@ int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask)
 
 	task_lock(current);
 	cs = nearest_hardwall_ancestor(task_cs(current));
+	allowed = node_isset(node, cs->mems_allowed);
 	task_unlock(current);
 
-	allowed = node_isset(node, cs->mems_allowed);
 	mutex_unlock(&callback_mutex);
 	return allowed;
 }
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm()
       [not found] ` <530F1117.1020605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2014-02-27 10:29   ` Li Zefan
  2014-02-27 14:37   ` Tejun Heo
  1 sibling, 0 replies; 5+ messages in thread
From: Li Zefan @ 2014-02-27 10:29 UTC (permalink / raw)
  To: Tejun Heo; +Cc: LKML, Cgroups

On 2014/2/27 18:19, Li Zefan wrote:
> I can trigger a lockdep warning:
> 
>   # mount -t cgroup -o cpuset xxx /cgroup
>   # mkdir /cgroup/cpuset
>   # mkdir /cgroup/tmp
>   # echo 0 > /cgroup/tmp/cpuset.cpus
>   # echo 0 > /cgroup/tmp/cpuset.mems
>   # echo 1 > /cgroup/tmp/cpuset.memory_migrate
>   # echo $$ > /cgroup/tmp/tasks
>   # echo 1 > /cgruop/tmp/cpuset.mems
> 
>   ===============================
>   [ INFO: suspicious RCU usage. ]
>   3.14.0-rc1-0.1-default+ #32 Not tainted
>   -------------------------------
>   include/linux/cgroup.h:682 suspicious rcu_dereference_check() usage!
>   ...
>     [<ffffffff81582174>] dump_stack+0x72/0x86
>     [<ffffffff810b8f01>] lockdep_rcu_suspicious+0x101/0x140
>     [<ffffffff81105ba1>] cpuset_migrate_mm+0xb1/0xe0
>   ...
> 
> We used to hold cgroup_mutex when calling cpuset_migrate_mm(), but now
> we hold cpuset_mutex, which causes task_css() to complain.
> 
> This is not a false-positive but a real issue.
> 
> Holding cpuset_mutex won't prevent a task's cpuset from changing, and

I meant it won't prevent a task from migrating to another cpuset.

> it won't prevent the original task->cgroup from destroying during this
> change.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm()
       [not found] ` <530F1117.1020605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  2014-02-27 10:29   ` [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm() Li Zefan
@ 2014-02-27 14:37   ` Tejun Heo
  1 sibling, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2014-02-27 14:37 UTC (permalink / raw)
  To: Li Zefan; +Cc: LKML, Cgroups

On Thu, Feb 27, 2014 at 06:19:03PM +0800, Li Zefan wrote:
> I can trigger a lockdep warning:
> 
>   # mount -t cgroup -o cpuset xxx /cgroup
>   # mkdir /cgroup/cpuset
>   # mkdir /cgroup/tmp
>   # echo 0 > /cgroup/tmp/cpuset.cpus
>   # echo 0 > /cgroup/tmp/cpuset.mems
>   # echo 1 > /cgroup/tmp/cpuset.memory_migrate
>   # echo $$ > /cgroup/tmp/tasks
>   # echo 1 > /cgruop/tmp/cpuset.mems
> 
>   ===============================
>   [ INFO: suspicious RCU usage. ]
>   3.14.0-rc1-0.1-default+ #32 Not tainted
>   -------------------------------
>   include/linux/cgroup.h:682 suspicious rcu_dereference_check() usage!
>   ...
>     [<ffffffff81582174>] dump_stack+0x72/0x86
>     [<ffffffff810b8f01>] lockdep_rcu_suspicious+0x101/0x140
>     [<ffffffff81105ba1>] cpuset_migrate_mm+0xb1/0xe0
>   ...
> 
> We used to hold cgroup_mutex when calling cpuset_migrate_mm(), but now
> we hold cpuset_mutex, which causes task_css() to complain.
> 
> This is not a false-positive but a real issue.
> 
> Holding cpuset_mutex won't prevent a task's cpuset from changing, and
> it won't prevent the original task->cgroup from destroying during this
> change.
> 
> Fixes: 5d21cc2db040 (cpuset: replace cgroup_mutex locking with cpuset internal locking)
> Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> # 3.9+
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

Applied to cgroup/for-3.14-fixes.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] cpuset: fix a race condition in __cpuset_node_allowed_softwall()
       [not found]   ` <530F1138.2090903-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2014-02-27 14:40     ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2014-02-27 14:40 UTC (permalink / raw)
  To: Li Zefan; +Cc: LKML, Cgroups

On Thu, Feb 27, 2014 at 06:19:36PM +0800, Li Zefan wrote:
> It's not safe to access task's cpuset after releasing task_lock().
> Holding callback_mutex won't help.
> 
> Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

Applied to cgroup/for-3.14-fixes.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-27 14:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-27 10:19 [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm() Li Zefan
2014-02-27 10:19 ` [PATCH 2/2] cpuset: fix a race condition in __cpuset_node_allowed_softwall() Li Zefan
     [not found]   ` <530F1138.2090903-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-02-27 14:40     ` Tejun Heo
     [not found] ` <530F1117.1020605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-02-27 10:29   ` [PATCH 1/2] cpuset: fix a locking issue in cpuset_migrate_mm() Li Zefan
2014-02-27 14:37   ` Tejun Heo

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).