From patchwork Wed Mar 1 08:27:00 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: 9597797 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 1EB6360429 for ; Wed, 1 Mar 2017 08:28:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E9D3284DD for ; Wed, 1 Mar 2017 08:28:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 011CE284E7; Wed, 1 Mar 2017 08:28: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 155B0284DD for ; Wed, 1 Mar 2017 08:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750947AbdCAI2j (ORCPT ); Wed, 1 Mar 2017 03:28:39 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:21234 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009AbdCAI2g (ORCPT ); Wed, 1 Mar 2017 03:28:36 -0500 X-IronPort-AV: E=Sophos;i="5.35,224,1483977600"; d="scan'208";a="100652870" Received: from mail-bn3nam01lp0184.outbound.protection.outlook.com (HELO NAM01-BN3-obe.outbound.protection.outlook.com) ([216.32.180.184]) by ob1.hgst.iphmx.com with ESMTP; 01 Mar 2017 16:27: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=1hpsDCF30VlF+vWagvVhvu9foyudKi49dAhbQE395lQ=; b=C19YF8qmQZv2ig8uzkATtEpTyvDOWPKlW2ggBP9v5C6jydrZb9/gnDMbJG6sbjbz+sSZYqQDqiWwZhwTLlsT01oSzmBqzgstv9flLdCiNM9DsdXcGW7nAl/Gvr+/3q2gdDXrrBoB5jIPhWeNbuRPR/BsLywwcGrn5GdtDge1llc= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.5) by CY1PR04MB1977.namprd04.prod.outlook.com (10.166.191.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.933.12; Wed, 1 Mar 2017 08:27:37 +0000 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , MPT-FusionLinux.pdl@broadcom.com, Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Damien Le Moal Subject: [PATCH v6] sd: Check for unaligned partial completion Date: Wed, 1 Mar 2017 17:27:00 +0900 Message-Id: <20170301082700.20413-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: BN6PR1301CA0027.namprd13.prod.outlook.com (10.174.84.168) To CY1PR04MB1977.namprd04.prod.outlook.com (10.166.191.13) X-MS-Office365-Filtering-Correlation-Id: ecfd11ea-f4b3-42c4-cb88-08d4607cd353 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY1PR04MB1977; X-Microsoft-Exchange-Diagnostics: 1; CY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BtjZxNsvrx1pDMXRiuI7YU4Xei/BIszmWX90MbyRxODcSvWt8GvvJ4ght0eIc02KXet/L1c7RKyjIztgsRWJbARrRQ5aCBMPWSvQttGUR3IbCM4K61cuo4cFQSp2IR1NDLTSRVzptvgoIQRlSpBi1nTr+a5dsvyssZXlhE4s/He8k7iOXNLkcmzuDyL/71NGvJbblu4Nok0ONgUIVaeUk74eHASqZ3ePBFmxEb1vYGqyezevoo7WmrF0sRDO/mmrRRN7v2w/J8KHoY7bObasZ7UfA3OFjP/qGR10fxpK2HM9zsEpai/xwYz3xgjbQO3s4BNqjNEsz+BdAuFgUE+NfOY1lEmhTv/4VePFtciWOvZlynPlN1zJIYrIMr/yjpjEMdodVRWMlf6gicccfKIsdBs8IFexiLwpM3HkO2r+jw5gl6Yku8q9xqM/cXlYKKgXvF1/uvv5w4BKXchP/lDbgfzXDKTBIB7 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)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123558025)(20161123555025)(20161123564025)(20161123560025)(6072148); SRVR:CY1PR04MB1977; BCL:0; PCL:0; RULEID:; SRVR:CY1PR04MB1977; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1977; 4:PnnW7BV7ViAaYGbvjKJFheaFf+zsl4XkpMjH6FNA09B/9rA/IpwJkgoqYxtidBDeRziyGv2P/0Ego0cPJv6J7ZCrlklpFfXzgfQSjND8tA6JdvNJroEE4fffdK7GQ3UZ8OE7x7ehleFwFKWewEwizIQfFjdHA4EoC265wh+gf0HS2vy6sxKOhmN0YdUe41h3alvqp7pRSFBiQ2etQKLSBf8P2JSdk2Ug+F/zdq+1afJ6+/cK0b5H7vUxVh9k0NUpS8fYscHYf3LwitkOLnkgYBxhXSe6DmFZ/VrhH21nEs7Yq3dyzSSrAf8hkhJntHXyHkLiYeHB6Vs4npwmloXkA0VRNxy2gsJg7+pOB0hPhM3RBssBvQu+2gcpszrBYFEIXXIJVSXJivgHi7V41ZJnaud/ifAH1mwuNc3mxDVi4UQOq+weKIYP4dYR+4b9/wIWyPly7b4N8ohkrWR5e9j2BmLgomjELu5qEiEhS4jPtN9rgUnyAJ6UJSbd4QhH2swqCMY6rhZxjRTfM2p1CwrMA09qODAlMBkkSnPT53N4LUKNoGCskFBXYuEpHr1rCKb4PWudSDvf+3LBSBcX5n9JcQciURuw0aEbrwW/aOM12nWRev1ahqGSQkWYi1/amDjB X-Forefront-PRVS: 0233768B38 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39410400002)(39450400003)(39850400002)(39840400002)(39860400002)(38730400002)(189998001)(110136004)(25786008)(8676002)(36756003)(47776003)(1076002)(50226002)(86362001)(42186005)(7736002)(81166006)(50986999)(4326008)(53936002)(305945005)(66066001)(33646002)(6512007)(50466002)(92566002)(6916009)(5003940100001)(6666003)(6506006)(6116002)(5660300001)(6486002)(54906002)(3846002)(2906002)(7099028); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR04MB1977; H:washi.fujisawa.hgst.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR04MB1977; 23:Sl4em1bd5UIkaSFoh3NFP6/ZMC0MadIRUXwZ1KkSd?= =?us-ascii?Q?3Hcp5a0nE7tFTsaamCxpqjeRfbxOnSkvBxt7mlri4W0Ms5brGwK6MKMrN0Mm?= =?us-ascii?Q?E3MQEKHsfr82W7sJ32R0O7EsxlvVR+PE2zvPq4DIhVB16peBh9ZSw/uB6oiA?= =?us-ascii?Q?lDEQQ3tGw1RI02tidi8HBPmCzecdUWytWGS0g16BOKAr5kBpjc/52PjkZar5?= =?us-ascii?Q?c5qiVAuCHkehwAfoaISTwF/OPU/n6Exi0QwXkvJBnS7mpcl2nLPdvcfeAo8A?= =?us-ascii?Q?FBuk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+c/0u48opG4Ka4e70txDXS5G/GTwx11Kni9J/FwdkMG/2p1dm5LJKvCQgZh6IvyUjOvIkDo5rObEL7tYJmqmVr5zZQE2VBOIssoRVoNu2ziO99TD+KKT7LBCQON9DLzx2ZN93pWTAJQdjyZPklhAulIc2mnLWSIV9/EQuYFS7lm+url1dctgLUivncjH/S X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2017 08:27:37.2526 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR04MB1977 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit ("mpt3sas: Force request partial completion alignment") was not considering the case of commands not operating on logical block size units (e.g. REQ_OP_ZONE_REPORT and its 64B aligned partial replies). In this case, forcing alignment of resid to the device logical block size can break the command result, e.g. in the case of REQ_OP_ZONE_REPORT, the exact number of zone reported by the device. Move the partial completion alignement check of mpt3sas to a generic implementation in sd_done(). The check is added within the default section of the initial req_op() switch case so that the report and reset zone commands are ignored. In addition, as sd_done() is not called for passthrough requests, resid corrections are not done as intended by the initial mpt3sas patch. Fixes: f2e767bb5d6e ("mpt3sas: Force request partial completion alignment") Signed-off-by: Damien Le Moal Acked-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 --------------- drivers/scsi/sd.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 46e866c..69c29c5 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -4677,7 +4677,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); @@ -4742,20 +4741,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(!blk_rq_is_passthrough(scmd->request) && 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 c7839f6..fb9b4d2 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1783,6 +1783,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; @@ -1813,6 +1815,21 @@ 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)) { + sd_printk(KERN_INFO, sdkp, + "Unaligned partial completion (resid=%u, sector_sz=%u)\n", + resid, sector_size); + resid = min(scsi_bufflen(SCpnt), + round_up(resid, sector_size)); + scsi_set_resid(SCpnt, resid); + } } if (result) {