Skip to content

Commit 657f197

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvme: fix deadlock caused by ANA update wrong locking
The deadlock combines 4 flows in parallel: - ns scanning (triggered from reconnect) - request timeout - ANA update (triggered from reconnect) - I/O coming into the mpath device (1) ns scanning triggers disk revalidation -> update disk info -> freeze queue -> but blocked, due to (2) (2) timeout handler reference the g_usage_counter - > but blocks in the transport .timeout() handler, due to (3) (3) the transport timeout handler (indirectly) calls nvme_stop_queue() -> which takes the (down_read) namespaces_rwsem - > but blocks, due to (4) (4) ANA update takes the (down_write) namespaces_rwsem -> calls nvme_mpath_set_live() -> which synchronize the ns_head srcu (see commit 504db08) -> but blocks, due to (5) (5) I/O came into nvme_mpath_make_request -> took srcu_read_lock -> direct_make_request > blk_queue_enter -> but blocked, due to (1) ==> the request queue is under freeze -> deadlock. The fix is making ANA update take a read lock as the namespaces list is not manipulated, it is just the ns and ns->head that are being updated (which is protected with the ns->head lock). Fixes: 0d0b660 ("nvme: add ANA support") Signed-off-by: Sagi Grimberg <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent a032e4f commit 657f197

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/nvme/host/multipath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
510510
if (!nr_nsids)
511511
return 0;
512512

513-
down_write(&ctrl->namespaces_rwsem);
513+
down_read(&ctrl->namespaces_rwsem);
514514
list_for_each_entry(ns, &ctrl->namespaces, list) {
515515
unsigned nsid = le32_to_cpu(desc->nsids[n]);
516516

@@ -521,7 +521,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
521521
if (++n == nr_nsids)
522522
break;
523523
}
524-
up_write(&ctrl->namespaces_rwsem);
524+
up_read(&ctrl->namespaces_rwsem);
525525
return 0;
526526
}
527527

0 commit comments

Comments
 (0)