Skip to content

Commit 47903fa

Browse files
ming1axboe
authored andcommitted
ublk: fix maple tree lockdep warning in ublk_buf_cleanup
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: 5e86443 ("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> Link: https://patch.msgid.link/20260423033058.2805135-2-tom.leiming@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1cdf3b2 commit 47903fa

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5486,11 +5486,14 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
54865486
struct ublk_buf_range *range;
54875487
struct page *pages[32];
54885488

5489+
mas_lock(&mas);
54895490
mas_for_each(&mas, range, ULONG_MAX) {
54905491
unsigned long base = mas.index;
54915492
unsigned long nr = mas.last - base + 1;
54925493
unsigned long off;
54935494

5495+
mas_erase(&mas);
5496+
54945497
for (off = 0; off < nr; ) {
54955498
unsigned int batch = min_t(unsigned long,
54965499
nr - off, 32);
@@ -5503,6 +5506,7 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
55035506
}
55045507
kfree(range);
55055508
}
5509+
mas_unlock(&mas);
55065510
mtree_destroy(&ub->buf_tree);
55075511
ida_destroy(&ub->buf_ida);
55085512
}

0 commit comments

Comments
 (0)