Skip to content

dm: separate device deletion from dm_put()

Kiyoshi Ueda dm-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3dm: prevent access to md being deleteddrivers/md/dm.c+1 -00 replies
2/3dm: release _hash_lock when removing device in remove_alldrivers/md/dm-ioctl.c+24 -220 replies
3/3dm: separate device deletion from dm_put()drivers/md/dm-ioctl.c drivers/md/dm.c drivers/md/dm.h+59 -202 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] dm: separate device deletion from dm_put()

Hi Alasdair,

This is an updated patch-set to fix bugs in device removal corner-cases, replacing the previous version found in:
https://patchwork.kernel.org/patch/83995/

Please review and take this patch-set instead.
This patch-set can be applied on top of 2.6.35-rc1 + your NEXT_PATCHES.

The patch-set contains 3 patches:
The 3rd patch is basically same as the one I posted before. The 1st patch is a new patch fixing possible NULL pointer dereference. The 2nd patch fixes a deadlock, which is introduced by the 3rd patch.

The deadlock is AB-BA deadlock between dm_hash_remove_all(), which waits for md->holders to be 0 with _hash_lock held, and other ioctls which waits for _hash_lock with md->holders held (e.g. table_status(), table_load()):
CPU0 CPU1
------------------------------------------------------------------
dm_hash_remove_all()

    down_write(_hash_lock)
                                  table_status()
                                    md = find_device()
                                           dm_get(md)
                                    dm_get_live_or_inactive_table()
                                      dm_get_inactive_table()
                                        down_write(_hash_lock)
    dm_destroy(md)
      while (md->holders)
        msleep(1)

To fix this deadlock problem, this patch-set changes dm_hash_remove_all() to release _hash_lock when removing a mapped_device, then, take _hash_lock and start over again.

Summary of the patch-set:
1/3: dm: prevent access to md being deleted
2/3: dm: release _hash_lock when removing device in remove_all 3/3: dm: separate device deletion from dm_put()

 drivers/md/dm-ioctl.c |   61 ++++++++++++++++++++++++++++----------------------
 drivers/md/dm.c       |   60 ++++++++++++++++++++++++++++++++++++-------------
 drivers/md/dm.h       |    5 ++++
 3 files changed, 84 insertions(+), 42 deletions(-)

Thanks,
Kiyoshi Ueda