[PATCH] null_blk: reset cache state before device setup

From: Baek Kyu, Kim

Date: Sun Oct 25 2026 - 12:11:51 EST


The CACHE flag belongs to nullb_device, which outlives each powered-on
nullb instance. Power-off discards the runtime cache but leaves the flag
set. If cache_size changes from 1 to 0 before the next power-on, the
queue advertises write-through while new page writes still go into the
cache tree. A completed write can then disappear at the next power-off.

Clear CACHE before creating the new instance. The existing cache_size
setup sets it again when the new instance needs a cache.

Signed-off-by: Baek Kyu, Kim <pocj8ur4in@xxxxxxxxx>
---
Tested under ARM64 QEMU/KVM through configfs and the null_blk block device.
After changing cache_size from 1 to 0, a 4 KiB direct write to a new page
read back immediately on both kernels. After a power cycle, the baseline
lost the pattern while the kernel with this CACHE change retained all 4 KiB.
Both queues advertised write-through.

drivers/block/null_blk/main.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 6beb1f5b71ac..ec0d7ba4d938 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1976,6 +1976,7 @@ static int null_add_dev(struct nullb_device *dev)
rv = null_validate_conf(dev);
if (rv)
return rv;
+ clear_bit(NULLB_DEV_FL_CACHE, &dev->flags);

nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node);
if (!nullb) {