]> git.baikalelectronics.ru Git - kernel.git/commit
Remove deadlock potential in md_open
authorNeilBrown <neilb@suse.de>
Mon, 10 Aug 2009 02:50:52 +0000 (12:50 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 10 Aug 2009 02:50:52 +0000 (12:50 +1000)
commite79c440aabb24a1175d90bf8e2e0cb46d6edad16
treeecf06a9e2b08edefe707da450b52a69f818ec7d6
parent3d07f5310badf51ad2c76486c97e9ae1c19d6081
Remove deadlock potential in md_open

A recent commit:
  commit 5e2b48073e4632bb9cebf444c84baa32d2dca9a3

introduced the possibility of an A-B/B-A deadlock between
bd_mutex and reconfig_mutex.

__blkdev_get holds bd_mutex while calling md_open which takes
   reconfig_mutex,
do_md_run is always called with reconfig_mutex held, and it now
   takes bd_mutex in the call the revalidate_disk.

This potential deadlock was not caught by lockdep due to the
use of mutex_lock_interruptible_nexted which was introduced
by
   commit 118d9b150360a9727a96f9aa7a0f4336a02737c1
do avoid a warning of an impossible deadlock.

It is quite possible to split reconfig_mutex in to two locks.
One protects the array data structures while it is being
reconfigured, the other ensures that an array is never even partially
open while it is being deactivated.
In particular, the second lock prevents an open from completing
between the time when do_md_stop checks if there are any active opens,
and the time when the array is either set read-only, or when ->pers is
set to NULL.  So we can be certain that no IO is in flight as the
array is being destroyed.

So create a new lock, open_mutex, just to ensure exclusion between
'open' and 'stop'.

This avoids the deadlock and also avoids the lockdep warning mentioned
in commit 118d9b150

Reported-by: "Mike Snitzer" <snitzer@gmail.com>
Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/md.c
drivers/md/md.h