From patchwork Thu Nov 7 08:42:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11232277 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2E671390 for ; Thu, 7 Nov 2019 08:42:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B58A421D7B for ; Thu, 7 Nov 2019 08:42:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="QUU1tdqj"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="HGXcey1f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733181AbfKGImn (ORCPT ); Thu, 7 Nov 2019 03:42:43 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:33042 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbfKGImn (ORCPT ); Thu, 7 Nov 2019 03:42:43 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0120D608FC; Thu, 7 Nov 2019 08:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1573116161; bh=FtDInhzlNbMYnaah34JKXnQVyTO/o1xFZ/slgp6EYrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QUU1tdqjx9o19obxJT26tMZaboE9qEr8UHYQQ+5C+JXCCbSGairwNLSvpqpQ5z4kD 0zluAuVJzLptT8N8lp21AYZPDRNcmImv2QQEWrgu+TB3Y4mcKL6Y4Uk4vqeZQlRuA8 MatQYJz+GHtO7V4mvS5qkodaoQ8cjPGDQd48TMyI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from pacamara-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 37C7B60779; Thu, 7 Nov 2019 08:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1573116159; bh=FtDInhzlNbMYnaah34JKXnQVyTO/o1xFZ/slgp6EYrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGXcey1f6BYXCUSdubFAHI3ITrH7n5tkn9SjOKVaebwSNvm8tQ+BPeGDoWt99EMMk a4ZMjlNjUR7B3ppPKltuOMBvBXEc1E11shjU3MNjtQVU2fJC74TWAQB6t8h+9MQeIM THtAl+jYy90EKuONisWGdURGW/0TuCLWUBRLAOuw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 37C7B60779 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Sayali Lokhande , Alim Akhtar , Avri Altman , Pedro Sousa , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Tomas Winkler , Venkat Gopalakrishnan , Subhash Jadavani , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1 1/6] scsi: ufs: Flush exception event before suspend Date: Thu, 7 Nov 2019 00:42:08 -0800 Message-Id: <1573116140-22408-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1573116140-22408-1-git-send-email-cang@codeaurora.org> References: <1573116140-22408-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Sayali Lokhande Exception event can be raised by the device when system suspend is in progress. This will result in unclocked register access in exception event handler as clocks will be turned off during suspend. This change makes sure to flush exception event handler work in suspend before disabling clocks to avoid unclocked register access issue. Signed-off-by: Sayali Lokhande Signed-off-by: Asutosh Das Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 1201578..c2de29f 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4760,8 +4760,15 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev) * UFS device needs urgent BKOPs. */ if (!hba->pm_op_in_progress && - ufshcd_is_exception_event(lrbp->ucd_rsp_ptr)) - schedule_work(&hba->eeh_work); + ufshcd_is_exception_event(lrbp->ucd_rsp_ptr)) { + /* + * Prevent suspend once eeh_work is scheduled + * to avoid deadlock between ufshcd_suspend + * and exception event handler. + */ + if (schedule_work(&hba->eeh_work)) + pm_runtime_get_noresume(hba->dev); + } break; case UPIU_TRANSACTION_REJECT_UPIU: /* TODO: handle Reject UPIU Response */ @@ -5215,7 +5222,14 @@ static void ufshcd_exception_event_handler(struct work_struct *work) out: scsi_unblock_requests(hba->host); - pm_runtime_put_sync(hba->dev); + /* + * pm_runtime_get_noresume is called while scheduling + * eeh_work to avoid suspend racing with exception work. + * Hence decrement usage counter using pm_runtime_put_noidle + * to allow suspend on completion of exception event handler. + */ + pm_runtime_put_noidle(hba->dev); + pm_runtime_put(hba->dev); return; } @@ -7901,6 +7915,7 @@ static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op) goto enable_gating; } + flush_work(&hba->eeh_work); ret = ufshcd_link_state_transition(hba, req_link_state, 1); if (ret) goto set_dev_active;