Commit 77bf25ea authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe

nvme: protect against simultaneous shutdown invocations

Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
[hch: split from a larger patch]
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 7385014c
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/poison.h> #include <linux/poison.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
...@@ -113,6 +114,7 @@ struct nvme_dev { ...@@ -113,6 +114,7 @@ struct nvme_dev {
struct work_struct reset_work; struct work_struct reset_work;
struct work_struct probe_work; struct work_struct probe_work;
struct work_struct scan_work; struct work_struct scan_work;
struct mutex shutdown_lock;
bool subsystem; bool subsystem;
void __iomem *cmb; void __iomem *cmb;
dma_addr_t cmb_dma_addr; dma_addr_t cmb_dma_addr;
...@@ -2073,6 +2075,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) ...@@ -2073,6 +2075,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
nvme_dev_list_remove(dev); nvme_dev_list_remove(dev);
mutex_lock(&dev->shutdown_lock);
if (dev->bar) { if (dev->bar) {
nvme_freeze_queues(dev); nvme_freeze_queues(dev);
csts = readl(dev->bar + NVME_REG_CSTS); csts = readl(dev->bar + NVME_REG_CSTS);
...@@ -2091,6 +2094,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev) ...@@ -2091,6 +2094,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
for (i = dev->queue_count - 1; i >= 0; i--) for (i = dev->queue_count - 1; i >= 0; i--)
nvme_clear_queue(dev->queues[i]); nvme_clear_queue(dev->queues[i]);
mutex_unlock(&dev->shutdown_lock);
} }
static int nvme_setup_prp_pools(struct nvme_dev *dev) static int nvme_setup_prp_pools(struct nvme_dev *dev)
...@@ -2333,6 +2337,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -2333,6 +2337,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
INIT_WORK(&dev->scan_work, nvme_dev_scan); INIT_WORK(&dev->scan_work, nvme_dev_scan);
INIT_WORK(&dev->probe_work, nvme_probe_work); INIT_WORK(&dev->probe_work, nvme_probe_work);
INIT_WORK(&dev->reset_work, nvme_reset_work); INIT_WORK(&dev->reset_work, nvme_reset_work);
mutex_init(&dev->shutdown_lock);
result = nvme_setup_prp_pools(dev); result = nvme_setup_prp_pools(dev);
if (result) if (result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment