]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nvme: Fix controller creation races with teardown flow
authorIsrael Rukshin <israelr@mellanox.com>
Tue, 24 Mar 2020 15:29:43 +0000 (17:29 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 11:17:49 +0000 (13:17 +0200)
[ Upstream commit ce1518139e6976cf19c133b555083354fdb629b8 ]

Calling nvme_sysfs_delete() when the controller is in the middle of
creation may cause several bugs. If the controller is in NEW state we
remove delete_controller file and don't delete the controller. The user
will not be able to use nvme disconnect command on that controller again,
although the controller may be active. Other bugs may happen if the
controller is in the middle of create_ctrl callback and
nvme_do_delete_ctrl() starts. For example, freeing I/O tagset at
nvme_do_delete_ctrl() before it was allocated at create_ctrl callback.

To fix all those races don't allow the user to delete the controller
before it was fully created.

Signed-off-by: Israel Rukshin <israelr@mellanox.com>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h

index 32cefbd80bdfb5ca89c57c6ab3ff1db4e24bc86b..438a03fc4bd94d23c73482465b04a72b57c34575 100644 (file)
@@ -3197,6 +3197,10 @@ static ssize_t nvme_sysfs_delete(struct device *dev,
 {
        struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
 
+       /* Can't delete non-created controllers */
+       if (!ctrl->created)
+               return -EBUSY;
+
        if (device_remove_file_self(dev, attr))
                nvme_delete_ctrl_sync(ctrl);
        return count;
@@ -3992,6 +3996,7 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
                nvme_queue_scan(ctrl);
                nvme_start_queues(ctrl);
        }
+       ctrl->created = true;
 }
 EXPORT_SYMBOL_GPL(nvme_start_ctrl);
 
index 66aafd42d2d916aae3980da4bb3b15a98b8d8bc7..5eb9500c89392b8d17f10c60a14750a7f4a83518 100644 (file)
@@ -253,6 +253,7 @@ struct nvme_ctrl {
        struct nvme_command ka_cmd;
        struct work_struct fw_act_work;
        unsigned long events;
+       bool created;
 
 #ifdef CONFIG_NVME_MULTIPATH
        /* asymmetric namespace access: */