Skip to content

Commit 142c779

Browse files
Alexey Makhalovmartinkpetersen
authored andcommitted
scsi: vmw_pvscsi: Set residual data length conditionally
The PVSCSI implementation in the VMware hypervisor under specific configuration ("SCSI Bus Sharing" set to "Physical") returns zero dataLen in the completion descriptor for READ CAPACITY(16). As a result, the kernel can not detect proper disk geometry. This can be recognized by the kernel message: [ 0.776588] sd 1:0:0:0: [sdb] Sector size 0 reported, assuming 512. The PVSCSI implementation in QEMU does not set dataLen at all, keeping it zeroed. This leads to a boot hang as was reported by Shmulik Ladkani. It is likely that the controller returns the garbage at the end of the buffer. Residual length should be set by the driver in that case. The SCSI layer will erase corresponding data. See commit bdb2b8c ("[SCSI] erase invalid data returned by device") for details. Commit e662502 ("scsi: vmw_pvscsi: Set correct residual data length") introduced the issue by setting residual length unconditionally, causing the SCSI layer to erase the useful payload beyond dataLen when this value is returned as 0. As a result, considering existing issues in implementations of PVSCSI controllers, we do not want to call scsi_set_resid() when dataLen == 0. Calling scsi_set_resid() has no effect if dataLen equals buffer length. Link: https://lore.kernel.org/lkml/20210824120028.30d9c071@blondie/ Link: https://lore.kernel.org/r/[email protected] Fixes: e662502 ("scsi: vmw_pvscsi: Set correct residual data length") Cc: Matt Wang <[email protected]> Cc: Martin K. Petersen <[email protected]> Cc: Vishal Bhakta <[email protected]> Cc: VMware PV-Drivers <[email protected]> Cc: James E.J. Bottomley <[email protected]> Cc: [email protected] Cc: [email protected] Reported-and-suggested-by: Shmulik Ladkani <[email protected]> Signed-off-by: Alexey Makhalov <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1b8d030 commit 142c779

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/scsi/vmw_pvscsi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,12 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
586586
* Commands like INQUIRY may transfer less data than
587587
* requested by the initiator via bufflen. Set residual
588588
* count to make upper layer aware of the actual amount
589-
* of data returned.
589+
* of data returned. There are cases when controller
590+
* returns zero dataLen with non zero data - do not set
591+
* residual count in that case.
590592
*/
591-
scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
593+
if (e->dataLen && (e->dataLen < scsi_bufflen(cmd)))
594+
scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
592595
cmd->result = (DID_OK << 16);
593596
break;
594597

0 commit comments

Comments
 (0)