All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: Check for unaligned partial completion
@ 2017-03-25 15:29 Damien Le Moal
  2017-03-27  5:53 ` Hannes Reinecke
  2017-03-27  8:34 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Damien Le Moal @ 2017-03-25 15:29 UTC (permalink / raw)
  To: stable
  Cc: gregkh, Martin K . Petersen, Hannes Reinecke, Christoph Hellwig,
	Bart Van Assche, Damien Le Moal

commit c46f09175dab ("scsi: sd: Check for unaligned partial completion")
upstream.

Commit <f2e767bb5d6e> ("mpt3sas: Force request partial completion
alignment") was not considering the case of commands not operating on
logical block size units (e.g. REQ_OP_ZONE_REPORT and its 64B aligned
partial replies). In this case, forcing alignment of resid to the device
logical block size can break the command result, e.g. in the case of
REQ_OP_ZONE_REPORT, the exact number of zone reported by the device.

Move the partial completion alignement check of mpt3sas to a generic
implementation in sd_done(). The check is added within the default
section of the initial req_op() switch case so that the report and reset
zone commands are ignored. In addition, as sd_done() is not called for
passthrough requests, resid corrections are not done as intended by the
initial mpt3sas patch.

Fixes: f2e767bb5d6e ("mpt3sas: Force request partial completion alignment")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Acked-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 ---------------
 drivers/scsi/sd.c                    | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 0b5b423..1961535 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4658,7 +4658,6 @@ _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;
 
 	mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
 	scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
@@ -4717,20 +4716,6 @@ _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;
-	if (unlikely(scmd->request->cmd_type == REQ_TYPE_FS && sector_sz &&
-		     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);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 1f5d92a..1ee5761 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1790,6 +1790,8 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 {
 	int result = SCpnt->result;
 	unsigned int good_bytes = result ? 0 : scsi_bufflen(SCpnt);
+	unsigned int sector_size = SCpnt->device->sector_size;
+	unsigned int resid;
 	struct scsi_sense_hdr sshdr;
 	struct scsi_disk *sdkp = scsi_disk(SCpnt->request->rq_disk);
 	struct request *req = SCpnt->request;
@@ -1820,6 +1822,21 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 			scsi_set_resid(SCpnt, blk_rq_bytes(req));
 		}
 		break;
+	default:
+		/*
+		 * In case of bogus fw or device, we could end up having
+		 * an unaligned partial completion. Check this here and force
+		 * alignment.
+		 */
+		resid = scsi_get_resid(SCpnt);
+		if (resid & (sector_size - 1)) {
+			sd_printk(KERN_INFO, sdkp,
+				"Unaligned partial completion (resid=%u, sector_sz=%u)\n",
+				resid, sector_size);
+			resid = min(scsi_bufflen(SCpnt),
+				    round_up(resid, sector_size));
+			scsi_set_resid(SCpnt, resid);
+		}
 	}
 
 	if (result) {
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: sd: Check for unaligned partial completion
  2017-03-25 15:29 [PATCH] scsi: sd: Check for unaligned partial completion Damien Le Moal
@ 2017-03-27  5:53 ` Hannes Reinecke
  2017-03-27  8:34 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2017-03-27  5:53 UTC (permalink / raw)
  To: Damien Le Moal, stable
  Cc: gregkh, Martin K . Petersen, Christoph Hellwig, Bart Van Assche

On 03/25/2017 04:29 PM, Damien Le Moal wrote:
> commit c46f09175dab ("scsi: sd: Check for unaligned partial completion")
> upstream.
> 
> Commit <f2e767bb5d6e> ("mpt3sas: Force request partial completion
> alignment") was not considering the case of commands not operating on
> logical block size units (e.g. REQ_OP_ZONE_REPORT and its 64B aligned
> partial replies). In this case, forcing alignment of resid to the device
> logical block size can break the command result, e.g. in the case of
> REQ_OP_ZONE_REPORT, the exact number of zone reported by the device.
> 
> Move the partial completion alignement check of mpt3sas to a generic
> implementation in sd_done(). The check is added within the default
> section of the initial req_op() switch case so that the report and reset
> zone commands are ignored. In addition, as sd_done() is not called for
> passthrough requests, resid corrections are not done as intended by the
> initial mpt3sas patch.
> 
> Fixes: f2e767bb5d6e ("mpt3sas: Force request partial completion alignment")
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
> Acked-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 ---------------
>  drivers/scsi/sd.c                    | 17 +++++++++++++++++
>  2 files changed, 17 insertions(+), 15 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: sd: Check for unaligned partial completion
  2017-03-25 15:29 [PATCH] scsi: sd: Check for unaligned partial completion Damien Le Moal
  2017-03-27  5:53 ` Hannes Reinecke
@ 2017-03-27  8:34 ` Christoph Hellwig
  2017-03-27 13:44   ` Damien Le Moal
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2017-03-27  8:34 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: stable, gregkh, Martin K . Petersen, Hannes Reinecke,
	Christoph Hellwig, Bart Van Assche

I guess this is for 4.10-stable only?  Looks fine for that.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scsi: sd: Check for unaligned partial completion
  2017-03-27  8:34 ` Christoph Hellwig
@ 2017-03-27 13:44   ` Damien Le Moal
  0 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2017-03-27 13:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: stable, gregkh, Martin K . Petersen, Hannes Reinecke, Bart Van Assche

Christoph,

On 3/27/17 01:34, Christoph Hellwig wrote:
> I guess this is for 4.10-stable only?  Looks fine for that.

Yes, this is for stable 4.10. The original upstream patch did not apply
cleanly. This one fixes that.

Best regards.

-- 
Damien Le Moal, Ph.D.
Sr Manager, System Software Group,
Western Digital Research
Damien.LeMoal@wdc.com
Tel: (+81) 0466-98-3593 (Ext. 51-3593)
1 kirihara-cho, Fujisawa, Kanagawa, 252-0888 Japan
www.wdc.com, www.hgst.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-27 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-25 15:29 [PATCH] scsi: sd: Check for unaligned partial completion Damien Le Moal
2017-03-27  5:53 ` Hannes Reinecke
2017-03-27  8:34 ` Christoph Hellwig
2017-03-27 13:44   ` Damien Le Moal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.