From patchwork Tue Feb 14 08:10:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9571447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4802B601E7 for ; Tue, 14 Feb 2017 08:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2965827D5E for ; Tue, 14 Feb 2017 08:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AB3F28394; Tue, 14 Feb 2017 08:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 244D727D5E for ; Tue, 14 Feb 2017 08:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbdBNIK6 (ORCPT ); Tue, 14 Feb 2017 03:10:58 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:2908 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbdBNIK5 (ORCPT ); Tue, 14 Feb 2017 03:10:57 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86123367" Received: from mail-cys01nam02lp0048.outbound.protection.outlook.com (HELO NAM02-CY1-obe.outbound.protection.outlook.com) ([207.46.163.48]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2017 16:10:44 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=/hMnNAilEVi8beK3zGStduAZ/7yeQvs6eCyROmOTYms=; b=j2jRE5gQrjQVjsD1eE5XTvhfzGgqcaLfRlYzjrqprlbbm5s28KyPcns2FwmTrd8oCvBwRI2Rx+4jo76UOJhtUPhGQv/pwSpEVc07F7XH4zg6z31HiGRbz5nj/tfOZH0mPvyOW32DW+9GpoOcmdHDh2aChayrGyAg+1UwN3Y9hd0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.5) by BY2PR04MB1974.namprd04.prod.outlook.com (10.166.111.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Tue, 14 Feb 2017 08:10:40 +0000 From: Damien Le Moal To: Jens Axboe Cc: linux-block@vger.kernel.org, Shaun Tancheff , Damien Le Moal Subject: [PATCH] sd: Check for unaligned partial completion Date: Tue, 14 Feb 2017 17:10:30 +0900 Message-Id: <20170214081030.24558-1-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 X-Originating-IP: [199.255.44.5] X-ClientProxiedBy: MWHPR21CA0030.namprd21.prod.outlook.com (10.175.142.144) To BY2PR04MB1974.namprd04.prod.outlook.com (10.166.111.14) X-MS-Office365-Filtering-Correlation-Id: 5344a9f2-4f85-4bdd-03aa-08d454b0f80d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BY2PR04MB1974; X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 3:dwS1dBqcKno//D4tYZdYBcuXAxIrUbAeK8yzWceiMgdimL5r0ayjAooErQOGC7nalKbTTCrxyhth9P/aBlsP2Crm2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kajlXNF195/WdyKavN3AJIwtHyOQkhR6u5Tj9tnPHFKT42TRT8Cs+FH55K17JDTfEOAGNvC7ZkKhoqjI3gE3cbo2x6DqMXTcR6lpoMLApYH925XhmXpyymzGC0DZ52kw7DlXAD3oOfAisCUPqlDfXlCFIjOPyVdV8KqWCA01MJgAgumsicx0LtXq2zNjnsir1Ab+luG2D4H6e1UaC4582f8sB5+M4SY6taT09ZH0eNcOUYKwNMY4liegRMAXn8+3lsyUPf+oKOkHhU/AfQWLzh/IH4YVQvwAYkZbVsUR/7PxWjdcYUzlNwLfTkSPFHZmZwqaEAiIcEAKzzVSAl+WOIJyWMtU3sw5fXSkSe+MlAdhmMXim5diiAQcxNWOpiuszIEyUCnnhka1xu8ex7jQLAIxsvLKNaGMUIysT9qdl7fRr4Z7Ibo/U X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(20161123562025)(20161123560025)(20161123555025)(20161123558025)(6072148); SRVR:BY2PR04MB1974; BCL:0; PCL:0; RULEID:; SRVR:BY2PR04MB1974; X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 4:TUaqIkIPnL8aNYYeeLw86+uEQsRxpaW742AI26gWyK7xzhfTvxE/X30r09tmgGhCzXV/HGzp34+XxX7a8V1k6zlhd5S+4NFBj3NFKJzqRg+PGo70P6E3XSjg9QjLfbYPC/fLcOFiVSQy1ZDxF40xmyYy+IqTTLN7gLNh/AbSsKloNsAUGIXSrGyGdgZCiXEjgcj+B6V3QT90zalDb7sMfaQpAcYeVi1wIS8fYwPrE0g0gWMl9c7Q4Km7CgZ2q570UHFXvmizdlzzmn8tG86j3tsm6Rzs7rPAngEPEYK0D3IZVarR7cDiXdc5YnUJzw6QzIU9Nb2O0LSQ3YxEMcteRjJYfVEvVe89LM3yTnA03/i34sHywDj8/1ti2HUx3/qxKInSbvrqejZn38YZmekJQ8wWkWXOMe+v8UYF2DR+LFb/LoLyTPOUy2vsybIAj/Gn2VhMz3NzbbpqUHLZL086HG+vg7FSZaTJghCOMcZKBHuR22VIOIBxKJ1AkcatVOrICCFDOdMqce/4YHvU12FZ9unwpYi41Qeo21719Ut8/QOGcMPJmKCZ1tgS7oRA7Sk+xMnqrrobD70F6vO5FSsOnaTQO0oJPHK7gnfZ2nJPDMQ62r3UwvK3BemwwpMcP0DG X-Forefront-PRVS: 0218A015FA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39860400002)(39450400003)(39840400002)(39850400002)(39410400002)(189002)(199003)(4326007)(50986999)(6666003)(86362001)(50466002)(6916009)(53936002)(48376002)(2906002)(33646002)(66066001)(47776003)(42186005)(81003)(36756003)(305945005)(7736002)(101416001)(97736004)(6116002)(5660300001)(106356001)(92566002)(6506006)(6486002)(68736007)(1076002)(105586002)(189998001)(54906002)(6512007)(25786008)(8676002)(5003940100001)(81156014)(81166006)(50226002)(38730400002)(110136004)(3846002)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR04MB1974; H:washi.fujisawa.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR04MB1974; 23:6/o5EYDVychivFOj6qqtJC9rCVN5W2IC/mTsNOcWe?= =?us-ascii?Q?IIiL7IrXOpG+ZTvQDg4wt8zsK6APiYlm+84CaIHiHcPXJOrQgXL9ChWT8obV?= =?us-ascii?Q?lfTKlZIhyruBEvbMK0q9dQdJlrQ/2u4eS2Ut4bAayUMSjzw7JcHm5jg4FvMx?= =?us-ascii?Q?MCdw4KUpXgQ3LqrTZsDYRqrnpxtjX/flvdY5YQw8ryTQvvZTRIlCmwzAU2wW?= =?us-ascii?Q?ls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pwrK381/lUY1S3tReKkq?= =?us-ascii?Q?WgMRKykKw+YPIC6Cybrl2+BIkNQ8vbsdyUzmjjuDgIABaHa/0/WXdg1NKn2h?= =?us-ascii?Q?F4ds5Wfig+JSZxH4HqYg1OY2ZL0Go4y7kjJPb6OpamOtKbIiJLrvZBFBI7Ko?= =?us-ascii?Q?2xOhMslOdsKwAq8AecKVCdpY/8tlK48g3tYjA6P?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 6:sNKI20GNUHuIEvd1lWevxQGHWVdJNBrRDsLzW2aCGpL6Ya+w8Dkg/O2A0WgIqa7kXD8pFFSicRl44KgaT+ucsQDDKx5HxtCWPsUEYwtrOGei2k2zrIgUBr/ZJSEYyM5PCxb+5xd0y/Cx2PN3xLHVFEyROgSUwc/HNaX20Cty3h/mHCryMa7UTXrqdCH2Hy7Mgv4xzgxZmn3W1LREniQSFRZ/nFdnRVK8nu6MwIBxVnzBl9oyoTe5t2Jlb49pKuIpvrkwdotXqgtXEEM+FHqKLLQ1svyjwEoMfiaziKK69VdShbXEZ2cUVJd8X9aN97Dd300AxTe+dqnpgnJfrx7LvQfv20tMsn9uUiln+yKIPwDfm/GUmyEg3NFEtU4s6N+bt3H9jJZCohVb17R6vQh+NVlu/JAr+Edput2DxvQC8Sw=; 5:pZOqt/bSXB6LFKbPUEhc7NOfSLr+3p7ASIaQGR3/PzYFYl7cpqqn0T0OW/xvHlK6gWxM3ETLcFzlvn1hMhHnMTcVoyAWkrjQRPGgSVlemAbVo4O78Un3dVzlFt4lwsS3pJhev/7il4OymS03bSr31A==; 24:fr+RWfsUglnZkHxkco4vM7ve24QWqQXPJKMQQgBN0BLEBHh+78lU09VwFFW3x9DwsY4y/X/MuirdazsSY7QH6T092z1LZ3+dyw0t257O5K8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR04MB1974; 7:SgXZZ65YFrjZE1ssRXGfR06PHgm4RIIlFaCYhlwBGwTtxfj8+oUdYjdJFIC8WvWUddnsfO+bJ3WdOYuGoXEY97BCr2zdbQTOY5rR7Is2OiyNJnrxvNrGukK6DeAAlJS2xbObbeutAec2HWxdRM34/KVYA1rBMrSEOxt8u0Mh6zIh0Rg5fll2GEUff1QZt1h61rkKJ/CDzTGZY5wL2lJ8LjmyhRDVCbKb6DdDpLH16cLfXU7lYkA931NQzEQPrSrvzV6PzpqDCbkJ1Hoz2NhPPFgau1oVXTEdlA8saMfMPvMjrz1UY3YW2jO0hzcXu9L3+WtOIEJ8LLF2pc+IZLMZU3Mnw0zSLfYFwKezd9e0k7dzVEisYTeDPvmgbWZz2xlhKuckoOEogrgyUt83dHkAq4H0HGK3rm2jwGWpGwK0mHSRHzYW/ftnMd0PpoSwQ1RO3pWz9R3WEPlLC43FMfNX4knhNxH0Ti4m1kIvAlwd5thdcFPheFTXLULyGYI8YpCyGgth/zZsTHd5R6n3m8qbMg==; 20:ScghbBDNdYPcxeuFEqSQNGYjdQEtxxaYheCCiKpuKtLSbprjfLnJSxuU4OuJffNdE5MWw2tve1Rrt/PzadgfjF5uu3kqo/DjSfA1nIrDLTe/r6OptNKwkNaKLFXzImo8gZ5DtZpcExUTTaxj0m38c/YOCEiBpPlMdazWeae2ZJr+oc7gHig99bC7SLBTeUMeBXYsdVRC90XEq9JEUX/elGVwM6pXcOG+uLt6WBRf22nUMJ6sXsbHUzAUU8zdZknH X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2017 08:10:40.7189 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR04MB1974 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit "mpt3sas: Force request partial completion alignment" was not considering the case of REQ_TYPE_FS commands not operating on sector size units (e.g. REQ_OP_ZONE_REPORT and its 64B aligned partial replies). This could result is incorrectly retrying (forever) those commands. Move the partial completion alignement check of mpt3sas to sd_done so that the check comes after good_bytes & resid corrections done in that function depending on the request command. Signed-off-by: Damien Le Moal --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 --------------- drivers/scsi/sd.c | 20 ++++++++++++++++++++ 2 files changed, 20 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..a3d8bc4 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_sz = 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; @@ -1829,6 +1831,24 @@ static int sd_done(struct scsi_cmnd *SCpnt) } sdkp->medium_access_timed_out = 0; + /* + * In case of bogus fw or device, we could end up having + * unaligned partial completion. Check this here. + */ + resid = scsi_get_resid(SCpnt); + if (SCpnt->request->cmd_type == REQ_TYPE_FS && + resid & (sector_sz - 1)) { + SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt, + "Unaligned partial completion (resid=%u, sector_sz=%u)\n", + resid, sector_sz)); + resid = round_up(resid, sector_sz); + if (resid < good_bytes) + good_bytes -= resid; + else + good_bytes = 0; + scsi_set_resid(SCpnt, resid); + } + if (driver_byte(result) != DRIVER_SENSE && (!sense_valid || sense_deferred)) goto out;