linux/drivers/nvme/host
Baegjae Sung 9bd82b1a44 nvme-multipath: fix sysfs dangerously created links
If multipathing is enabled, each NVMe subsystem creates a head
namespace (e.g., nvme0n1) and multiple private namespaces
(e.g., nvme0c0n1 and nvme0c1n1) in sysfs. When creating links for
private namespaces, links of head namespace are used, so the
namespace creation order must be followed (e.g., nvme0n1 ->
nvme0c1n1). If the order is not followed, links of sysfs will be
incomplete or kernel panic will occur.

The kernel panic was:
  kernel BUG at fs/sysfs/symlink.c:27!
  Call Trace:
    nvme_mpath_add_disk_links+0x5d/0x80 [nvme_core]
    nvme_validate_ns+0x5c2/0x850 [nvme_core]
    nvme_scan_work+0x1af/0x2d0 [nvme_core]

Correct order
Context A     Context B
nvme0n1
nvme0c0n1     nvme0c1n1

Incorrect order
Context A     Context B
              nvme0c1n1
nvme0n1
nvme0c0n1

The nvme_mpath_add_disk (for creating head namespace) is called
just before the nvme_mpath_add_disk_links (for creating private
namespaces). In nvme_mpath_add_disk, the first context acquires
the lock of subsystem and creates a head namespace, and other
contexts do nothing by checking GENHD_FL_UP of a head namespace
after waiting to acquire the lock. We verified the code with or
without multipathing using three vendors of dual-port NVMe SSDs.

Signed-off-by: Baegjae Sung <baegjae@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
2018-02-28 02:46:48 -07:00
..
core.c nvme-multipath: fix sysfs dangerously created links 2018-02-28 02:46:48 -07:00
fabrics.c nvme-fabrics: don't check for non-NULL module in nvmf_register_transport 2018-02-22 01:45:30 -07:00
fabrics.h nvme-fabrics: protect against module unload during create_ctrl 2018-01-08 11:01:56 +01:00
fc.c blk-mq: introduce BLK_STS_DEV_RESOURCE 2018-01-30 20:18:28 -07:00
Kconfig nvme: implement multipath access to nvme subsystems 2017-11-10 19:53:25 -07:00
lightnvm.c lightnvm: make geometry structures 2.0 ready 2018-01-05 08:50:12 -07:00
Makefile nvme: add tracepoint for nvme_setup_cmd 2018-01-26 12:34:40 +01:00
multipath.c nvme-multipath: fix sysfs dangerously created links 2018-02-28 02:46:48 -07:00
nvme.h Merge branch 'for-4.16/block' of git://git.kernel.dk/linux-block 2018-01-29 11:51:49 -08:00
pci.c nvme-pci: Fix nvme queue cleanup if IRQ setup fails 2018-02-26 01:53:32 -07:00
rdma.c nvme-rdma: use blk_rq_payload_bytes instead of blk_rq_bytes 2018-02-22 01:45:32 -07:00
trace.c nvme: add tracepoint for nvme_setup_cmd 2018-01-26 12:34:40 +01:00
trace.h nvme: add tracepoint for nvme_complete_rq 2018-01-26 12:34:40 +01:00