Revision b1dd693e5b9348bd68a80e679e03cf9c0973b01b authored by Daisuke Nishimura on 24 November 2010, 20:57:06 UTC, committed by Linus Torvalds on 24 November 2010, 21:50:44 UTC
__mem_cgroup_try_charge() can be called under down_write(&mmap_sem)(e.g.
mlock does it). This means it can cause deadlock if it races with move charge:

Ex.1)
                move charge             |        try charge
  --------------------------------------+------------------------------
    mem_cgroup_can_attach()             |  down_write(&mmap_sem)
      mc.moving_task = current          |    ..
      mem_cgroup_precharge_mc()         |  __mem_cgroup_try_charge()
        mem_cgroup_count_precharge()    |    prepare_to_wait()
          down_read(&mmap_sem)          |    if (mc.moving_task)
          -> cannot aquire the lock     |    -> true
                                        |      schedule()

Ex.2)
                move charge             |        try charge
  --------------------------------------+------------------------------
    mem_cgroup_can_attach()             |
      mc.moving_task = current          |
      mem_cgroup_precharge_mc()         |
        mem_cgroup_count_precharge()    |
          down_read(&mmap_sem)          |
          ..                            |
          up_read(&mmap_sem)            |
                                        |  down_write(&mmap_sem)
    mem_cgroup_move_task()              |    ..
      mem_cgroup_move_charge()          |  __mem_cgroup_try_charge()
        down_read(&mmap_sem)            |    prepare_to_wait()
        -> cannot aquire the lock       |    if (mc.moving_task)
                                        |    -> true
                                        |      schedule()

To avoid this deadlock, we do all the move charge works (both can_attach() and
attach()) under one mmap_sem section.
And after this patch, we set/clear mc.moving_task outside mc.lock, because we
use the lock only to check mc.from/to.

Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 11e7946
History
File Mode Size
crush
Kconfig -rw-r--r-- 753 bytes
Makefile -rw-r--r-- 766 bytes
armor.c -rw-r--r-- 1.9 KB
auth.c -rw-r--r-- 5.6 KB
auth_none.c -rw-r--r-- 2.9 KB
auth_none.h -rw-r--r-- 536 bytes
auth_x.c -rw-r--r-- 16.2 KB
auth_x.h -rw-r--r-- 847 bytes
auth_x_protocol.h -rw-r--r-- 1.7 KB
buffer.c -rw-r--r-- 1.4 KB
ceph_common.c -rw-r--r-- 11.9 KB
ceph_fs.c -rw-r--r-- 1.7 KB
ceph_hash.c -rw-r--r-- 2.7 KB
ceph_strings.c -rw-r--r-- 2.5 KB
crypto.c -rw-r--r-- 10.2 KB
crypto.h -rw-r--r-- 1.3 KB
debugfs.c -rw-r--r-- 6.5 KB
messenger.c -rw-r--r-- 60.7 KB
mon_client.c -rw-r--r-- 24.4 KB
msgpool.c -rw-r--r-- 1.5 KB
osd_client.c -rw-r--r-- 44.9 KB
osdmap.c -rw-r--r-- 26.6 KB
pagelist.c -rw-r--r-- 3.6 KB
pagevec.c -rw-r--r-- 4.5 KB

back to top