From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Caleb Sander Mateos <csander@purestorage.com>,
"Liam R . Howlett" <liam.howlett@oracle.com>,
Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Ming Lei <tom.leiming@gmail.com>
Subject: [PATCH 1/3] ublk: fix maple tree lockdep warning in ublk_buf_cleanup
Date: Thu, 23 Apr 2026 11:30:56 +0800 [thread overview]
Message-ID: <20260423033058.2805135-2-tom.leiming@gmail.com> (raw)
In-Reply-To: <20260423033058.2805135-1-tom.leiming@gmail.com>
ublk_buf_cleanup() iterates the maple tree with mas_for_each()
without holding mas_lock, triggering a lockdep splat on
CONFIG_PROVE_RCU kernels since mas_find() internally uses
rcu_dereference_check() which requires either RCU or the tree lock.
Fix by holding mas_lock around the iteration, and call mas_erase()
before freeing each range to avoid dangling pointers in the tree.
Fixes: 5e864438e285 ("ublk: replace xarray with IDA for shmem buffer index allocation")
Reported-by: Jens Axboe <axboe@kernel.dk>
Closes: https://lore.kernel.org/linux-block/0349d72d-dff8-4f9f-b448-919fa5ae96da@kernel.dk/
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
drivers/block/ublk_drv.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 49fb584e392b..e8d71617fbda 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -5469,11 +5469,14 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
struct ublk_buf_range *range;
struct page *pages[32];
+ mas_lock(&mas);
mas_for_each(&mas, range, ULONG_MAX) {
unsigned long base = mas.index;
unsigned long nr = mas.last - base + 1;
unsigned long off;
+ mas_erase(&mas);
+
for (off = 0; off < nr; ) {
unsigned int batch = min_t(unsigned long,
nr - off, 32);
@@ -5486,6 +5489,7 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
}
kfree(range);
}
+ mas_unlock(&mas);
mtree_destroy(&ub->buf_tree);
ida_destroy(&ub->buf_ida);
}
--
2.53.0
next prev parent reply other threads:[~2026-04-23 3:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-23 3:30 [PATCH 0/3] ublk: fix maple tree lockdep warning and cleanup Ming Lei
2026-04-23 3:30 ` Ming Lei [this message]
2026-04-23 3:30 ` [PATCH 2/3] ublk: refactor common helper ublk_shmem_remove_ranges() Ming Lei
2026-04-23 3:30 ` [PATCH 3/3] ublk: avoid unpinning pages under maple tree spinlock Ming Lei
2026-04-23 10:55 ` [PATCH 0/3] ublk: fix maple tree lockdep warning and cleanup Jens Axboe
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=20260423033058.2805135-2-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=liam.howlett@oracle.com \
--cc=linux-block@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox