mbox series

[0/2] scsi: sd: use READ/WRITE/SYNC (16) commands per ZBC

Message ID 20221109025941.1594612-1-shinichiro.kawasaki@wdc.com
Headers show
Series scsi: sd: use READ/WRITE/SYNC (16) commands per ZBC | expand

Message

Shinichiro Kawasaki Nov. 9, 2022, 2:59 a.m. UTC
During work for a recent fix in libata-scsi [1], we checked which commands ZBC,
or Zoned Block Commands specification, mandates for zoned block devices. We
found two points to improve and this series has two patches to address them.

The first patch improves READ/WRITE (16) command enforcement. ZBC does not
mandate these commands to host-aware zoned block devices but current code in
sd_zbc_read_zones() assumes it. The second patch improves SYNCHRONIZE CACHE
(16) command enforcement. ZBC mandates it for host-managed zoned block
devices, and it should call it in place of SYNCHRONIZE CACHE (10).

Of note is that the second patch depends on the libata-scsi fix [1], and should
be merged to upstream after it.

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

Shin'ichiro Kawasaki (2):
  scsi: sd_zbc: do not enforce READ/WRITE (16) on host-aware devices
  scsi: sd: enforce SYNCHRONIZE CACHE (16) on host-managed devices

 drivers/scsi/sd.c          | 16 ++++++++++++----
 drivers/scsi/sd_zbc.c      |  9 ++++++---
 include/scsi/scsi_device.h |  1 +
 3 files changed, 19 insertions(+), 7 deletions(-)

Comments

Damien Le Moal Nov. 9, 2022, 5:17 a.m. UTC | #1
On 11/9/22 11:59, Shin'ichiro Kawasaki wrote:
> ZBC Zoned Block Commands specification mandates READ (16) and WRITE (16)
> commands only for host-managed zoned block devices. It does not mandate
> the commands for host-aware zoned block devices. However, current
> sd_zbc_read_zones() code assumes the commands were mandated for host-
> aware devices also and enforces the commands. If the host-aware drives
> do not support the commands, they may fail.
> 
> To conform to the ZBC specification and to avoid the failure, check
> device type and modify use_16_for_rw and use_10_for_rw flags only for
> host-managed zoned block devices, so that the READ (16) and WRITE (16)
> commands are not enforced on host-aware zoned block devices.
> 
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>  drivers/scsi/sd_zbc.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index bd15624c6322..4717a55dbf35 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -921,9 +921,11 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE])
>  		return 0;
>  	}
>  
> -	/* READ16/WRITE16 is mandatory for ZBC disks */
> -	sdkp->device->use_16_for_rw = 1;
> -	sdkp->device->use_10_for_rw = 0;
> +	/* READ16/WRITE16 is mandatory for host-managed devices */
> +	if (sdkp->device->type == TYPE_ZBC) {
> +		sdkp->device->use_16_for_rw = 1;
> +		sdkp->device->use_10_for_rw = 0;
> +	}
>  
>  	if (!blk_queue_is_zoned(q)) {
>  		/*

Looks good to me.

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Christoph Hellwig Nov. 9, 2022, 12:36 p.m. UTC | #2
What is the point in relaxing this?  Every modern device better support
16 byte commands even if they aren't strictly required for host aware
devices.
Shinichiro Kawasaki Nov. 10, 2022, 2:20 a.m. UTC | #3
On Nov 09, 2022 / 04:36, Christoph Hellwig wrote:
> What is the point in relaxing this?  Every modern device better support
> 16 byte commands even if they aren't strictly required for host aware
> devices.

My point was to make the check strictly follow the ZBC spec. But now I see that
it's the better to keep enforcing 16 byte commands to host-aware devices. I will
drop the first patch and revise the second patch to enforce SYNC 16 on both
host-aware and host-managed devices.
Christoph Hellwig Nov. 10, 2022, 8:19 a.m. UTC | #4
On Thu, Nov 10, 2022 at 02:20:09AM +0000, Shinichiro Kawasaki wrote:
> My point was to make the check strictly follow the ZBC spec. But now I see that
> it's the better to keep enforcing 16 byte commands to host-aware devices. I will
> drop the first patch and revise the second patch to enforce SYNC 16 on both
> host-aware and host-managed devices.

We don't "enforce" anything.  We just don't send the legacy commands for
devices that are guaranteed to be modern.  What is the advantage of
ever sending 10 bytes commands (inluding SYNCHRONIZE CACHE) to a modern
device?
Damien Le Moal Nov. 10, 2022, 8:31 a.m. UTC | #5
On 11/10/22 17:19, hch@infradead.org wrote:
> On Thu, Nov 10, 2022 at 02:20:09AM +0000, Shinichiro Kawasaki wrote:
>> My point was to make the check strictly follow the ZBC spec. But now I see that
>> it's the better to keep enforcing 16 byte commands to host-aware devices. I will
>> drop the first patch and revise the second patch to enforce SYNC 16 on both
>> host-aware and host-managed devices.
> 
> We don't "enforce" anything.  We just don't send the legacy commands for
> devices that are guaranteed to be modern.  What is the advantage of
> ever sending 10 bytes commands (inluding SYNCHRONIZE CACHE) to a modern
> device?

The ZBC specs define SYNC 16 as optional while SYNC 10 is mandatory. So
the device may not support SYNC 16 and we would get an invalid opcode
error. For SYNC, no advantages between SYNC 10 and SYNC 16. Not even
sure why they both exist. The point here is making sure we use the one
that the drive MUST support. That is, SYNC 16 for host managed and SYNC
10 for host aware (but these likely all also support SYNC 16, but we
cannot be sure of it).
Shinichiro Kawasaki Nov. 14, 2022, 10:58 a.m. UTC | #6
On Nov 10, 2022 / 17:31, Damien Le Moal wrote:
> On 11/10/22 17:19, hch@infradead.org wrote:
> > On Thu, Nov 10, 2022 at 02:20:09AM +0000, Shinichiro Kawasaki wrote:
> >> My point was to make the check strictly follow the ZBC spec. But now I see that
> >> it's the better to keep enforcing 16 byte commands to host-aware devices. I will
> >> drop the first patch and revise the second patch to enforce SYNC 16 on both
> >> host-aware and host-managed devices.
> > 
> > We don't "enforce" anything.  We just don't send the legacy commands for
> > devices that are guaranteed to be modern.

I see, the word "enforce" was not a good choice. Will rephrase it in v3.

> > What is the advantage of
> > ever sending 10 bytes commands (inluding SYNCHRONIZE CACHE) to a modern
> > device?
> 
> The ZBC specs define SYNC 16 as optional while SYNC 10 is mandatory. So
> the device may not support SYNC 16 and we would get an invalid opcode
> error. For SYNC, no advantages between SYNC 10 and SYNC 16. Not even
> sure why they both exist. The point here is making sure we use the one
> that the drive MUST support. That is, SYNC 16 for host managed and SYNC
> 10 for host aware (but these likely all also support SYNC 16, but we
> cannot be sure of it).

Damien, thanks for the explanation. I think Christoph, Damien and I are on the
same page: we should call 16 byte WRITE/READ/SYNC commands to modern devices.
And both host-managed and host-aware ZBC devices are the modern devices.

Will prepare v3 based on this understanding.