Skip to contentSkip to conversation

scsi: zero per-cmd driver data before each I/O

PATCH Superseded Christoph Hellwig 3 participants 3 messages Feb 20, 2017 – Feb 21, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: zero per-cmd driver data before each I/O

Without this drivers that don't clear the state themselves can see off effects. For example Hyper-V VMs using the storvsc driver will often hang during boot due to uncleared Test Unit Ready failures.

Fixes e9c787e6 ("scsi: allocate scsi_cmnd structures as part of struct request")
---
 drivers/scsi/scsi_lib.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/scsi_lib.c +1 -0
index 90f65c8f487a..daced9db8af8 100644
@@ -1167,6 +1167,7 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
 	/* zero out the cmd, except for the embedded scsi_request */
 	memset((char *)cmd + sizeof(cmd->req), 0,
 		sizeof(*cmd) - sizeof(cmd->req));
+	memset((char *)(cmd + 1), 0, dev->host->hostt->cmd_size);
 
 	cmd->device = dev;
 	cmd->sense_buffer = buf;
Signature · 1 line
2.11.0
#1 lore raw

On 02/20/2017 08:52 AM, Christoph Hellwig wrote:=0A=

Quoted 5 lines

Without this drivers that don't clear the state themselves can see off=0A= effects. For example Hyper-V VMs using the storvsc driver will often=0A= hang during boot due to uncleared Test Unit Ready failures.=0A= =0A=

Fixes e9c787e6 ("scsi: allocate scsi_cmnd structures as part of struct r=

equest")=0A=

drivers/scsi/scsi_lib.c=0A= void scsi_init_command(struct scsi_device *dev, str=

Quoted 12 lines

---=0A=
drivers/scsi/scsi_lib.c | 1 +=0A=

 1 file changed, 1 insertion(+)=0A=

=0A=

drivers/scsi/scsi_lib.c=0A= +0 -0
index 90f65c8f487a..daced9db8af8 100644=0A=
@@ -1167,6 +1167,7 @@ void scsi_init_command(struct scsi_device *dev, str=

uct scsi_cmnd *cmd)=0A=

drivers/scsi/scsi_lib.c=0A= void scsi_init_command(struct scsi_device *dev, str= · line 1170

Quoted 4 lines
drivers/scsi/scsi_lib.c=0A= +1 -0
 	/* zero out the cmd, except for the embedded scsi_request */=0A=
 	memset((char *)cmd + sizeof(cmd->req), 0,=0A=
 		sizeof(*cmd) - sizeof(cmd->req));=0A=
+	memset((char *)(cmd + 1), 0, dev->host->hostt->cmd_size);=0A=

=0A=
Hello Christoph,=0A=
=0A=
Since this code is in the hot path: please combine the two memset()=0A= calls into a single memset() call.=0A=
=0A=
Thanks,=0A=
=0A=
Bart.=0A=

Reviewed-by on v1 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

Without this drivers that don't clear the state themselves can see off effects. For example Hyper-V VMs using the storvsc driver will often hang during boot due to uncleared Test Unit Ready failures.

Fixes e9c787e6 ("scsi: allocate scsi_cmnd structures as part of struct request")
---
 drivers/scsi/scsi_lib.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/scsi_lib.c +0 -0
index 90f65c8f487a..daced9db8af8 100644

drivers/scsi/scsi_lib.c void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd) · line 1173

Quoted 7 lines
drivers/scsi/scsi_lib.c +1 -0
@@ -1167,6 +1167,7 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
 	/* zero out the cmd, except for the embedded scsi_request */
 	memset((char *)cmd + sizeof(cmd->req), 0,
 		sizeof(*cmd) - sizeof(cmd->req));
+	memset((char *)(cmd + 1), 0, dev->host->hostt->cmd_size);
 
 	cmd->device = dev;
 	cmd->sense_buffer = buf;

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)