Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5238015pxj; Tue, 22 Jun 2021 19:06:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgGW7y7PlymYkszyNLzs9iDikK9dx+7J6WduKSnpQFXMrdE33VeLaukuSvgXWadyssG8XQ X-Received: by 2002:a05:6e02:1d1c:: with SMTP id i28mr1184311ila.13.1624413972960; Tue, 22 Jun 2021 19:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624413972; cv=none; d=google.com; s=arc-20160816; b=OxvFOa67h+GWlHmYdt+htxWfTmhVoJ8ziXULl2N+qnLk3nv289B0UgJwZvmM9vcr3e zqv+zvbKOlXTUYO1kvQ9VvPsDiOkTNlsoVPro8CDwdxeByJmlcrhRdSXZggrtWuVaH9E xvP3GZHFzMyu+C+7NwOXYJ/6fvwgYKoWxcj8pP3v6mURMLohULGMckTivFWxKcfpOq3o uDJpDImuOYmyIo628WUFRcBgsA3IuebPVXEspecZqOvdlDvjwBMLRVMGq/HxoidasCx0 uK5USr1tIbTIUiLelYmNE8Q3gTq5h/y6yFGb4bwZXoUn0i4ZFY/AABticCBMLXL5HZko yedg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=BWE4cJP9A5iMFs64pOQ4hiJd/MsZBADGs5e5FvhncRA=; b=jKor4befH1oYU+vXhHGNwqnKX7suyP0pktBbiMWbbs2QJvvp0EQd7b0RbDroa00f1r TjxuE8ocQzY/1HPnAVHESgj2mjeuBFjWkY04Vw2WQNsF5cWWhQ/oD14j2cABNYUSEAZq ILlwky+tzpVbcJeAo4xgeOhc/uKNyJNDNT+NTlreG/zyfWtCd+X/U7SJXAsvJQY5Uvvf uZsg7idpdCYBlRK/997HpcTeCSmMUzIVKu9AI+9vFMccBcfo91b39ysOVeRSIdNbnFXK qwwD+lO1gGDFALBRplrBNJr/hrrB7QqZo8luPkQpiQRb5deKXbH9byhBD/i/uXhJ0Tdo gCmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=Wye0EUVD; 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 t6si28062910iov.63.2021.06.22.19.06.00; Tue, 22 Jun 2021 19:06:12 -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=pass header.i=@mg.codeaurora.org header.s=smtp header.b=Wye0EUVD; 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 S229890AbhFWCHU (ORCPT + 99 others); Tue, 22 Jun 2021 22:07:20 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:20467 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbhFWCHS (ORCPT ); Tue, 22 Jun 2021 22:07:18 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624413901; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=BWE4cJP9A5iMFs64pOQ4hiJd/MsZBADGs5e5FvhncRA=; b=Wye0EUVDUmnAbYgOZsfBC2mpoquDZStDd5PblpKG4F2WT5E0pnZsI8auhOL2d/l3l6tNxH/4 kgJZj+BRHkIAYW9PnNVD22N5isg4ER3dWcGUXZ5HZM5P4rfXOoc4SWTpfkJtBCFUDWNtqJvN AozDkae43Gu4yWN8pSkHPqnjF1Y= X-Mailgun-Sending-Ip: 198.61.254.9 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-n07.prod.us-west-2.postgun.com with SMTP id 60d296b8638039e9978f46fe (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 23 Jun 2021 02:04:40 GMT Sender: cang=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 5A329C43148; Wed, 23 Jun 2021 02:04:40 +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=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00 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 1753FC4338A; Wed, 23 Jun 2021 02:04:39 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 23 Jun 2021 10:04:39 +0800 From: Can Guo To: Bart Van Assche Cc: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, Stanley Chu , Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Matthias Brugger , Bean Huo , Jaegeuk Kim , Adrian Hunter , Kiwoong Kim , Satya Tangirala , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: Re: [PATCH v1 2/3] scsi: ufs: Optimize host lock on transfer requests send/compl paths In-Reply-To: References: <1621845419-14194-1-git-send-email-cang@codeaurora.org> <1621845419-14194-3-git-send-email-cang@codeaurora.org> Message-ID: X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bart, On 2021-06-17 10:49, Bart Van Assche wrote: > On 5/24/21 1:36 AM, Can Guo wrote: >> @@ -2688,6 +2705,43 @@ static int ufshcd_queuecommand(struct Scsi_Host >> *host, struct scsi_cmnd *cmd) >> + case UFSHCD_STATE_EH_SCHEDULED_FATAL: >> + /* >> + * pm_runtime_get_sync() is used at error handling preparation >> + * stage. If a scsi cmd, e.g. the SSU cmd, is sent from hba's >> + * PM ops, it can never be finished if we let SCSI layer keep >> + * retrying it, which gets err handler stuck forever. Neither >> + * can we let the scsi cmd pass through, because UFS is in bad >> + * state, the scsi cmd may eventually time out, which will get >> + * err handler blocked for too long. So, just fail the scsi cmd >> + * sent from PM ops, err handler can recover PM error anyways. >> + */ >> + if (hba->pm_op_in_progress) { >> + hba->force_reset = true; >> + set_host_byte(cmd, DID_BAD_TARGET); >> + cmd->scsi_done(cmd); >> + goto out; >> + } >> + fallthrough; > > Hi Can, > > I know that this patch only moves the above code and that the above > code > has not been introduced by this patch. Anyway, is my understanding > correct that ufshcd_err_handler() can change the host controller state > from UFSHCD_STATE_EH_SCHEDULED_FATAL into UFSHCD_STATE_RESET and next > into UFSHCD_STATE_OPERATIONAL? If so, if the above code completes a > READ > with status DID_BAD_TARGET and if recovery by the error handler > succeeds, will that cause the filesystem above the UFS driver to change > into read-only mode? If the above code completes a WRITE with status > DID_BAD_TARGET, will that cause data corruption? Is there any other > solution to prevent data corruption than merging the > UFSHCD_STATE_EH_SCHEDULED_FATAL and UFSHCD_STATE_EH_SCHEDULED_NON_FATAL > back into a single state and changing the ufshcd_rpm_get_sync(hba) call > in ufshcd_err_handling_prepare() into a pm_runtime_get_noresume() call? > Here, when hba->pm_op_in_progress is true, there cannot be READ or WRITE command since hba is resuming or suspending. When fatal erorr happens, the DID_BAD_TARGET above is intend to let the SSU (or whatever PM requests blocking suspend/resume) fail fast (neither returning HOST_BUSY nor letting the cmd pass through can achieve such purpose), so that error handling prepare won't get stuck [1] when it calls lock_system_sleep() runtime_pm_get_sync() The reason why I split UFSHCD_STATE_EH_SCHEDULED to UFSHCD_STATE_EH_SCHEDULED_FATAL and UFSHCD_STATE_EH_SCHEDULED_NON_FATAL is that 1. For non-fatal errors, HW can recover by itself, so when host state is UFSHCD_STATE_EH_SCHEDULED_NON_FATAL, cmd can still passthrough. 2. When non-fatal error (LINE-RESET for example) happens, error handler only needs to do a power mode transition without a full reset. If we only have one state, returning HOST_BUSY will get error handling prepare stuck [1], while fast failing SSU cmds shall make error handler do a full reset (which goes too far for non-fatal errors). Thanks, Can Guo. > Thanks, > > Bart.