From: sashiko-bot@kernel.org
To: "Shin'ichiro Kawasaki" <shinichiro.kawasaki@wdc.com>,
linux-rdma@vger.kernel.org
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v2] RDMA/cma: Use a separate lockdep class for the listening cm_id
Date: Tue, 17 Nov 2026 11:48:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-218731@kernel.org> (raw)
In-Reply-To: <20261117113129.746490-1-shinichiro.kawasaki@wdc.com>
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@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
prev parent reply other threads:[~2026-11-17 11:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:31 [PATCH v2] RDMA/cma: Use a separate lockdep class for the listening cm_id Shin'ichiro Kawasaki
2026-11-17 11:48 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-218731@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-rdma@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.