[PATCH 1/2] nvme-pci: Fix multiple races in nvme_setup_io_queues()

Keith Busch kbusch at kernel.org
Wed Jun 23 07:50:07 PDT 2021


On Tue, Jun 22, 2021 at 09:14:21PM -0700, Casey Chen wrote:
> +/*
> + * Try getting shutdown_lock while setting up IO queues.
> + * Caller remember to unlock if success.
> + */
> +static int nvme_setup_io_queues_trylock(struct nvme_dev *dev)
> +{
> +       /*
> +       * Lock is being held by nvme_dev_disable(), fail early.
> +       */
> +       if (!mutex_trylock(&dev->shutdown_lock))
> +               return -ENODEV;
> +
> +       /*
> +       * Controller is in wrong state, fail early.
> +        */
> +       if (dev->ctrl.state != NVME_CTRL_CONNECTING) {
> +               mutex_unlock(&dev->shutdown_lock);
> +               return -ENODEV;
> +       }
> +
> +       return 0;
> +}
> +

Yes, thank you, this is aligned with what I suggested.



More information about the Linux-nvme mailing list