Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: core: Clear driver private data when retrying request

After commit 1bad6c4a57ef ("scsi: zero per-cmd private driver data for each
MQ I/O"), the xen-scsifront/virtio_scsi/snic drivers all removed code that
explicitly zeroed driver-private command data.

In combination with commit 464a00c9e0ad ("scsi: core: Kill DRIVER_SENSE"),
after virtio_scsi performs a capacity expansion, the first request will
return a unit attention to indicate that the capacity has changed. And then
the original command is retried. As driver-private command data was not
cleared, the request would return UA again and eventually time out and fail.

Zero driver-private command data when a request is retried.

Fixes: f7de50da1479 ("scsi: xen-scsifront: Remove code that zeroes driver-private command data")
Fixes: c2bb87318baa ("scsi: virtio_scsi: Remove code that zeroes driver-private command data")
Fixes: c3006a926468 ("scsi: snic: Remove code that zeroes driver-private command data")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20250217021628.2929248-1-yebin@huaweicloud.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Ye Bin and committed by
Martin K. Petersen
dce5c4af 4fa382be

+7 -7
+7 -7
drivers/scsi/scsi_lib.c
··· 1669 1669 if (in_flight) 1670 1670 __set_bit(SCMD_STATE_INFLIGHT, &cmd->state); 1671 1671 1672 - /* 1673 - * Only clear the driver-private command data if the LLD does not supply 1674 - * a function to initialize that data. 1675 - */ 1676 - if (!shost->hostt->init_cmd_priv) 1677 - memset(cmd + 1, 0, shost->hostt->cmd_size); 1678 - 1679 1672 cmd->prot_op = SCSI_PROT_NORMAL; 1680 1673 if (blk_rq_bytes(req)) 1681 1674 cmd->sc_data_direction = rq_dma_dir(req); ··· 1834 1841 } 1835 1842 if (!scsi_host_queue_ready(q, shost, sdev, cmd)) 1836 1843 goto out_dec_target_busy; 1844 + 1845 + /* 1846 + * Only clear the driver-private command data if the LLD does not supply 1847 + * a function to initialize that data. 1848 + */ 1849 + if (shost->hostt->cmd_size && !shost->hostt->init_cmd_priv) 1850 + memset(cmd + 1, 0, shost->hostt->cmd_size); 1837 1851 1838 1852 if (!(req->rq_flags & RQF_DONTPREP)) { 1839 1853 ret = scsi_prepare_cmd(req);