Skip to content

Commit d592974

Browse files
committed
Merge branch 'nvme-5.0' of git://git.infradead.org/nvme into for-linus
Pull NVMe fixes from Christoph for this release. * 'nvme-5.0' of git://git.infradead.org/nvme: nvme-pci: fix rapid add remove sequence nvme: lock NS list changes while handling command effects
2 parents ec51f8e + 5c959d7 commit d592974

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

drivers/nvme/host/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
12531253
* effects say only one namespace is affected.
12541254
*/
12551255
if (effects & (NVME_CMD_EFFECTS_LBCC | NVME_CMD_EFFECTS_CSE_MASK)) {
1256+
mutex_lock(&ctrl->scan_lock);
12561257
nvme_start_freeze(ctrl);
12571258
nvme_wait_freeze(ctrl);
12581259
}
@@ -1281,8 +1282,10 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
12811282
*/
12821283
if (effects & NVME_CMD_EFFECTS_LBCC)
12831284
nvme_update_formats(ctrl);
1284-
if (effects & (NVME_CMD_EFFECTS_LBCC | NVME_CMD_EFFECTS_CSE_MASK))
1285+
if (effects & (NVME_CMD_EFFECTS_LBCC | NVME_CMD_EFFECTS_CSE_MASK)) {
12851286
nvme_unfreeze(ctrl);
1287+
mutex_unlock(&ctrl->scan_lock);
1288+
}
12861289
if (effects & NVME_CMD_EFFECTS_CCC)
12871290
nvme_init_identify(ctrl);
12881291
if (effects & (NVME_CMD_EFFECTS_NIC | NVME_CMD_EFFECTS_NCC))
@@ -3401,6 +3404,7 @@ static void nvme_scan_work(struct work_struct *work)
34013404
if (nvme_identify_ctrl(ctrl, &id))
34023405
return;
34033406

3407+
mutex_lock(&ctrl->scan_lock);
34043408
nn = le32_to_cpu(id->nn);
34053409
if (ctrl->vs >= NVME_VS(1, 1, 0) &&
34063410
!(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
@@ -3409,6 +3413,7 @@ static void nvme_scan_work(struct work_struct *work)
34093413
}
34103414
nvme_scan_ns_sequential(ctrl, nn);
34113415
out_free_id:
3416+
mutex_unlock(&ctrl->scan_lock);
34123417
kfree(id);
34133418
down_write(&ctrl->namespaces_rwsem);
34143419
list_sort(NULL, &ctrl->namespaces, ns_cmp);
@@ -3652,6 +3657,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
36523657

36533658
ctrl->state = NVME_CTRL_NEW;
36543659
spin_lock_init(&ctrl->lock);
3660+
mutex_init(&ctrl->scan_lock);
36553661
INIT_LIST_HEAD(&ctrl->namespaces);
36563662
init_rwsem(&ctrl->namespaces_rwsem);
36573663
ctrl->dev = dev;

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct nvme_ctrl {
154154
enum nvme_ctrl_state state;
155155
bool identified;
156156
spinlock_t lock;
157+
struct mutex scan_lock;
157158
const struct nvme_ctrl_ops *ops;
158159
struct request_queue *admin_q;
159160
struct request_queue *connect_q;

drivers/nvme/host/pci.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,16 +2557,7 @@ static void nvme_reset_work(struct work_struct *work)
25572557
if (dev->ctrl.ctrl_config & NVME_CC_ENABLE)
25582558
nvme_dev_disable(dev, false);
25592559

2560-
/*
2561-
* Introduce CONNECTING state from nvme-fc/rdma transports to mark the
2562-
* initializing procedure here.
2563-
*/
2564-
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) {
2565-
dev_warn(dev->ctrl.device,
2566-
"failed to mark controller CONNECTING\n");
2567-
goto out;
2568-
}
2569-
2560+
mutex_lock(&dev->shutdown_lock);
25702561
result = nvme_pci_enable(dev);
25712562
if (result)
25722563
goto out;
@@ -2585,6 +2576,17 @@ static void nvme_reset_work(struct work_struct *work)
25852576
*/
25862577
dev->ctrl.max_hw_sectors = NVME_MAX_KB_SZ << 1;
25872578
dev->ctrl.max_segments = NVME_MAX_SEGS;
2579+
mutex_unlock(&dev->shutdown_lock);
2580+
2581+
/*
2582+
* Introduce CONNECTING state from nvme-fc/rdma transports to mark the
2583+
* initializing procedure here.
2584+
*/
2585+
if (!nvme_change_ctrl_state(&dev->ctrl, NVME_CTRL_CONNECTING)) {
2586+
dev_warn(dev->ctrl.device,
2587+
"failed to mark controller CONNECTING\n");
2588+
goto out;
2589+
}
25882590

25892591
result = nvme_init_identify(&dev->ctrl);
25902592
if (result)

0 commit comments

Comments
 (0)