Skip to contentSkip to conversation

scsi: scsi_debug: Make the READ CAPACITY response compliant with ZBC

PATCH Superseded Bart Van Assche 2 participants 4 messages Oct 31, 2022 – Nov 1, 2022 SCSI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsi_debug: Make the READ CAPACITY response compliant with ZBC

From ZBC-1:
* RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the highest LBA of a contiguous range of zones that are not sequential write required zones starting with the first zone.
* RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA of the last logical block on the logical unit.

The current scsi_debug READ CAPACITY response does not comply with the above if there are one or more sequential write required zones. SCSI initiators need a way to retrieve the largest valid LBA from SCSI devices. Reporting the largest valid LBA if there are one or more sequential zones requires to set the RC BASIS field in the READ CAPACITY response to one. Hence this patch.

---
 drivers/scsi/scsi_debug.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/scsi_debug.c +4 -0
index 697fc57bc711..fec87296cf06 100644
@@ -1899,6 +1899,10 @@ static int resp_readcap16(struct scsi_cmnd *scp,
 			arr[14] |= 0x40;
 	}
 
+	/* Set RC BASIS = 1 for host-managed devices. */
+	if (devip->zmodel == BLK_ZONED_HM)
+		arr[12] |= 1 << 4;
+
 	arr[15] = sdebug_lowest_aligned & 0xff;
 
 	if (have_dif_prot) {
#1 lore raw
Quoted 27 lines · Bart Van Assche

From ZBC-1:
* RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the highest LBA of a contiguous range of zones that are not sequential write required zones starting with the first zone.
* RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA of the last logical block on the logical unit.

The current scsi_debug READ CAPACITY response does not comply with the above if there are one or more sequential write required zones. SCSI initiators need a way to retrieve the largest valid LBA from SCSI devices. Reporting the largest valid LBA if there are one or more sequential zones requires to set the RC BASIS field in the READ CAPACITY response to one. Hence this patch.

---
 drivers/scsi/scsi_debug.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/scsi_debug.c +0 -0
index 697fc57bc711..fec87296cf06 100644

drivers/scsi/scsi_debug.c static int resp_readcap16(struct scsi_cmnd *scp, · line 1902

Quoted 4 lines
drivers/scsi/scsi_debug.c +1 -0
@@ -1899,6 +1899,10 @@ static int resp_readcap16(struct scsi_cmnd *scp,
 			arr[14] |= 0x40;
 	}
 
+	/* Set RC BASIS = 1 for host-managed devices. */

No it is not necessarily set. It is up to the device vendor to choose if RC_BASIS is set or not, based on the device implementation. Applicability of RC = 0 or RC = 1 depends on the presence of conventional zones. so:

1) If there are conventional zones, then using RC_BASIS = 1 or = 0 are both OK with HM devices. In the case of RC_BASIS = 0, the host can issue a report zones and get the device max lba from the report header (sd_zbc.c does that).
2) If there are no conventional zones, then using RC_BASIS = 0 does not make much sense, but nothing in the ZBC text prevent it either...

So we should refine this and maybe add an option to allow specifying rc basis ?

Quoted 6 lines
drivers/scsi/scsi_debug.c +3 -0
+	if (devip->zmodel == BLK_ZONED_HM)
+		arr[12] |= 1 << 4;
+
 	arr[15] = sdebug_lowest_aligned & 0xff;
 
 	if (have_dif_prot) {
Signature · 2 lines
Damien Le Moal
Western Digital Research
#2 lore raw
Quoted 21 lines · Damien Le Moal

drivers/scsi/scsi_debug.c static int resp_readcap16(struct scsi_cmnd *scp, · line 1902

Quoted 7 lines · Bart Van Assche
drivers/scsi/scsi_debug.c +1 -0
@@ -1899,6 +1899,10 @@ static int resp_readcap16(struct scsi_cmnd *scp,
  			arr[14] |= 0x40;
  	}
 
+	/* Set RC BASIS = 1 for host-managed devices. */

No it is not necessarily set. It is up to the device vendor to choose if RC_BASIS is set or not, based on the device implementation. Applicability of RC = 0 or RC = 1 depends on the presence of conventional zones. so:

1) If there are conventional zones, then using RC_BASIS = 1 or = 0 are both OK with HM devices. In the case of RC_BASIS = 0, the host can issue a report zones and get the device max lba from the report header (sd_zbc.c does that).
2) If there are no conventional zones, then using RC_BASIS = 0 does not make much sense, but nothing in the ZBC text prevent it either...

