Skip to content

Commit 4027807

Browse files
ming1kawasaki
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 <[email protected]> Closes: https://lore.kernel.org/linux-block/[email protected]/ Signed-off-by: Ming Lei <[email protected]>
1 parent 6a0b974 commit 4027807

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
@@ -5478,11 +5478,14 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
54785478
struct ublk_buf_range *range;
54795479
struct page *pages[32];
54805480

5481+
mas_lock(&mas);
54815482
mas_for_each(&mas, range, ULONG_MAX) {
54825483
unsigned long base = mas.index;
54835484
unsigned long nr = mas.last - base + 1;
54845485
unsigned long off;
54855486

5487+
mas_erase(&mas);
5488+
54865489
for (off = 0; off < nr; ) {
54875490
unsigned int batch = min_t(unsigned long,
54885491
nr - off, 32);
@@ -5495,6 +5498,7 @@ static void ublk_buf_cleanup(struct ublk_device *ub)
54955498
}
54965499
kfree(range);
54975500
}
5501+
mas_unlock(&mas);
54985502
mtree_destroy(&ub->buf_tree);
54995503
ida_destroy(&ub->buf_ida);
55005504
}

0 commit comments

Comments
 (0)