[PATCH] nvme-pci: silence a lockdep complaint

Christoph Hellwig hch at lst.de
Thu May 23 01:06:52 PDT 2024


On Wed, May 22, 2024 at 03:36:19PM -0600, Keith Busch wrote:
> +	mutex_lock(&ctrl->namespaces_lock);
> +	list_del_rcu(&ns->list);
> +	mutex_unlock(&ctrl->namespaces_lock);

This needs a synchronize_srcu().  Maybe factor out a helper to share the
code with nvme_ns_remove?

> -	down_write(&ctrl->namespaces_rwsem);
> +	mutex_lock(&ctrl->namespaces_lock);
>  	list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
>  		if (ns->head->ns_id > nsid)
> -			list_move_tail(&ns->list, &rm_list);
> +			list_splice_init_rcu(&ns->list, &rm_list, synchronize_rcu);

Overly long line here.

>  	}
> -	up_write(&ctrl->namespaces_rwsem);
> +	mutex_unlock(&ctrl->namespaces_lock);
>  
>  	list_for_each_entry_safe(ns, next, &rm_list, list)
>  		nvme_ns_remove(ns);
>  
> +	synchronize_srcu(&ctrl->srcu);

The synchronize_srcu should go right after the mutex_unlock as it
synchronizes the ctrl->namespaces access.

> +	mutex_lock(&ctrl->namespaces_lock);
> +	list_splice_init_rcu(&ctrl->namespaces, &ns_list, synchronize_rcu);
> +	mutex_unlock(&ctrl->namespaces_lock);
>  
>  	list_for_each_entry_safe(ns, next, &ns_list, list)
>  		nvme_ns_remove(ns);
> +
> +	synchronize_srcu(&ctrl->srcu);

Same here.

>  	kref_get(&ns->kref);
> -	up_read(&ctrl->namespaces_rwsem);
> +	srcu_read_unlock(&ctrl->srcu, srcu_idx);

The kref_get here has to become a kref_get_unless_zero (aka nvme_get_ns).




More information about the Linux-nvme mailing list