Skip to content

Commit 6d1400b

Browse files
Keith Buschgregkh
authored andcommitted
nvme: protect against simultaneous shutdown invocations
commit 77bf25ea70200cddf083f74b7f617e5f07fac8bd upstream. [Back-ported to 4.4. The difference is the file location of the struct definition that's adding the mutex. This fixes reported kernel panics in 4.4-stable from simultaneous controller resets that was never supposed to be allowed to happen.] 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 33d1fa4 commit 6d1400b

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/nvme/host/nvme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef _NVME_H
1515
#define _NVME_H
1616

17+
#include <linux/mutex.h>
1718
#include <linux/nvme.h>
1819
#include <linux/pci.h>
1920
#include <linux/kref.h>
@@ -62,6 +63,7 @@ struct nvme_dev {
6263
struct work_struct reset_work;
6364
struct work_struct probe_work;
6465
struct work_struct scan_work;
66+
struct mutex shutdown_lock;
6567
char name[12];
6668
char serial[20];
6769
char model[40];

drivers/nvme/host/pci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
29542954

29552955
nvme_dev_list_remove(dev);
29562956

2957+
mutex_lock(&dev->shutdown_lock);
29572958
if (pci_is_enabled(to_pci_dev(dev->dev))) {
29582959
nvme_freeze_queues(dev);
29592960
csts = readl(&dev->bar->csts);
@@ -2972,6 +2973,7 @@ static void nvme_dev_shutdown(struct nvme_dev *dev)
29722973

29732974
for (i = dev->queue_count - 1; i >= 0; i--)
29742975
nvme_clear_queue(dev->queues[i]);
2976+
mutex_unlock(&dev->shutdown_lock);
29752977
}
29762978

29772979
static void nvme_dev_remove(struct nvme_dev *dev)
@@ -3328,6 +3330,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
33283330

33293331
INIT_LIST_HEAD(&dev->namespaces);
33303332
INIT_WORK(&dev->reset_work, nvme_reset_work);
3333+
mutex_init(&dev->shutdown_lock);
33313334
dev->dev = get_device(&pdev->dev);
33323335
pci_set_drvdata(pdev, dev);
33333336

0 commit comments

Comments
 (0)