[PATCH v2 1/2] mtd: rawnand: nandsim: use a NOIO scope for cache file I/O

From: Tal Zussman

Date: Fri Oct 16 2026 - 15:01:04 EST


nandsim reads and writes its cache file from inside MTD operations,
with the chip lock held. Reclaim from an allocation in that path must
not issue I/O that can come back to this MTD, whether the superblock
shrinker evicting an inode of the filesystem on top of it or swap on
an mtdblock device over it, since either would take the chip lock
again on the same thread. The driver ensures that by running
kernel_read() and kernel_write() under PF_MEMALLOC, which is more than
it needs. Use memalloc_noio_save() instead.

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
drivers/mtd/nand/raw/nandsim.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c
index fe968037f75a..586f4622b59e 100644
--- a/drivers/mtd/nand/raw/nandsim.c
+++ b/drivers/mtd/nand/raw/nandsim.c
@@ -1342,14 +1342,14 @@ static ssize_t ns_read_file(struct nandsim *ns, struct file *file, void *buf,
{
ssize_t tx;
int err;
- unsigned int noreclaim_flag;
+ unsigned int noio_flag;

err = ns_get_pages(ns, file, count, pos);
if (err)
return err;
- noreclaim_flag = memalloc_noreclaim_save();
+ noio_flag = memalloc_noio_save();
tx = kernel_read(file, buf, count, &pos);
- memalloc_noreclaim_restore(noreclaim_flag);
+ memalloc_noio_restore(noio_flag);
ns_put_pages(ns);
return tx;
}
@@ -1359,14 +1359,14 @@ static ssize_t ns_write_file(struct nandsim *ns, struct file *file, void *buf,
{
ssize_t tx;
int err;
- unsigned int noreclaim_flag;
+ unsigned int noio_flag;

err = ns_get_pages(ns, file, count, pos);
if (err)
return err;
- noreclaim_flag = memalloc_noreclaim_save();
+ noio_flag = memalloc_noio_save();
tx = kernel_write(file, buf, count, &pos);
- memalloc_noreclaim_restore(noreclaim_flag);
+ memalloc_noio_restore(noio_flag);
ns_put_pages(ns);
return tx;
}

--
2.39.5