Skip to content

Commit 9c38475

Browse files
committed
Merge tag 'nvme-5.13-2021-05-05' of git://git.infradead.org/nvme into block-5.13
Pull NVMe fixes from Christoph: "nvme updates for Linux 5.13 - reset the bdev to ns head when failover (Daniel Wagner) - remove unsupported command noise (Keith Busch) - misc passthrough improvements (Kanchan Joshi) - fix controller ioctl through ns_head (Minwoo Im) - fix controller timeouts during reset (Tao Chiu)" * tag 'nvme-5.13-2021-05-05' of git://git.infradead.org/nvme: nvmet: remove unsupported command noise nvme-multipath: reset bdev to ns head when failover nvme-pci: fix controller reset hang when racing with nvme_timeout nvme: move the fabrics queue ready check routines to core nvme: avoid memset for passthrough requests nvme: add nvme_get_ns helper nvme: fix controller ioctl through ns_head
2 parents cd2c754 + 4a20342 commit 9c38475

File tree

12 files changed

+143
-134
lines changed

12 files changed

+143
-134
lines changed

drivers/nvme/host/core.c

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ static void nvme_free_ns(struct kref *kref)
576576
kfree(ns);
577577
}
578578

579+
static inline bool nvme_get_ns(struct nvme_ns *ns)
580+
{
581+
return kref_get_unless_zero(&ns->kref);
582+
}
583+
579584
void nvme_put_ns(struct nvme_ns *ns)
580585
{
581586
kref_put(&ns->kref, nvme_free_ns);
@@ -584,9 +589,6 @@ EXPORT_SYMBOL_NS_GPL(nvme_put_ns, NVME_TARGET_PASSTHRU);
584589

585590
static inline void nvme_clear_nvme_request(struct request *req)
586591
{
587-
struct nvme_command *cmd = nvme_req(req)->cmd;
588-
589-
memset(cmd, 0, sizeof(*cmd));
590592
nvme_req(req)->retries = 0;
591593
nvme_req(req)->flags = 0;
592594
req->rq_flags |= RQF_DONTPREP;
@@ -637,6 +639,66 @@ static struct request *nvme_alloc_request_qid(struct request_queue *q,
637639
return req;
638640
}
639641

642+
/*
643+
* For something we're not in a state to send to the device the default action
644+
* is to busy it and retry it after the controller state is recovered. However,
645+
* if the controller is deleting or if anything is marked for failfast or
646+
* nvme multipath it is immediately failed.
647+
*
648+
* Note: commands used to initialize the controller will be marked for failfast.
649+
* Note: nvme cli/ioctl commands are marked for failfast.
650+
*/
651+
blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
652+
struct request *rq)
653+
{
654+
if (ctrl->state != NVME_CTRL_DELETING_NOIO &&
655+
ctrl->state != NVME_CTRL_DEAD &&
656+
!test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) &&
657+
!blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))
658+
return BLK_STS_RESOURCE;
659+
return nvme_host_path_error(rq);
660+
}
661+
EXPORT_SYMBOL_GPL(nvme_fail_nonready_command);
662+
663+
bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
664+
bool queue_live)
665+
{
666+
struct nvme_request *req = nvme_req(rq);
667+
668+
/*
669+
* currently we have a problem sending passthru commands
670+
* on the admin_q if the controller is not LIVE because we can't
671+
* make sure that they are going out after the admin connect,
672+
* controller enable and/or other commands in the initialization
673+
* sequence. until the controller will be LIVE, fail with
674+
* BLK_STS_RESOURCE so that they will be rescheduled.
675+
*/
676+
if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD))
677+
return false;
678+
679+
if (ctrl->ops->flags & NVME_F_FABRICS) {
680+
/*
681+
* Only allow commands on a live queue, except for the connect
682+
* command, which is require to set the queue live in the
683+
* appropinquate states.
684+
*/
685+
switch (ctrl->state) {
686+
case NVME_CTRL_CONNECTING:
687+
if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) &&
688+
req->cmd->fabrics.fctype == nvme_fabrics_type_connect)
689+
return true;
690+
break;
691+
default:
692+
break;
693+
case NVME_CTRL_DEAD:
694+
return false;
695+
}
696+
}
697+
698+
return queue_live;
699+
}
700+
EXPORT_SYMBOL_GPL(__nvme_check_ready);
701+
640702
static int nvme_toggle_streams(struct nvme_ctrl *ctrl, bool enable)
641703
{
642704
struct nvme_command c;
@@ -898,8 +960,10 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
898960
struct nvme_command *cmd = nvme_req(req)->cmd;
899961
blk_status_t ret = BLK_STS_OK;
900962

901-
if (!(req->rq_flags & RQF_DONTPREP))
963+
if (!(req->rq_flags & RQF_DONTPREP)) {
902964
nvme_clear_nvme_request(req);
965+
memset(cmd, 0, sizeof(*cmd));
966+
}
903967

904968
switch (req_op(req)) {
905969
case REQ_OP_DRV_IN:
@@ -1494,7 +1558,7 @@ static int nvme_ns_open(struct nvme_ns *ns)
14941558
/* should never be called due to GENHD_FL_HIDDEN */
14951559
if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head)))
14961560
goto fail;
1497-
if (!kref_get_unless_zero(&ns->kref))
1561+
if (!nvme_get_ns(ns))
14981562
goto fail;
14991563
if (!try_module_get(ns->ctrl->ops->module))
15001564
goto fail_put_ns;
@@ -1999,28 +2063,6 @@ static const struct block_device_operations nvme_bdev_ops = {
19992063
.pr_ops = &nvme_pr_ops,
20002064
};
20012065

