[PATCH] mtd: blktrans: keep reclaim out of the ->release paths
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 16 21:40:09 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: blktrans: missing Fixes trailer for reclaim deadlock in
release paths
--
commit 232393974881d584472bbb349c3d7552980a5ca0
Author: Shuai Liu <847807867 at qq.com>
> mtd: blktrans: keep reclaim out of the ->release paths
>
> blktrans_release() invokes tr->release() while holding dev->lock, and
> translators can walk down into the flash driver from there:
> mtdblock_release() flushes its write cache via write_cached_data() ->
> erase_write() -> mtd_erase(), and concat_erase() allocates a struct
> erase_info with GFP_KERNEL. del_mtd_blktrans_dev() calls ->release()
> under the same lock on the device removal path.
>
> Reclaim from those allocations can recurse back into the same block
> queue and deadlock. lockdep reports the full cycle when a write to the
> concat device is flushed at last close:
>
> init/1 is trying to acquire lock:
> fs_reclaim, at: __kmalloc_cache_noprof
> but task is already holding lock:
> &mtdblk->cache_mutex, at: mtdblock_release
>
> Chain exists of:
> fs_reclaim --> &new->lock --> &mtdblk->cache_mutex
>
> the existing dependency chain (in reverse order) is:
> fs_reclaim -> q_usage_counter(io) -> elevator_lock
> -> set->srcu -> new->lock -> mtdblk->cache_mutex
>
> Call Trace:
> concat_erase
> mtd_erase
> erase_write
> write_cached_data
> mtdblock_release
> blktrans_release
> bdev_release
>
> The io path is already protected: mtd_queue_rq() disables reclaim
> across dispatch with memalloc_noio_save(), because translators may
> allocate while processing requests under dev->lock and the srcu read
> side. ->release() runs under the same locks, so give it the same
> treatment in blktrans_release() and del_mtd_blktrans_dev().
>
> Verified with mtdram + block2mtd + concat + mtdblock on QEMU
> (CONFIG_PROVE_LOCKING): writing through /dev/mtdblockN and closing
> the fd produces the warning above on the unpatched kernel and stays
> silent with this patch, with the readback still succeeding.
>
> Reported-by: syzbot+c66e7044aa73c620d862 at syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=c66e7044aa73c620d862
> Signed-off-by: Shuai Liu <847807867 at qq.com>
[Severity: Low]
This fixes a reclaim recursion deadlock when ->release() is called under
the per-device mutex introduced by commit 048d87199566 ("mtd: blktrans:
Hotplug fixes"). Should the commit message include a Fixes tag for stable
backporting:
Fixes: 048d87199566 ("mtd: blktrans: Hotplug fixes")
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_B9AEB406CBA2FC785312AE8158D20489FB06@qq.com?part=1
More information about the linux-mtd
mailing list