From: Bart Van Assche <Bart.VanAssche@sandisk.com>
To: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"James.Bottomley@HansenPartnership.com"
<James.Bottomley@HansenPartnership.com>,
Damien Le Moal <Damien.LeMoal@wdc.com>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Cc: "chaitra.basappa@broadcom.com" <chaitra.basappa@broadcom.com>,
"sathya.prakash@broadcom.com" <sathya.prakash@broadcom.com>,
"suganath-prabu.subramani@broadcom.com"
<suganath-prabu.subramani@broadcom.com>,
"hare@suse.de" <hare@suse.de>,
"MPT-FusionLinux.pdl@broadcom.com"
<MPT-FusionLinux.pdl@broadcom.com>, "hch@lst.de" <hch@lst.de>
Subject: Re: [PATCH v4] sd: Check for unaligned partial completion
Date: Wed, 15 Feb 2017 16:42:56 +0000 [thread overview]
Message-ID: <1487176942.2666.1.camel@sandisk.com> (raw)
In-Reply-To: <20170215021230.11181-1-damien.lemoal@wdc.com>
On Wed, 2017-02-15 at 11:12 +0900, Damien Le Moal wrote:
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 1f5d92a..d05a328 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,24 @@ 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)) {
> + SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
> + "Unaligned partial completion (resid=%u, sector_sz=%u)\n",
> + resid, sector_size));
> + resid = round_up(resid, sector_size);
> + if (resid < good_bytes)
> + good_bytes -= resid;
> + else
> + good_bytes = 0;
> + scsi_set_resid(SCpnt, resid);
> + }
> }
>
> if (result) {
An additional concern: what if the size of the Data-Out buffer is not a
multiple of the logical block size? Shouldn't we round down (good_bytes -
resid) instead of rounding up resid?
Thanks,
Bart.
next prev parent reply other threads:[~2017-02-15 16:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-15 2:12 [PATCH v4] sd: Check for unaligned partial completion Damien Le Moal
2017-02-15 6:34 ` Christoph Hellwig
2017-02-15 6:48 ` Damien Le Moal
2017-02-15 7:06 ` Ram Pai
2017-02-16 19:34 ` Guilherme G. Piccoli
2017-02-15 15:10 ` Bart Van Assche
2017-02-16 0:50 ` Damien Le Moal
2017-02-15 16:42 ` Bart Van Assche [this message]
2017-02-16 0:54 ` Damien Le Moal
2017-02-16 1:10 ` Bart Van Assche
2017-02-16 2:52 ` Damien Le Moal
2017-02-16 3:00 ` Damien Le Moal
2017-02-16 3:28 ` Bart Van Assche
2017-02-16 5:17 ` Damien Le Moal
2017-02-16 3:36 ` Martin K. Petersen
2017-02-16 4:16 ` Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1487176942.2666.1.camel@sandisk.com \
--to=bart.vanassche@sandisk.com \
--cc=Damien.LeMoal@wdc.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=MPT-FusionLinux.pdl@broadcom.com \
--cc=chaitra.basappa@broadcom.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sathya.prakash@broadcom.com \
--cc=suganath-prabu.subramani@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.