diff mbox series

[REPOST] scsi: sd: Fix wrong zone_write_granularity value at revalidate

Message ID 20230306063024.3376959-1-shinichiro.kawasaki@wdc.com (mailing list archive)
State Accepted
Commit 288b3271d920c9ba949c3bab0f749f4cecc70e09
Headers show
Series [REPOST] scsi: sd: Fix wrong zone_write_granularity value at revalidate | expand

Commit Message

Shinichiro Kawasaki March 6, 2023, 6:30 a.m. UTC
When 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 it for the host-managed
disks. Between the calls to disk_set_zoned() and sd_zbc_read_zone(),
there exists a window that the attribute shows the logical block size as
the zone_write_granularity value, which is wrong for the 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: a805a4fa4fa3 ("block: introduce zone_write_granularity limit")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
This patch is a repost of the second patch of another series [1]. Reviews
and comments will be welcomed.

[1] https://lore.kernel.org/linux-scsi/20230303014422.2466103-1-shinichiro.kawasaki@wdc.com/

 drivers/scsi/sd.c     | 7 ++++++-
 drivers/scsi/sd_zbc.c | 8 --------
 2 files changed, 6 insertions(+), 9 deletions(-)

Comments

Damien Le Moal March 6, 2023, 6:58 a.m. UTC | #1
On 2023/03/06 15:30, Shin'ichiro Kawasaki wrote:
> When 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 it for the host-managed
> disks. Between the calls to disk_set_zoned() and sd_zbc_read_zone(),
> there exists a window that the attribute shows the logical block size as
> the zone_write_granularity value, which is wrong for the 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: a805a4fa4fa3 ("block: introduce zone_write_granularity limit")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

Looks good.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Johannes Thumshirn March 6, 2023, 10:43 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Bart Van Assche March 6, 2023, 1:54 p.m. UTC | #3
On 3/5/23 22:30, Shin'ichiro Kawasaki wrote:
> When 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 it for the host-managed
> disks. Between the calls to disk_set_zoned() and sd_zbc_read_zone(),
> there exists a window that the attribute shows the logical block size as
> the zone_write_granularity value, which is wrong for the 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.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Martin K. Petersen March 7, 2023, 2:57 a.m. UTC | #4
On Mon, 06 Mar 2023 15:30:24 +0900, Shin'ichiro Kawasaki wrote:

> When 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 it for the host-managed
> disks. Between the calls to disk_set_zoned() and sd_zbc_read_zone(),
> there exists a window that the attribute shows the logical block size as
> the zone_write_granularity value, which is wrong for the host-managed
> disks. The duration of the window is from 20ms to 200ms, depending on
> report zone command execution time.
> 
> [...]

Applied to 6.3/scsi-fixes, thanks!

[1/1] scsi: sd: Fix wrong zone_write_granularity value at revalidate
      https://git.kernel.org/mkp/scsi/c/288b3271d920
diff mbox series

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4f28dd617eca..4bb87043e6db 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2988,8 +2988,13 @@  static void sd_read_block_characteristics(struct scsi_disk *sdkp)
 	}
 
 	if (sdkp->device->type == TYPE_ZBC) {
-		/* Host-managed */
+		/*
+		 * Host-managed: Per ZBC and ZAC specifications, writes in
+		 * sequential write required zones of host-managed devices must
+		 * be aligned to the device physical block size.
+		 */
 		disk_set_zoned(sdkp->disk, BLK_ZONED_HM);
+		blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
 	} else {
 		sdkp->zoned = zoned;
 		if (sdkp->zoned == 1) {
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 6b3a02d4406c..22801c24ea19 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -965,14 +965,6 @@  int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
 	disk_set_max_active_zones(disk, 0);
 	nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
 
-	/*
-	 * Per ZBC and ZAC specifications, writes in sequential write required
-	 * zones of host-managed devices must be aligned to the device physical
-	 * block size.
-	 */
-	if (blk_queue_zoned_model(q) == BLK_ZONED_HM)
-		blk_queue_zone_write_granularity(q, sdkp->physical_block_size);
-
 	sdkp->early_zone_info.nr_zones = nr_zones;
 	sdkp->early_zone_info.zone_blocks = zone_blocks;