Skip to content

Commit 0c9c830

Browse files
committed
Merge branch 'nvme-5.3-rc' of git://git.infradead.org/nvme into for-linus
Pull NVMe fixes from Sagi: "Few nvme fixes for the next rc round. - detect capacity changes on the mpath disk from Anthony - probe/remove fix from Keith - various fixes to pass blktests from Logan - deadlock in reset/scan race fix - nvme-rdma use-after-free fix - deadlock fix when passthru commands race mpath disk info update" * 'nvme-5.3-rc' of git://git.infradead.org/nvme: nvme-pci: Fix async probe remove race nvme: fix controller removal race with scan work nvme-rdma: fix possible use-after-free in connect error flow nvme: fix a possible deadlock when passthru commands sent to a multipath device nvme-core: Fix extra device_put() call on error path nvmet-file: fix nvmet_file_flush() always returning an error nvmet-loop: Flush nvme_delete_wq when removing the port nvmet: Fix use-after-free bug when a port is removed nvme-multipath: revalidate nvme_ns_head gendisk in nvme_validate_ns
2 parents 20621fe + bd46a90 commit 0c9c830

9 files changed

Lines changed: 143 additions & 15 deletions

File tree

‎drivers/nvme/host/core.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,9 @@ static u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
12861286
*/
12871287
if (effects & (NVME_CMD_EFFECTS_LBCC | NVME_CMD_EFFECTS_CSE_MASK)) {
12881288
mutex_lock(&ctrl->scan_lock);
1289+
mutex_lock(&ctrl->subsys->lock);
1290+
nvme_mpath_start_freeze(ctrl->subsys);
1291+
nvme_mpath_wait_freeze(ctrl->subsys);
12891292
nvme_start_freeze(ctrl);
12901293
nvme_wait_freeze(ctrl);
12911294
}
@@ -1316,6 +1319,8 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
13161319
nvme_update_formats(ctrl);
13171320
if (effects & (NVME_CMD_EFFECTS_LBCC | NVME_CMD_EFFECTS_CSE_MASK)) {
13181321
nvme_unfreeze(ctrl);
1322+
nvme_mpath_unfreeze(ctrl->subsys);
1323+
mutex_unlock(&ctrl->subsys->lock);
13191324
mutex_unlock(&ctrl->scan_lock);
13201325
}
13211326
if (effects & NVME_CMD_EFFECTS_CCC)
@@ -1715,6 +1720,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
17151720
if (ns->head->disk) {
17161721
nvme_update_disk_info(ns->head->disk, ns, id);
17171722
blk_queue_stack_limits(ns->head->disk->queue, ns->queue);
1723+
revalidate_disk(ns->head->disk);
17181724
}
17191725
#endif
17201726
}
@@ -2487,6 +2493,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
24872493
if (ret) {
24882494
dev_err(ctrl->device,
24892495
"failed to register subsystem device.\n");
2496+
put_device(&subsys->dev);
24902497
goto out_unlock;
24912498
}
24922499
ida_init(&subsys->ns_ida);
@@ -2509,7 +2516,6 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
25092516
nvme_put_subsystem(subsys);
25102517
out_unlock:
25112518
mutex_unlock(&nvme_subsystems_lock);
2512-
put_device(&subsys->dev);
25132519
return ret;
25142520
}
25152521

@@ -3571,6 +3577,13 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)
35713577
struct nvme_ns *ns, *next;
35723578
LIST_HEAD(ns_list);
35733579

3580+
/*
3581+
* make sure to requeue I/O to all namespaces as these
3582+
* might result from the scan itself and must complete
3583+
* for the scan_work to make progress
3584+
*/
3585+
nvme_mpath_clear_ctrl_paths(ctrl);
3586+
35743587
/* prevent racing with ns scanning */
35753588
flush_work(&ctrl->scan_work);
35763589

‎drivers/nvme/host/multipath.c‎

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ module_param(multipath, bool, 0444);
1212
MODULE_PARM_DESC(multipath,
1313
"turn on native support for multiple controllers per subsystem");
1414

