Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp426078pxa; Fri, 31 Jul 2020 16:19:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRIoKjjLnbq31ezTrWT8/jSExacfm+qdvy4COW2t9/Txd1WNx/jn1x4SJyOQgZLfqps+ns X-Received: by 2002:a17:906:aac6:: with SMTP id kt6mr6104239ejb.475.1596237596498; Fri, 31 Jul 2020 16:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596237596; cv=none; d=google.com; s=arc-20160816; b=MVMJOGZTGV1xTkCM0XMk/rhZu8qUT8cBNKygpXVQmkzqHH9CFksqvHIi1VN6tX8c+W Lx1BvTsBgS14L1JOtNTh4XC1K/9GnFpjcZFZChTVjEkEVa8F+zF7q5TBTumyCz8uwv0F f905Y153Sp0CiW3DLZryueznlgr5PmdgR8fxDdnWNSxdaCZ5vjyyYBjYxImkm0y6o61V xrQjwE7wgYYGYe3/3S+MJQ05Kvrxwx1Kq4oISKXSOdQNz+jvxhlXNhPuCMbqoi1Se1im HI0nmq4S9aqD1YEcQguIS4XQ7jAM9aBSfTdeld5LDqXESMgS0JIVPUOy77POio5fjv/5 mXxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:mime-version:dkim-signature; bh=1zsJhq/goG5jxNbt1w2QIRo86ReaWeQ6QGLznVlr6Jk=; b=M1ooj/gho54ZkzCV+Dd87Ap1ZdXPt091UU+0ZfoosQXH1Khybi4iOiAtxLs3joVm09 FA/FlLA8a85deHggAxj4Js4lqEGgf44YZJefFWjLdaBSXBP1917rqKhanaSBm5paZXsK qe0DfQVBdT6CE49uXrdWtnLr7pHBYLAzG3a1OWYOFqbOGIt9fand6U9Fvlx/QFxmVPlt zK2Uluo0dKJo4JtmLbjb4rQXKxfapAUioOBKxuVpAWgFZzdDOwDyEYhABuBn2kIP3xlJ 0Xy3PRJnZbz7jV25t4bs7q4mhxLWa0pZliK2uN84/YyHRHbfY4K7ErZ9bQPOO8tOvT/7 gfFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=lz98SC0u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g26si6073597edr.126.2020.07.31.16.19.34; Fri, 31 Jul 2020 16:19:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=lz98SC0u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726826AbgGaXRM (ORCPT + 99 others); Fri, 31 Jul 2020 19:17:12 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:43648 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbgGaXRM (ORCPT ); Fri, 31 Jul 2020 19:17:12 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1596237430; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Type: MIME-Version: Sender; bh=1zsJhq/goG5jxNbt1w2QIRo86ReaWeQ6QGLznVlr6Jk=; b=lz98SC0u/J/t0okJYxrcYKTqfSF/zZabwQFLWHF2UIyVrode7uCSfIUS2tsSCtpk/pGqkgAE nC4v5Zw4f4bN5nElJFdIFyfWBR/+Qp/ufl3SfTRJIq1jm1o5oTaQryyQJ/VCPEJ/FgUdi3bG 4V5mgUeRFBU36UAjcTNBW02t4No= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n19.prod.us-west-2.postgun.com with SMTP id 5f24a676e7a13aa2041a72e1 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 31 Jul 2020 23:17:10 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 2CA68C433B1; Fri, 31 Jul 2020 23:17:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id BF5A5C433CA; Fri, 31 Jul 2020 23:17:08 +0000 (UTC) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_5c3e63ea4c7ecc7e8e595b7c9d9d7f3e" Date: Sat, 01 Aug 2020 07:17:08 +0800 From: Can Guo To: Bart Van Assche Cc: Stanley Chu , Avri Altman , linux-scsi@vger.kernel.org, martin.petersen@oracle.com, alim.akhtar@samsung.com, jejb@linux.ibm.com, beanhuo@micron.com, asutoshd@codeaurora.org, matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kuohong.wang@mediatek.com, peter.wang@mediatek.com, chun-hung.wu@mediatek.com, andy.teng@mediatek.com, chaotian.jing@mediatek.com, cc.chou@mediatek.com Subject: Re: [PATCH v4] scsi: ufs: Cleanup completed request without interrupt notification In-Reply-To: References: <20200724140246.19434-1-stanley.chu@mediatek.com> <1596159018.17247.53.camel@mtkswgap22> <97f1dfb0-41b6-0249-3e82-cae480b0efb6@acm.org> <8b0a158a7c3ee2165e09290996521ffc@codeaurora.org> Message-ID: <548b602daa1e15415625cb8d1f81a208@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=_5c3e63ea4c7ecc7e8e595b7c9d9d7f3e Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed Hi Bart, On 2020-08-01 00:51, Bart Van Assche wrote: > On 2020-07-31 01:00, Can Guo wrote: >> AFAIK, sychronization of scsi_done is not a problem here, because scsi >> layer >> use the atomic state, namely SCMD_STATE_COMPLETE, of a scsi cmd to >> prevent >> the concurrency of abort and real completion of it. >> >> Check func scsi_times_out(), hope it helps. >> >> enum blk_eh_timer_return scsi_times_out(struct request *req) >> { >> ... >>         if (rtn == BLK_EH_DONE) { >>                 /* >>                  * Set the command to complete first in order to >> prevent >> a real >>                  * completion from releasing the command while error >> handling >>                  * is using it. If the command was already completed, >> then the >>                  * lower level driver beat the timeout handler, and it >> is safe >>                  * to return without escalating error recovery. >>                  * >>                  * If timeout handling lost the race to a real >> completion, the >>                  * block layer may ignore that due to a fake timeout >> injection, >>                  * so return RESET_TIMER to allow error handling >> another >> shot >>                  * at this command. >>                  */ >>                 if (test_and_set_bit(SCMD_STATE_COMPLETE, >> &scmd->state)) >>                         return BLK_EH_RESET_TIMER; >>                 if (scsi_abort_command(scmd) != SUCCESS) { >>                         set_host_byte(scmd, DID_TIME_OUT); >>                         scsi_eh_scmd_add(scmd); >>                 } >>         } >> } > > I am familiar with this mechanism. My concern is that both the regular > completion path and the abort handler must call scsi_dma_unmap() before > calling cmd->scsi_done(cmd). I don't see how > test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state) could prevent that > the regular completion path and the abort handler call scsi_dma_unmap() > concurrently since both calls happen before the SCMD_STATE_COMPLETE bit > is set? > > Thanks, > > Bart. For scsi_dma_unmap() part, that is true - we should make it serialized with any other completion paths. I've found it during my fault injection test, so I've made a patch to fix it, but it only comes in my next error recovery enhancement patch series. Please check the attachment. Thanks, Can Guo. --=_5c3e63ea4c7ecc7e8e595b7c9d9d7f3e Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0005-scsi-ufs-Properly-release-resources-if-a-task-is-abo.patch Content-Disposition: attachment; filename=0005-scsi-ufs-Properly-release-resources-if-a-task-is-abo.patch; size=1473 RnJvbSBlZjg3ODMyYjVmNmZmNmFmMjlhYzliYWM3ZmRlYTFlMjQ1YzgxNjJiIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBDYW4gR3VvIDxjYW5nQGNvZGVhdXJvcmEub3JnPgpEYXRlOiBT dW4sIDcgSnVuIDIwMjAgMTI6MTY6MDEgKzA4MDAKU3ViamVjdDogW1BBVENIIDUvNl0gc2NzaTog dWZzOiBQcm9wZXJseSByZWxlYXNlIHJlc291cmNlcyBpZiBhIHRhc2sgaXMKIGFib3J0ZWQgc3Vj Y2Vzc2Z1bGx5CgpJbiBjdXJyZW50IFVGUyB0YXNrIGFib3J0IGhvb2ssIG5hbWVseSB1ZnNoY2Rf YWJvcnQoKSwgaWYgYSB0YXNrIGlzCmFib3J0ZWQgc3VjY2Vzc2Z1bGx5LCBjbG9jayBzY2FsaW5n IGJ1c3kgdGltZSBzdGF0aXN0aWNzIGlzIG5vdCB1cGRhdGVkCmFuZCwgbW9zdCBpbXBvcnRhbnQs IGNsa19nYXRpbmcuYWN0aXZlX3JlcXMgaXMgbm90IGRlY3JlYXNlZCwgd2hpY2ggbWFrZXMKY2xr X2dhdGluZy5hY3RpdmVfcmVxcyBzdGF5IGFib3ZlIHplcm8gZm9yZXZlciwgbWVhbmluZyBjbG9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