Skip to content

Commit 288b327

Browse files
kawasakimartinkpetersen
authored andcommitted
scsi: sd: Fix wrong zone_write_granularity value during revalidate
When the sd driver revalidates host-managed SMR disks, it calls disk_set_zoned() which changes the zone_write_granularity attribute value to the logical block size regardless of the device type. After that, the sd driver overwrites the value in sd_zbc_read_zone() with the physical block size, since ZBC/ZAC requires this for host-managed disks. Between the calls to disk_set_zoned() and sd_zbc_read_zone(), there exists a window where the attribute shows the logical block size as the zone_write_granularity value, which is wrong for host-managed disks. The duration of the window is from 20ms to 200ms, depending on report zone command execution time. To avoid the wrong zone_write_granularity value between disk_set_zoned() and sd_zbc_read_zone(), modify the value not in sd_zbc_read_zone() but just after disk_set_zoned() call. Fixes: a805a4f ("block: introduce zone_write_granularity limit") Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 11d9874 commit 288b327

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

drivers/scsi/sd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2988,8 +2988,13 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp)
29882988
}
29892989

29902990
if (sdkp->device->type == TYPE_ZBC) {
2991-
/* Host-managed */
2991+
/*
2992+
* Host-managed: Per ZBC and ZAC specifications, writes in
2993+
* sequential write required zones of host-managed devices must
2994+
* be aligned to the device physical block size.
2995+
*/
29922996
disk_set_zoned(sdkp->disk, BLK_ZONED_HM);
2997+
blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
29932998
} else {
29942999
sdkp->zoned = zoned;
29953000
if (sdkp->zoned == 1) {

drivers/scsi/sd_zbc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -965,14 +965,6 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
965965
disk_set_max_active_zones(disk, 0);
966966
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
967967

968-
/*
969-
* Per ZBC and ZAC specifications, writes in sequential write required
970-
* zones of host-managed devices must be aligned to the device physical
971-
* block size.
972-
*/
973-
if (blk_queue_zoned_model(q) == BLK_ZONED_HM)
974-
blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
975-
976968
sdkp->early_zone_info.nr_zones = nr_zones;
977969
sdkp->early_zone_info.zone_blocks = zone_blocks;
978970

0 commit comments

Comments
 (0)