From patchwork Tue Feb 14 12:42:28 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: 9571849 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 8446560586 for ; Tue, 14 Feb 2017 12:43:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7105227C2D for ; Tue, 14 Feb 2017 12:43:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 659C8283F2; Tue, 14 Feb 2017 12:43:15 +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 A4ECB27C2D for ; Tue, 14 Feb 2017 12:43:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752228AbdBNMnN (ORCPT ); Tue, 14 Feb 2017 07:43:13 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:48800 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753234AbdBNMmy (ORCPT ); Tue, 14 Feb 2017 07:42:54 -0500 X-IronPort-AV: E=Sophos;i="5.35,161,1483977600"; d="scan'208";a="81297291" Received: from mail-sn1nam01lp0119.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.119]) by ob1.hgst.iphmx.com with ESMTP; 14 Feb 2017 20:44:53 +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=7BOk/PttFxcfudOnE+szdxU0Y95t6kDtQdcazN6O7dA=; b=FpJ9iQ+J6KQOSW73vQ5OHL/4quIAMGW6hkkXc6gouSnv9qhVlnw74Jna5ME4LoTPyjkLsy9ABgK77KTxc+EzIjUio3Fvk0IiYtEuturCkL8ea0y1S4Q4hJ04aUItv6HIV9K3OyCLrnAJ6I57ZHRKrsZRnNGkxsGRln5MpdVS/sc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.5) by CY1PR04MB1978.namprd04.prod.outlook.com (10.166.191.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 12:42:38 +0000 From: Damien Le Moal To: Jens Axboe Cc: linux-block@vger.kernel.org, Shaun Tancheff , Damien Le Moal Subject: [PATCH v3] sd: Check for unaligned partial completion Date: Tue, 14 Feb 2017 21:42:28 +0900 Message-Id: <20170214124228.3386-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: MWHPR21CA0031.namprd21.prod.outlook.com (10.175.142.145) To CY1PR04MB1978.namprd04.prod.outlook.com (10.166.191.14) X-MS-Office365-Filtering-Correlation-Id: 329ffa5e-e28e-432c-c520-08d454d6f5e9 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY1PR04MB1978; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1978; 3:t2i3DkrR2oQhLaW4iY5o7u/QfoFE194yd99ZQMcIoj4x5PBqKQaT7rylVtaqd6Un5wJy//yNBLKz1BacTUvUR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tE395Xs0OENAUSfTrDnh6U5XcGea1Kr3z7k5mmWoK/6d7CxJgBm+arbyEaq0yK5/wN+M44GFKt+3LIfpzmdcnmTDNTGz5npkxQIqTfRcSEfT3xetCgy17hsT4gKUW81zjb7rKu37RSpvpCsll8Y82iUzq/h+JqPDh548vJsWCkqLR/LY1sQSFq1m99UxznydVc4ThagGMuQ3YbUIWRGZ8OEOqv2gUIDd3grb2lEXczu8v1PT/Sc0Tb47I3u3zWL2G8UmdvERSUPb9JVlgiy+Psi0iw2/+nCo/tU22OwpIHSE9sLW5I8Ip8y8VXXZLIOHCXbwCaAN1Nml9OlKJmLxQ7FKhmS79zN7dxSCrYdlfUjsi7+LCmZgmnVzgaNbiUplhVWDYgEaAFOmdRGBhU1c+q49/OngKeodNn9Mz 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:CY1PR04MB1978; BCL:0; PCL:0; RULEID:; SRVR:CY1PR04MB1978; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1978; 4:EkDo3lWwi/wb2kZgb1e9v83tvw4Hiz3tmFntLFdhGPsxntdFTrKLrmtQ3cTV7UyhQ+M10rJXLwbrF6BQpPE3Nd5P+ERlIXgWWmxuAcWwy+8P8WabQoX23n+ztqfCgwZLOF59qW5zmMCgGRoHqNhfVuH8WjTTmOXJoYQFo/zKKvmCKHaysdOxjiZv23nHm3IohUXcXzRi47iRKuGYzuLRrUw+Cd2HbFsSE9iO6pELhFvi81zBtRd5ktMvZWGG4lKgnFoUlUncU8VFh1O4tWyLtJlcaK3L8fspIGtbO8i7N3rnkFHvWb1z6S3KKLd0A1McLNVBKlk+z/rRJhpCsNxzw5RHoX0yB74/zkMNxTSNess8Nd4IF0wJqHcu0S7vvo1FTR5ppLFwKNOON8o72paAZtXbHhGS7gxuKr7yEMA3u3xXTvdFO7f5hR9hLYvkrGPwQL0kRWYUfN02La0Gr8OZrBS/yDWOERz17LX8LzEs7z2Afv1wS6eNNCm2dSwV9be/Es8JG/wIV/JxAHEpQMYDrTSoGrCONbo6nZ5hA/wK5oFcRLRL4KiZXgp3ab8xA9UaHbMK7rtPSc/yPaGluLMAmkE4ci6M3nbAWkgwUXRTmercqW4Wi9PwXfyLhA1M9QH8 X-Forefront-PRVS: 0218A015FA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39850400002)(39860400002)(39450400003)(39840400002)(39410400002)(189002)(199003)(6916009)(8676002)(50226002)(5003940100001)(50466002)(68736007)(106356001)(101416001)(6666003)(5660300001)(6512007)(42186005)(81156014)(81166006)(50986999)(48376002)(81003)(105586002)(92566002)(38730400002)(6486002)(25786008)(47776003)(6506006)(305945005)(54906002)(36756003)(7736002)(66066001)(97736004)(33646002)(6116002)(1076002)(3846002)(189998001)(86362001)(4326007)(2906002)(53936002)(110136004)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR04MB1978; 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; CY1PR04MB1978; 23:rvYi8uPKHlgawcgbKHNdPCxBxzgQX9siyCnQohs+5?= =?us-ascii?Q?SEiKcdnhUcXsxORp2tVk/Rlr/m2ZkG9jMM7FW/sLYN8yukerfCdM2gTWjB5M?= =?us-ascii?Q?XaY3sXHi2oDsN8IdBBuLO/9tBxXK+7kZL59+ucFzOMVQJu3YQdY5pAAXDHcw?= =?us-ascii?Q?NUuKPrL3DWszf/ar2Xl3f+IUyhvIjQi1Dp0H+SUzzyndezSueVFTrMRSOjdP?= =?us-ascii?Q?eGW/RiE95utz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?= =?us-ascii?Q?nSAL2RAXPKs8bhL10LphLKulHOEhXFrU8IhmHnD78SfFXuvAQTnpem817/0r?= =?us-ascii?Q?mYEw4uzuVj/8tjyUU0VIrppCx6Txj6uqHN8f9NI0qUSdGAdjITd9NaDHFXwD?= =?us-ascii?Q?tD2greg+XcZwdjLAo/jrzwv/DuaWC7LB54RvQ2U?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1978; 6:ckC0oe0l54u9R4i+DkG5VRmKp/qPw6LyU5fqsMTx33BGwp7AIQAfO6eDI/RDskH1CTPlfQYx0KtIGpxgNE365fIYdFnUKgx8fuLO19IzvrcAwDXMvt7dOLOahJes591L2WRbaKrs337c1MxPXAjUVH4Dxl13D6StQHxGm8Am96w/YJxuV42ymDTobOS4idurCLX8GOpLSFTLXmcmZZUqsFtoWDhmUrea/VkQQPFqCberQwXplNN2voxos1g7ZXlIaKEJh9UU0mUmfFCZ48UhoWklCp8zEGYfp1WMC+tjUru3R61iWtO1Hgekww6ZEtfTZshP1O2l1RJXbGKp8cDG1KCE/0tb+aVvR0h8yNlE1z/g6xu/eSwoxsAuUXRx8jLCjquk+E86mlQrPtAWoQtsmA==; 5:9ibx9mS473Tj+E5fqRDMxNOkZZ30jdSBuYKOjBTz9BFvkAYo/lp2Q9u4DuxDOLsQn9z7RyUrbzdd1lJXM+o02VA9svR9gg4FfQC/tSDHyx8xUEERUyrc9S1QjkLSYoMvseYb/T5Bq03CmMPs9nhVmA==; 24:6SnBvjnEnSiOS17uTal8bo+1xJIwsDyshqoauS924VhA3KKyBtlaLAtnGgGZgtkdkQiR3nKAgYUhw7zPltN+wL5RXWYKqU9hHMgO63wBAFo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1978; 7:1zNhYB14o7kiePc0J0MMiNkh+p//v4rT8OhdreSFVmc/Zv8jQLsPt47yCvPDiHF5Q+fui7CFJyiZ2qhOqaiH8L1U1ip2TZCUmDOX5/nayq3w4o5n1SboMhHXrR0C8bvUJ8j56JpBQ5YbIAxehnczdnLstD4A/mOXYJk2d7uH/XiA7JkxntwFywMASGlEpcUh36ylqMynAyhaNa8EZUSZbsx8M8E9Tllcq8MoQXzEZatQ94S465X9eJWA2cePd5h0wRFtvH/9SyZg/0yLxRWJtXPLbj828sF7XrOImCuz1s/EUi+OP4ME2N7FStBlMSfbuYF5q/pEMzHA46KunLWzAOqr3TANrtpzc5saKCIabB2tvQlGa/4C1Z0Ckb3eyeq9lZdxqOJs2aWfyTD+4Tf6nb9f/gka0fmWe0BAjQIamiutHnrE3RqVGeWn4oQDHfxYDGJGBNmvSSluTG1qWqN+cEam03fpHSti27ZpyJ0S0ugk7WalOvPGSYx5kJAYhqWM+X43avD/FUZ84UOUUx/EDg==; 20:2/+JS5EG2AEEWDnNcqu9M1Y/Pkjj3rd+CiBFSYVWn1AlUX3jALxpt3Rp/ArVSqxRGAmUnnjltMwxVKHwQy0Iz6aUZwPKQakOM6bLcdZnHQi9bJ3Ocstfp2Q8P7/1ncYJu3Ratx6mce8EkRJ219WFaxrkImF3Lu6GxnmcNFpuUju5VDvmeXWJU3cznqo7Th9zOdFsbr1wqV7nZc9WqayUPybh2cGX/dFSdQpAoX8EDmt1oOhT+PhZygElexEM6hC8 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2017 12:42:38.0576 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR04MB1978 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 --- Changes from v2: - Fixed good_bytes calculation after correction of unaligned resid It should be good_bytes=scsi_buflen() - resid, and not good_bytes-=resid 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..2f70b36 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 < scsi_bufflen(SCpnt)) + good_bytes = scsi_bufflen(SCpnt) - resid; + else + good_bytes = 0; + scsi_set_resid(SCpnt, resid); + } + if (driver_byte(result) != DRIVER_SENSE && (!sense_valid || sense_deferred)) goto out;