]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
nvme: protect against simultaneous shutdown invocations
authorKeith Busch <keith.busch@intel.com>
Thu, 26 Nov 2015 11:21:29 +0000 (12:21 +0100)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 1 Jun 2017 20:40:43 +0000 (13:40 -0700)
Signed-off-by: Keith Busch <keith.busch@intel.com>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
(cherry picked from commit 77bf25ea70200cddf083f74b7f617e5f07fac8bd)

Orabug: 25130845

Signed-off-by: Ashok Vairavan <ashok.vairavan@oracle.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/nvme/host/pci.c

index 82b8bf86b06b89b222ce011fb8400783d955c8d5..f5ca07040c995dad1a12ad13fdaf9435878ada44 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
 #include <linux/pci.h>
 #include <linux/poison.h>
 #include <linux/ptrace.h>
@@ -121,6 +122,7 @@ struct nvme_dev {
        struct work_struct reset_work;
        struct work_struct probe_work;
        struct work_struct scan_work;
+       struct mutex shutdown_lock;
        bool subsystem;
        void __iomem *cmb;
        dma_addr_t cmb_dma_addr;
@@ -2111,6 +2113,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
 
        nvme_dev_list_remove(dev);
 
+       mutex_lock(&dev->shutdown_lock);
        if (dev->bar) {
                nvme_freeze_queues(dev);
                csts = readl(dev->bar + NVME_REG_CSTS);
@@ -2129,6 +2132,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
 
        for (i = dev->queue_count - 1; i >= 0; i--)
                nvme_clear_queue(dev->queues[i]);
+       mutex_unlock(&dev->shutdown_lock);
 }
 
 static int nvme_setup_prp_pools(struct nvme_dev *dev)
@@ -2376,6 +2380,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->probe_work, nvme_probe_work);
        INIT_WORK(&dev->reset_work, nvme_reset_work);
+       mutex_init(&dev->shutdown_lock);
 
        result = nvme_setup_prp_pools(dev);
        if (result)