Skip to content

Commit f2e767b

Browse files
Ram Paimartinkpetersen
authored andcommitted
scsi: mpt3sas: Force request partial completion alignment
The firmware or device, possibly under a heavy I/O load, can return on a partial unaligned boundary. Scsi-ml expects these requests to be completed on an alignment boundary. Scsi-ml blindly requeues the I/O without checking the alignment boundary of the I/O request for the remaining bytes. This leads to errors, since devices cannot perform non-aligned read/write operations. This patch fixes the issue in the driver. It aligns unaligned completions of FS requests, by truncating them to the nearest alignment boundary. [mkp: simplified if statement] Reported-by: Mauricio Faria De Oliveira <[email protected]> Signed-off-by: Guilherme G. Piccoli <[email protected]> Signed-off-by: Ram Pai <[email protected]> Acked-by: Sreekanth Reddy <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 2780f3c commit f2e767b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/scsi/mpt3sas/mpt3sas_scsih.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,7 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
46574657
struct MPT3SAS_DEVICE *sas_device_priv_data;
46584658
u32 response_code = 0;
46594659
unsigned long flags;
4660+
unsigned int sector_sz;
46604661

46614662
mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
46624663
scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
@@ -4715,6 +4716,20 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
47154716
}
47164717

47174718
xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4719+
4720+
/* In case of bogus fw or device, we could end up having
4721+
* unaligned partial completion. We can force alignment here,
4722+
* then scsi-ml does not need to handle this misbehavior.
4723+
*/
4724+
sector_sz = scmd->device->sector_size;
4725+
if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
4726+
xfer_cnt % sector_sz)) {
4727+
sdev_printk(KERN_INFO, scmd->device,
4728+
"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4729+
xfer_cnt, sector_sz);
4730+
xfer_cnt = round_down(xfer_cnt, sector_sz);
4731+
}
4732+
47184733
scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
47194734
if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
47204735
log_info = le32_to_cpu(mpi_reply->IOCLogInfo);

0 commit comments

Comments
 (0)