Re: [PATCH v2] mtd: blktrans: keep reclaim out of the ->release paths
From: Shuai Liu
Date: Tue Nov 17 2026 - 03:40:30 EST
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