Rebased fixes
cover Rebased fixes
This rebases the hot plug fixes to the current linux-block/for-linus, folds in the review comments, a couple minor fixes (described in the individual patches), reorders the series to minimize churn, and squashes two previous patches for "namespace removal deadlock"; the two separate patches weren't really useful on their own.
The last two patches are not hot-plug related, but fix kernel crashes from user misuse/abuse of the passthru interface. These were already posted separatedly, but they are included in this series to complete everything I believe includes all important fixes I know about for 4.5.
Keith Busch (7):
NVMe: Don't unmap controller registers on reset
NVMe: Use IDA for namespace disk naming
NVMe: Fix namespace removal deadlock
NVMe: Simplify device reset failure
NVMe: Move error handling to failed reset handler
NVMe: Don't allow unsupported flags
NVMe: Fix 0-length integrity payload
drivers/nvme/host/core.c | 81 ++++++++++++++++++-------- drivers/nvme/host/nvme.h | 8 +++ drivers/nvme/host/pci.c | 149 ++++++++++++++++++++++++++++------------------- 3 files changed, 156 insertions(+), 82 deletions(-)
Signature · 1 line
2.6.2.307.g37023ba
PATCH 1/7 NVMe: Don't unmap controller registers on reset
Unmapping the registers on reset or shutdown is not necessary. Keeping the mapping simplifies reset handling.
--- drivers/nvme/host/pci.c | 71 +++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 29 deletions(-)
drivers/nvme/host/pci.c +42 -29
@@ -1694,10 +1694,10 @@ static int nvme_dev_add(struct nvme_dev *dev)return 0 ; } -static int nvme_dev_map (struct nvme_dev *dev) +static int nvme_pci_enable (struct nvme_dev *dev) {u64 cap; -int bars, result = -ENOMEM ; +int result = -ENOMEM ;struct pci_dev *pdev =to_pci_dev (dev->dev);if (pci_enable_device_mem (pdev))
@@ -1705,24 +1705,14 @@ static int nvme_dev_map(struct nvme_dev *dev) dev->entry[0 ].vector = pdev->irq;pci_set_master (pdev); - bars =pci_select_bars (pdev,IORESOURCE_MEM ); -if (!bars) - goto disable_pci; - -if (pci_request_selected_regions (pdev, bars,"nvme" )) - goto disable_pci;if (dma_set_mask_and_coherent (dev->dev,DMA_BIT_MASK (64 )) &&dma_set_mask_and_coherent (dev->dev,DMA_BIT_MASK (32 ))) goto disable; - dev->bar =ioremap (pci_resource_start (pdev,0 ),8192 ); -if (!dev->bar) - goto disable; -if (readl (dev->bar +NVME_REG_CSTS ) ==-1 ) { result = -ENODEV ; - goto unmap; + goto disable; }/*
@@ -1732,7 +1722,7 @@ static int nvme_dev_map(struct nvme_dev *dev)if (!pdev->irq) { result =pci_enable_msix (pdev, dev->entry,1 );if (result <0 ) - goto unmap; + goto disable; } cap =lo_hi_readq (dev->bar +NVME_REG_CAP );
@@ -1759,18 +1749,20 @@ static int nvme_dev_map(struct nvme_dev *dev)pci_save_state (pdev);return 0 ; - unmap: -iounmap (dev->bar); - dev->bar =NULL ; disable: -pci_release_regions (pdev); - disable_pci:pci_disable_device (pdev);return result; }static void nvme_dev_unmap (struct nvme_dev *dev) { +if (dev->bar) +iounmap (dev->bar); +pci_release_regions (to_pci_dev (dev->dev)); +} + +static void nvme_pci_disable (struct nvme_dev *dev) +{struct pci_dev *pdev =to_pci_dev (dev->dev);if (pdev->msi_enabled)
@@ -1778,12 +1770,6 @@ static void nvme_dev_unmap(struct nvme_dev *dev)else if (pdev->msix_enabled)pci_disable_msix (pdev); -if (dev->bar) { -iounmap (dev->bar); - dev->bar =NULL ; -pci_release_regions (pdev); - } -if (pci_is_enabled (pdev)) {pci_disable_pcie_error_reporting (pdev);pci_disable_device (pdev);
@@ -1842,7 +1828,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)nvme_dev_list_remove (dev);mutex_lock (&dev->shutdown_lock); -if (dev->bar) { +if (pci_is_enabled (to_pci_dev (dev->dev))) {nvme_stop_queues (&dev->ctrl); csts =readl (dev->bar +NVME_REG_CSTS ); }
@@ -1855,7 +1841,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)nvme_disable_io_queues (dev);nvme_disable_admin_queue (dev, shutdown); } -nvme_dev_unmap (dev); +nvme_pci_disable (dev);for (i = dev->queue_count -1 ; i >=0 ; i--)nvme_clear_queue (dev->queues[i]);
@@ -1911,12 +1897,12 @@ static void nvme_reset_work(struct work_struct *work)* If we're called to reset a live controller first shut it down before * moving on. */ -if (dev->bar) +if (dev->ctrl.ctrl_config &NVME_CC_ENABLE )nvme_dev_disable (dev, false);set_bit (NVME_CTRL_RESETTING , &dev->flags); - result =nvme_dev_map (dev); + result =nvme_pci_enable (dev);if (result) goto out;
@@ -2042,6 +2028,27 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { .free_ctrl = nvme_pci_free_ctrl, }; +static int nvme_dev_map (struct nvme_dev *dev) +{ +int bars; +struct pci_dev *pdev =to_pci_dev (dev->dev); + + bars =pci_select_bars (pdev,IORESOURCE_MEM ); +if (!bars) +return -ENODEV ; +if (pci_request_selected_regions (pdev, bars,"nvme" )) +return -ENODEV ; + + dev->bar =ioremap (pci_resource_start (pdev,0 ),8192 ); +if (!dev->bar) + goto release; + +return 0 ; + release: +pci_release_regions (pdev); +return -ENODEV ; +} +static int nvme_probe (struct pci_dev *pdev,const struct pci_device_id *id) {int node, result = -ENOMEM ;
@@ -2066,6 +2073,10 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) dev->dev =get_device (&pdev->dev);pci_set_drvdata (pdev, dev); + result =nvme_dev_map (dev); +if (result) + goto free; +INIT_LIST_HEAD (&dev->node);INIT_WORK (&dev->scan_work, nvme_dev_scan);INIT_WORK (&dev->reset_work, nvme_reset_work);
@@ -2089,6 +2100,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)nvme_release_prp_pools (dev); put_pci:put_device (dev->dev); +nvme_dev_unmap (dev); free:kfree (dev->queues);kfree (dev->entry);
@@ -2126,6 +2138,7 @@ static void nvme_remove(struct pci_dev *pdev)nvme_free_queues (dev,0 );nvme_release_cmb (dev);nvme_release_prp_pools (dev); +nvme_dev_unmap (dev);nvme_put_ctrl (&dev->ctrl); }
Signature · 1 line
2.6.2.307.g37023ba
PATCH 2/7 NVMe: Use IDA for namespace disk naming
In reply to Keith BuschA namespace may be detached from a controller, but a user may be holding a reference to it. Attaching a new namespace with the same NSID will create duplicate names when using the NSID to name the disk.
This patch uses an IDA that is released only when the last reference is released instead of using the namespace ID.
---
Changes from previous:
Delete the controller's IDA when the last controller reference is released rather than device is removed. This keeps it available for all namespace lifetime.
drivers/nvme/host/core.c | 16 +++++++++++++--- drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +12 -3
@@ -55,8 +55,9 @@ static void nvme_free_ns(struct kref *kref) ns->disk->private_data =NULL ;spin_unlock (&dev_list_lock); -nvme_put_ctrl (ns->ctrl);put_disk (ns->disk); +ida_simple_remove (&ns->ctrl->ns_ida, ns->instance); +nvme_put_ctrl (ns->ctrl);kfree (ns); }
@@ -1118,9 +1119,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (!ns)return ; + ns->instance =ida_simple_get (&ctrl->ns_ida,1 ,0 ,GFP_KERNEL ); +if (ns->instance <0 ) + goto out_free_ns; + ns->queue =blk_mq_init_queue (ctrl->tagset);if (IS_ERR (ns->queue)) - goto out_free_ns; + goto out_release_instance;queue_flag_set_unlocked (QUEUE_FLAG_NONROT , ns->queue); ns->queue->queuedata = ns; ns->ctrl = ctrl;
@@ -1153,7 +1158,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) disk->queue = ns->queue; disk->driverfs_dev = ctrl->device; disk->flags =GENHD_FL_EXT_DEVT ; -sprintf (disk->disk_name,"nvme%dn%d" , ctrl->instance, nsid); +sprintf (disk->disk_name,"nvme%dn%d" , ctrl->instance, ns->instance);if (nvme_revalidate_disk (ns->disk)) goto out_free_disk;
@@ -1173,6 +1178,8 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)kfree (disk); out_free_queue:blk_cleanup_queue (ns->queue); + out_release_instance: +ida_simple_remove (&ctrl->ns_ida, ns->instance); out_free_ns:kfree (ns); }
@@ -1350,6 +1358,7 @@ static void nvme_free_ctrl(struct kref *kref)put_device (ctrl->device);nvme_release_instance (ctrl); +ida_destroy (&ctrl->ns_ida); ctrl->ops->free_ctrl (ctrl); }
@@ -1390,6 +1399,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev, }get_device (ctrl->device);dev_set_drvdata (ctrl->device, ctrl); +ida_init (&ctrl->ns_ida);spin_lock (&dev_list_lock);list_add_tail (&ctrl->node, &nvme_ctrl_list);
drivers/nvme/host/nvme.h +2 -0
@@ -72,6 +72,7 @@ struct nvme_ctrl {struct mutex namespaces_mutex;struct device *device;/* char device */ struct list_head node; +struct ida ns_ida;char name[12 ];char serial[20 ];
@@ -102,6 +103,7 @@ struct nvme_ns {struct request_queue *queue;struct gendisk *disk;struct kref kref; +int instance;u8 eui[8 ];u8 uuid[16 ];
Signature · 1 line
2.6.2.307.g37023ba
PATCH 2/7 NVMe: Use IDA for namespace disk naming
Quoted 8 lines · Keith Busch
A namespace may be detached from a controller, but a user may be holding a reference to it. Attaching a new namespace with the same NSID will create duplicate names when using the NSID to name the disk.
This patch uses an IDA that is released only when the last reference is released instead of using the namespace ID.
Signed-off-by Keith Busch <keith.busch at intel.com>
PATCH 2/7 NVMe: Use IDA for namespace disk naming
In reply to Keith BuschQuoted 9 lines · Keith Busch
A namespace may be detached from a controller, but a user may be holding a reference to it. Attaching a new namespace with the same NSID will create duplicate names when using the NSID to name the disk.
This patch uses an IDA that is released only when the last reference is released instead of using the namespace ID.
Signed-off-by Keith Busch <keith.busch at intel.com>Reviewed-by Sagi Grimberg <sagig at mellanox.com>
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 3/7 NVMe: Fix namespace removal deadlock
In reply to Keith BuschThis patch makes nvme namespace removal lockless. It is up to the caller to ensure no active namespace scanning is occuring. To ensure no scan work occurs, the nvme pci driver adds a removing state to the controller device to avoid queueing scan work during removal. The work is flushed after setting the state, so no new scan work can be queued.
The lockless removal allows the driver to cleanup a namespace request_queue if the controller fails during removal. Previously this could deadlock trying to acquire the namespace mutex in order to handle such events.
---v3->v4:
This combines two patches from the previous series into a single commit as it these two make a single feature.
The test for controller removing is done prior to queueing scan work instead of in the scan work itself, and adds a code comment explaining its purpose.
drivers/nvme/host/core.c | 12 +++++++----- drivers/nvme/host/nvme.h | 4 ++++ drivers/nvme/host/pci.c | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-)
drivers/nvme/host/core.c +7 -5
@@ -1186,11 +1186,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)static void nvme_ns_remove (struct nvme_ns *ns) { -bool kill =nvme_io_incapable (ns->ctrl) && - !blk_queue_dying (ns->queue); +bool kill; -lockdep_assert_held (&ns->ctrl->namespaces_mutex); +if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags)) +return ; + kill =nvme_io_incapable (ns->ctrl) && + !blk_queue_dying (ns->queue);if (kill) {blk_set_queue_dying (ns->queue);
@@ -1213,7 +1215,9 @@ static void nvme_ns_remove(struct nvme_ns *ns)blk_mq_abort_requeue_list (ns->queue);blk_cleanup_queue (ns->queue); } +mutex_lock (&ns->ctrl->namespaces_mutex);list_del_init (&ns->list); +mutex_unlock (&ns->ctrl->namespaces_mutex);nvme_put_ns (ns); }
@@ -1308,10 +1312,8 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl) {struct nvme_ns *ns, *next; -mutex_lock (&ctrl->namespaces_mutex);list_for_each_entry_safe (ns, next, &ctrl->namespaces, list)nvme_ns_remove (ns); -mutex_unlock (&ctrl->namespaces_mutex); }static DEFINE_IDA (nvme_instance_ida);
drivers/nvme/host/nvme.h +4 -0
@@ -114,6 +114,10 @@ struct nvme_ns {bool ext;u8 pi_type;int type; +unsigned long flags; + +#define NVME_NS_REMOVING 0 +u64 mode_select_num_blocks;u32 mode_select_block_len; };
drivers/nvme/host/pci.c +15 -2
@@ -120,6 +120,7 @@ struct nvme_dev {unsigned long flags;#define NVME_CTRL_RESETTING 0 +#define NVME_CTRL_REMOVING 1struct nvme_ctrl ctrl;struct completion ioq_wait;
@@ -286,6 +287,17 @@ static int nvme_init_request(void *data, struct request *req,return 0 ; } +static void nvme_queue_scan (struct nvme_dev *dev) +{ +/* +* Do not queue new scan work when a controller is reset during +* removal. +*/ +if (test_bit (NVME_CTRL_REMOVING , &dev->flags)) +return ; +queue_work (nvme_workq, &dev->scan_work); +} +static void nvme_complete_async_event (struct nvme_dev *dev,struct nvme_completion *cqe) {
@@ -300,7 +312,7 @@ static void nvme_complete_async_event(struct nvme_dev *dev,switch (result &0xff07 ) {case NVME_AER_NOTICE_NS_CHANGED :dev_info (dev->dev,"rescanning\n" ); -queue_work (nvme_workq, &dev->scan_work); +nvme_queue_scan (dev);default :dev_warn (dev->dev,"async event result %08x\n" , result); }
@@ -1690,7 +1702,7 @@ static int nvme_dev_add(struct nvme_dev *dev)return 0 ; dev->ctrl.tagset = &dev->tagset; } -queue_work (nvme_workq, &dev->scan_work); +nvme_queue_scan (dev);return 0 ; }
@@ -2128,6 +2140,7 @@ static void nvme_remove(struct pci_dev *pdev) {struct nvme_dev *dev =pci_get_drvdata (pdev); +set_bit (NVME_CTRL_REMOVING , &dev->flags);pci_set_drvdata (pdev,NULL );flush_work (&dev->scan_work);nvme_remove_namespaces (&dev->ctrl);
Signature · 1 line
2.6.2.307.g37023ba
PATCH 3/7 NVMe: Fix namespace removal deadlock
Looks fine,
PATCH 4/7 NVMe: Simplify device reset failure
In reply to Keith BuschA reset failure schedules the device to unbind from the driver through the pci driver's remove. This cleans up all intialization, so there is no need to duplicate the potentially racy cleanup.
To help understand why a reset failed, the status is logged with the existing warning message.
--- drivers/nvme/host/pci.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-)
drivers/nvme/host/pci.c +21 -27
@@ -86,7 +86,6 @@ struct nvme_queue;static int nvme_reset (struct nvme_dev *dev);static void nvme_process_cq (struct nvme_queue *nvmeq); -static void nvme_remove_dead_ctrl (struct nvme_dev *dev);static void nvme_dev_disable (struct nvme_dev *dev,bool shutdown);/*
@@ -1897,10 +1896,19 @@ static void nvme_pci_free_ctrl(struct nvme_ctrl *ctrl)kfree (dev); } +static void nvme_remove_dead_ctrl (struct nvme_dev *dev,int status) +{ +dev_warn (dev->dev,"Removing after probe failure status: %d\n" , status); + +kref_get (&dev->ctrl.kref); +if (!schedule_work (&dev->remove_work)) +nvme_put_ctrl (&dev->ctrl); +} +static void nvme_reset_work (struct work_struct *work) { struct nvme_dev *dev = container_of(work, struct nvme_dev, reset_work); -int result; +int result = -ENODEV ;if (WARN_ON (test_bit (NVME_CTRL_RESETTING , &dev->flags))) goto out;
@@ -1920,26 +1928,26 @@ static void nvme_reset_work(struct work_struct *work) result =nvme_configure_admin_queue (dev);if (result) - goto unmap; + goto out;nvme_init_queue (dev->queues[0 ],0 ); result =nvme_alloc_admin_tags (dev);if (result) - goto disable; + goto out; result =nvme_init_identify (&dev->ctrl);if (result) - goto free_tags; + goto out; result =nvme_setup_io_queues (dev);if (result) - goto free_tags; + goto out; dev->ctrl.event_limit =NVME_NR_AEN_COMMANDS ; result =nvme_dev_list_add (dev);if (result) - goto remove; + goto out;/* * Keep the controller around but remove all namespaces if we don't have
@@ -1956,19 +1964,8 @@ static void nvme_reset_work(struct work_struct *work)clear_bit (NVME_CTRL_RESETTING , &dev->flags);return ; - remove: -nvme_dev_list_remove (dev); - free_tags: -nvme_dev_remove_admin (dev); -blk_put_queue (dev->ctrl.admin_q); - dev->ctrl.admin_q =NULL ; - dev->queues[0 ]->tags =NULL ; - disable: -nvme_disable_admin_queue (dev, false); - unmap: -nvme_dev_unmap (dev); out: -nvme_remove_dead_ctrl (dev); +nvme_remove_dead_ctrl (dev, result); }static void nvme_remove_dead_ctrl_work (struct work_struct *work)
@@ -1981,14 +1978,6 @@ static void nvme_remove_dead_ctrl_work(struct work_struct *work)nvme_put_ctrl (&dev->ctrl); } -static void nvme_remove_dead_ctrl (struct nvme_dev *dev) -{ -dev_warn (dev->dev,"Removing after probe failure\n" ); -kref_get (&dev->ctrl.kref); -if (!schedule_work (&dev->remove_work)) -nvme_put_ctrl (&dev->ctrl); -} -static int nvme_reset (struct nvme_dev *dev) {if (!dev->ctrl.admin_q ||blk_queue_dying (dev->ctrl.admin_q))
@@ -2136,6 +2125,11 @@ static void nvme_shutdown(struct pci_dev *pdev)nvme_dev_disable (dev, true); } +/* +* The driver's remove may be called on a device in a partially initialized +* state. This function must not have any dependencies on the device state in +* order to proceed. +*/ static void nvme_remove (struct pci_dev *pdev) {struct nvme_dev *dev =pci_get_drvdata (pdev);
Signature · 1 line
2.6.2.307.g37023ba
PATCH 5/7 NVMe: Move error handling to failed reset handler
In reply to Keith BuschThis moves failed queue handling out of the namespace removal path and into the reset failure path, fixing a hanging condition if the controller fails or link down during del_gendisk. Previously the driver had to see the controller as degraded prior to calling del_gendisk to setup the queues to fail. But, if the controller happened to fail after this, there was no task to end outstanding requests.
On failure, all namespace states are set to dead. This has capacity revalidate to 0, and ends all new requests with error status.
---v3->v4:
Set the BLK_QUEUE_RQ_ERROR when no namespace is available, as was the original intention.
Restart the admin h/w queue to flush potentially pending requests to their completion.
drivers/nvme/host/core.c | 53 ++++++++++++++++++++++++++++++++---------------- drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/pci.c | 13 +++++++++++- 3 files changed, 50 insertions(+), 18 deletions(-)
drivers/nvme/host/core.c +36 -17
@@ -557,6 +557,10 @@ static int nvme_revalidate_disk(struct gendisk *disk)u16 old_ms;unsigned short bs; +if (test_bit (NVME_NS_DEAD , &ns->flags)) { +set_capacity (disk,0 ); +return -ENODEV ; + }if (nvme_identify_ns (ns->ctrl, ns->ns_id, &id)) {dev_warn (ns->ctrl->dev,"%s: Identify failure nvme%dn%d\n" , __func__, ns->ctrl->instance, ns->ns_id);
@@ -1186,32 +1190,15 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)static void nvme_ns_remove (struct nvme_ns *ns) { -bool kill; -if (test_and_set_bit (NVME_NS_REMOVING , &ns->flags))return ; - kill =nvme_io_incapable (ns->ctrl) && - !blk_queue_dying (ns->queue); -if (kill) { -blk_set_queue_dying (ns->queue); - -/* -* The controller was shutdown first if we got here through -* device removal. The shutdown may requeue outstanding -* requests. These need to be aborted immediately so -* del_gendisk doesn't block indefinitely for their completion. -*/ -blk_mq_abort_requeue_list (ns->queue); - }if (ns->disk->flags &GENHD_FL_UP ) {if (blk_get_integrity (ns->disk))blk_integrity_unregister (ns->disk);sysfs_remove_group (&disk_to_dev (ns->disk)->kobj, &nvme_ns_attr_group);del_gendisk (ns->disk); - } -if (kill || !blk_queue_dying (ns->queue)) {blk_mq_abort_requeue_list (ns->queue);blk_cleanup_queue (ns->queue); }
@@ -1414,6 +1401,38 @@ out:return ret; } +/** +* nvme_kill_queues(): Ends all namespace queues +* @ctrl: the dead controller that needs to end +* +* Call this function when the driver determines it is unable to get the +* controller in a state capable of servicing IO. +*/ +void nvme_kill_queues (struct nvme_ctrl *ctrl) +{ +struct nvme_ns *ns; + +mutex_lock (&ctrl->namespaces_mutex); +list_for_each_entry (ns, &ctrl->namespaces, list) { +if (!kref_get_unless_zero (&ns->kref)) +continue ; + +/* +* Revalidating a dead namespace sets capacity to 0. This will +* end buffered writers dirtying pages that can't be synced. +*/ +if (!test_and_set_bit (NVME_NS_DEAD , &ns->flags)) +revalidate_disk (ns->disk); + +blk_set_queue_dying (ns->queue); +blk_mq_abort_requeue_list (ns->queue); +blk_mq_start_stopped_hw_queues (ns->queue, true); + +nvme_put_ns (ns); + } +mutex_unlock (&ctrl->namespaces_mutex); +} +void nvme_stop_queues (struct nvme_ctrl *ctrl) {struct nvme_ns *ns;
drivers/nvme/host/nvme.h +2 -0
@@ -117,6 +117,7 @@ struct nvme_ns {unsigned long flags;#define NVME_NS_REMOVING 0 +#define NVME_NS_DEAD 1u64 mode_select_num_blocks;u32 mode_select_block_len;
@@ -246,6 +247,7 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl);void nvme_stop_queues (struct nvme_ctrl *ctrl);void nvme_start_queues (struct nvme_ctrl *ctrl); +void nvme_kill_queues (struct nvme_ctrl *ctrl);struct request *nvme_alloc_request (struct request_queue *q,struct nvme_command *cmd,unsigned int flags);
drivers/nvme/host/pci.c +12 -1
@@ -690,7 +690,10 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,spin_lock_irq (&nvmeq->q_lock);if (unlikely (nvmeq->cq_vector <0 )) { - ret =BLK_MQ_RQ_QUEUE_BUSY ; +if (ns && !test_bit (NVME_NS_DEAD , &ns->flags)) + ret =BLK_MQ_RQ_QUEUE_BUSY ; +else + ret =BLK_MQ_RQ_QUEUE_ERROR ;spin_unlock_irq (&nvmeq->q_lock); goto out; }
@@ -1261,6 +1264,12 @@ static struct blk_mq_ops nvme_mq_ops = {static void nvme_dev_remove_admin (struct nvme_dev *dev) {if (dev->ctrl.admin_q && !blk_queue_dying (dev->ctrl.admin_q)) { +/* +* If the controller was reset during removal, it's possible +* user requests may be waiting on a stopped queue. Start the +* queue to flush these to completion. +*/ +blk_mq_start_stopped_hw_queues (dev->ctrl.admin_q, true);blk_cleanup_queue (dev->ctrl.admin_q);blk_mq_free_tag_set (&dev->admin_tagset); }
@@ -1901,6 +1910,7 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, int status)dev_warn (dev->dev,"Removing after probe failure status: %d\n" , status);kref_get (&dev->ctrl.kref); +nvme_dev_disable (dev, false);if (!schedule_work (&dev->remove_work))nvme_put_ctrl (&dev->ctrl); }
@@ -1973,6 +1983,7 @@ static void nvme_remove_dead_ctrl_work(struct work_struct *work) struct nvme_dev *dev = container_of(work, struct nvme_dev, remove_work);struct pci_dev *pdev =to_pci_dev (dev->dev); +nvme_kill_queues (&dev->ctrl);if (pci_get_drvdata (pdev))pci_stop_and_remove_bus_device_locked (pdev);nvme_put_ctrl (&dev->ctrl);
Signature · 1 line
2.6.2.307.g37023ba
PATCH 5/7 NVMe: Move error handling to failed reset handler
Quoted 9 lines · Keith Busch
This moves failed queue handling out of the namespace removal path and into the reset failure path, fixing a hanging condition if the controller fails or link down during
del_gendisk. Previously the driver had to see the controller as degraded prior to callingdel_gendiskto setup the queues to fail. But, if the controller happened to fail after this, there was no task to end outstanding requests.On failure, all namespace states are set to dead. This has capacity revalidate to 0, and ends all new requests with error status.
This removes the last call of nvme_io_incapable and thus the io_incapable method as well as nvme_pci_io_incapable. Do you have any plans to bring back users of these, or can we remove this infrastructure?
PATCH 6/7 NVMe: Don't allow unsupported flags
In reply to Keith BuschThe command flags can change the meaning of other fields in the command that the driver is not prepared to handle. Specifically, the user could passthrough an SGL flag, causing the controller to misinterpret the PRP list the driver created, potentially corrupting memory or data.
---
Quoted 1 line
From previous version:
Return an error if the user requested an unsupported flag.
drivers/nvme/host/core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/host/core.c +4 -0
@@ -374,6 +374,8 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)if (copy_from_user (&io, uio,sizeof (io)))return -EFAULT ; +if (io.flags) +return -EINVAL ;switch (io.opcode) {case nvme_cmd_write:
@@ -425,6 +427,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,return -EACCES ;if (copy_from_user (&cmd, ucmd,sizeof (cmd)))return -EFAULT ; +if (cmd.flags) +return -EINVAL ;memset (&c,0 ,sizeof (c)); c.common.opcode = cmd.opcode;
Signature · 1 line
2.6.2.307.g37023ba
PATCH 6/7 NVMe: Don't allow unsupported flags
Looks fine,
PATCH 6/7 NVMe: Don't allow unsupported flags
In reply to Keith BuschQuoted 7 lines · Keith Busch
The command flags can change the meaning of other fields in the command that the driver is not prepared to handle. Specifically, the user could passthrough an SGL flag, causing the controller to misinterpret the PRP list the driver created, potentially corrupting memory or data.
Signed-off-by Keith Busch <keith.busch at intel.com>Reviewed-by Jon Derrick <jonathan.derrick at intel.com>
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH 7/7 NVMe: Fix 0-length integrity payload
In reply to Keith BuschA user could send a passthrough IO command with a metadata pointer to a namespace without metadata. With metadata length of 0, kmalloc returns ZERO_SIZE_PTR. Since that is not NULL, the driver would have set this as the bio's integrity payload, which causes an access fault on completion.
This patch ignores the users metadata buffer if the namespace format does not support separate metadata.
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -184,7 +184,7 @@ int __nvme_submit_user_cmd(struct request_queue *q, struct nvme_command *cmd, goto out_unmap; } -if (meta_buffer) { +if (meta_buffer && meta_len) {struct bio_integrity_payload *bip; meta =kmalloc (meta_len,GFP_KERNEL );
Signature · 1 line
2.6.2.307.g37023ba
PATCH 7/7 NVMe: Fix 0-length integrity payload
Quoted 5 lines · Keith Busch
A user could send a passthrough IO command with a metadata pointer to a namespace without metadata. With metadata length of 0, kmalloc returns
ZERO_SIZE_PTR. Since that is not NULL, the driver would have set this as the bio's integrity payload, which causes an access fault on completion.
Quoted 7 lines
This patch ignores the users metadata buffer if the namespace format does not support separate metadata.
Reported-by Stephen Bates <stephen.bates at microsemi.com>Signed-off-by Keith Busch <keith.busch at intel.com>Reviewed-by Sagi Grimberg <sagig at mellanox.com>Reviewed-by Christoph Hellwig <hch at lst.de>
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850