Skip to contentSkip to conversation

pvscsi: Fix uninitialized sense buffer with swiotlb

PATCH In review Jim Gill 1 participant 1 message Aug 12, 2020

Subsystems (2)
lore
Share & tools
lore

Jim Gill

author
#0 lore raw

PATCH 3/3 pvscsi: Fix uninitialized sense buffer with swiotlb

It seems like the device sometimes leaves part of the
sense buffer uninitialized. This causes massive problems with swiotlb where any previous initialization of the sense buffer by the scsi middle-layer is not propagated to the device since we use DMA_FROM_DEVICE when dma-mapping the sense buffer. Fix this by specifying DMA_BIDIRECTIONAL instead. Makes the scsi errors go away.

Tested using a bonnie++ run on an swiotlb=force booted kernel.

[[email protected]: Forwarding patch on behalf of thellstrom]
---
 drivers/scsi/vmw_pvscsi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/vmw_pvscsi.c +3 -3
index fa2748f..c179a5d 100644
@@ -429,7 +429,7 @@ static void pvscsi_unmap_buffers(const struct pvscsi_adapter *adapter,
 	}
 	if (cmd->sense_buffer)
 		dma_unmap_single(&adapter->dev->dev, ctx->sensePA,
-				 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+				 SCSI_SENSE_BUFFERSIZE, DMA_BIDIRECTIONAL);
 }
 
 static int pvscsi_allocate_rings(struct pvscsi_adapter *adapter)
@@ -714,7 +714,7 @@ static int pvscsi_queue_ring(struct pvscsi_adapter *adapter,
 	if (cmd->sense_buffer) {
 		ctx->sensePA = dma_map_single(&adapter->dev->dev,
 				cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
-				DMA_FROM_DEVICE);
+				DMA_BIDIRECTIONAL);
 		if (dma_mapping_error(&adapter->dev->dev, ctx->sensePA)) {
 			scmd_printk(KERN_DEBUG, cmd,
 				    "vmw_pvscsi: Failed to map sense buffer for DMA.\n");
@@ -746,7 +746,7 @@ static int pvscsi_queue_ring(struct pvscsi_adapter *adapter,
 		if (cmd->sense_buffer) {
 			dma_unmap_single(&adapter->dev->dev, ctx->sensePA,
 					 SCSI_SENSE_BUFFERSIZE,
-					 DMA_FROM_DEVICE);
+					 DMA_BIDIRECTIONAL);
 			ctx->sensePA = 0;
 		}
 		return -ENOMEM;
Signature · 1 line
2.7.4