Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2496029ybg; Fri, 31 Jul 2020 01:03:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5839K0j+kIi9hrUj2OUkbA8gdbxjD3Lg4thiH3VQhlvXzUAFTpkAaXo/Y8ETmQI7TBJN2 X-Received: by 2002:a50:da04:: with SMTP id z4mr2597020edj.375.1596182596993; Fri, 31 Jul 2020 01:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596182596; cv=none; d=google.com; s=arc-20160816; b=HyVJ+gU9DxE0PIhC71qHm91Ug64ZQrGZLy7CxCaQ+59+sJ7kQEHKFmxpHIF+IctE7O d2V3Xavz83I/9uKuCqA51Wa6GtpIjnk0kyjjl141vDL6Fm2KGxh9/eKyjh48/gfZUK98 lgGlm9y9okUYo8/DQdJAL6RBKvoya2Hr9poWgcUwzPkVcwT4BH3KPBOQTzmuy+Fowy5C sHqkVDz0fG/sLewCzZFVcjfjlqJUR4xaR7GVm3pm13BuhoB2okLVuWS8XPjD6Nf2UWD9 GzV0mZhH/V5F1BAZMrX0LQWQQtdW6SUoRUVih4/7Pb1qAWEUjjcod+zL31mqT4E3XQOt ltEg== 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:content-transfer-encoding :mime-version:dkim-signature; bh=MKSQY5RVrXIwpdJw6RKFSgNCGEE7ar+hIe83C8B0HxA=; b=GgnKsRduo0oBrRGwURSamPit8hDWx//Rj3xaGrzD0RG1A9qK8K30BHzr4g5eQ1p/Gj pno7Os14BEeVdZOmzq9bvqGPUniR5Gy/uN+G4UXZ32r3qjFOLBXp8IoAxCLddrCIqweI /nw2285PRLnLEYeFG1VZLCYgk41K4jKcYtYpCa8OmC40fUaKPjGxtQeSd379Zx8y5gQX QUnaATfb62k5A3dPcF/MxcK0PkvsTH+kWJQO3pTc8zH2DQdU3zVU0HRdSx1oeF1B/Jz9 weEMYzZcQ7nZ+OsQBSQmlPRn3iNvqN7rkYt8jwBWneK7TQYqcWESR86SixwDiLNDV3Lw yLPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=wxS4YMU2; 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 mj19si4476516ejb.291.2020.07.31.01.02.54; Fri, 31 Jul 2020 01:03:16 -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=wxS4YMU2; 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 S1731744AbgGaICm (ORCPT + 99 others); Fri, 31 Jul 2020 04:02:42 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:59141 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731616AbgGaICm (ORCPT ); Fri, 31 Jul 2020 04:02:42 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1596182561; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=MKSQY5RVrXIwpdJw6RKFSgNCGEE7ar+hIe83C8B0HxA=; b=wxS4YMU2VfrNUJH58mNK1eVaQzRZ84zP2Zh7wGtU7ZWvlbTf6MghF+oUUGpQXV2nCpfga1lK hhETzrEq3ozmCC46rB4A1az5S4Gp21jemOomhpSddpFZBmnSo48jtlFsBDaAWQjJaqtaQyyf rqMKIKb3BTi9fbEB4h+wCE0L7AM= 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-n09.prod.us-east-1.postgun.com with SMTP id 5f23cfa014acd1952be8fde7 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 31 Jul 2020 08:00:32 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id DF499C433A1; Fri, 31 Jul 2020 08:00:31 +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 881C9C4339C; Fri, 31 Jul 2020 08:00:28 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 31 Jul 2020 16:00:28 +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: <97f1dfb0-41b6-0249-3e82-cae480b0efb6@acm.org> References: <20200724140246.19434-1-stanley.chu@mediatek.com> <1596159018.17247.53.camel@mtkswgap22> <97f1dfb0-41b6-0249-3e82-cae480b0efb6@acm.org> Message-ID: <8b0a158a7c3ee2165e09290996521ffc@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 Hi Bart, On 2020-07-31 12:06, Bart Van Assche wrote: > On 2020-07-30 18:30, Stanley Chu wrote: >> On Mon, 2020-07-27 at 11:18 +0000, Avri Altman wrote: >>> Looks good to me. >>> But better wait and see if Bart have any further reservations. >> >> Would you have any further suggestions? > > Today is the first time that I took a look at ufshcd_abort(). The > approach of that function looks wrong to me. This is how I think that a > SCSI LLD abort handler should work: > (1) Serialize against the completion path > (__ufshcd_transfer_req_compl()) such that it cannot happen that the > abort handler and the regular completion path both call > cmd->scsi_done(cmd) at the same time. I'm not sure whether an existing > synchronization object can be used for this purpose or whether a new > synchronization object has to be introduced to serialize scsi_done() > calls from __ufshcd_transfer_req_compl() and ufshcd_abort(). > (2) While holding that synchronization object, check whether the SCSI > command is still outstanding. If so, submit a SCSI abort TMR to the > device. > (3) If the command has been aborted, call scsi_done() and return > SUCCESS. If aborting failed and the command is still in progress, > return > FAILED. > > An example is available in srp_abort() in > drivers/infiniband/ulp/srp/ib_srp.c. > > Bart. 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); } } } Thanks, Can Guo.