null_blk: reset cache state before device setup
PATCH 1/1 null_blk: reset cache state before device setup
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.
---
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(+)
drivers/block/null_blk/main.c +1 -0
@@ -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) {
Looks good:
Quoted 10 lines · Kim
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. Ifcache_sizechanges 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_sizesetup sets it again when the new instance needs a cache.[...]
Applied, thanks!
[1/1] null_blk: reset cache state before device setup
commit: 5a4236bf22622c291a96c139bfe54117f4cf1af6
Best regards,
Signature · 1 line
Jens Axboe