Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 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>
Link: https://patch.msgid.link/20260423033058.2805135-2-tom.leiming@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
47903faa 1cdf3b28

+4
+4
drivers/block/ublk_drv.c
··· 5486 5486 struct ublk_buf_range *range; 5487 5487 struct page *pages[32]; 5488 5488 5489 + mas_lock(&mas); 5489 5490 mas_for_each(&mas, range, ULONG_MAX) { 5490 5491 unsigned long base = mas.index; 5491 5492 unsigned long nr = mas.last - base + 1; 5492 5493 unsigned long off; 5494 + 5495 + mas_erase(&mas); 5493 5496 5494 5497 for (off = 0; off < nr; ) { 5495 5498 unsigned int batch = min_t(unsigned long, ··· 5506 5503 } 5507 5504 kfree(range); 5508 5505 } 5506 + mas_unlock(&mas); 5509 5507 mtree_destroy(&ub->buf_tree); 5510 5508 ida_destroy(&ub->buf_ida); 5511 5509 }