Re: [PATCH v2] blk-mq: use NOIO context to prevent deadlock during debugfs creation

From: Shinichiro Kawasaki

Date: Tue Feb 17 2026 - 02:02:17 EST


On Feb 14, 2026 / 13:43, Yu Kuai wrote:
> Creating debugfs entries can trigger fs reclaim, which can enter back
> into the block layer request_queue. This can cause deadlock if the
> queue is frozen.
>
> Previously, a WARN_ON_ONCE check was used in debugfs_create_files()
> to detect this condition, but it was racy since the queue can be frozen
> from another context at any time.
>
> Introduce blk_debugfs_lock()/blk_debugfs_unlock() helpers that combine
> the debugfs_mutex with memalloc_noio_save()/restore() to prevent fs
> reclaim from triggering block I/O. Also add blk_debugfs_lock_nomemsave()
> and blk_debugfs_unlock_nomemrestore() variants for callers that don't
> need NOIO protection (e.g., debugfs removal or read-only operations).
>
> Replace all raw debugfs_mutex lock/unlock pairs with these helpers,
> using the _nomemsave/_nomemrestore variants where appropriate.
>
> Reported-by: Yi Zhang <yi.zhang@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/CAHj4cs9gNKEYAPagD9JADfO5UH+OiCr4P7OO2wjpfOYeM-RV=A@xxxxxxxxxxxxxx/
> Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@xxxxxxx>
> Closes: https://lore.kernel.org/all/aYWQR7CtYdk3K39g@shinmob/
> Suggested-by: Christoph Hellwig <hch@xxxxxx>
> Signed-off-by: Yu Kuai <yukuai@xxxxxxxxx>

Yu, thank you for fixing this. I applied this patch on top of the kernel
next-20260211 and confirmed that the WARN is no longer reported for the
test case zbd/012. I also ran whole blktests and observed no regression.

Tested-by: Shinichiro Kawasaki <shinichiro.kawasaki@xxxxxxx>