15+
void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
16+
{
17+
struct nvme_ns_head *h;
18+
19+
lockdep_assert_held(&subsys->lock);
20+
list_for_each_entry(h, &subsys->nsheads, entry)
21+
if (h->disk)
22+
blk_mq_unfreeze_queue(h->disk->queue);
23+
}
24+
25+
void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
26+
{
27+
struct nvme_ns_head *h;
28+
29+
lockdep_assert_held(&subsys->lock);
30+
list_for_each_entry(h, &subsys->nsheads, entry)
31+
if (h->disk)
32+
blk_mq_freeze_queue_wait(h->disk->queue);
33+
}
34+
35+
void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
36+
{
37+
struct nvme_ns_head *h;
38+
39+
lockdep_assert_held(&subsys->lock);
40+
list_for_each_entry(h, &subsys->nsheads, entry)
41+
if (h->disk)
42+
blk_freeze_queue_start(h->disk->queue);
43+
}
44+
1545
/*
1646
* If multipathing is enabled we need to always use the subsystem instance
1747
* number for numbering our devices to avoid conflicts between subsystems that
@@ -104,18 +134,34 @@ static const char *nvme_ana_state_names[] = {
104134
[NVME_ANA_CHANGE] = "change",
105135
};
106136

107-
void nvme_mpath_clear_current_path(struct nvme_ns *ns)
137+
bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
108138
{
109139
struct nvme_ns_head *head = ns->head;
140+
bool changed = false;
110141
int node;
111142

112143
if (!head)
113-
return;
144+
goto out;
114145

115146
for_each_node(node) {
116-
if (ns == rcu_access_pointer(head->current_path[node]))
147+
if (ns == rcu_access_pointer(head->current_path[node])) {
117148
rcu_assign_pointer(head->current_path[node], NULL);
149+
changed = true;
150+
}
118151
}
152+
out:
153+
return changed;
154+
}
155+
156+
void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
157+
{
158+
struct nvme_ns *ns;
159+
160+
mutex_lock(&ctrl->scan_lock);
161+
list_for_each_entry(ns, &ctrl->namespaces, list)
162+
if (nvme_mpath_clear_current_path(ns))
163+
kblockd_schedule_work(&ns->head->requeue_work);
164+
mutex_unlock(&ctrl->scan_lock);
119165
}
120166

121167
static bool nvme_path_is_disabled(struct nvme_ns *ns)
@@ -226,6 +272,24 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
226272
return ns;
227273
}
228274

275+
static bool nvme_available_path(struct nvme_ns_head *head)
276+
{
277+
struct nvme_ns *ns;
278+
279+
list_for_each_entry_rcu(ns, &head->list, siblings) {
280+
switch (ns->ctrl->state) {
281+
case NVME_CTRL_LIVE:
282+
case NVME_CTRL_RESETTING:
283+
case NVME_CTRL_CONNECTING:
284+
/* fallthru */
285+
return true;
286+
default:
287+
break;
288+
}
289+
}
290+
return false;
291+
}
292+
229293
static blk_qc_t nvme_ns_head_make_request(struct request_queue *q,
230294
struct bio *bio)
231295
{
@@ -252,14 +316,14 @@ static blk_qc_t nvme_ns_head_make_request(struct request_queue *q,
252316
disk_devt(ns->head->disk),
253317
bio->bi_iter.bi_sector);
254318
ret = direct_make_request(bio);
255-
} else if (!list_empty_careful(&head->list)) {
256-
dev_warn_ratelimited(dev, "no path available - requeuing I/O\n");
319+
} else if (nvme_available_path(head)) {
320+
dev_warn_ratelimited(dev, "no usable path - requeuing I/O\n");
257321

258322
spin_lock_irq(&head->requeue_lock);
259323
bio_list_add(&head->requeue_list, bio);
260324
spin_unlock_irq(&head->requeue_lock);
261325
} else {
262-
dev_warn_ratelimited(dev, "no path - failing I/O\n");
326+
dev_warn_ratelimited(dev, "no available path - failing I/O\n");
263327

264328
bio->bi_status = BLK_STS_IOERR;
265329
bio_endio(bio);

‎drivers/nvme/host/nvme.h‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
490490
return ctrl->ana_log_buf != NULL;
491491
}
492492

493+
void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
494+
void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
495+
void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
493496
void nvme_set_disk_name(char *disk_name, struct nvme_ns *ns,
494497
struct nvme_ctrl *ctrl, int *flags);
495498
void nvme_failover_req(struct request *req);
@@ -500,7 +503,8 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head);
500503
int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id);
501504
void nvme_mpath_uninit(struct nvme_ctrl *ctrl);
502505
void nvme_mpath_stop(struct nvme_ctrl *ctrl);
503-
void nvme_mpath_clear_current_path(struct nvme_ns *ns);
506+
bool nvme_mpath_clear_current_path(struct nvme_ns *ns);
507+
void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl);
504508
struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
505509

506510
static inline void nvme_mpath_check_last_path(struct nvme_ns *ns)
@@ -548,7 +552,11 @@ static inline void nvme_mpath_add_disk(struct nvme_ns *ns,
548552
static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head)
549553
{
550554
}
551-
static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns)
555+
static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
556+
{
557+
return false;
558+
}
559+
static inline void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl)
552560
{
553561
}
554562
static inline void nvme_mpath_check_last_path(struct nvme_ns *ns)
@@ -568,6 +576,15 @@ static inline void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
568576
static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl)
569577
{
570578
}
579+
static inline void nvme_mpath_unfreeze(struct nvme_subsystem *subsys)
580+
{
581+
}
582+
static inline void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys)
583+
{
584+
}
585+
static inline void nvme_mpath_start_freeze(struct nvme_subsystem *subsys)
586+
{
587+
}
571588
#endif /* CONFIG_NVME_MULTIPATH */
572589

573590
#ifdef CONFIG_NVM

