* [syzbot] [mtd?] possible deadlock in blktrans_release
@ 2026-11-16 16:01 syzbot
2026-11-17 5:28 ` [PATCH] mtd: blktrans: keep reclaim out of the ->release paths Shuai Liu
0 siblings, 1 reply; 6+ messages in thread
From: syzbot @ 2026-11-16 16:01 UTC (permalink / raw)
To: linux-kernel, linux-mtd, miquel.raynal, richard, syzkaller-bugs,
vigneshr
Hello,
syzbot found the following issue on:
HEAD commit: 23c62304dde2 Merge tag 'for-linus-7.4a-rc3-tag' of git://g..
git tree: https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux master
console output: https://syzkaller.appspot.com/x/log.txt?x=136febfd580000
kernel config: https://syzkaller.appspot.com/x/.config?x=78b97db96b301702
dashboard link: https://syzkaller.appspot.com/bug?extid=c66e7044aa73c620d862
compiler: aarch64-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
userspace arch: arm64
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/fa3fbcfdac58/non_bootable_disk-23c62304.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/72fee1819d5c/vmlinux-23c62304.xz
kernel image: https://storage.googleapis.com/syzbot-assets/aee675e8df7d/Image-23c62304.gz.xz
AI-generated root cause summary:
A circular locking dependency (deadlock) occurs between memory reclaim
(fs_reclaim) and MTD block device locks (&dev->lock and &mtdblk->cache_mutex).
During regular block request processing, mtd_queue_rq() in
drivers/mtd/mtd_blkdevs.c acquires &dev->lock (and &mtdblk->cache_mutex for
flushes) within the block I/O dispatch path, shielded by memalloc_noio_save().
However, in blktrans_release(), dev->tr->release() (mtdblock_release()) is
invoked while holding &dev->lock without NOIO protection, locking
&mtdblk->cache_mutex to write dirty cached data via write_cached_data() ->
erase_write() -> mtd_erase(). When operating over an mtdconcat device,
concat_erase() in drivers/mtd/mtdconcat.c executes kmalloc_obj(struct
erase_info) with GFP_KERNEL just to make a synchronous local copy of a 24-byte
struct, acquiring fs_reclaim while holding &dev->lock and &mtdblk->cache_mutex
and creating an ABBA deadlock.
full analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=c66e7044aa73c620d862
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+c66e7044aa73c620d862@syzkaller.appspotmail.com
mtdblock_release
mtdblock: writing cached data for "0.flash" at 0x40000, size 0x40000
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Tainted: G L
------------------------------------------------------
syz.3.780/6156 is trying to acquire lock:
ffff8000887b8e80
(fs_reclaim){+.+.}-{0:0}, at: might_alloc include/linux/sched/mm.h:316 [inline]
(fs_reclaim){+.+.}-{0:0}, at: slab_pre_alloc_hook mm/slub.c:4673 [inline]
(fs_reclaim){+.+.}-{0:0}, at: slab_alloc_node mm/slub.c:5011 [inline]
(fs_reclaim){+.+.}-{0:0}, at: __kmalloc_cache_noprof+0x60/0x680 mm/slub.c:5676
but task is already holding lock:
ffff0000180b1db0
(&mtdblk->cache_mutex){+.+.}-{4:4}, at: mtdblock_release+0x28/0x1ec drivers/mtd/mtdblock.c:288
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #5 (&mtdblk->cache_mutex){+.+.}-{4:4}:
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x14c/0x1000 kernel/locking/mutex.c:821
mutex_lock_nested+0x24/0x30 kernel/locking/mutex.c:874
mtdblock_release+0x28/0x1ec drivers/mtd/mtdblock.c:288
blktrans_release+0x198/0x238 drivers/mtd/mtd_blkdevs.c:246
blkdev_put_whole+0x98/0xf0 block/bdev.c:766
bdev_release+0x2a4/0x510 block/bdev.c:1189
blkdev_release+0x14/0x30 block/fops.c:690
__fput+0x2d0/0x980 fs/file_table.c:512
fput_close_sync+0xe0/0x238 fs/file_table.c:618
filp_close_sync+0x5c/0x98 fs/open.c:1574
__do_sys_close fs/open.c:1597 [inline]
__se_sys_close fs/open.c:1584 [inline]
__arm64_sys_close+0x64/0xc0 fs/open.c:1584
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x74/0x240 arch/arm64/kernel/syscall.c:49
el0_svc_common.constprop.0+0xac/0x230 arch/arm64/kernel/syscall.c:121
do_el0_svc+0x40/0x58 arch/arm64/kernel/syscall.c:140
el0_svc+0x58/0x21c arch/arm64/kernel/entry-common.c:797
el0t_64_sync_handler+0xa0/0xe4 arch/arm64/kernel/entry-common.c:816
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
-> #4 (&new->lock){+.+.}-{4:4}:
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x14c/0x1000 kernel/locking/mutex.c:821
mutex_lock_nested+0x24/0x30 kernel/locking/mutex.c:874
mtd_blktrans_work drivers/mtd/mtd_blkdevs.c:152 [inline]
mtd_queue_rq+0x324/0x1754 drivers/mtd/mtd_blkdevs.c:183
blk_mq_dispatch_rq_list+0x2e0/0x177c block/blk-mq.c:2141
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:168 [inline]
blk_mq_do_dispatch_sched block/blk-mq-sched.c:182 [inline]
__blk_mq_sched_dispatch_requests+0xc58/0xe60 block/blk-mq-sched.c:307
blk_mq_sched_dispatch_requests+0x7c/0x110 block/blk-mq-sched.c:329
blk_mq_run_hw_queue+0x204/0x4f4 block/blk-mq.c:2379
blk_mq_dispatch_list+0x3fc/0xc80 block/blk-mq.c:2942
blk_mq_flush_plug_list block/blk-mq.c:2990 [inline]
blk_mq_flush_plug_list+0xf0/0x520 block/blk-mq.c:2962
__blk_flush_plug+0x210/0x3d0 block/blk-core.c:1274
blk_finish_plug block/blk-core.c:1301 [inline]
blk_finish_plug+0x5c/0xa8 block/blk-core.c:1298
read_pages+0x3f0/0x9f0 mm/readahead.c:187
page_cache_ra_order+0x4c0/0xd28 mm/readahead.c:541
page_cache_sync_ra+0x5d4/0x990 mm/readahead.c:649
filemap_get_pages+0x278/0x1760 mm/filemap.c:2743
filemap_splice_read+0x3a8/0xb30 mm/filemap.c:3132
blkdev_splice_read+0x84/0xc0 block/fops.c:912
do_splice_read fs/splice.c:907 [inline]
do_splice_read+0x1bc/0x364 fs/splice.c:881
splice_direct_to_actor+0x21c/0x86c fs/splice.c:1004
do_splice_direct_actor fs/splice.c:1157 [inline]
do_splice_direct+0x114/0x1e0 fs/splice.c:1183
do_sendfile+0x798/0xbd0 fs/read_write.c:1351
__do_sys_sendfile64 fs/read_write.c:1412 [inline]
__se_sys_sendfile64 fs/read_write.c:1398 [inline]
__arm64_sys_sendfile64+0x214/0x260 fs/read_write.c:1398
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x74/0x240 arch/arm64/kernel/syscall.c:49
el0_svc_common.constprop.0+0xac/0x230 arch/arm64/kernel/syscall.c:121
do_el0_svc+0x40/0x58 arch/arm64/kernel/syscall.c:140
el0_svc+0x58/0x21c arch/arm64/kernel/entry-common.c:797
el0t_64_sync_handler+0xa0/0xe4 arch/arm64/kernel/entry-common.c:816
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
-> #3 (set->srcu){.+.+}-{0:0}:
lock_sync kernel/locking/lockdep.c:5991 [inline]
lock_sync+0xec/0x17c kernel/locking/lockdep.c:5979
srcu_lock_sync include/linux/srcu.h:261 [inline]
__synchronize_srcu+0xa8/0x2c8 kernel/rcu/srcutree.c:1662
synchronize_srcu_expedited kernel/rcu/srcutree.c:1707 [inline]
synchronize_srcu+0xb8/0x3a0 kernel/rcu/srcutree.c:1763
blk_mq_wait_quiesce_done block/blk-mq.c:284 [inline]
blk_mq_wait_quiesce_done block/blk-mq.c:281 [inline]
blk_mq_quiesce_queue block/blk-mq.c:304 [inline]
blk_mq_quiesce_queue+0xf4/0x160 block/blk-mq.c:299
elevator_switch+0x118/0x430 block/elevator.c:576
elevator_change+0x294/0x420 block/elevator.c:681
elevator_set_default+0x210/0x2b8 block/elevator.c:754
blk_register_queue+0x37c/0x508 block/blk-sysfs.c:992
__add_disk+0x588/0xc0c block/genhd.c:531
add_disk_fwnode+0x110/0x3e0 block/genhd.c:600
device_add_disk+0x14/0x20 block/genhd.c:630
add_disk include/linux/blkdev.h:799 [inline]
nbd_dev_add+0x604/0x9a0 drivers/block/nbd.c:2026
nbd_init+0x184/0x1a4 drivers/block/nbd.c:2743
do_one_initcall+0x134/0x854 init/main.c:1419
do_initcall_level init/main.c:1481 [inline]
do_initcalls init/main.c:1497 [inline]
do_basic_setup init/main.c:1517 [inline]
kernel_init_freeable+0x5e8/0x66c init/main.c:1732
kernel_init+0x2c/0x14c init/main.c:1622
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:870
-> #2 (&q->elevator_lock){+.+.}-{4:4}:
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x14c/0x1000 kernel/locking/mutex.c:821
mutex_lock_nested+0x24/0x30 kernel/locking/mutex.c:874
queue_requests_store+0x28c/0x4e0 block/blk-sysfs.c:124
queue_attr_store+0x1f8/0x260 block/blk-sysfs.c:906
sysfs_kf_write+0xc4/0x10c fs/sysfs/file.c:145
kernfs_fop_write_iter+0x2a4/0x460 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:575 [inline]
vfs_write+0x5b0/0xcc8 fs/read_write.c:667
ksys_write+0xf0/0x1e0 fs/read_write.c:719
__do_sys_write fs/read_write.c:730 [inline]
__se_sys_write fs/read_write.c:727 [inline]
__arm64_sys_write+0x70/0xa0 fs/read_write.c:727
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x74/0x240 arch/arm64/kernel/syscall.c:49
el0_svc_common.constprop.0+0xac/0x230 arch/arm64/kernel/syscall.c:121
do_el0_svc+0x40/0x58 arch/arm64/kernel/syscall.c:140
el0_svc+0x58/0x21c arch/arm64/kernel/entry-common.c:797
el0t_64_sync_handler+0xa0/0xe4 arch/arm64/kernel/entry-common.c:816
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
-> #1 (&q->q_usage_counter(io)#51){++++}-{0:0}:
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
blk_alloc_queue+0x4e0/0x640 block/blk-core.c:505
blk_mq_alloc_queue+0x148/0x230 block/blk-mq.c:4468
__blk_mq_alloc_disk+0x20/0x120 block/blk-mq.c:4515
null_add_dev+0x9dc/0x17e8 drivers/block/null_blk/main.c:2018
null_create_dev drivers/block/null_blk/main.c:2115 [inline]
null_init+0x248/0x2f4 drivers/block/null_blk/main.c:2179
do_one_initcall+0x134/0x854 init/main.c:1419
do_initcall_level init/main.c:1481 [inline]
do_initcalls init/main.c:1497 [inline]
do_basic_setup init/main.c:1517 [inline]
kernel_init_freeable+0x5e8/0x66c init/main.c:1732
kernel_init+0x2c/0x14c init/main.c:1622
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:870
-> #0 (fs_reclaim){+.+.}-{0:0}:
check_prev_add+0x110/0xcb4 kernel/locking/lockdep.c:3209
check_prevs_add kernel/locking/lockdep.c:3328 [inline]
validate_chain kernel/locking/lockdep.c:3952 [inline]
__lock_acquire+0x1490/0x1af0 kernel/locking/lockdep.c:5288
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
__fs_reclaim_acquire mm/page_alloc.c:4375 [inline]
fs_reclaim_acquire+0x130/0x160 mm/page_alloc.c:4389
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4673 [inline]
slab_alloc_node mm/slub.c:5011 [inline]
__kmalloc_cache_noprof+0x60/0x680 mm/slub.c:5676
_kmalloc_noprof include/linux/slab.h:991 [inline]
concat_erase+0xf4/0x734 drivers/mtd/mtdconcat.c:407
mtd_erase+0x29c/0xb04 drivers/mtd/mtdcore.c:1497
erase_write+0xb0/0x170 drivers/mtd/mtdblock.c:57
write_cached_data+0xe0/0x270 drivers/mtd/mtdblock.c:90
mtdblock_release+0x30/0x1ec drivers/mtd/mtdblock.c:289
blktrans_release+0x198/0x238 drivers/mtd/mtd_blkdevs.c:246
blkdev_put_whole+0x98/0xf0 block/bdev.c:766
bdev_release+0x2a4/0x510 block/bdev.c:1189
blkdev_release+0x14/0x30 block/fops.c:690
__fput+0x2d0/0x980 fs/file_table.c:512
____fput+0x14/0x20 fs/file_table.c:541
task_work_run+0x134/0x238 kernel/task_work.c:233
get_signal+0x9d0/0x1b18 kernel/signal.c:2885
arch_do_signal_or_restart+0x1a0/0x6f4 arch/arm64/kernel/signal.c:1651
__exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
exit_to_user_mode_loop+0x13c/0x1c8 kernel/entry/common.c:101
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
arm64_syscall_exit_to_user_mode arch/arm64/kernel/entry-common.c:147 [inline]
el0_svc+0x1dc/0x21c arch/arm64/kernel/entry-common.c:798
el0t_64_sync_handler+0xa0/0xe4 arch/arm64/kernel/entry-common.c:816
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
other info that might help us debug this:
Chain exists of:
fs_reclaim --> &new->lock --> &mtdblk->cache_mutex
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&mtdblk->cache_mutex);
lock(&new->lock);
lock(&mtdblk->cache_mutex);
lock(fs_reclaim);
*** DEADLOCK ***
locks held by syz.3.780/6156: 3, on CPU#1:
#0: ffff000016ef7350 (&disk->open_mutex){+.+.}-{4:4}, at: bdev_release+0x104/0x510 block/bdev.c:1173
#1: ffff0000180b1c80 (&new->lock){+.+.}-{4:4}, at: blktrans_release+0x40/0x238 drivers/mtd/mtd_blkdevs.c:237
#2: ffff0000180b1db0 (&mtdblk->cache_mutex){+.+.}-{4:4}, at: mtdblock_release+0x28/0x1ec drivers/mtd/mtdblock.c:288
stack backtrace:
CPU: 1 UID: 0 PID: 6156 Comm: syz.3.780 Tainted: G L syzkaller #0 PREEMPT
Tainted: [L]=SOFTLOCKUP
Hardware name: linux,dummy-virt (DT)
dump_backtrace(regs = 0000000000000000 tsk = 0000000000000000)
Call trace:
show_stack+0x18/0x24 arch/arm64/kernel/stacktrace.c:499 (C)
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x7c/0xb0 lib/dump_stack.c:120
dump_stack+0x1c/0x28 lib/dump_stack.c:129
print_circular_bug+0x23c/0x284 kernel/locking/lockdep.c:2087
check_noncircular+0x174/0x194 kernel/locking/lockdep.c:2219
check_prev_add+0x110/0xcb4 kernel/locking/lockdep.c:3209
check_prevs_add kernel/locking/lockdep.c:3328 [inline]
validate_chain kernel/locking/lockdep.c:3952 [inline]
__lock_acquire+0x1490/0x1af0 kernel/locking/lockdep.c:5288
lock_acquire kernel/locking/lockdep.c:5942 [inline]
lock_acquire+0x2b8/0x3fc kernel/locking/lockdep.c:5899
__fs_reclaim_acquire mm/page_alloc.c:4375 [inline]
fs_reclaim_acquire+0x130/0x160 mm/page_alloc.c:4389
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4673 [inline]
slab_alloc_node mm/slub.c:5011 [inline]
__kmalloc_cache_noprof+0x60/0x680 mm/slub.c:5676
_kmalloc_noprof include/linux/slab.h:991 [inline]
concat_erase+0xf4/0x734 drivers/mtd/mtdconcat.c:407
mtd_erase+0x29c/0xb04 drivers/mtd/mtdcore.c:1497
erase_write+0xb0/0x170 drivers/mtd/mtdblock.c:57
write_cached_data+0xe0/0x270 drivers/mtd/mtdblock.c:90
mtdblock_release+0x30/0x1ec drivers/mtd/mtdblock.c:289
blktrans_release+0x198/0x238 drivers/mtd/mtd_blkdevs.c:246
blkdev_put_whole+0x98/0xf0 block/bdev.c:766
bdev_release+0x2a4/0x510 block/bdev.c:1189
blkdev_release+0x14/0x30 block/fops.c:690
__fput+0x2d0/0x980 fs/file_table.c:512
____fput+0x14/0x20 fs/file_table.c:541
task_work_run+0x134/0x238 kernel/task_work.c:233
get_signal+0x9d0/0x1b18 kernel/signal.c:2885
arch_do_signal_or_restart+0x1a0/0x6f4 arch/arm64/kernel/signal.c:1651
__exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
exit_to_user_mode_loop+0x13c/0x1c8 kernel/entry/common.c:101
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
arm64_syscall_exit_to_user_mode arch/arm64/kernel/entry-common.c:147 [inline]
el0_svc+0x1dc/0x21c arch/arm64/kernel/entry-common.c:798
el0t_64_sync_handler+0xa0/0xe4 arch/arm64/kernel/entry-common.c:816
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
ok
---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH] mtd: blktrans: keep reclaim out of the ->release paths
2026-11-16 16:01 [syzbot] [mtd?] possible deadlock in blktrans_release syzbot
@ 2026-11-17 5:28 ` Shuai Liu
2026-11-17 5:40 ` sashiko-bot
0 siblings, 1 reply; 6+ messages in thread
From: Shuai Liu @ 2026-11-17 5:28 UTC (permalink / raw)
To: linux-mtd
Cc: miquel.raynal, richard, vigneshr, syzbot+c66e7044aa73c620d862,
linux-kernel, Shuai Liu
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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c66e7044aa73c620d862
Signed-off-by: Shuai Liu <847807867@qq.com>
---
drivers/mtd/mtd_blkdevs.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 42f250344f0cd..be4ead01f5210 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -233,6 +233,7 @@ static int blktrans_open(struct gendisk *disk, blk_mode_t mode)
static void blktrans_release(struct gendisk *disk)
{
struct mtd_blktrans_dev *dev = disk->private_data;
+ unsigned int noio_flags;
mutex_lock(&dev->lock);
@@ -242,8 +243,12 @@ static void blktrans_release(struct gendisk *disk)
module_put(dev->tr->owner);
if (dev->mtd) {
- if (dev->tr->release)
+ if (dev->tr->release) {
+ /* Reclaim must not recurse into I/O while releasing the device. */
+ noio_flags = memalloc_noio_save();
dev->tr->release(dev);
+ memalloc_noio_restore(noio_flags);
+ }
__put_mtd_device(dev->mtd);
}
unlock:
@@ -410,6 +415,7 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
unsigned long flags;
unsigned int memflags;
+ unsigned int noio_flags;
lockdep_assert_held(&mtd_table_mutex);
@@ -435,8 +441,11 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
then put mtd device, and don't touch it again */
mutex_lock(&old->lock);
if (old->open) {
- if (old->tr->release)
+ if (old->tr->release) {
+ noio_flags = memalloc_noio_save();
old->tr->release(old);
+ memalloc_noio_restore(noio_flags);
+ }
__put_mtd_device(old->mtd);
}
base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] mtd: blktrans: keep reclaim out of the ->release paths
2026-11-17 5:28 ` [PATCH] mtd: blktrans: keep reclaim out of the ->release paths Shuai Liu
@ 2026-11-17 5:40 ` sashiko-bot
2026-11-17 6:08 ` [PATCH v2] " Shuai Liu
0 siblings, 1 reply; 6+ messages in thread
From: sashiko-bot @ 2026-11-17 5:40 UTC (permalink / raw)
To: Shuai Liu, linux-mtd
Cc: miquel.raynal, richard, vigneshr, syzbot+c66e7044aa73c620d862
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@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@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=c66e7044aa73c620d862
> Signed-off-by: Shuai Liu <847807867@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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2] mtd: blktrans: keep reclaim out of the ->release paths
2026-11-17 5:40 ` sashiko-bot
@ 2026-11-17 6:08 ` Shuai Liu
2026-11-17 6:53 ` sashiko-bot
0 siblings, 1 reply; 6+ messages in thread
From: Shuai Liu @ 2026-11-17 6:08 UTC (permalink / raw)
To: linux-mtd
Cc: miquel.raynal, richard, vigneshr, syzbot+c66e7044aa73c620d862,
sashiko-bot, linux-kernel, 847807867
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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c66e7044aa73c620d862
Fixes: 048d87199566 ("mtd: blktrans: Hotplug fixes")
Signed-off-by: Shuai Liu <847807867@qq.com>
---
Changes in v2:
- Add Fixes tag pointing to 048d87199566 ("mtd: blktrans: Hotplug fixes"),
which made ->release() run under dev->lock and added the ->release()
call to del_mtd_blktrans_dev() (Sashiko)
drivers/mtd/mtd_blkdevs.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 42f250344f0cd..be4ead01f5210 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -233,6 +233,7 @@ static int blktrans_open(struct gendisk *disk, blk_mode_t mode)
static void blktrans_release(struct gendisk *disk)
{
struct mtd_blktrans_dev *dev = disk->private_data;
+ unsigned int noio_flags;
mutex_lock(&dev->lock);
@@ -242,8 +243,12 @@ static void blktrans_release(struct gendisk *disk)
module_put(dev->tr->owner);
if (dev->mtd) {
- if (dev->tr->release)
+ if (dev->tr->release) {
+ /* Reclaim must not recurse into I/O while releasing the device. */
+ noio_flags = memalloc_noio_save();
dev->tr->release(dev);
+ memalloc_noio_restore(noio_flags);
+ }
__put_mtd_device(dev->mtd);
}
unlock:
@@ -410,6 +415,7 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
unsigned long flags;
unsigned int memflags;
+ unsigned int noio_flags;
lockdep_assert_held(&mtd_table_mutex);
@@ -435,8 +441,11 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
then put mtd device, and don't touch it again */
mutex_lock(&old->lock);
if (old->open) {
- if (old->tr->release)
+ if (old->tr->release) {
+ noio_flags = memalloc_noio_save();
old->tr->release(old);
+ memalloc_noio_restore(noio_flags);
+ }
__put_mtd_device(old->mtd);
}
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] mtd: blktrans: keep reclaim out of the ->release paths
2026-11-17 6:08 ` [PATCH v2] " Shuai Liu
@ 2026-11-17 6:53 ` sashiko-bot
2026-11-17 8:40 ` Shuai Liu
0 siblings, 1 reply; 6+ messages in thread
From: sashiko-bot @ 2026-11-17 6:53 UTC (permalink / raw)
To: Shuai Liu, linux-mtd
Cc: miquel.raynal, richard, vigneshr, syzbot+c66e7044aa73c620d862
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mtd: blktrans: missing memalloc_noio_save() in mtd_queue_rq()
I/O path
--
commit 8a8ffa3e0c75306708e0a409beff68c7d20840ca
Author: Shuai Liu <847807867@qq.com>
mtd: blktrans: keep reclaim out of the ->release paths
This commit wraps the translator ->release() callbacks in
blktrans_release() and del_mtd_blktrans_dev() with memalloc_noio_save()
and memalloc_noio_restore() to prevent memory reclaim from recursing into
the block queue under dev->lock.
> 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().
[ ... ]
> diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
> index 4d2e7b7774e90..86a8644881ce7 100644
> --- a/drivers/mtd/mtd_blkdevs.c
> +++ b/drivers/mtd/mtd_blkdevs.c
> @@ -228,6 +228,7 @@ static int blktrans_open(struct gendisk *disk, blk_mode_t mode)
> static void blktrans_release(struct gendisk *disk)
> {
> struct mtd_blktrans_dev *dev = disk->private_data;
> + unsigned int noio_flags;
>
> mutex_lock(&dev->lock);
>
> @@ -237,8 +238,12 @@ static void blktrans_release(struct gendisk *disk)
> module_put(dev->tr->owner);
>
> if (dev->mtd) {
> - if (dev->tr->release)
> + if (dev->tr->release) {
> + /* Reclaim must not recurse into I/O while releasing the device. */
> + noio_flags = memalloc_noio_save();
> dev->tr->release(dev);
> + memalloc_noio_restore(noio_flags);
> + }
> __put_mtd_device(dev->mtd);
> }
[Severity: High]
Does mtd_queue_rq() or mtd_blktrans_work() actually call
memalloc_noio_save()?
Contrary to the commit message, neither function sets PF_MEMALLOC_NOIO:
drivers/mtd/mtd_blkdevs.c:mtd_queue_rq() {
...
spin_lock_irq(&dev->queue_lock);
list_add_tail(&bd->rq->queuelist, &dev->rq_list);
mtd_blktrans_work(dev);
spin_unlock_irq(&dev->queue_lock);
return BLK_STS_OK;
}
During normal request dispatch under set->srcu and dev->lock,
mtd_blktrans_work() -> do_blktrans_request() invokes translator callbacks
that allocate with GFP_KERNEL. For example, a REQ_OP_FLUSH request calls
mtdblock_flush(), which takes mtdblk->cache_mutex and runs
write_cached_data() -> erase_write() -> mtd_erase() -> concat_erase(),
hitting the same fs_reclaim lockdep cycle and reclaim deadlock on the I/O
path as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_9B9358CCE5C39B1E7017C4B42600DC95A409@qq.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] mtd: blktrans: keep reclaim out of the ->release paths
2026-11-17 6:53 ` sashiko-bot
@ 2026-11-17 8:40 ` Shuai Liu
0 siblings, 0 replies; 6+ messages in thread
From: Shuai Liu @ 2026-11-17 8:40 UTC (permalink / raw)
To: sashiko-bot
Cc: linux-mtd, miquel.raynal, richard, vigneshr,
syzbot+c66e7044aa73c620d862, linux-kernel, 847807867
Hi,
> [Severity: High]
> Does mtd_queue_rq() or mtd_blktrans_work() actually call
> memalloc_noio_save()?
Yes, the I/O path is already covered on the current tree.
mtd_queue_rq() wraps the whole dispatch in memalloc_noio_save() /
memalloc_noio_restore() (drivers/mtd/mtd_blkdevs.c, linux-next
next-20261113):
static blk_status_t mtd_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct mtd_blktrans_dev *dev;
unsigned int noio_flags;
dev = hctx->queue->queuedata;
if (!dev) {
blk_mq_start_request(bd->rq);
return BLK_STS_IOERR;
}
/* Reclaim must not recurse into I/O while processing requests. */
noio_flags = memalloc_noio_save();
spin_lock_irq(&dev->queue_lock);
list_add_tail(&bd->rq->queuelist, &dev->rq_list);
mtd_blktrans_work(dev);
spin_unlock_irq(&dev->queue_lock);
memalloc_noio_restore(noio_flags);
return BLK_STS_OK;
}
This was added by commit d498b2ddda99e ("mtd: block: prevent reclaim
I/O during request processing"), which is also the precedent this patch
mirrors for the ->release() paths.
The REQ_OP_FLUSH example given in the review (mtdblock_flush() ->
write_cached_data() -> erase_write() -> mtd_erase() -> concat_erase())
runs inside mtd_blktrans_work() as called from mtd_queue_rq(), i.e.
within the PF_MEMALLOC_NOIO scope, so it cannot record the
fs_reclaim -> cache_mutex edge. I verified this empirically in QEMU:
a flush issued while cache pressure is high stays clean, while the
same flush invoked from ->release() (process context, no noio scope
before this patch) triggers the lockdep cycle.
I believe the review comment was based on a truncated snippet that
dropped the memalloc_noio_save()/memalloc_noio_restore() lines
surrounding the quoted block.
Thanks,
Shuai Liu
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 8:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 16:01 [syzbot] [mtd?] possible deadlock in blktrans_release syzbot
2026-11-17 5:28 ` [PATCH] mtd: blktrans: keep reclaim out of the ->release paths Shuai Liu
2026-11-17 5:40 ` sashiko-bot
2026-11-17 6:08 ` [PATCH v2] " Shuai Liu
2026-11-17 6:53 ` sashiko-bot
2026-11-17 8:40 ` Shuai Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox