Skip to content

Commit

Permalink
scsi: vmw_pvscsi: Fix swiotlb operation
Browse files Browse the repository at this point in the history
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" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Suggested-by: Vishal Bhakta <[email protected]>
Acked-by: Jim Gill <[email protected]>
Signed-off-by: Thomas Hellstrom <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
thomashvmw authored and martinkpetersen committed Dec 20, 2019
1 parent a808a04 commit f465275
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/scsi/vmw_pvscsi.c
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit f465275

Please sign in to comment.