Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: bypass the STABLE_WRITES flag for protection information

Currently registering a checksum-enabled (aka PI) integrity profile sets
the QUEUE_FLAG_STABLE_WRITE flag, and unregistering it clears the flag.
This can incorrectly clear the flag when the driver requires stable
writes even without PI, e.g. in case of iSCSI or NVMe/TCP with data
digest enabled.

Fix this by looking at the csum_type directly in bdev_stable_writes and
not setting the queue flag. Also remove the blk_queue_stable_writes
helper as the only user in nvme wants to only look at the actual
QUEUE_FLAG_STABLE_WRITE flag as it inherits the integrity configuration
by other means.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20240613084839.1044015-11-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
3c3e85dd 43c5dbe9

+10 -11
-6
block/blk-integrity.c
··· 379 379 bi->tag_size = template->tag_size; 380 380 bi->pi_offset = template->pi_offset; 381 381 382 - if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE) 383 - blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue); 384 - 385 382 #ifdef CONFIG_BLK_INLINE_ENCRYPTION 386 383 if (disk->queue->crypto_profile) { 387 384 pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n"); ··· 401 404 402 405 if (!bi->tuple_size) 403 406 return; 404 - 405 - if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE) 406 - blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue); 407 407 memset(bi, 0, sizeof(*bi)); 408 408 } 409 409 EXPORT_SYMBOL(blk_integrity_unregister);
+2 -1
drivers/nvme/host/multipath.c
··· 875 875 nvme_mpath_set_live(ns); 876 876 } 877 877 878 - if (blk_queue_stable_writes(ns->queue) && ns->head->disk) 878 + if (test_bit(QUEUE_FLAG_STABLE_WRITES, &ns->queue->queue_flags) && 879 + ns->head->disk) 879 880 blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, 880 881 ns->head->disk->queue); 881 882 #ifdef CONFIG_BLK_DEV_ZONED
+8 -4
include/linux/blkdev.h
··· 571 571 #define blk_queue_noxmerges(q) \ 572 572 test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) 573 573 #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) 574 - #define blk_queue_stable_writes(q) \ 575 - test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags) 576 574 #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) 577 575 #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) 578 576 #define blk_queue_zone_resetall(q) \ ··· 1298 1300 1299 1301 static inline bool bdev_stable_writes(struct block_device *bdev) 1300 1302 { 1301 - return test_bit(QUEUE_FLAG_STABLE_WRITES, 1302 - &bdev_get_queue(bdev)->queue_flags); 1303 + struct request_queue *q = bdev_get_queue(bdev); 1304 + 1305 + #ifdef CONFIG_BLK_DEV_INTEGRITY 1306 + /* BLK_INTEGRITY_CSUM_NONE is not available in blkdev.h */ 1307 + if (q->integrity.csum_type != 0) 1308 + return true; 1309 + #endif 1310 + return test_bit(QUEUE_FLAG_STABLE_WRITES, &q->queue_flags); 1303 1311 } 1304 1312 1305 1313 static inline bool bdev_write_cache(struct block_device *bdev)