2002-
#ifdef CONFIG_NVME_MULTIPATH
2003-
struct nvme_ctrl *nvme_find_get_live_ctrl(struct nvme_subsystem *subsys)
2004-
{
2005-
struct nvme_ctrl *ctrl;
2006-
int ret;
2007-
2008-
ret = mutex_lock_killable(&nvme_subsystems_lock);
2009-
if (ret)
2010-
return ERR_PTR(ret);
2011-
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry) {
2012-
if (ctrl->state == NVME_CTRL_LIVE)
2013-
goto found;
2014-
}
2015-
mutex_unlock(&nvme_subsystems_lock);
2016-
return ERR_PTR(-EWOULDBLOCK);
2017-
found:
2018-
nvme_get_ctrl(ctrl);
2019-
mutex_unlock(&nvme_subsystems_lock);
2020-
return ctrl;
2021-
}
2022-
#endif /* CONFIG_NVME_MULTIPATH */
2023-
20242066
static int nvme_wait_ready(struct nvme_ctrl *ctrl, u64 cap, bool enabled)
20252067
{
20262068
unsigned long timeout =
@@ -3604,7 +3646,7 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
36043646
down_read(&ctrl->namespaces_rwsem);
36053647
list_for_each_entry(ns, &ctrl->namespaces, list) {
36063648
if (ns->head->ns_id == nsid) {
3607-
if (!kref_get_unless_zero(&ns->kref))
3649+
if (!nvme_get_ns(ns))
36083650
continue;
36093651
ret = ns;
36103652
break;

drivers/nvme/host/fabrics.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -533,63 +533,6 @@ static struct nvmf_transport_ops *nvmf_lookup_transport(
533533
return NULL;
534534
}
535535

536-
/*
537-
* For something we're not in a state to send to the device the default action
538-
* is to busy it and retry it after the controller state is recovered. However,
539-
* if the controller is deleting or if anything is marked for failfast or
540-
* nvme multipath it is immediately failed.
541-
*
542-
* Note: commands used to initialize the controller will be marked for failfast.
543-
* Note: nvme cli/ioctl commands are marked for failfast.
544-
*/
545-
blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl,
546-
struct request *rq)
547-
{
548-
if (ctrl->state != NVME_CTRL_DELETING_NOIO &&
549-
ctrl->state != NVME_CTRL_DEAD &&
550-
!test_bit(NVME_CTRL_FAILFAST_EXPIRED, &ctrl->flags) &&
551-
!blk_noretry_request(rq) && !(rq->cmd_flags & REQ_NVME_MPATH))
552-
return BLK_STS_RESOURCE;
553-
return nvme_host_path_error(rq);
554-
}
555-
EXPORT_SYMBOL_GPL(nvmf_fail_nonready_command);
556-
557-
bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
558-
bool queue_live)
559-
{
560-
struct nvme_request *req = nvme_req(rq);
561-
562-
/*
563-
* currently we have a problem sending passthru commands
564-
* on the admin_q if the controller is not LIVE because we can't
565-
* make sure that they are going out after the admin connect,
566-
* controller enable and/or other commands in the initialization
567-
* sequence. until the controller will be LIVE, fail with
568-
* BLK_STS_RESOURCE so that they will be rescheduled.
569-
*/
570-
if (rq->q == ctrl->admin_q && (req->flags & NVME_REQ_USERCMD))
571-
return false;
572-
573-
/*
574-
* Only allow commands on a live queue, except for the connect command,
575-
* which is require to set the queue live in the appropinquate states.
576-
*/
577-
switch (ctrl->state) {
578-
case NVME_CTRL_CONNECTING:
579-
if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) &&
580-
req->cmd->fabrics.fctype == nvme_fabrics_type_connect)
581-
return true;
582-
break;
583-
default:
584-
break;
585-
case NVME_CTRL_DEAD:
586-
return false;
587-
}
588-
589-
return queue_live;
590-
}
591-
EXPORT_SYMBOL_GPL(__nvmf_check_ready);
592-
593536
static const match_table_t opt_tokens = {
594537
{ NVMF_OPT_TRANSPORT, "transport=%s" },
595538
{ NVMF_OPT_TRADDR, "traddr=%s" },

drivers/nvme/host/fabrics.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,7 @@ void nvmf_unregister_transport(struct nvmf_transport_ops *ops);
184184
void nvmf_free_options(struct nvmf_ctrl_options *opts);
185185
int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
186186
bool nvmf_should_reconnect(struct nvme_ctrl *ctrl);
187-
blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl,
188-
struct request *rq);
189-
bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
190-
bool queue_live);
191187
bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
192188
struct nvmf_ctrl_options *opts);
193189

