Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2519507imu; Thu, 29 Nov 2018 06:19:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/UCbLQeVlss3CmiXVF/oGL7xnhR5SacmcgNp1M6ED91nlSP92zRsNFvEP79JzBnYzVXbTCH X-Received: by 2002:a62:d148:: with SMTP id t8mr1620995pfl.52.1543501187860; Thu, 29 Nov 2018 06:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501187; cv=none; d=google.com; s=arc-20160816; b=bYfWr7++++hls8j2phQ8ec23vmRcshkYE2hWzxGvIojN5voNlRJIkH6K7Tnx9qOyLx YGsFK1P7pkIh0hpUbGt6qGP5ApowsM2b1TBwrbh2kRRb6fezci/ik8sKBhN1cXmBLW11 f8PhzKgZxjPb3XG0wVdJvr/baYCxZb4JSWbHfymxFTGbuN9E2v02xKzVLZhUngi6sEoK ppYoRezPZkowippj+Yk7BMB5mBE+6D4dVbYcgmml8KRUycMKld829Lnu8gC99cF9DSSo ktKU3wV8gZzyrx2ba9veihlAzKQQhNhUYkmq6j7lbqGHO2wX9FTtSrhJscCsBKoEfi7q tyjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HtdThUPs/YsiIuHcmKVEGaXB+jJsQV7dVXHXfVm7/co=; b=yK7xAm5ZaZTEtq6kdkOqaqplWp9c0oucNWTQsl3mLrURmnS5RgoIcugEmKVcvvEXE7 lNBZrxlIkrCB9fnR/p+CBHl1Y3APt4XGXlRYlBFsJx+cKVVA+tf2p0PwMvxqtjXqCuw9 c2JDI304efZil3h39KrxIWpZ3km/2zCMvLmIdkNU98o9tR3oPIZOUqw2SCnUcHh1YOJq /9WHxJYD2a9KLvmwl+cGMqX8QYvkzr33LiYPnO2mFCA4WiVOJMWZy4MMTh26gq9nHsLc 51EhdtXPZmUZZOM0d56hJYlF1t0ujMnh0nITtm/VOZlL7ubMcsOzo6bgPD4J0SPaNByf TyMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T7ABMbZo; 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 i5si2234808pfo.189.2018.11.29.06.19.33; Thu, 29 Nov 2018 06:19:47 -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=pass header.i=@kernel.org header.s=default header.b=T7ABMbZo; 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 S1730150AbeK3BWT (ORCPT + 99 others); Thu, 29 Nov 2018 20:22:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:43954 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728190AbeK3BWS (ORCPT ); Thu, 29 Nov 2018 20:22:18 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A18921019; Thu, 29 Nov 2018 14:16:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501007; bh=JeAtgXFutTxNt3/ZJwk06qrlNAYBFxJt9NcDrhRjBmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T7ABMbZowHDU2gexqamz9M7Dgz+t2Bt9RMOTnZfwGaQjn53owzb5v7hmv2g8NOhsx 6I6htN5/Xd8TcHimf6wuk7lJ8Qg4S1HdYgcLjYbCsTjGXiK7fmxkye/zuIFCZandYk hpDzFPKRpvvRpxTrKhIE/cdDcf/et74n9+cGLkvw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Venkat Gopalakrishnan , Subhash Jadavani , "Martin K. Petersen" , Amit Pundir Subject: [PATCH 3.18 77/83] scsi: ufshcd: Fix race between clk scaling and ungate work Date: Thu, 29 Nov 2018 15:12:35 +0100 Message-Id: <20181129140142.401400052@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140138.002176596@linuxfoundation.org> References: <20181129140138.002176596@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Venkat Gopalakrishnan commit f2a785ac23125fa0774327d39e837e45cf28fe92 upstream. The ungate work turns on the clock before it exits hibern8, if the link was put in hibern8 during clock gating work. There occurs a race condition when clock scaling work calls ufshcd_hold() to make sure low power states cannot be entered, but that returns by checking only whether the clocks are on. This causes the clock scaling work to issue UIC commands when the link is in hibern8 causing failures. Make sure we exit hibern8 state before returning from ufshcd_hold(). Callstacks for race condition: ufshcd_scale_gear ufshcd_devfreq_scale ufshcd_devfreq_target update_devfreq devfreq_monitor process_one_work worker_thread kthread ret_from_fork ufshcd_uic_hibern8_exit ufshcd_ungate_work process_one_work worker_thread kthread ret_from_fork Signed-off-by: Venkat Gopalakrishnan Signed-off-by: Subhash Jadavani Signed-off-by: Martin K. Petersen Signed-off-by: Amit Pundir Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/ufs/ufshcd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -570,6 +570,21 @@ int ufshcd_hold(struct ufs_hba *hba, boo start: switch (hba->clk_gating.state) { case CLKS_ON: + /* + * Wait for the ungate work to complete if in progress. + * Though the clocks may be in ON state, the link could + * still be in hibner8 state if hibern8 is allowed + * during clock gating. + * Make sure we exit hibern8 state also in addition to + * clocks being ON. + */ + if (ufshcd_can_hibern8_during_gating(hba) && + ufshcd_is_link_hibern8(hba)) { + spin_unlock_irqrestore(hba->host->host_lock, flags); + flush_work(&hba->clk_gating.ungate_work); + spin_lock_irqsave(hba->host->host_lock, flags); + goto start; + } break; case REQ_CLKS_OFF: if (cancel_delayed_work(&hba->clk_gating.gate_work)) {