[PATCH v2] mtd: blktrans: keep reclaim out of the ->release paths

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 16 22:53:25 PST 2026


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 at 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



More information about the linux-mtd mailing list