194-
static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
195-
bool queue_live)
196-
{
197-
if (likely(ctrl->state == NVME_CTRL_LIVE ||
198-
ctrl->state == NVME_CTRL_DELETING))
199-
return true;
200-
return __nvmf_check_ready(ctrl, rq, queue_live);
201-
}
202-
203190
#endif /* _NVME_FABRICS_H */

drivers/nvme/host/fc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,8 +2766,8 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx,
27662766
blk_status_t ret;
27672767

27682768
if (ctrl->rport->remoteport.port_state != FC_OBJSTATE_ONLINE ||
2769-
!nvmf_check_ready(&queue->ctrl->ctrl, rq, queue_ready))
2770-
return nvmf_fail_nonready_command(&queue->ctrl->ctrl, rq);
2769+
!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready))
2770+
return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq);
27712771

27722772
ret = nvme_setup_cmd(ns, rq);
27732773
if (ret)

drivers/nvme/host/ioctl.c

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -370,41 +370,45 @@ long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
370370
}
371371

372372
#ifdef CONFIG_NVME_MULTIPATH
373-
static int nvme_ns_head_ctrl_ioctl(struct nvme_ns_head *head,
374-
unsigned int cmd, void __user *argp)
373+
static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd,
374+
void __user *argp, struct nvme_ns_head *head, int srcu_idx)
375375
{
376-
struct nvme_ctrl *ctrl = nvme_find_get_live_ctrl(head->subsys);
376+
struct nvme_ctrl *ctrl = ns->ctrl;
377377
int ret;
378378

379-
if (IS_ERR(ctrl))
380-
return PTR_ERR(ctrl);
381-
ret = nvme_ctrl_ioctl(ctrl, cmd, argp);
382-
nvme_put_ctrl(ctrl);
383-
return ret;
384-
}
379+
nvme_get_ctrl(ns->ctrl);
380+
nvme_put_ns_from_disk(head, srcu_idx);
381+
ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp);
385382

386-
static int nvme_ns_head_ns_ioctl(struct nvme_ns_head *head,
387-
unsigned int cmd, void __user *argp)
388-
{
389-
int srcu_idx = srcu_read_lock(&head->srcu);
390-
struct nvme_ns *ns = nvme_find_path(head);
391-
int ret = -EWOULDBLOCK;
392-
393-
if (ns)
394-
ret = nvme_ns_ioctl(ns, cmd, argp);
395-
srcu_read_unlock(&head->srcu, srcu_idx);
383+
nvme_put_ctrl(ctrl);
396384
return ret;
397385
}
398386

399387
int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
400388
unsigned int cmd, unsigned long arg)
401389
{
402-
struct nvme_ns_head *head = bdev->bd_disk->private_data;
390+
struct nvme_ns_head *head = NULL;
403391
void __user *argp = (void __user *)arg;
392+
struct nvme_ns *ns;
393+
int srcu_idx, ret;
394+
395+
ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
396+
if (unlikely(!ns))
397+
return -EWOULDBLOCK;
404398

399+
/*
400+
* Handle ioctls that apply to the controller instead of the namespace
401+
* seperately and drop the ns SRCU reference early. This avoids a
402+
* deadlock when deleting namespaces using the passthrough interface.
403+
*/
405404
if (is_ctrl_ioctl(cmd))
406-
return nvme_ns_head_ctrl_ioctl(head, cmd, argp);
407-
return nvme_ns_head_ns_ioctl(head, cmd, argp);
405+
ret = nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx);
406+
else {
407+
ret = nvme_ns_ioctl(ns, cmd, argp);
408+
nvme_put_ns_from_disk(head, srcu_idx);
409+
}
410+
411+
return ret;
408412
}
409413

