From patchwork Wed Feb 15 02:12: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: 9573203 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 6DF806045F for ; Wed, 15 Feb 2017 02:14:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5423228420 for ; Wed, 15 Feb 2017 02:14:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 488E82844E; Wed, 15 Feb 2017 02:14:43 +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 96FFE28420 for ; Wed, 15 Feb 2017 02:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751290AbdBOCOb (ORCPT ); Tue, 14 Feb 2017 21:14:31 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:54513 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750791AbdBOCOa (ORCPT ); Tue, 14 Feb 2017 21:14:30 -0500 X-IronPort-AV: E=Sophos;i="5.35,163,1483977600"; d="scan'208";a="81861237" Received: from mail-co1nam03lp0017.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) ([216.32.181.17]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 10:23:06 +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=OgFISZIABjtffgTtZ6UxxY0fpu7RWlgTwXRzm/fnLj0=; b=krqxsMz7Re1VIL7IC2a6lq5UPw1CIJ3TCC+5puo1qAhWok1/2lootqsn2ltTthjq9JEE1LjuzwTbuJshCDsT4Vgy397ttw/6nrsuExX2bxSji3gGQrRVLf95AEykrdOms/lcVFakw0TIoYVnDQsVQN2Uc21TkBJr2Zj0oXhY9lI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.44.5) by CY1PR04MB1980.namprd04.prod.outlook.com (10.166.191.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Wed, 15 Feb 2017 02:12:39 +0000 From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" , "James E . J . Bottomley" Cc: Sathya Prakash , Chaitra P B , Suganath Prabu Subramani , MPT-FusionLinux.pdl@broadcom.com, Hannes Reinecke , Christoph Hellwig , Damien Le Moal Subject: [PATCH v4] sd: Check for unaligned partial completion Date: Wed, 15 Feb 2017 11:12:30 +0900 Message-Id: <20170215021230.11181-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: DM5PR1601CA0025.namprd16.prod.outlook.com (10.174.111.38) To CY1PR04MB1980.namprd04.prod.outlook.com (10.166.191.16) X-MS-Office365-Filtering-Correlation-Id: 496bc982-6751-4fad-2b4f-08d455481f55 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY1PR04MB1980; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 3:DT412J1egFCoj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TQDYLffmzQid1XY5b35TEUGK98ENZbWD1/7DNBN41Q4H6yM0hyLMdYohjMhV+OGE42ZZUTkDqU8evV41JDa3qHmDvt0Fzy1hMVQ2ZbvhUm6qx5jVSsq1O4hV4twYBFrz6nNOZAKXZAb16rhjodlicRHazwvjZHMXDaQ+X2BHs/tT3qwNSidopSON5hOLT8YYa0Mg9+b+8IOM4G+DyUW/57U2zZFShFRyd0uHGqzkgYjI4tTQcOG8MtH/y0hMnqxdovrw4l3FJLq+QhnQ0TK4mKpsUZ39YxtI4s3yncHx6hbbq5jI5VodKGajhuJrxL3W1KGMGzIdvZ4ZSvFcZ+HgVwG5mqvn9j6CAHSiNf4Sc3+UpkcXoOACIEYxen833YWeg0HQSV6Op0APcNEUgPZWh5r1WFjjO3s6uatrIhFQQZSbA6zphepqQLCmCIlvVSGKWBV0jsrcrV6hRQaBQVoruSy7jH 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)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123558025)(20161123564025)(6072148); SRVR:CY1PR04MB1980; BCL:0; PCL:0; RULEID:; SRVR:CY1PR04MB1980; X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 4:/pZuN63UrlZbNzOu+hcTU53b0aOvXLCA7DfMxIYfCdHzUxSz+UQSjJm3CcwphaCq9RXQLmx60DQr3jwoTDzd+f1EsZCzMKvMQcOVDoFtCc29MTyrEpG0o4KwbLrWPDY8S/swIw+nSgB8s3Tn+ssH0+DRUgdqIY2LVxcDcNFqRayhn9WLcdeXrYa36M25BQvIFXNygFse0ODRrd2DIy2rv4qLJdzD/pYHF9fMzumXzY3luYp7zo6poPoG5bk1WKVcpQPUM25xY6mnfecfU7xVo0i/3FulnKH7iiKKZSXAgFBWxI8JMQHtwi99UXXvLHbn04SYirXyV/FtfkjnuvUYjtMnb4WAYZUr4eOP429CgZ4j1ThuXmz2H5/7EJRk49aj0G5puNDsAs3AXqxq8Q43s3+JccwJw4zEsrOsBnHozCe+Yzmbkd+ML7rTwz2Lnl7KSTUsobKZuhI4BGIRw8KXn433iSSesVMLpxJrxzSE6AVZfaNGW+2rZrbPAOfAATMTccW2Sd09TyHW5FwJWA6HaAeHrsRpgNXgDNRiSWSP5Fll/EwzEtgr3QovSDJ5kNmUCONM1iWDEwySWTF9heQdF59Fgl/j4rM3YFSR/WElGwiOJyV5JVXr/2/Tqc1MqxX1 X-Forefront-PRVS: 021975AE46 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39840400002)(39860400002)(39410400002)(39850400002)(39450400003)(189002)(199003)(86362001)(54906002)(50986999)(81156014)(81166006)(50226002)(5660300001)(42186005)(25786008)(68736007)(6486002)(7736002)(6512007)(2906002)(105586002)(106356001)(389900002)(92566002)(33646002)(4326007)(305945005)(6506006)(1076002)(8676002)(101416001)(53936002)(6116002)(36756003)(38730400002)(97736004)(66066001)(3846002)(47776003)(6666003)(48376002)(50466002)(5003940100001)(189998001)(7099028)(5005270100013); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR04MB1980; 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; CY1PR04MB1980; 23:ZZRBcqADBPdiywunvZNzhOYYEtOu0CmvS+6RWjkqS?= =?us-ascii?Q?mvB9WlTmyD1V0J/Uk9Yu1ym3pt87MoHQDkr6Ti2nGYtMWnz0hYwKhSUfO2w+?= =?us-ascii?Q?VKzQZQ8gGivSDX8gK/46IQQ3qU7Dn3c0gUizHWIoSCxGh4bq636eNqQ96vXc?= =?us-ascii?Q?2FJL+3BGvWqh6rMipp0ZC0B7MsjWxiBSKAY8DURzRT60sK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8n6+SsMJKEmmBWmnJH3faj9Em3TBEuZSEwZpGoNpkcaHMvMEBI?= =?us-ascii?Q?J1DiD+KKmmowVpwkPWWsYg4mPe785Z9Kw8y0W7uNzaXEIc1y21M7KzKM0ZoZ?= =?us-ascii?Q?SKn9f+9EMNZh5id+Z8HLmR052QpvwK6xrHdrucTVMEDR16jy1/Ev/ZaBA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 6:4RtTbV5imTmhnyjS48e0qAV4tjZ2bko9pGNrChMpPdsT170B4DE2aVK9GPLU0rZQOv8lWut35Te1BPwMmrHdn9SnOJghFxzhPHdMsvIr+GwqjuUqdp93EQc4NYFTFqL/aXlmdllN9GK9tozy9wsAf+uac1WMOLielsSwk+RmSrHNev66zpKyUShWVPbIC4cs76df4w5R5X5B9H8xnri0zhTaQ8aL6S4mONuximK1ZkeH1ZYAaLyQ2/bLhOUfebcnhmfwFK+vlQYjwy04AP5f1e3RoHVqe2gSN4/KPNJPy0TQwPD97QmocxZ5CoP7odKOszXZYWiSS/AfRemOJd2GyHFmhfRiqZhUqYqRVK40XSnDbJ8z+Yt6v0b5lkZxF64ucRCrrgcv57kSBtYBhRZHJA==; 5:b6GCgpU7819O29J3P0MMsm9dAcqs+8mQ7vvFpNlwp11HJLxawjlgr1htrTfWXySHZxJ3xKJGuR0tymX9WS0LdGBJ9mtmMASq7XQlXZdlRpnmklqpwIV8dXcvQuCK79KNrBTkHXbg/14Hj3eB89MKLQ==; 24:PH5RWy1GGYZZ8qj2J6YzxrArrww20cOXS9rPMjuxpbEWeuWgtLNz7bmdDKe97uPojTtBhjxB4/H4QGHhmNBOY/OAWMpf/csTkN5esoypyKU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR04MB1980; 7:SlrbOj2lwZaXjSydk5aVKvfu5SaZ9dAHr8YsUelHUptQss11CRPg2PjcVprvKN5szDs3d+waV5wAU9z1i1duNfmBqQ/xln+QqFMkRXuAqnyk2Vs1M5hDpHPJrJheO9twTTvevxLjThO4nDb7zQQqflwxg36lVSYIdCWouAjwN9pfnYVpMjAerJIyS29Ibv8zzcoycVtje/GgGDWrVORc6RIUXQLplVi24pvDcQ8cEKTFYBm0a6HsiPSUnRqvaiztzhkra1+R4CEUALUGjTwoNvjNsYKqQ8sHjNO+YRbfUZfnGK5UO1rFkSOskcvc6ohHFMQr2lcaQwgJ6QwPiaSVG16+wiUWwUHcj3TvqMFgpYZQkvo2g8OZ39lT6f2F5VDuzIuB4u2VCRvmR+7w5mpzXYp1Nw1yANI3bFwx0zS73GhfrzqV8eUecFsLWii6sSspzLup1AK0GhXCSFVG84J8f8AU09Zlk51Z+oF8zrle2M8No+U28aT8J6i8POx0LrP2PP1LXSbbdqCAGU7cLLygbQ==; 20:l9OWvF0wiI2GfD4YW2jViUcEfLlQ6mZrwwcJLzgeK2wsV98jkiIbSC6QqCv/sejrAvnjA4qVHuqWwZZXtUvHBHFH0+sqiMx24CbUDmHETIfG2u66/nLzY0p9wdU9mRdxD8UDQm9D0j2zx2lMlOivgQXVigPaIX10t7/g8QffE0N+SXoC1/ALs+Vrh8wCcMMvx0YyUcaeZwqgXXn2Gb04Rt1xQVSAgzxKGtmCHsqaizNb0mB87N5IzJ+RYEdF0f84 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2017 02:12:39.4865 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR04MB1980 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 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 a generic implementation in sd_done so that the check comes after good_bytes and resid corrections done in that function depending on the request command. The check is added to the initial command switch so that commands with special payload size handling are ignored. Signed-off-by: Damien Le Moal --- Changes from v3: - Moved check to initial switch-case so that commands with special payload handling are ignored. 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..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) {