Skip to content

Commit 3c3e85d

Browse files
Christoph Hellwigaxboe
authored andcommitted
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>
1 parent 43c5dbe commit 3c3e85d

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

block/blk-integrity.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,6 @@ void blk_integrity_register(struct gendisk *disk, struct blk_integrity *template
379379
bi->tag_size = template->tag_size;
380380
bi->pi_offset = template->pi_offset;
381381

382-
if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE)
383-
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
384-
385382
#ifdef CONFIG_BLK_INLINE_ENCRYPTION
386383
if (disk->queue->crypto_profile) {
387384
pr_warn("blk-integrity: Integrity and hardware inline encryption are not supported together. Disabling hardware inline encryption.\n");
@@ -404,9 +401,6 @@ void blk_integrity_unregister(struct gendisk *disk)
404401

405402
if (!bi->tuple_size)
406403
return;
407-
408-
if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE)
409-
blk_queue_flag_clear(QUEUE_FLAG_STABLE_WRITES, disk->queue);
410404
memset(bi, 0, sizeof(*bi));
411405
}
412406
EXPORT_SYMBOL(blk_integrity_unregister);

drivers/nvme/host/multipath.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
875875
nvme_mpath_set_live(ns);
876876
}
877877

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)
879880
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES,
880881
ns->head->disk->queue);
881882
#ifdef CONFIG_BLK_DEV_ZONED

include/linux/blkdev.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,6 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
571571
#define blk_queue_noxmerges(q) \
572572
test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
573573
#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)
576574
#define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
577575
#define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
578576
#define blk_queue_zone_resetall(q) \
@@ -1300,8 +1298,14 @@ static inline bool bdev_synchronous(struct block_device *bdev)
13001298

13011299
static inline bool bdev_stable_writes(struct block_device *bdev)
13021300
{
1303-
return test_bit(QUEUE_FLAG_STABLE_WRITES,
1304-
&bdev_get_queue(bdev)->queue_flags);
1301+
struct request_queue *q = bdev_get_queue(bdev);
1302+
1303+
#ifdef CONFIG_BLK_DEV_INTEGRITY
1304+
/* BLK_INTEGRITY_CSUM_NONE is not available in blkdev.h */
1305+
if (q->integrity.csum_type != 0)
1306+
return true;
1307+
#endif
1308+
return test_bit(QUEUE_FLAG_STABLE_WRITES, &q->queue_flags);
13051309
}
13061310

13071311
static inline bool bdev_write_cache(struct block_device *bdev)

0 commit comments

Comments
 (0)