Skip to contentSkip to conversation

scsi: vmw_pvscsi: Fix swiotlb operation

PATCH RESEND In review Thomas Hellström (VMware) 3 participants 4 messages Dec 3, 2019 – Dec 20, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/2 scsi: vmw_pvscsi: Fix swiotlb operation

From: Thomas Hellstrom <[email protected]>

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.

---
 drivers/scsi/vmw_pvscsi.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/scsi/vmw_pvscsi.c +14 -0
index 70008816c91f..8a09d184a320 100644
@@ -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);
Signature · 1 line
2.21.0
#1 lore raw

PATCH RESEND 2/2 scsi: vmw_pvscsi: Silence dma mapping errors

From: Thomas Hellstrom <[email protected]>

These errors typically occur with swiotlb when the swiotlb buffer is full. But they are transient and would typically unnecessarily worry a user. Instead of errors, print debug messages.

Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 drivers/scsi/vmw_pvscsi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/vmw_pvscsi.c +3 -3
index 8a09d184a320..c3f010df641e 100644
@@ -365,7 +365,7 @@ static int pvscsi_map_buffers(struct pvscsi_adapter *adapter,
 		int segs = scsi_dma_map(cmd);
 
 		if (segs == -ENOMEM) {
-			scmd_printk(KERN_ERR, cmd,
+			scmd_printk(KERN_DEBUG, cmd,
 				    "vmw_pvscsi: Failed to map cmd sglist for DMA.\n");
 			return -ENOMEM;
 		} else if (segs > 1) {
@@ -392,7 +392,7 @@ static int pvscsi_map_buffers(struct pvscsi_adapter *adapter,
 		ctx->dataPA = dma_map_single(&adapter->dev->dev, sg, bufflen,
 					     cmd->sc_data_direction);
 		if (dma_mapping_error(&adapter->dev->dev, ctx->dataPA)) {
-			scmd_printk(KERN_ERR, cmd,
+			scmd_printk(KERN_DEBUG, cmd,
 				    "vmw_pvscsi: Failed to map direct data buffer for DMA.\n");
 			return -ENOMEM;
 		}
@@ -725,7 +725,7 @@ static int pvscsi_queue_ring(struct pvscsi_adapter *adapter,
 				cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
 				DMA_FROM_DEVICE);
 		if (dma_mapping_error(&adapter->dev->dev, ctx->sensePA)) {
-			scmd_printk(KERN_ERR, cmd,
+			scmd_printk(KERN_DEBUG, cmd,
 				    "vmw_pvscsi: Failed to map sense buffer for DMA.\n");
 			ctx->sensePA = 0;
 			return -ENOMEM;
Signature · 1 line
2.21.0
#2 lore raw
In reply to Thomas Hellström (VMware)

Thomas,

Quoted 3 lines

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!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
Quoted 7 lines · Martin K. Petersen

Thomas,

Quoted 3 lines

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