[PATCH] nvme: fix deadlock between reset and scan

Keith Busch kbusch at kernel.org
Mon Nov 27 10:07:12 PST 2023


On Thu, Nov 23, 2023 at 07:00:13PM +0800, Bitao Hu wrote:
> @@ -3631,6 +3631,11 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
>  		goto out_unlink_ns;
>  
>  	down_write(&ctrl->namespaces_rwsem);
> +	/* preventing adding ns during resetting */
> +	if (unlikely(ctrl->state != NVME_CTRL_LIVE)) {

We can't rely on ctrl->state for preventing deadlocks. Reading unlocked
ctrl->state is often used, but should be considered advisory-only since
the state could change immediatly after reading it.

> +		up_write(&ctrl->namespaces_rwsem);
> +		goto out_unlink_ns;
> +	}
>  	nvme_ns_add_to_ctrl_list(ns);
>  	up_write(&ctrl->namespaces_rwsem);
>  	nvme_get_ctrl(ctrl);



More information about the Linux-nvme mailing list