Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4447028ybv; Mon, 10 Feb 2020 19:50:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxWtheOwTtKuCyjKgs+3MzWxVATaOADiUzUmCCFctCODBp3plBj416qaHc/6xQuHwk/Dduw X-Received: by 2002:a9d:64d8:: with SMTP id n24mr3458733otl.71.1581393026109; Mon, 10 Feb 2020 19:50:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581393026; cv=none; d=google.com; s=arc-20160816; b=mfPxOi91NjqceMEWIu7JO2p6WBtmvRJ5Go5Oo8BjSfX3WsRSupueLpfzl9bCryf5SN j4+AP0v4b9p0dthf67kIgqtKuPKZ8CTM8BnZarzsWfz/MiuTDJqDYO87ap87WJzlftoR j/Nla5q5Mic0Kngm5t2dDQnvnD3LgfPKNVIkb7ulbTAaTA54IwsqYCiEqicluDOcp9Ro kvMThpAGnKBG0VUB4eRcDN5FvFoZ+sAHTA/F/iDt1v+LTLh97bnxmJvem2KHxn1nsNdz Pv4G/T+1yZpm12n3di4kIl2srgjckY9+3mfJpjBTQ+R3ayYAY69In/gBX042h1tbvDxO f+AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=f1HTEkpxUdDYbFLcYWFshQ3BL0C5vGP4FbG4ywXAapM=; b=euMiX1llPiYR3RrcPrH1v54Q4HqyHkFrGwlIdldURqZOTJySNMe5rWLeCkw345KKAy l9RS34F0BYYj+s9gA5SjaWbZEQacperLitDYo92THv3xboQDR1ZgvBErDVuyMx28SuNN nf1r2GhNFyzxE9Hj9TSQj+cG3wtsjsu/+7fCmXLiQeUtnzt5BOMMhZZwnqXpSIkhYc2e aVyBNCDtQfhBLxdO7PSjlWpzPGRUgEYSuz7BcWDrmGNLbK9kNLVYw1uLUIGiTOm8/vfq tt+Vt2+oZCtmJtVaRSAgH3VDOgHPs1vU6tQ76mtILq+AuzGBzT/ppuKYG3FOl3BXTKf2 N89w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b="MBKhz/fD"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10si1059958oiy.254.2020.02.10.19.50.13; Mon, 10 Feb 2020 19:50:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b="MBKhz/fD"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727887AbgBKDlK (ORCPT + 99 others); Mon, 10 Feb 2020 22:41:10 -0500 Received: from mail26.static.mailgun.info ([104.130.122.26]:61227 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727752AbgBKDlK (ORCPT ); Mon, 10 Feb 2020 22:41:10 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1581392470; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=f1HTEkpxUdDYbFLcYWFshQ3BL0C5vGP4FbG4ywXAapM=; b=MBKhz/fDN4QBXWZVHhJaAtM2GnGPujgjFppF5UxsVFj0fkXPKZEKyax2l6A/BJHDxdjcZC4Z ZZnB+TF8WOdwuu5KsL8N+gsp/j3qvKeewFJTvkmTpGTJyJD90ugu8O7vGOx1Ke+OBU47buCE EMN6k4BIkAlmz1ZrRIWP5YPoQ7Q= X-Mailgun-Sending-Ip: 104.130.122.26 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 mxa.mailgun.org with ESMTP id 5e422252.7ffa15fe9298-smtp-out-n02; Tue, 11 Feb 2020 03:41:06 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 9B81EC447A6; Tue, 11 Feb 2020 03:41:04 +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,SPF_NONE autolearn=unavailable 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) by smtp.codeaurora.org (Postfix) with ESMTPSA id B9E27C433A2; Tue, 11 Feb 2020 03:41:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B9E27C433A2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=cang@codeaurora.org From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@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 , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , Venkat Gopalakrishnan , Tomas Winkler , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v10 1/7] scsi: ufs: Flush exception event before suspend Date: Mon, 10 Feb 2020 19:40:44 -0800 Message-Id: <1581392451-28743-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1581392451-28743-1-git-send-email-cang@codeaurora.org> References: <1581392451-28743-1-git-send-email-cang@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Reviewed-by: Bean Huo --- 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 abd0e6b..10dbc0c 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -4730,8 +4730,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) && + schedule_work(&hba->eeh_work)) { + /* + * Prevent suspend once eeh_work is scheduled + * to avoid deadlock between ufshcd_suspend + * and exception event handler. + */ + pm_runtime_get_noresume(hba->dev); + } break; case UPIU_TRANSACTION_REJECT_UPIU: /* TODO: handle Reject UPIU Response */ @@ -5184,7 +5191,14 @@ static void ufshcd_exception_event_handler(struct work_struct *work) out: ufshcd_scsi_unblock_requests(hba); - 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; } @@ -7924,6 +7938,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; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project