Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2527185imu; Thu, 29 Nov 2018 06:26:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uw0GnWiG0/Wb3hdMzmddo0a4bG6Oe6YQnoDqXcUQsOdvA4cHzvJxMXdJVJwcbAXADW/Okg X-Received: by 2002:a63:6dc8:: with SMTP id i191mr1355509pgc.215.1543501566986; Thu, 29 Nov 2018 06:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501566; cv=none; d=google.com; s=arc-20160816; b=TVQGfTMnXMKbOUmQAU2OrNowDGRN9xSRFDCAlD6AywxQbMt3XOhPUMNZCo22N1+syc n35fX573gXnFEh8MEjif2dLmOIRNF38an/qGuuQ9IFUCdKLsfclqMQlX0eFvihUMN7BT ra6MASw5TkSxtDDjpqvAZrxlJPr4wMfkit1ce7aT2bqP5/mzStMreJwwsBnHTHDwE+3A XrHE1SackO3NI6NS5KHwaEqBQyaTYkWDfUeRFHJRyFftzbSv+X8s9CltRgUMTq3vdhYr qlxaNPjeUbLYlm0mvPQXiiE8kNRJnQsNv0zf8rZIGDE5hJST90POP03bB1hzpV2G8v9h hjjg== 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=5Tfo7kqvtp0FQns0VqB2XhP0RHQ6/AfbPo0sH6ZpRAQ=; b=OQIbfYTD0OKL2dfLs/G28dCNrxxglYj+LPE97I63KD5I3c09HdB1ihAzJ5Eo3cw7DR JfPmaIehvmvv9UCOElzlc5Wh9IZ1BJ6oyYiuMQa8RACBRGiRdcwNr0doLEpNqRhWUkJ3 pxB4OkhgsmXELCUsFIV70X4pToyUNkHPhR4DBsILidTF2UVGzu+UhXANrQcQf6kQdduU JaBSdARQSJwBlFWH1xLPD5pNQmqzjNJgs4JNvUfq1MmE9WAkZDE6gTE0F0cz0ZtVW0Cm SUNDFVYJxIb/zt7/IVIePY7yGBMHoGBgEDVUeu9WUq2C0siW57HUydt01IobjQHt3deg T/jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OFNpId4O; 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 a20si2302837pfh.163.2018.11.29.06.25.35; Thu, 29 Nov 2018 06:26:06 -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=OFNpId4O; 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 S1732301AbeK3B2y (ORCPT + 99 others); Thu, 29 Nov 2018 20:28:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:54856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731487AbeK3B2x (ORCPT ); Thu, 29 Nov 2018 20:28:53 -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 B8BFB2145D; Thu, 29 Nov 2018 14:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501402; bh=4NMHMXWbfTSVfDlvs7JONDWPY2hDrVZ7bOVKcvj/IPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFNpId4OvHHxN/PGfY5HwirG8CPIsSKuCMKcuvQ4tuyc88cFh3ndqKHLOhwj2k1iP c/+rUigo/yDCmLP1fny/pDoMeoXUknePuuq06xlwRQN9tf4/EkohAZJd74lqzrmUZX OPcJ6FAcx6siKKQyKvOM4K32pOGS+RVJzh2MIMic= 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 4.9 76/92] scsi: ufshcd: Fix race between clk scaling and ungate work Date: Thu, 29 Nov 2018 15:12:45 +0100 Message-Id: <20181129140112.641547400@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140106.520639693@linuxfoundation.org> References: <20181129140106.520639693@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 4.9-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 @@ -672,6 +672,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)) {