<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/drivers/md/md.c, branch v4.9.87</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>md: only allow remove_and_add_spares when no sync_thread running.</title>
<updated>2018-03-11T15:21:31+00:00</updated>
<author>
<name>NeilBrown</name>
<email>neilb@suse.com</email>
</author>
<published>2018-02-02T22:19:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=eb2593fbd643f68a557b62141106788242183954'/>
<id>eb2593fbd643f68a557b62141106788242183954</id>
<content type='text'>
commit 39772f0a7be3b3dc26c74ea13fe7847fd1522c8b upstream.

The locking protocols in md assume that a device will
never be removed from an array during resync/recovery/reshape.
When that isn't happening, rcu or reconfig_mutex is needed
to protect an rdev pointer while taking a refcount.  When
it is happening, that protection isn't needed.

Unfortunately there are cases were remove_and_add_spares() is
called when recovery might be happening: is state_store(),
slot_store() and hot_remove_disk().
In each case, this is just an optimization, to try to expedite
removal from the personality so the device can be removed from
the array.  If resync etc is happening, we just have to wait
for md_check_recover to find a suitable time to call
remove_and_add_spares().

This optimization and not essential so it doesn't
matter if it fails.
So change remove_and_add_spares() to abort early if
resync/recovery/reshape is happening, unless it is called
from md_check_recovery() as part of a newly started recovery.
The parameter "this" is only NULL when called from
md_check_recovery() so when it is NULL, there is no need to abort.

As this can result in a NULL dereference, the fix is suitable
for -stable.

cc: yuyufen &lt;yuyufen@huawei.com&gt;
Cc: Tomasz Majchrzak &lt;tomasz.majchrzak@intel.com&gt;
Fixes: 8430e7e0af9a ("md: disconnect device from personality before trying to remove it.")
Cc: stable@ver.kernel.org (v4.8+)
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;sh.li@alibaba-inc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 39772f0a7be3b3dc26c74ea13fe7847fd1522c8b upstream.

The locking protocols in md assume that a device will
never be removed from an array during resync/recovery/reshape.
When that isn't happening, rcu or reconfig_mutex is needed
to protect an rdev pointer while taking a refcount.  When
it is happening, that protection isn't needed.

Unfortunately there are cases were remove_and_add_spares() is
called when recovery might be happening: is state_store(),
slot_store() and hot_remove_disk().
In each case, this is just an optimization, to try to expedite
removal from the personality so the device can be removed from
the array.  If resync etc is happening, we just have to wait
for md_check_recover to find a suitable time to call
remove_and_add_spares().

This optimization and not essential so it doesn't
matter if it fails.
So change remove_and_add_spares() to abort early if
resync/recovery/reshape is happening, unless it is called
from md_check_recovery() as part of a newly started recovery.
The parameter "this" is only NULL when called from
md_check_recovery() so when it is NULL, there is no need to abort.

As this can result in a NULL dereference, the fix is suitable
for -stable.

cc: yuyufen &lt;yuyufen@huawei.com&gt;
Cc: Tomasz Majchrzak &lt;tomasz.majchrzak@intel.com&gt;
Fixes: 8430e7e0af9a ("md: disconnect device from personality before trying to remove it.")
Cc: stable@ver.kernel.org (v4.8+)
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;sh.li@alibaba-inc.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: fix super_offset endianness in super_1_rdev_size_change</title>
<updated>2017-07-15T10:16:15+00:00</updated>
<author>
<name>Jason Yan</name>
<email>yanaijie@huawei.com</email>
</author>
<published>2017-03-10T03:27:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3953403ca660817a33e7f7ad65a265facc0e59c7'/>
<id>3953403ca660817a33e7f7ad65a265facc0e59c7</id>
<content type='text'>
commit 3fb632e40d7667d8bedfabc28850ac06d5493f54 upstream.

The sb-&gt;super_offset should be big-endian, but the rdev-&gt;sb_start is in
host byte order, so fix this by adding cpu_to_le64.

Signed-off-by: Jason Yan &lt;yanaijie@huawei.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 3fb632e40d7667d8bedfabc28850ac06d5493f54 upstream.

The sb-&gt;super_offset should be big-endian, but the rdev-&gt;sb_start is in
host byte order, so fix this by adding cpu_to_le64.

Signed-off-by: Jason Yan &lt;yanaijie@huawei.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: fix incorrect use of lexx_to_cpu in does_sb_need_changing</title>
<updated>2017-07-15T10:16:15+00:00</updated>
<author>
<name>Jason Yan</name>
<email>yanaijie@huawei.com</email>
</author>
<published>2017-03-10T03:49:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9a37d02c497cd839beee3e0cab0fc606bcfe08bf'/>
<id>9a37d02c497cd839beee3e0cab0fc606bcfe08bf</id>
<content type='text'>
commit 1345921393ba23b60d3fcf15933e699232ad25ae upstream.

The sb-&gt;layout is of type __le32, so we shoud use le32_to_cpu.

Signed-off-by: Jason Yan &lt;yanaijie@huawei.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 1345921393ba23b60d3fcf15933e699232ad25ae upstream.

The sb-&gt;layout is of type __le32, so we shoud use le32_to_cpu.

Signed-off-by: Jason Yan &lt;yanaijie@huawei.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop</title>
<updated>2017-05-25T13:44:33+00:00</updated>
<author>
<name>NeilBrown</name>
<email>neilb@suse.com</email>
</author>
<published>2017-04-06T03:16:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7e789787878321fc2b1b7869963fa5eeede7402e'/>
<id>7e789787878321fc2b1b7869963fa5eeede7402e</id>
<content type='text'>
commit 065e519e71b2c1f41936cce75b46b5ab34adb588 upstream.

if called md_set_readonly and set MD_CLOSING bit, the mddev cannot
be opened any more due to the MD_CLOING bit wasn't cleared. Thus it
needs to be cleared in md_ioctl after any call to md_set_readonly()
or do_md_stop().

Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: Zhilong Liu &lt;zlliu@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 065e519e71b2c1f41936cce75b46b5ab34adb588 upstream.

if called md_set_readonly and set MD_CLOSING bit, the mddev cannot
be opened any more due to the MD_CLOING bit wasn't cleared. Thus it
needs to be cleared in md_ioctl after any call to md_set_readonly()
or do_md_stop().

Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: Zhilong Liu &lt;zlliu@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: fix refcount problem on mddev when stopping array.</title>
<updated>2017-01-12T10:39:35+00:00</updated>
<author>
<name>NeilBrown</name>
<email>neilb@suse.com</email>
</author>
<published>2016-12-05T05:40:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5cc85ef4ffe6c3f1d35b75975c5731248c5af4a7'/>
<id>5cc85ef4ffe6c3f1d35b75975c5731248c5af4a7</id>
<content type='text'>
commit e2342ca832726a840ca6bd196dd2cc073815b08a upstream.

md_open() gets a counted reference on an mddev using mddev_find().
If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped.
One only happens if the process is signalled and an awkward time,
which is quite unlikely.
The other was introduced recently in commit af8d8e6f0.

Change the code to ensure the drop the reference when returning an error,
and make it harded to re-introduce this sort of bug in the future.

Reported-by: Marc Smith &lt;marc.smith@mcc.edu&gt;
Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Acked-by: Guoqing Jiang &lt;gqjiang@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit e2342ca832726a840ca6bd196dd2cc073815b08a upstream.

md_open() gets a counted reference on an mddev using mddev_find().
If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped.
One only happens if the process is signalled and an awkward time,
which is quite unlikely.
The other was introduced recently in commit af8d8e6f0.

Change the code to ensure the drop the reference when returning an error,
and make it harded to re-introduce this sort of bug in the future.

Reported-by: Marc Smith &lt;marc.smith@mcc.edu&gt;
Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Acked-by: Guoqing Jiang &lt;gqjiang@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: MD_RECOVERY_NEEDED is set for mddev-&gt;recovery</title>
<updated>2017-01-12T10:39:34+00:00</updated>
<author>
<name>Shaohua Li</name>
<email>shli@fb.com</email>
</author>
<published>2016-12-08T23:48:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=60a931c20d1a401b79ff742142225c300d545af0'/>
<id>60a931c20d1a401b79ff742142225c300d545af0</id>
<content type='text'>
commit 82a301cb0ea2df8a5c88213094a01660067c7fb4 upstream.

