diff mbox

[v2] mpt3sas: Force request partial completion alignment

Message ID yq1a8aebt4q.fsf@oracle.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Martin K. Petersen Jan. 25, 2017, 11:46 p.m. UTC
>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:

Hi Guilherme,

Comments

Guilherme G. Piccoli Jan. 26, 2017, 1:31 p.m. UTC | #1
On 01/25/2017 09:46 PM, Martin K. Petersen wrote:
>>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:
> 
> Hi Guilherme,

Hi Martin, thanks for the review!


> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 75f3fce..e52c942 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))) {
> 
> Maybe a bit zealous on the sanity checking...

A bit...? heheh
Too much I'd say. Since this is dealing with a bogus FW scenario, I
found more safe to check everything...of course we can remove checks if
it's sure req isn't NULL ever. The sector_sz check is avoiding
degenerate cases, since our division below.


> 
> +		sdev_printk(KERN_INFO, scmd->device,
> +			"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
> +			xfer_cnt, sector_sz);
> +		xfer_cnt = (xfer_cnt / sector_sz) * sector_sz;
> 
> Not so keen on divisions. xfer_cnt = round_down(xfer_cnt, sector_sz), maybe?
>

Martin, I might be completely wrong here (please correct me if this is
the case), but isn't C standard integer division a truncation that acts
like a round down? I checked (what I think is) the specification of C
language (ISO/IEC 9899:1999), and it seems the division proposed by Ram
Pai is accurate in this case. Also, both variables are unsigned.

Let me know your thoughts.
Thanks,


Guilherme

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ram Pai Jan. 26, 2017, 5:02 p.m. UTC | #2
On Thu, Jan 26, 2017 at 11:31:53AM -0200, Guilherme G. Piccoli wrote:
> On 01/25/2017 09:46 PM, Martin K. Petersen wrote:
> >>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:
> > 
> > Hi Guilherme,
> 
> Hi Martin, thanks for the review!
> 
> 
> > 
> > diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> > index 75f3fce..e52c942 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))) {
> > 
> > Maybe a bit zealous on the sanity checking...
> 
> A bit...? heheh
> Too much I'd say. Since this is dealing with a bogus FW scenario, I
> found more safe to check everything...of course we can remove checks if
> it's sure req isn't NULL ever. The sector_sz check is avoiding
> degenerate cases, since our division below.
> 
> 
> > 
> > +		sdev_printk(KERN_INFO, scmd->device,
> > +			"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
> > +			xfer_cnt, sector_sz);
> > +		xfer_cnt = (xfer_cnt / sector_sz) * sector_sz;
> > 
> > Not so keen on divisions. xfer_cnt = round_down(xfer_cnt, sector_sz), maybe?
> >
> 
> Martin, I might be completely wrong here (please correct me if this is
> the case), but isn't C standard integer division a truncation that acts
> like a round down? I checked (what I think is) the specification of C
> language (ISO/IEC 9899:1999), and it seems the division proposed by Ram
> Pai is accurate in this case. Also, both variables are unsigned.

Guilherme,  Its better to use round_down() instead of division. Among
other things it saves a few nanoseconds.

RP

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guilherme G. Piccoli Jan. 26, 2017, 6:37 p.m. UTC | #3
On 01/26/2017 03:02 PM, Ram Pai wrote:
> On Thu, Jan 26, 2017 at 11:31:53AM -0200, Guilherme G. Piccoli wrote:
>> On 01/25/2017 09:46 PM, Martin K. Petersen wrote:
>>>>>>>> "Guilherme" == Guilherme G Piccoli <gpiccoli@linux.vnet.ibm.com> writes:
>>>
>>> Hi Guilherme,
>>
>> Hi Martin, thanks for the review!
>>
>>
>>>
>>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
>>> index 75f3fce..e52c942 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))) {
>>>
>>> Maybe a bit zealous on the sanity checking...
>>
>> A bit...? heheh
>> Too much I'd say. Since this is dealing with a bogus FW scenario, I
>> found more safe to check everything...of course we can remove checks if
>> it's sure req isn't NULL ever. The sector_sz check is avoiding
>> degenerate cases, since our division below.
>>
>>
>>>
>>> +		sdev_printk(KERN_INFO, scmd->device,
>>> +			"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
>>> +			xfer_cnt, sector_sz);
>>> +		xfer_cnt = (xfer_cnt / sector_sz) * sector_sz;
>>>
>>> Not so keen on divisions. xfer_cnt = round_down(xfer_cnt, sector_sz), maybe?
>>>
>>
>> Martin, I might be completely wrong here (please correct me if this is
>> the case), but isn't C standard integer division a truncation that acts
>> like a round down? I checked (what I think is) the specification of C
>> language (ISO/IEC 9899:1999), and it seems the division proposed by Ram
>> Pai is accurate in this case. Also, both variables are unsigned.
> 
> Guilherme,  Its better to use round_down() instead of division. Among
> other things it saves a few nanoseconds.

Thanks Ram and Martin for the suggestion and explanation. I just sent a V3.

Cheers,


Guilherme

> 
> RP
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 75f3fce..e52c942 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))) {

Maybe a bit zealous on the sanity checking...

+		sdev_printk(KERN_INFO, scmd->device,
+			"unaligned partial completion avoided (xfer_cnt=%u, sector_sz=%u)\n",
+			xfer_cnt, sector_sz);
+		xfer_cnt = (xfer_cnt / sector_sz) * sector_sz;

Not so keen on divisions. xfer_cnt = round_down(xfer_cnt, sector_sz), maybe?