From patchwork Tue Feb 14 09:00:49 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: 9571477 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 33078601E7 for ; Tue, 14 Feb 2017 09:01:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24402271BC for ; Tue, 14 Feb 2017 09:01:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1753A2793B; Tue, 14 Feb 2017 09:01:40 +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 6AA71271BC for ; Tue, 14 Feb 2017 09:01:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751635AbdBNJBj (ORCPT ); Tue, 14 Feb 2017 04:01:39 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:10986 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750859AbdBNJBh (ORCPT ); Tue, 14 Feb 2017 04:01:37 -0500 X-IronPort-AV: E=Sophos;i="5.35,160,1483977600"; d="scan'208";a="81157667" Received: from mail-co1nam03lp0018.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.18]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2017 17:11:36 +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=FJIk+bnA+JQnPPQyp9s02RUjRxw+2J1O3wPpMA4v0qM=; b=GlziX9sxgMY019iOdnqEjDEWFPzHqKIOEUZJuqZcN7WCeIiff5L0cKjhkUp6i6bGe6K8xEwu6vKN6wAisVLDNGuJx7tScPhv6GsprsKBO967y0RflV0IAfHRFIpVcpya8/nWy90ZIwRcwesoGhgRPn+eEo6TxoygqET4m8DcDWQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.5) by BL2PR04MB1969.namprd04.prod.outlook.com (10.167.97.141) 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 09:00:56 +0000 From: Damien Le Moal To: Jens Axboe Cc: linux-block@vger.kernel.org, Shaun Tancheff , Damien Le Moal Subject: [PATCH v2] sd: Check for unaligned partial completion Date: Tue, 14 Feb 2017 18:00:49 +0900 Message-Id: <20170214090049.29910-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: MWHPR10CA0058.namprd10.prod.outlook.com (10.169.238.20) To BL2PR04MB1969.namprd04.prod.outlook.com (10.167.97.141) X-MS-Office365-Filtering-Correlation-Id: ee4ff50e-0403-40d5-d307-08d454b7fde2 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BL2PR04MB1969; X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1969; 3:BD+o/6EELX9tCh77XEIZZGBCQLHzKZpe5fWMFSVIOD0QfFxw+eSr7sPDxsDxIDBnjYjvySoVTFeE/LdtCc5Lk2kFep/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BoIITiUohFrul32Wfev5aY9xNvvNtYsTwb0nujquwMzuSCKYBOAZ9+QZXQGnL8YjNP/M6qXWCadd0ihdbt3Z8nN/A9pAqm3JvGbiSOuCCWa2v4YBw2Z0tsjAyeITaenHNjkCTtKbX/BGZun7QktMuMYW2FCPOuxV9XF9eEmQQZonOdi0T6Hhyfuzl1zopdmAP2K43o71dFb1XBDXob29Lz9WJXgTX6QyPNI9XAV8NQIFyCOhe8mKwM0XIuFjU7aQ1umI5siG3e10trTFABaImXEjrB6HN+O2LDY/NtLINSwLfJHvUxxu+gQJNyl3vRbJ9OZ1tGGI2fZDHMQ4bdHc2CXXR/LUZJug2wVmV0pc/4JpRNDkSvjNc+4s3n+JhJm61irvfjJu15QIQGyRfiDiq7pVSam9Yj X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(20161123555025)(20161123558025)(20161123562025)(20161123560025)(6072148); SRVR:BL2PR04MB1969; BCL:0; PCL:0; RULEID:; SRVR:BL2PR04MB1969; X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1969; 4:ox7ALWtC3EglsMLT1LO/8Q4v9Hh2CouhvSNu6a1qWiCz2ctu3OjqYvxpKEDH57Hcznuwc8jhgrIZ96qKD1xj097+QnEQgK+Xiw4N9kcCY2u5npDLv83FwAZhj2TFHSy9wPkEfbMuSoMhsNp9E8Dqy0mcnI3uzYHbYS6a0hSnp6VLKkBX3HnVPhjLaZXfRDpRAIC9A75EA/KAzDSwp7hH7Im1sh5XgsEAZSnaeDftHwLVRG29hIEsbBw6llK2XkQbp0Fa4OdX+H6DmgGNiPtaMGdAA/twkQPIBrzVilgQ8Vjq2F6UPvWy9m1JU1I+px+cF8vN+0y1uH5CDVp5RGxIkLt/o8EbAM79OCQuc9UYKRgMl0sDzhdYVCjwiSuvczfxdQY5pNNEDdvlWik0nT8U+r0TRQ+vn9IHJ3ZETeGLGdCUC+6ji1rc6IO8DwtmPWMbg41Cy2/YkDCUeVUnKym2QA+DzHvVCmXlzeaQ5XpyvyEAQyr6BH0ssEBcMSjmuRVyuUbAF/D0UxNIzsL8jjl8+Z31TfgigCSG4YHvgVJwMsYcxhrvMfqtnmLe6u7eWuPzO0jgNuBmfl4qfxktBD/TCFohszuI07+y3pQsmqQN6hZoY1GLxVCFm1am7zsFfL5C X-Forefront-PRVS: 0218A015FA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(39840400002)(39850400002)(39410400002)(39860400002)(189002)(199003)(106356001)(81156014)(42186005)(5003940100001)(1076002)(38730400002)(110136004)(6916009)(53936002)(6116002)(3846002)(6666003)(81166006)(6512007)(36756003)(54906002)(97736004)(575784001)(81003)(86362001)(50226002)(8676002)(105586002)(6486002)(25786008)(92566002)(189998001)(50466002)(48376002)(68736007)(6506006)(47776003)(66066001)(33646002)(2906002)(4326007)(101416001)(7736002)(305945005)(5660300001)(50986999)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR04MB1969; 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; BL2PR04MB1969; 23:WXMIPjjcS4ouAy7zAw4AHMEQ2aeibZ+NMOZ2QfOey?= =?us-ascii?Q?g4XePJ/DK6yAFCuCNzYpXcsipzDkI9DUK1O2iqrf1u4/VuJ8ADCbIF5XsWqp?= =?us-ascii?Q?/x7L4QDBfenqbAsf2DLXVoInMe+5LNVvloXvjUzKo3Z+hRbygktHM+VO5wij?= =?us-ascii?Q?DdNblDI+oQ47q4r307VS0HRRDtp8t8jFGourl940TMVwsvnIH+XsjXqw6W36?= =?us-ascii?Q?k5O/i8mKPM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jFSZJEHAglrJ1w?= =?us-ascii?Q?DSeVYQHm37omW2gKYpq2u6flf9tArnNoCX36fjBCKEjcnCPhDzBHCsqqtPh7?= =?us-ascii?Q?tpCRxDkXs+ZvED2jg3Sle8NjJyl72AmIwn/JB3QpFuq1dhLeA28gp6jprGku?= =?us-ascii?Q?bHGzA9j1l0PQM7Ud3pApOFM325MyevKPrENlJAcKQHeVAMA4WyTmEWqj/1xM?= =?us-ascii?B?dz09?= X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1969; 6:9N81hyCboNJbFlxDDHiOUz1hjooHpCUEI5FzmfgO1NShfulkC/j4kD9TSLrI4Ihr/Eob92Q880yRo1VzD1HWZ4AoZsU5+raZMYt2qVXamPs7dbrdTY1N3n+5B0HgZOdxLoJAaqIhbVqZCucfAw0nrx4yjGjZXiahcS2/CNo1gMuCkVIJi5bNnz8XNux6wjDjYfzomouPMtMrkVQneVSplJFaEyv5P86tWA1Rz3hMK06mABwUfNdmjD44oh50Dt/5+K71inssH8RRqW04A52Thqoc5mIdx6d8tsGOiAIhlpuoio4jcH2peWrRzeAH0FMExX+JyadqaV4pizZVUKSh1w9Bh5j30d2IS80z/imHrK6vUzx+I4ybp/1MU1BbcLsLLlclF9H24nJCk8E/nMj2FQ==; 5:egJTY4B8P5Myo0hzY/ExcYsbdeX4vVc6ph+Suda3lQqBkZVAAJatAdXPWR8+kK8cSwraYY1QyV1zDXIos55Ak/RXSnWzo36AhbyEw334DBac6rZihkFh1s+aUxcJtvqhLRaOI3E5pZde8pwGAU2M1Q==; 24:mCKBSrYa2ozAp5KiDmak8G/Mex0J2+8FbLMnvDo9BKs+//fPTOg3Cvz2KOoaID3jXMqIE0/EP6405pHYVy4+HtsTE4tArrVxhIU2S/cb0Ss= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BL2PR04MB1969; 7:9rlMqy006HXGFCUYF2GxJ2q8uEf6jldYXQVRaUlc56CiBtzBStczNs35dpJrgbYQOzlP8qVbE0X5iQDOPyYpPPRRvhfnfZ8tTzJxVMtZB6MuI0Y8bBcqZUdCvjXFyb4NYb5SJgeRISYTAtvXhZLYE40fk61eDjPCianK747xgSi5JAg4b9xqoMdmmajp7VOCVSjuJSHpvRCrJSk2rfjSY12sGeNKOEX70J2fTl51fQ9Qvj0uZjf/kj/wWuzWREvpezfWS2ArUaEkhW/Woz1Hah7tF5d6mHif4i3hrMxIl1anT5CckLh4lPdX87cbkwFVzDTi0SsOLK+e4C8Nfdge/5QAaIxkXtgFabz0ZFVGq0v/S1ZU/7QXZFj77f/C/wAEtzwyBF/tqJEmFZ9+rV9AePsSnEF9IWHdZ4WGVyK+DfwiiRq8iFx4pqLjZLkGeNnx9IzSyHrfirV4vUg0Vn6xzumjNLxOk17wavOVJbDWxSgjBq7MkIq5edBUeukBizZmAjMjGht5DD8MYeSf23tQAw==; 20:WV6kk7pXkxAhleP2CNOGEhCu50GCDGgZpENIfMDMk617KaWb/ZZKEXx8u9Ihyw3yD9qNXxqKiec20q2AFUOc+5gVnuHjrpDhigTlLOeFq7Z8eMfkTbF4MFPNYD5T+uQv3poFakOa0f81xhgulyltpg7EYlh6GBV/TNymXZT7dzdfTYg07W99THs2SImV46hBoMENl+2x4QTMGaLXi89MsHfJrcGW37Fa+WrTGw9N9ntmnek76OceXoP+HLlB1qLE X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2017 09:00:56.7360 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR04MB1969 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 of done in that function depending on the request command to avoid false positive. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- 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..b0cb9c5 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; @@ -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 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 (driver_byte(result) != DRIVER_SENSE && (!sense_valid || sense_deferred)) goto out;