410414
long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
@@ -414,10 +418,23 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
414418
struct nvme_ns_head *head =
415419
container_of(cdev, struct nvme_ns_head, cdev);
416420
void __user *argp = (void __user *)arg;
421+
struct nvme_ns *ns;
422+
int srcu_idx, ret;
423+
424+
srcu_idx = srcu_read_lock(&head->srcu);
425+
ns = nvme_find_path(head);
426+
if (!ns) {
427+
srcu_read_unlock(&head->srcu, srcu_idx);
428+
return -EWOULDBLOCK;
429+
}
417430

418431
if (is_ctrl_ioctl(cmd))
419-
return nvme_ns_head_ctrl_ioctl(head, cmd, argp);
420-
return nvme_ns_head_ns_ioctl(head, cmd, argp);
432+
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx);
433+
434+
ret = nvme_ns_ioctl(ns, cmd, argp);
435+
nvme_put_ns_from_disk(head, srcu_idx);
436+
437+
return ret;
421438
}
422439
#endif /* CONFIG_NVME_MULTIPATH */
423440

drivers/nvme/host/multipath.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void nvme_failover_req(struct request *req)
7070
struct nvme_ns *ns = req->q->queuedata;
7171
u16 status = nvme_req(req)->status & 0x7ff;
7272
unsigned long flags;
73+
struct bio *bio;
7374

7475
nvme_mpath_clear_current_path(ns);
7576

@@ -84,6 +85,8 @@ void nvme_failover_req(struct request *req)
8485
}
8586

8687
spin_lock_irqsave(&ns->head->requeue_lock, flags);
88+
for (bio = req->bio; bio; bio = bio->bi_next)
89+
bio_set_dev(bio, ns->head->disk->part0);
8790
blk_steal_bios(&ns->head->requeue_list, req);
8891
spin_unlock_irqrestore(&ns->head->requeue_lock, flags);
8992

drivers/nvme/host/nvme.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,21 @@ struct request *nvme_alloc_request(struct request_queue *q,
638638
struct nvme_command *cmd, blk_mq_req_flags_t flags);
639639
void nvme_cleanup_cmd(struct request *req);
640640
blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req);
641+
blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl,
642+
struct request *req);
643+
bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
644+
bool queue_live);
645+
646+
static inline bool nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
647+
bool queue_live)
648+
{
649+
if (likely(ctrl->state == NVME_CTRL_LIVE))
650+
return true;
651+
if (ctrl->ops->flags & NVME_F_FABRICS &&
652+
ctrl->state == NVME_CTRL_DELETING)
653+
return true;
654+
return __nvme_check_ready(ctrl, rq, queue_live);
655+
}
641656
int nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
642657
void *buf, unsigned bufflen);
643658
int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
@@ -664,7 +679,6 @@ struct nvme_ns *nvme_get_ns_from_disk(struct gendisk *disk,
664679
void nvme_put_ns_from_disk(struct nvme_ns_head *head, int idx);
665680
bool nvme_tryget_ns_head(struct nvme_ns_head *head);
666681
void nvme_put_ns_head(struct nvme_ns_head *head);
667-
struct nvme_ctrl *nvme_find_get_live_ctrl(struct nvme_subsystem *subsys);
668682
int nvme_cdev_add(struct cdev *cdev, struct device *cdev_device,
669683
const struct file_operations *fops, struct module *owner);
670684
void nvme_cdev_del(struct cdev *cdev, struct device *cdev_device);

drivers/nvme/host/pci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,9 @@ static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
933933
if (unlikely(!test_bit(NVMEQ_ENABLED, &nvmeq->flags)))
934934
return BLK_STS_IOERR;
935935

936+
if (!nvme_check_ready(&dev->ctrl, req, true))
937+
return nvme_fail_nonready_command(&dev->ctrl, req);
938+
936939
ret = nvme_setup_cmd(ns, req);
937940
if (ret)
938941
return ret;

0 commit comments

Comments
 (0)