diff mbox

[v3] mpt3sas: Force request partial completion alignment

Message ID 1485455821-9176-1-git-send-email-gpiccoli@linux.vnet.ibm.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Guilherme G. Piccoli Jan. 26, 2017, 6:37 p.m. UTC
From: Ram Pai <linuxram@us.ibm.com>

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.

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>
---
v2->v3:
  * Changed division to round_down() [suggestion by Martin].

 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Martin K. Petersen Feb. 1, 2017, 3:34 a.m. UTC | #1
>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:

Guilherme> The firmware or device, possibly under a heavy I/O load, can
Guilherme> return on a partial unaligned boundary. Scsi-ml expects these
Guilherme> requests to be completed on an alignment boundary. Scsi-ml
Guilherme> blindly requeues the I/O without checking the alignment
Guilherme> boundary of the I/O request for the remaining bytes. This
Guilherme> leads to errors, since devices cannot perform non-aligned
Guilherme> read/write operations.

Guilherme> This patch fixes the issue in the driver. It aligns unaligned
Guilherme> completions of FS requests, by truncating them to the nearest
Guilherme> alignment boundary.

Applied to 4.10/scsi-fixes.
Guilherme G. Piccoli Feb. 1, 2017, 11:48 a.m. UTC | #2
On 01/02/2017 01:34, Martin K. Petersen wrote:
>>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:
> 
> Guilherme> The firmware or device, possibly under a heavy I/O load, can
> Guilherme> return on a partial unaligned boundary. Scsi-ml expects these
> Guilherme> requests to be completed on an alignment boundary. Scsi-ml
> Guilherme> blindly requeues the I/O without checking the alignment
> Guilherme> boundary of the I/O request for the remaining bytes. This
> Guilherme> leads to errors, since devices cannot perform non-aligned
> Guilherme> read/write operations.
> 
> Guilherme> This patch fixes the issue in the driver. It aligns unaligned
> Guilherme> completions of FS requests, by truncating them to the nearest
> Guilherme> alignment boundary.
> 
> Applied to 4.10/scsi-fixes.
> 

Thanks Martin!
diff mbox

Patch

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 75f3fce..a6b6f58 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4657,6 +4657,8 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 	struct MPT3SAS_DEVICE *sas_device_priv_data;
 	u32 response_code = 0;
 	unsigned long flags;
+	unsigned int sector_sz;
+	struct request *req;
 
 	mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
 	scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
@@ -4715,6 +4717,21 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 	}
 
 	xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
+
+	/* In case of bogus fw or device, we could end up having
+	 * unaligned partial completion. We can force alignment here,
+	 * then scsi-ml does not need to handle this misbehavior.
+	 */
+	sector_sz = scmd->device->sector_size;
+	req = scmd->request;
+	if (unlikely(sector_sz && req && (req->cmd_type == REQ_TYPE_FS) &&
+		    (xfer_cnt % sector_sz))) {
+		sdev_printk(KERN_INFO, scmd->device,
+			"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
+			xfer_cnt, sector_sz);
+		xfer_cnt = round_down(xfer_cnt, sector_sz);
+	}
+
 	scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
 	if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
 		log_info =  le32_to_cpu(mpi_reply->IOCLogInfo);