remarkable-linux/drivers/nvdimm
Dan Williams 452bae0aed libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering
A debug patch to turn the standard device_lock() into something that
lockdep can analyze yielded the following:

 ======================================================
 [ INFO: possible circular locking dependency detected ]
 4.11.0-rc4+ #106 Tainted: G           O
 -------------------------------------------------------
 lt-libndctl/1898 is trying to acquire lock:
  (&dev->nvdimm_mutex/3){+.+.+.}, at: [<ffffffffc023c948>] nd_attach_ndns+0x178/0x1b0 [libnvdimm]

 but task is already holding lock:
  (&nvdimm_bus->reconfig_mutex){+.+.+.}, at: [<ffffffffc022e0b1>] nvdimm_bus_lock+0x21/0x30 [libnvdimm]

 which lock already depends on the new lock.

 the existing dependency chain (in reverse order) is:

 -> #1 (&nvdimm_bus->reconfig_mutex){+.+.+.}:
        lock_acquire+0xf6/0x1f0
        __mutex_lock+0x88/0x980
        mutex_lock_nested+0x1b/0x20
        nvdimm_bus_lock+0x21/0x30 [libnvdimm]
        nvdimm_namespace_capacity+0x1b/0x40 [libnvdimm]
        nvdimm_namespace_common_probe+0x230/0x510 [libnvdimm]
        nd_pmem_probe+0x14/0x180 [nd_pmem]
        nvdimm_bus_probe+0xa9/0x260 [libnvdimm]

 -> #0 (&dev->nvdimm_mutex/3){+.+.+.}:
        __lock_acquire+0x1107/0x1280
        lock_acquire+0xf6/0x1f0
        __mutex_lock+0x88/0x980
        mutex_lock_nested+0x1b/0x20
        nd_attach_ndns+0x178/0x1b0 [libnvdimm]
        nd_namespace_store+0x308/0x3c0 [libnvdimm]
        namespace_store+0x87/0x220 [libnvdimm]

In this case '&dev->nvdimm_mutex/3' mirrors '&dev->mutex'.

Fix this by replacing the use of device_lock() with nvdimm_bus_lock() to protect
nd_{attach,detach}_ndns() operations.

Cc: <stable@vger.kernel.org>
Fixes: 8c2f7e8658 ("libnvdimm: infrastructure for btt devices")
Reported-by: Yi Zhang <yizhan@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2017-05-01 08:29:37 -07:00
..
blk.c libnvdimm for 4.8 2016-07-28 17:38:16 -07:00
btt.c nvdimm, btt: add a size attribute for BTTs 2016-08-08 09:26:14 -07:00
btt.h
btt_devs.c libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering 2017-05-01 08:29:37 -07:00
bus.c libnvdimm: rework region badblocks clearing 2017-04-29 15:24:03 -07:00
claim.c libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering 2017-05-01 08:29:37 -07:00
core.c libnvdimm: fix clear poison locking with spinlock and GFP_NOWAIT allocation 2017-04-13 14:23:51 -07:00
dax_devs.c libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering 2017-05-01 08:29:37 -07:00
dimm.c libnvdimm: allow a platform to force enable label support 2016-10-19 08:57:33 -07:00
dimm_devs.c libnvdimm: fix blk free space accounting 2017-04-04 15:08:36 -07:00
e820.c libnvdimm, e820: use module_platform_driver 2016-12-05 08:52:21 -08:00
Kconfig Linux 4.9-rc4 2016-11-18 16:13:41 -07:00
label.c nvdimm: use the right length of "pmem" 2016-11-11 20:37:42 -08:00
label.h
Makefile libnvdimm, dax: introduce device-dax infrastructure 2016-05-09 15:35:42 -07:00
namespace_devs.c nfit, libnvdimm: fix interleave set cookie calculation 2017-03-01 00:49:42 -08:00
nd-core.h libnvdimm: fix clear poison locking with spinlock and GFP_NOWAIT allocation 2017-04-13 14:23:51 -07:00
nd.h libnvdimm: add mechanism to publish badblocks at the region level 2017-04-12 21:56:42 -07:00
pfn.h libnvdimm, dax: autodetect support 2016-05-20 22:02:57 -07:00
pfn_devs.c libnvdimm: fix nvdimm_bus_lock() vs device_lock() ordering 2017-05-01 08:29:37 -07:00
pmem.c libnvdimm, pmem: fix a NULL pointer BUG in nd_pmem_notify 2017-04-28 12:46:47 -07:00
pmem.h pmem: kill __pmem address space 2016-07-12 19:25:38 -07:00
region.c libnvdimm: rework region badblocks clearing 2017-04-29 15:24:03 -07:00
region_devs.c libnvdimm: rework region badblocks clearing 2017-04-29 15:24:03 -07:00