diff mbox series

[RESEND,1/2] scsi: vmw_pvscsi: Fix swiotlb operation

Message ID 20191203193052.7583-1-thomas_os@shipmail.org (mailing list archive)
State Mainlined
Commit f4652752a428f65936a7da5884095ef43a3cac18
Headers show
Series [RESEND,1/2] scsi: vmw_pvscsi: Fix swiotlb operation | expand

Commit Message

Thomas Hellström (Intel) Dec. 3, 2019, 7:30 p.m. UTC
From: Thomas Hellstrom <thellstrom@vmware.com>

With swiotlb, the first byte of the sense buffer may in some cases be
uninitialized since we use DMA_FROM_DEVICE, and the device incorrectly
doesn't clear it. In those cases, clear it after DMA unmapping.

Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Suggested-by: Vishal Bhakta <vbhakta@vmware.com>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Acked-by: Jim Gill <jgill@vmware.com>
---
 drivers/scsi/vmw_pvscsi.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Martin K. Petersen Dec. 20, 2019, 3:44 a.m. UTC | #1
Thomas,

> With swiotlb, the first byte of the sense buffer may in some cases be
> uninitialized since we use DMA_FROM_DEVICE, and the device incorrectly
> doesn't clear it. In those cases, clear it after DMA unmapping.

Applied 1+2 to 5.6/scsi-queue, thanks!
Thomas Hellstrom Dec. 20, 2019, 8:56 a.m. UTC | #2
On 12/20/19 4:44 AM, Martin K. Petersen wrote:
> Thomas,
>
>> With swiotlb, the first byte of the sense buffer may in some cases be
>> uninitialized since we use DMA_FROM_DEVICE, and the device incorrectly
>> doesn't clear it. In those cases, clear it after DMA unmapping.
> Applied 1+2 to 5.6/scsi-queue, thanks!
>
Thanks!

Thomas
diff mbox series

Patch

diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 70008816c91f..8a09d184a320 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -402,6 +402,17 @@  static int pvscsi_map_buffers(struct pvscsi_adapter *adapter,
 	return 0;
 }
 
+/*
+ * The device incorrectly doesn't clear the first byte of the sense
+ * buffer in some cases. We have to do it ourselves.
+ * Otherwise we run into trouble when SWIOTLB is forced.
+ */
+static void pvscsi_patch_sense(struct scsi_cmnd *cmd)
+{
+	if (cmd->sense_buffer)
+		cmd->sense_buffer[0] = 0;
+}
+
 static void pvscsi_unmap_buffers(const struct pvscsi_adapter *adapter,
 				 struct pvscsi_ctx *ctx)
 {
@@ -544,6 +555,8 @@  static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 	cmd = ctx->cmd;
 	abort_cmp = ctx->abort_cmp;
 	pvscsi_unmap_buffers(adapter, ctx);
+	if (sdstat != SAM_STAT_CHECK_CONDITION)
+		pvscsi_patch_sense(cmd);
 	pvscsi_release_context(adapter, ctx);
 	if (abort_cmp) {
 		/*
@@ -873,6 +886,7 @@  static void pvscsi_reset_all(struct pvscsi_adapter *adapter)
 			scmd_printk(KERN_ERR, cmd,
 				    "Forced reset on cmd %p\n", cmd);
 			pvscsi_unmap_buffers(adapter, ctx);
+			pvscsi_patch_sense(cmd);
 			pvscsi_release_context(adapter, ctx);
 			cmd->result = (DID_RESET << 16);
 			cmd->scsi_done(cmd);