From: Keith Busch Date: Mon, 29 Jul 2019 22:34:52 +0000 (-0600) Subject: nvme-pci: Fix async probe remove race X-Git-Tag: v5.2.12~131 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c88a50ced6de8188725681ed70abe7f0b0133c94;p=users%2Fdwmw2%2Flinux.git nvme-pci: Fix async probe remove race [ Upstream commit bd46a90634302bfe791e93ad5496f98f165f7ae0 ] Ensure the controller is not in the NEW state when nvme_probe() exits. This will always allow a subsequent nvme_remove() to set the state to DELETING, fixing a potential race between the initial asynchronous probe and device removal. Reported-by: Li Zhong Reviewed-by: Sagi Grimberg Signed-off-by: Keith Busch Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index f9959eaaa185e..09ffd21d18096 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2712,7 +2712,7 @@ static void nvme_async_probe(void *data, async_cookie_t cookie) { struct nvme_dev *dev = data; - nvme_reset_ctrl_sync(&dev->ctrl); + flush_work(&dev->ctrl.reset_work); flush_work(&dev->ctrl.scan_work); nvme_put_ctrl(&dev->ctrl); } @@ -2778,6 +2778,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) dev_info(dev->ctrl.device, "pci function %s\n", dev_name(&pdev->dev)); + nvme_reset_ctrl(&dev->ctrl); nvme_get_ctrl(&dev->ctrl); async_schedule(nvme_async_probe, dev);