‎drivers/nvme/host/pci.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ static void nvme_async_probe(void *data, async_cookie_t cookie)
26952695
{
26962696
struct nvme_dev *dev = data;
26972697

2698-
nvme_reset_ctrl_sync(&dev->ctrl);
2698+
flush_work(&dev->ctrl.reset_work);
26992699
flush_work(&dev->ctrl.scan_work);
27002700
nvme_put_ctrl(&dev->ctrl);
27012701
}
@@ -2761,6 +2761,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
27612761

27622762
dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev));
27632763

2764+
nvme_reset_ctrl(&dev->ctrl);
27642765
nvme_get_ctrl(&dev->ctrl);
27652766
async_schedule(nvme_async_probe, dev);
27662767

‎drivers/nvme/host/rdma.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,17 @@ static int nvme_rdma_alloc_queue(struct nvme_rdma_ctrl *ctrl,
562562
return ret;
563563
}
564564

565+
static void __nvme_rdma_stop_queue(struct nvme_rdma_queue *queue)
566+
{
567+
rdma_disconnect(queue->cm_id);
568+
ib_drain_qp(queue->qp);
569+
}
570+
565571
static void nvme_rdma_stop_queue(struct nvme_rdma_queue *queue)
566572
{
567573
if (!test_and_clear_bit(NVME_RDMA_Q_LIVE, &queue->flags))
568574
return;
569-
570-
rdma_disconnect(queue->cm_id);
571-
ib_drain_qp(queue->qp);
575+
__nvme_rdma_stop_queue(queue);
572576
}
573577

574578
static void nvme_rdma_free_queue(struct nvme_rdma_queue *queue)
@@ -607,11 +611,13 @@ static int nvme_rdma_start_queue(struct nvme_rdma_ctrl *ctrl, int idx)
607611
else
608612
ret = nvmf_connect_admin_queue(&ctrl->ctrl);
609613

610-
if (!ret)
614+
if (!ret) {
611615
set_bit(NVME_RDMA_Q_LIVE, &queue->flags);
612-
else
616+
} else {
617+
__nvme_rdma_stop_queue(queue);
613618
dev_info(ctrl->ctrl.device,
614619
"failed to connect queue: %d ret=%d\n", idx, ret);
620+
}
615621
return ret;
616622
}
617623

‎drivers/nvme/target/configfs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ static void nvmet_port_subsys_drop_link(struct config_item *parent,
675675

676676
found:
677677
list_del(&p->entry);
678+
nvmet_port_del_ctrls(port, subsys);
678679
nvmet_port_disc_changed(port, subsys);
679680

680681
if (list_empty(&port->subsystems))

‎drivers/nvme/target/core.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ inline u16 errno_to_nvme_status(struct nvmet_req *req, int errno)
4646
u16 status;
4747

4848
switch (errno) {
49+
case 0:
50+
status = NVME_SC_SUCCESS;
51+
break;
4952
case -ENOSPC:
5053
req->error_loc = offsetof(struct nvme_rw_command, length);
5154
status = NVME_SC_CAP_EXCEEDED | NVME_SC_DNR;
@@ -280,6 +283,18 @@ void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops)
280283
}
281284
EXPORT_SYMBOL_GPL(nvmet_unregister_transport);
282285

286+
void nvmet_port_del_ctrls(struct nvmet_port *port, struct nvmet_subsys *subsys)
287+
{
288+
struct nvmet_ctrl *ctrl;
289+
290+
mutex_lock(&subsys->lock);
291+
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
292+
if (ctrl->port == port)
293+
ctrl->ops->delete_ctrl(ctrl);
294+
}
295+
mutex_unlock(&subsys->lock);
296+
}
297+
283298
int nvmet_enable_port(struct nvmet_port *port)
284299
{
285300
const struct nvmet_fabrics_ops *ops;

‎drivers/nvme/target/loop.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ static void nvme_loop_remove_port(struct nvmet_port *port)
654654
mutex_lock(&nvme_loop_ports_mutex);
655655
list_del_init(&port->entry);
656656
mutex_unlock(&nvme_loop_ports_mutex);
657+
658+
/*
659+
* Ensure any ctrls that are in the process of being
660+
* deleted are in fact deleted before we return
661+
* and free the port. This is to prevent active
662+
* ctrls from using a port after it's freed.
663+
*/
664+
flush_workqueue(nvme_delete_wq);
657665
}
658666

659667
static const struct nvmet_fabrics_ops nvme_loop_ops = {

‎drivers/nvme/target/nvmet.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ void nvmet_port_send_ana_event(struct nvmet_port *port);
418418
int nvmet_register_transport(const struct nvmet_fabrics_ops *ops);
419419
void nvmet_unregister_transport(const struct nvmet_fabrics_ops *ops);
420420

421+
void nvmet_port_del_ctrls(struct nvmet_port *port,
422+
struct nvmet_subsys *subsys);
423+
421424
int nvmet_enable_port(struct nvmet_port *port);
422425
void nvmet_disable_port(struct nvmet_port *port);
423426

0 commit comments

Comments
 (0)