[PATCH 2/2] nvme: fix unmatched id's under delayed path deletion

Nilay Shroff nilay at linux.ibm.com
Wed Feb 25 23:04:35 PST 2026



On 2/26/26 1:51 AM, Keith Busch wrote:
> From: Keith Busch <kbusch at kernel.org>
> 
> The NVMe controller is allowed to reuse an NSID for a new namespace after
> deleting the previous namespace that had been using it. The delayed removal may
> have the stale namespace head in the subsystem list pending the timer, which
> would cause the scan to falsely report an ID mismatch error for the new
> namespace. Flush the pending removal work and retry to resolve this.
> 
> Signed-off-by: Keith Busch <kbusch at kernel.org>
> ---
>  drivers/nvme/host/core.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 3de52f1d27234..e731d3182f095 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3966,6 +3966,7 @@ static int nvme_global_check_duplicate_ids(struct nvme_subsystem *this,
>  
>  static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
>  {
> +	bool retry = IS_ENABLED(CONFIG_NVME_MULTIPATH);
>  	struct nvme_ctrl *ctrl = ns->ctrl;
>  	struct nvme_ns_head *head = NULL;
>  	int ret;
> @@ -4008,6 +4009,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
>  		ctrl->quirks |= NVME_QUIRK_BOGUS_NID;
>  	}
>  
> +again:
>  	mutex_lock(&ctrl->subsys->lock);
>  	head = nvme_find_ns_head(ctrl, info->nsid);
>  	if (!head) {
> @@ -4033,6 +4035,22 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
>  			goto out_put_ns_head;
>  		}
>  		if (!nvme_ns_ids_equal(&head->ids, &info->ids)) {
> +			/*
> +			 * A newly created namespace can reuse an NSID that was
> +			 * previously deleted. If the head has no active paths,
> +			 * it is pending delayed removal and still occupying
> +			 * this NSID in the subsystem list. Flush the removal
> +			 * work to clear the stale head and retry.
> +			 */
> +			if (retry && list_empty(&head->list)) {
> +				mutex_unlock(&ctrl->subsys->lock);
> +				flush_delayed_work(&head->remove_work);
> +				nvme_put_ns_head(head);
> +				retry = false;
> +				goto again;
> +			}
> +
> +			WARN_ONCE(list_empty(&head->list));

We need to replace WARN_ONCE with WARN_ON_ONCE (as you already mentioned 
in another thread), so with that change applied, this looks good to me:

Reviewed-by: Nilay Shroff <nilay at linux.ibm.com>




More information about the Linux-nvme mailing list