Skip to content

Commit 3529600

Browse files
Ram Paigregkh
authored andcommitted
scsi: mpt3sas: Force request partial completion alignment
commit f2e767bb5d6ee0d988cb7d4e54b0b21175802b6b upstream. 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 <mauricfo@linux.vnet.ibm.com> Signed-off-by: Guilherme G. Piccoli <gpiccoli@linux.vnet.ibm.com> Signed-off-by: Ram Pai <linuxram@us.ibm.com> Acked-by: Sreekanth Reddy <Sreekanth.Reddy@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 58b7cb1 commit 3529600

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/scsi/mpt3sas/mpt3sas_scsih.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4452,6 +4452,7 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
44524452
struct MPT3SAS_DEVICE *sas_device_priv_data;
44534453
u32 response_code = 0;
44544454
unsigned long flags;
4455+
unsigned int sector_sz;
44554456

44564457
mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
44574458
scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
@@ -4510,6 +4511,20 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
45104511
}
45114512

45124513
xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4514+
4515+
/* In case of bogus fw or device, we could end up having
4516+
* unaligned partial completion. We can force alignment here,
4517+
* then scsi-ml does not need to handle this misbehavior.
4518+
*/
4519+
sector_sz = scmd->device->sector_size;
4520+
if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
4521+
xfer_cnt % sector_sz)) {
4522+
sdev_printk(KERN_INFO, scmd->device,
4523+
"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
4524+
xfer_cnt, sector_sz);
4525+
xfer_cnt = round_down(xfer_cnt, sector_sz);
4526+
}
4527+
45134528
scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
45144529
if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
45154530
log_info = le32_to_cpu(mpi_reply->IOCLogInfo);

0 commit comments

Comments
 (0)