Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d1400b0 authored by Keith Busch's avatar Keith Busch Committed by Greg Kroah-Hartman
Browse files

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: 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>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 33d1fa43
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,7 @@
#ifndef _NVME_H
#ifndef _NVME_H
#define _NVME_H
#define _NVME_H


#include <linux/mutex.h>
#include <linux/nvme.h>
#include <linux/nvme.h>
#include <linux/pci.h>
#include <linux/pci.h>
#include <linux/kref.h>
#include <linux/kref.h>
@@ -62,6 +63,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;
	char name[12];
	char name[12];
	char serial[20];
	char serial[20];
	char model[40];
	char model[40];
+3 −0
Original line number Original line Diff line number Diff line
@@ -2954,6 +2954,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 (pci_is_enabled(to_pci_dev(dev->dev))) {
	if (pci_is_enabled(to_pci_dev(dev->dev))) {
		nvme_freeze_queues(dev);
		nvme_freeze_queues(dev);
		csts = readl(&dev->bar->csts);
		csts = readl(&dev->bar->csts);
@@ -2972,6 +2973,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 void nvme_dev_remove(struct nvme_dev *dev)
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)


	INIT_LIST_HEAD(&dev->namespaces);
	INIT_LIST_HEAD(&dev->namespaces);
	INIT_WORK(&dev->reset_work, nvme_reset_work);
	INIT_WORK(&dev->reset_work, nvme_reset_work);
	mutex_init(&dev->shutdown_lock);
	dev->dev = get_device(&pdev->dev);
	dev->dev = get_device(&pdev->dev);
	pci_set_drvdata(pdev, dev);
	pci_set_drvdata(pdev, dev);