[PATCH v2] RDMA/cma: Use a separate lockdep class for the listening cm_id

sashiko-bot at kernel.org sashiko-bot at kernel.org
Tue Nov 17 03:48:42 PST 2026


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] RDMA/cma: unsafe lockdep_set_class() placement in
  rdma_listen()
- [Low] RDMA/cma: unreclassified handler_mutex on
  nvmet_rdma_enable_port() error
--

commit d2c299202b2d013f5516cd16c2fdd187fc66e56a
Author: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>

RDMA/cma: Use a separate lockdep class for the listening cm_id

This commit assigns a separate lockdep class to id_priv->handler_mutex at the
start of rdma_listen() to prevent a false-positive circular locking dependency
warning between listening and connected cm_ids in nvmet-rdma.

Link: https://lore.kernel.org/linux-nvme/at36um4zrsfOr3kh@shinmob/

> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 337a49d1acf72..b3678ddc79a4a 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -3949,6 +3949,13 @@ int rdma_listen(struct rdma_cm_id *id, int backlog)
>  		container_of(id, struct rdma_id_private, id);
>  	int ret;
>  
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC
> +	static struct lock_class_key cma_listen_handler_mutex_key;
> +
> +	lockdep_set_class(&id_priv->handler_mutex,
> +			  &cma_listen_handler_mutex_key);
> +#endif
> +
>  	if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_LISTEN)) {
>  		struct sockaddr_in any_in = {
>  			.sin_family = AF_INET,

[Severity: Medium]
Can calling lockdep_set_class() here race with concurrent users of
id_priv->handler_mutex and misclassify non-listening IDs?

rdma_listen() reinitializes id_priv->handler_mutex.dep_map before validating
id_priv->state and without holding id_priv->handler_mutex.  Through
ucma_listen(), userspace only holds ctx->mutex and can call rdma_listen() on a
cm_id in any state while another thread or CM callback acquires or releases
id_priv->handler_mutex:

CPU0                                  CPU1
ucma_listen()                         cma_ib_handler()
  mutex_lock(&ctx->mutex)               mutex_lock(&id_priv->handler_mutex)
  rdma_listen()                           look_up_lock_class()
    lockdep_set_class(&handler_mutex)     ...  <-- data race on dep_map
    cma_comp_exch() -> fails

Even when id_priv->state is RDMA_CM_ADDR_BOUND, id_priv is already on
cma_dev->id_list, where cma_send_device_removal_put() or addr_handler() can
hold id_priv->handler_mutex concurrently.  Mutating dep_map while the mutex is
being acquired or held can trigger the lockdep WARN_ONCE() in
look_up_lock_class() or corrupt the held-lock stack on unlock and disable
lockdep.

In addition, if rdma_listen() fails the state check, fails rdma_bind_addr(),
or jumps to err: and reverts id_priv->state to RDMA_CM_ADDR_BOUND, a
non-listening cm_id is left with cma_listen_handler_mutex_key, defeating the
lock-class separation if the ID is later used for a connection.

[Severity: Low]
Does reclassifying id_priv->handler_mutex in rdma_listen() still leave the
false-positive lockdep splat reachable when nvmet_rdma_enable_port() fails
before reaching rdma_listen()?

nvmet_port_subsys_allow_link() holds nvmet_config_sem across
nvmet_enable_port() -> nvmet_rdma_add_port() -> nvmet_rdma_enable_port():

drivers/nvme/target/rdma.c:nvmet_rdma_enable_port() {
    ...
	ret = rdma_bind_addr(cm_id, addr);
	if (ret) {
		pr_err("binding CM ID to %pISpcs failed (%d)\n", addr, ret);
		goto out_destroy_id;
	}

	ret = rdma_listen(cm_id, 128);
	if (ret) {
		pr_err("listening to %pISpcs failed (%d)\n", addr, ret);
		goto out_destroy_id;
	}

	port->priv = cm_id;
	return 0;

out_destroy_id:
	rdma_destroy_id(cm_id);
	return ret;
}

If rdma_set_afonly() or rdma_bind_addr() fails, rdma_destroy_id(cm_id) locks
id_priv->handler_mutex under nvmet_config_sem while handler_mutex still has
the default lockdep class, recording the same nvmet_config_sem ->
handler_mutex dependency as before.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117113129.746490-1-shinichiro.kawasaki@wdc.com?part=1



More information about the Linux-nvme mailing list