Quoted 2 lines

So we should refine this and maybe add an option to allow specifying rc basis ?

Hi Damien,

If I remember correctly the conclusion from a previous conversation is that setting RC BASIS = 1 for host-managed devices is what is done by all SMR vendors and is always correct for host-managed devices.

I think the description of the my patch is correct, namely that it makes the READ CAPACITY response compliant with ZBC. I did not claim that my patch is the only possible approach for making the READ CAPACITY response ZBC compliant.

Are there any use cases for reporting RC BASIS = 0 in combination with the capacity of conventional zones for host-managed devices other than testing the Linux kernel ZBC code?

Thanks,

Bart.

#3 lore raw
Quoted 26 lines · Bart Van Assche
Quoted 21 lines · Damien Le Moal

drivers/scsi/scsi_debug.c static int resp_readcap16(struct scsi_cmnd *scp, · line 1902

Quoted 7 lines · Bart Van Assche
drivers/scsi/scsi_debug.c +1 -0
@@ -1899,6 +1899,10 @@ static int resp_readcap16(struct scsi_cmnd *scp,
  			arr[14] |= 0x40;
  	}
 
+	/* Set RC BASIS = 1 for host-managed devices. */

No it is not necessarily set. It is up to the device vendor to choose if RC_BASIS is set or not, based on the device implementation. Applicability of RC = 0 or RC = 1 depends on the presence of conventional zones. so:

1) If there are conventional zones, then using RC_BASIS = 1 or = 0 are both OK with HM devices. In the case of RC_BASIS = 0, the host can issue a report zones and get the device max lba from the report header (sd_zbc.c does that).
2) If there are no conventional zones, then using RC_BASIS = 0 does not make much sense, but nothing in the ZBC text prevent it either...

Quoted 2 lines

So we should refine this and maybe add an option to allow specifying rc basis ?

Hi Damien,

Quoted 8 lines

If I remember correctly the conclusion from a previous conversation is that setting RC BASIS = 1 for host-managed devices is what is done by all SMR vendors and is always correct for host-managed devices.

I think the description of the my patch is correct, namely that it makes the READ CAPACITY response compliant with ZBC. I did not claim that my patch is the only possible approach for making the READ CAPACITY response ZBC compliant.

Yes, your patch is correct given how scsi_debug always reports the total drive capacity. So to clarify with regards to the specs and what is allowed to do, I think that this comment:

/* Set RC BASIS = 1 for host-managed devices. */

should be changed to something like this:

/*
* Given that scsi_debug READ CAPACITY implementation always reports
* the total disk capacity, set RC BASIS = 1 for host-managed ZBC devices. */

Thoughts ?

With that changed, I think your patch is good to go !

Quoted 3 lines

Are there any use cases for reporting RC BASIS = 0 in combination with the capacity of conventional zones for host-managed devices other than testing the Linux kernel ZBC code?

No use case specific to this I think, given that the kernel always corrects the reported capacity to the entire drive cap, the user never sees any difference between rc basis = 0 and rc basis = 1, at least for a system that support host-managed SMR.
I only was thinking about sd tests :)

And for systems that do not support HM SMR, we would not even see the drive anyway.

Quoted 4 lines

Thanks,

Bart.

Signature · 2 lines
Damien Le Moal
Western Digital Research