Fixes: 90f5f7ad4f38("md: Wait for md_check_recovery before attempting device
removal.")

Reviewed-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 82a301cb0ea2df8a5c88213094a01660067c7fb4 upstream.

Fixes: 90f5f7ad4f38("md: Wait for md_check_recovery before attempting device
removal.")

Reviewed-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>md: be careful not lot leak internal curr_resync value into metadata. -- (all)</title>
<updated>2016-10-29T05:04:05+00:00</updated>
<author>
<name>NeilBrown</name>
<email>neilb@suse.com</email>
</author>
<published>2016-10-28T04:59:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1217e1d1999ed6c9c1e1b1acae0a74ab70464ae2'/>
<id>1217e1d1999ed6c9c1e1b1acae0a74ab70464ae2</id>
<content type='text'>
mddev-&gt;curr_resync usually records where the current resync is up to,
but during the starting phase it has some "magic" values.

 1 - means that the array is trying to start a resync, but has yielded
     to another array which shares physical devices, and also needs to
     start a resync
 2 - means the array is trying to start resync, but has found another
     array which shares physical devices and has already started resync.

 3 - means that resync has commensed, but it is possible that nothing
     has actually been resynced yet.

It is important that this value not be visible to user-space and
particularly that it doesn't get written to the metadata, as the
resync or recovery checkpoint.  In part, this is because it may be
slightly higher than the correct value, though this is very rare.
In part, because it is not a multiple of 4K, and some devices only
support 4K aligned accesses.

There are two places where this value is propagates into either
-&gt;curr_resync_completed or -&gt;recovery_cp or -&gt;recovery_offset.
These currently avoid the propagation of values 1 and 3, but will
allow 3 to leak through.

Change them to only propagate the value if it is &gt; 3.

As this can cause an array to fail, the patch is suitable for -stable.

Cc: stable@vger.kernel.org (v3.7+)
Reported-by: Viswesh &lt;viswesh.vichu@gmail.com&gt;
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
mddev-&gt;curr_resync usually records where the current resync is up to,
but during the starting phase it has some "magic" values.

 1 - means that the array is trying to start a resync, but has yielded
     to another array which shares physical devices, and also needs to
     start a resync
 2 - means the array is trying to start resync, but has found another
     array which shares physical devices and has already started resync.

 3 - means that resync has commensed, but it is possible that nothing
     has actually been resynced yet.

It is important that this value not be visible to user-space and
particularly that it doesn't get written to the metadata, as the
resync or recovery checkpoint.  In part, this is because it may be
slightly higher than the correct value, though this is very rare.
In part, because it is not a multiple of 4K, and some devices only
support 4K aligned accesses.

There are two places where this value is propagates into either
-&gt;curr_resync_completed or -&gt;recovery_cp or -&gt;recovery_offset.
These currently avoid the propagation of values 1 and 3, but will
allow 3 to leak through.

Change them to only propagate the value if it is &gt; 3.

As this can cause an array to fail, the patch is suitable for -stable.

Cc: stable@vger.kernel.org (v3.7+)
Reported-by: Viswesh &lt;viswesh.vichu@gmail.com&gt;
Signed-off-by: NeilBrown &lt;neilb@suse.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>md: report 'write_pending' state when array in sync</title>
<updated>2016-10-24T22:28:19+00:00</updated>
<author>
<name>Tomasz Majchrzak</name>
<email>tomasz.majchrzak@intel.com</email>
</author>
<published>2016-10-24T10:47:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=16f889499a5214ebe038f8bd00f4c0094ed0ed75'/>
<id>16f889499a5214ebe038f8bd00f4c0094ed0ed75</id>
<content type='text'>
If there is a bad block on a disk and there is a recovery performed from
this disk, the same bad block is reported for a new disk. It involves
setting MD_CHANGE_PENDING flag in rdev_set_badblocks. For external
metadata this flag is not being cleared as array state is reported as
'clean'. The read request to bad block in RAID5 array gets stuck as it
is waiting for a flag to be cleared - as per commit c3cce6cda162
("md/raid5: ensure device failure recorded before write request
returns.").

The meaning of MD_CHANGE_PENDING and MD_CHANGE_CLEAN flags has been
clarified in commit 070dc6dd7103 ("md: resolve confusion of
MD_CHANGE_CLEAN"), however MD_CHANGE_PENDING flag has been used in
personality error handlers since and it doesn't fully comply with
initial purpose. It was supposed to notify that write request is about
to start, however now it is also used to request metadata update.
Initially (in md_allow_write, md_write_start) MD_CHANGE_PENDING flag has
been set and in_sync has been set to 0 at the same time. Error handlers
just set the flag without modifying in_sync value. Sysfs array state is
a single value so now it reports 'clean' when MD_CHANGE_PENDING flag is
set and in_sync is set to 1. Userspace has no idea it is expected to
take some action.

Swap the order that array state is checked so 'write_pending' is
reported ahead of 'clean' ('write_pending' is a misleading name but it
is too late to rename it now).

Signed-off-by: Tomasz Majchrzak &lt;tomasz.majchrzak@intel.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If there is a bad block on a disk and there is a recovery performed from
this disk, the same bad block is reported for a new disk. It involves
setting MD_CHANGE_PENDING flag in rdev_set_badblocks. For external
metadata this flag is not being cleared as array state is reported as
'clean'. The read request to bad block in RAID5 array gets stuck as it
is waiting for a flag to be cleared - as per commit c3cce6cda162
("md/raid5: ensure device failure recorded before write request
returns.").

The meaning of MD_CHANGE_PENDING and MD_CHANGE_CLEAN flags has been
clarified in commit 070dc6dd7103 ("md: resolve confusion of
MD_CHANGE_CLEAN"), however MD_CHANGE_PENDING flag has been used in
personality error handlers since and it doesn't fully comply with
initial purpose. It was supposed to notify that write request is about
to start, however now it is also used to request metadata update.
Initially (in md_allow_write, md_write_start) MD_CHANGE_PENDING flag has
been set and in_sync has been set to 0 at the same time. Error handlers
just set the flag without modifying in_sync value. Sysfs array state is
a single value so now it reports 'clean' when MD_CHANGE_PENDING flag is
set and in_sync is set to 1. Userspace has no idea it is expected to
take some action.

Swap the order that array state is checked so 'write_pending' is
reported ahead of 'clean' ('write_pending' is a misleading name but it
is too late to rename it now).

Signed-off-by: Tomasz Majchrzak &lt;tomasz.majchrzak@intel.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>md: set rotational bit</title>
<updated>2016-10-03T17:20:27+00:00</updated>
<author>
<name>Shaohua Li</name>
<email>shli@fb.com</email>
</author>
<published>2016-09-30T16:45:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=bb086a89a406b5d877ee616f1490fcc81f8e1b2b'/>
<id>bb086a89a406b5d877ee616f1490fcc81f8e1b2b</id>
<content type='text'>
if all disks in an array are non-rotational, set the array
non-rotational.

This only works for array with all disks populated at startup. Support
for disk hotadd/hotremove could be added later if necessary.

Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
if all disks in an array are non-rotational, set the array
non-rotational.

This only works for array with all disks populated at startup. Support
for disk hotadd/hotremove could be added later if necessary.

Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>md: fix a potential deadlock</title>
<updated>2016-09-21T16:09:44+00:00</updated>
<author>
<name>Shaohua Li</name>
<email>shli@fb.com</email>
</author>
<published>2016-09-14T21:26:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=90bcf1338193da4c87fb7492c716f225b907acf4'/>
<id>90bcf1338193da4c87fb7492c716f225b907acf4</id>
<content type='text'>
lockdep reports a potential deadlock. Fix this by droping the mutex
before md_import_device

[ 1137.126601] ======================================================
[ 1137.127013] [ INFO: possible circular locking dependency detected ]
[ 1137.127013] 4.8.0-rc4+ #538 Not tainted
[ 1137.127013] -------------------------------------------------------
[ 1137.127013] mdadm/16675 is trying to acquire lock:
[ 1137.127013]  (&amp;bdev-&gt;bd_mutex){+.+.+.}, at: [&lt;ffffffff81243cf3&gt;] __blkdev_get+0x63/0x450
[ 1137.127013]
but task is already holding lock:
[ 1137.127013]  (detected_devices_mutex){+.+.+.}, at: [&lt;ffffffff81a5138c&gt;] md_ioctl+0x2ac/0x1f50
[ 1137.127013]
which lock already depends on the new lock.

[ 1137.127013]
the existing dependency chain (in reverse order) is:
[ 1137.127013]
-&gt; #1 (detected_devices_mutex){+.+.+.}:
[ 1137.127013]        [&lt;ffffffff810b6f19&gt;] lock_acquire+0xb9/0x220
[ 1137.127013]        [&lt;ffffffff81c51647&gt;] mutex_lock_nested+0x67/0x3d0
[ 1137.127013]        [&lt;ffffffff81a4eeaf&gt;] md_autodetect_dev+0x3f/0x90
[ 1137.127013]        [&lt;ffffffff81595be8&gt;] rescan_partitions+0x1a8/0x2c0
[ 1137.127013]        [&lt;ffffffff81590081&gt;] __blkdev_reread_part+0x71/0xb0
[ 1137.127013]        [&lt;ffffffff815900e5&gt;] blkdev_reread_part+0x25/0x40
[ 1137.127013]        [&lt;ffffffff81590c4b&gt;] blkdev_ioctl+0x51b/0xa30
[ 1137.127013]        [&lt;ffffffff81242bf1&gt;] block_ioctl+0x41/0x50
[ 1137.127013]        [&lt;ffffffff81214c96&gt;] do_vfs_ioctl+0x96/0x6e0
[ 1137.127013]        [&lt;ffffffff81215321&gt;] SyS_ioctl+0x41/0x70
[ 1137.127013]        [&lt;ffffffff81c56825&gt;] entry_SYSCALL_64_fastpath+0x18/0xa8
[ 1137.127013]
-&gt; #0 (&amp;bdev-&gt;bd_mutex){+.+.+.}:
[ 1137.127013]        [&lt;ffffffff810b6af2&gt;] __lock_acquire+0x1662/0x1690
[ 1137.127013]        [&lt;ffffffff810b6f19&gt;] lock_acquire+0xb9/0x220
[ 1137.127013]        [&lt;ffffffff81c51647&gt;] mutex_lock_nested+0x67/0x3d0
[ 1137.127013]        [&lt;ffffffff81243cf3&gt;] __blkdev_get+0x63/0x450
[ 1137.127013]        [&lt;ffffffff81244307&gt;] blkdev_get+0x227/0x350
[ 1137.127013]        [&lt;ffffffff812444f6&gt;] blkdev_get_by_dev+0x36/0x50
[ 1137.127013]        [&lt;ffffffff81a46d65&gt;] lock_rdev+0x35/0x80
[ 1137.127013]        [&lt;ffffffff81a49bb4&gt;] md_import_device+0xb4/0x1b0
[ 1137.127013]        [&lt;ffffffff81a513d6&gt;] md_ioctl+0x2f6/0x1f50
[ 1137.127013]        [&lt;ffffffff815909b3&gt;] blkdev_ioctl+0x283/0xa30
[ 1137.127013]        [&lt;ffffffff81242bf1&gt;] block_ioctl+0x41/0x50
[ 1137.127013]        [&lt;ffffffff81214c96&gt;] do_vfs_ioctl+0x96/0x6e0
[ 1137.127013]        [&lt;ffffffff81215321&gt;] SyS_ioctl+0x41/0x70
[ 1137.127013]        [&lt;ffffffff81c56825&gt;] entry_SYSCALL_64_fastpath+0x18/0xa8
[ 1137.127013]
other info that might help us debug this:

[ 1137.127013]  Possible unsafe locking scenario:

[ 1137.127013]        CPU0                    CPU1
[ 1137.127013]        ----                    ----
[ 1137.127013]   lock(detected_devices_mutex);
[ 1137.127013]                                lock(&amp;bdev-&gt;bd_mutex);
[ 1137.127013]                                lock(detected_devices_mutex);
[ 1137.127013]   lock(&amp;bdev-&gt;bd_mutex);
[ 1137.127013]
 *** DEADLOCK ***

Cc: Cong Wang &lt;xiyou.wangcong@gmail.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
lockdep reports a potential deadlock. Fix this by droping the mutex
before md_import_device

[ 1137.126601] ======================================================
[ 1137.127013] [ INFO: possible circular locking dependency detected ]
[ 1137.127013] 4.8.0-rc4+ #538 Not tainted
[ 1137.127013] -------------------------------------------------------
[ 1137.127013] mdadm/16675 is trying to acquire lock:
[ 1137.127013]  (&amp;bdev-&gt;bd_mutex){+.+.+.}, at: [&lt;ffffffff81243cf3&gt;] __blkdev_get+0x63/0x450
[ 1137.127013]
but task is already holding lock:
[ 1137.127013]  (detected_devices_mutex){+.+.+.}, at: [&lt;ffffffff81a5138c&gt;] md_ioctl+0x2ac/0x1f50
[ 1137.127013]
which lock already depends on the new lock.

[ 1137.127013]
the existing dependency chain (in reverse order) is:
[ 1137.127013]
-&gt; #1 (detected_devices_mutex){+.+.+.}:
[ 1137.127013]        [&lt;ffffffff810b6f19&gt;] lock_acquire+0xb9/0x220
[ 1137.127013]        [&lt;ffffffff81c51647&gt;] mutex_lock_nested+0x67/0x3d0
[ 1137.127013]        [&lt;ffffffff81a4eeaf&gt;] md_autodetect_dev+0x3f/0x90
[ 1137.127013]        [&lt;ffffffff81595be8&gt;] rescan_partitions+0x1a8/0x2c0
[ 1137.127013]        [&lt;ffffffff81590081&gt;] __blkdev_reread_part+0x71/0xb0
[ 1137.127013]        [&lt;ffffffff815900e5&gt;] blkdev_reread_part+0x25/0x40
[ 1137.127013]        [&lt;ffffffff81590c4b&gt;] blkdev_ioctl+0x51b/0xa30
[ 1137.127013]        [&lt;ffffffff81242bf1&gt;] block_ioctl+0x41/0x50
[ 1137.127013]        [&lt;ffffffff81214c96&gt;] do_vfs_ioctl+0x96/0x6e0
[ 1137.127013]        [&lt;ffffffff81215321&gt;] SyS_ioctl+0x41/0x70
[ 1137.127013]        [&lt;ffffffff81c56825&gt;] entry_SYSCALL_64_fastpath+0x18/0xa8
[ 1137.127013]
-&gt; #0 (&amp;bdev-&gt;bd_mutex){+.+.+.}:
[ 1137.127013]        [&lt;ffffffff810b6af2&gt;] __lock_acquire+0x1662/0x1690
[ 1137.127013]        [&lt;ffffffff810b6f19&gt;] lock_acquire+0xb9/0x220
[ 1137.127013]        [&lt;ffffffff81c51647&gt;] mutex_lock_nested+0x67/0x3d0
[ 1137.127013]        [&lt;ffffffff81243cf3&gt;] __blkdev_get+0x63/0x450
[ 1137.127013]        [&lt;ffffffff81244307&gt;] blkdev_get+0x227/0x350
[ 1137.127013]        [&lt;ffffffff812444f6&gt;] blkdev_get_by_dev+0x36/0x50
[ 1137.127013]        [&lt;ffffffff81a46d65&gt;] lock_rdev+0x35/0x80
[ 1137.127013]        [&lt;ffffffff81a49bb4&gt;] md_import_device+0xb4/0x1b0
[ 1137.127013]        [&lt;ffffffff81a513d6&gt;] md_ioctl+0x2f6/0x1f50
[ 1137.127013]        [&lt;ffffffff815909b3&gt;] blkdev_ioctl+0x283/0xa30
[ 1137.127013]        [&lt;ffffffff81242bf1&gt;] block_ioctl+0x41/0x50
[ 1137.127013]        [&lt;ffffffff81214c96&gt;] do_vfs_ioctl+0x96/0x6e0
[ 1137.127013]        [&lt;ffffffff81215321&gt;] SyS_ioctl+0x41/0x70
[ 1137.127013]        [&lt;ffffffff81c56825&gt;] entry_SYSCALL_64_fastpath+0x18/0xa8
[ 1137.127013]
other info that might help us debug this:

[ 1137.127013]  Possible unsafe locking scenario:

[ 1137.127013]        CPU0                    CPU1
[ 1137.127013]        ----                    ----
[ 1137.127013]   lock(detected_devices_mutex);
[ 1137.127013]                                lock(&amp;bdev-&gt;bd_mutex);
[ 1137.127013]                                lock(detected_devices_mutex);
[ 1137.127013]   lock(&amp;bdev-&gt;bd_mutex);
[ 1137.127013]
 *** DEADLOCK ***

Cc: Cong Wang &lt;xiyou.wangcong@gmail.com&gt;
Signed-off-by: Shaohua Li &lt;shli@fb.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
