stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: vmw_pvscsi: Set residual data length conditionally
@ 2021-12-20 19:05 Alexey Makhalov
  2021-12-23  5:08 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Makhalov @ 2021-12-20 19:05 UTC (permalink / raw)
  To: linux-scsi
  Cc: namit, srivatsa, shmulik.ladkani, Alexey Makhalov, Matt Wang,
	Martin K . Petersen, Vishal Bhakta, VMware PV-Drivers,
	James E . J . Bottomley, stable

PVSCSI implementation in VMware hypervisor under specific configuration
("SCSI Bus Sharing" set to "Physical") returns zero dataLen in completion
descriptor for read_capacity_16. As a result, the kernel can not detect proper
disk geometry. It can be recognized by the kernel message:
[    0.776588] sd 1:0:0:0: [sdb] Sector size 0 reported, assuming 512.

PVSCSI implementation in QEMU does not set dataLen at all keeping it zeroed,
leading to the 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. scsi_lib layer will
erase corresponding data. See commit bdb2b8cab439 ("[SCSI] erase invalid data
returned by device") for details.

Commit e662502b3a78 ("scsi: vmw_pvscsi: Set correct residual data length")
introduced the issue by setting residual length unconditionally causing
scsi_lib layer to erase the useful payload beyond dataLen in the mentioned
above cases.

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.

Fixes: e662502b3a78 ("scsi: vmw_pvscsi: Set correct residual data length")
Reported-and-suggested-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
Link: https://lore.kernel.org/lkml/20210824120028.30d9c071@blondie/
Cc: Matt Wang <wwentao@vmware.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Vishal Bhakta <vbhakta@vmware.com>
Cc: VMware PV-Drivers <pv-drivers@vmware.com>
Cc: James E.J. Bottomley <jejb@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
---
 drivers/scsi/vmw_pvscsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index ce1ba1b93..9419d6d1d 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -586,9 +586,12 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 			 * Commands like INQUIRY may transfer less data than
 			 * requested by the initiator via bufflen. Set residual
 			 * count to make upper layer aware of the actual amount
-			 * of data returned.
+			 * of data returned. There are cases when controller
+			 * returns zero dataLen with non zero data - do not set
+			 * residual count in that case.
 			 */
-			scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
+			if (e->dataLen && (e->dataLen < scsi_bufflen(cmd)))
+				scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
 			cmd->result = (DID_OK << 16);
 			break;
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: vmw_pvscsi: Set residual data length conditionally
  2021-12-20 19:05 [PATCH] scsi: vmw_pvscsi: Set residual data length conditionally Alexey Makhalov
@ 2021-12-23  5:08 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2021-12-23  5:08 UTC (permalink / raw)
  To: Alexey Makhalov, linux-scsi
  Cc: Martin K . Petersen, Matt Wang, James E . J . Bottomley,
	srivatsa, shmulik.ladkani, VMware PV-Drivers, Vishal Bhakta,
	namit, stable

On Mon, 20 Dec 2021 11:05:14 -0800, Alexey Makhalov wrote:

> PVSCSI implementation in VMware hypervisor under specific configuration
> ("SCSI Bus Sharing" set to "Physical") returns zero dataLen in completion
> descriptor for read_capacity_16. As a result, the kernel can not detect proper
> disk geometry. It can be recognized by the kernel message:
> [    0.776588] sd 1:0:0:0: [sdb] Sector size 0 reported, assuming 512.
> 
> PVSCSI implementation in QEMU does not set dataLen at all keeping it zeroed,
> leading to the boot hang, as was reported by Shmulik Ladkani.
> 
> [...]

Applied to 5.16/scsi-fixes, thanks!

[1/1] scsi: vmw_pvscsi: Set residual data length conditionally
      https://git.kernel.org/mkp/scsi/c/142c779d05d1

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-23  5:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 19:05 [PATCH] scsi: vmw_pvscsi: Set residual data length conditionally Alexey Makhalov
2021-12-23  5:08 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).