Netdev List
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Allison Henderson <achender@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v7 0/3] net/rds: fix the probe cm_id lock ordering
Date: Fri,  4 Dec 2026 10:22:41 +0800	[thread overview]
Message-ID: <20261204022245.381-1-chenaibing@cmss.chinamobile.com> (raw)

syzbot reported a circular locking dependency between rds_trans_sem and
rdma_cm's handler_mutex:

  CPU0 (passive connection)          CPU1 (bind)
  ----                               ----
  mutex_lock(&handler_mutex)         down_read(&rds_trans_sem)
  rds_ib_cm_handle_connect()         rds_ib_laddr_check()
    rds_conn_create()                  rdma_destroy_id()
      rds_trans_get_preferred()          mutex_lock(&handler_mutex)
        down_read(&rds_trans_sem)

Patch 2 fixes the cycle the way the review asked for: take the module
reference for the candidate transport under rds_trans_sem, drop the
semaphore, and only then call ->laddr_check().

Dropping the semaphore means rds_trans_unregister() no longer waits for
an in-flight ->laddr_check(), so the module reference has to be
sufficient on its own.  It is not while the module is being initialized:
rds_rdma_init() calls rds_ib_init(), which registers the transport, and
only then creates the RDMA CM listener; if that fails, rds_ib_exit()
unregisters again, and do_init_module() frees the module without waiting
for a reference taken on a module in MODULE_STATE_COMING.  Patch 1
registers the transport only once the listener is up, so a transport is
never reachable from a module that can still fail to initialize.

Patch 3 handles the second problem on the same path: when ->laddr_check()
runs from the passive connection path, cma_ib_req_handler() already holds
the listener's handler_mutex, and rds_ib_laddr_check() destroys a probe
cm_id whose rdma_destroy_id() takes the handler mutex of the probe id.
Both are instances of the same lock class, so lockdep reports recursive
locking once the semaphore cycle is gone.  Queue that destroy on rds_wq.

Evidence, both nodes on a PROVE_LOCKING kernel, rxe0 on each node, an RDS
connection established and then a bind() to an address that is not on an
RDMA device (which is what reaches rds_ib_laddr_check_cm()):

  mainline:  WARNING: possible circular locking dependency detected
             rds_trans_sem --> &id_priv->handler_mutex
                           --> &id_priv->handler_mutex/1
             ... rdma_destroy_id <- rds_ib_laddr_check
                 <- rds_trans_get_preferred <- rds_bind
                 and down_read(rds_trans_sem) <- rds_trans_get_preferred
                 <- __rds_conn_create

  this series: no lockdep report at all in the same run.

I could not run syzbot's reproducer; the setup above is a hand-made
equivalent.  No runtime testing on real RDMA hardware was done, so the
patches are compile tested (W=1) and tested on rxe only.

v7:
- add patch 1: the module reference taken once rds_trans_sem is dropped
  cannot pin a module in MODULE_STATE_COMING that do_init_module() is
  about to free; move the transport registration after the listener.
- patch 3: describe the -ENOMEM bound as bounding the queue of pending
  destroys, and note that a failing laddr_check() is handled like any
  other unsuccessful check.
- fix the comments that still described the old locking.

v6:
- add patch 2: the ordering fix alone still leaves the probe cm_id
  destroy nested under the CM handler's mutex, which lockdep reports as
  recursive locking once the semaphore cycle is gone.

v5:
- implement the ordering fix in rds_trans_get_preferred() as requested
  in the review (dropping the net/rds/ib.c workqueue, the global cap and
  the rds_wq flush of v4) and describe the report as a lock class
  conflict rather than a deadlock.

v4 and earlier:
- deferred rdma_destroy_id() to a workqueue and bounded the backlog.

Reported-by: syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <achender@kernel.org>
Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>

Aibing Chen (3):
  net/rds: register the IB transport last
  net/rds: drop rds_trans_sem around laddr_check()
  net/rds: defer the probe cm_id destroy to rds_wq

 net/rds/ib.c             | 56 ++++++++++++++++++++++++++++++++++++----
 net/rds/rdma_transport.c |  7 ++++-
 net/rds/transport.c      | 25 +++++++++++++-----
 3 files changed, 75 insertions(+), 13 deletions(-)




             reply	other threads:[~2026-12-04  2:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:22 Aibing Chen [this message]
2026-12-04  2:22 ` [PATCH net v7 1/3] net/rds: register the IB transport last Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko

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=20261204022245.381-1-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=achender@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox