Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2523891imu; Thu, 29 Nov 2018 06:23:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/XU/LMV9RFFHc2mMQp8HvrfL/g+pgXkiixl2MzfN/g3NHiwKxemmA6X1QlfRQapdOwbwAl6 X-Received: by 2002:a17:902:b595:: with SMTP id a21mr1612774pls.120.1543501403641; Thu, 29 Nov 2018 06:23:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501403; cv=none; d=google.com; s=arc-20160816; b=EdchUpZFFabb1S1w3rL//67ZPTBdi5JIWbjeOmoXloRu+C70QSMoNkABUzo+Qsd/Xq ld+IVO90z42unM/bVCqQ8Du9bPkD9Hy5z0dq/0gc9/M5PjC2EM+FpxHeSjJCHxFhpX3x F3UwwTkQKgqU7RXhisCu6qLH6iICj1DdXtPu8k27rF2Zz1TDBxGXOfQ9ImXEd5kJNFMZ oRy9L0O7EvG/XpH+G9ZV1fVBYJeA0recMIiRMYVzRVTM+H2M/45P53hYkvjpb8mxYU8A pSkXFQ1EkE5iJvU0aqe3mVI3vBEYv/X+dnlkxS8vYaK06geJLzjEu35nS3PjJ9+2kx3s rW3A== 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=+r7obgict15dQvPbZp3qzqXeMlGZ8twn5depCh/PljQ=; b=ZNvN5JiYwc8/331wf3t9Ykr5H5r9pxcVyFqbW690JBxeJg9WmLevQ0kKlhFw/8llHB L6mrPtZruvAmPulqF8LE50pr5aZeWptzJhmEpSonCoLheqXuef1Y5QOXPN1eTLZzkBhh UstITBnr/fVeRplZrxJB/Y8RZG/uk4SySDVVV93aOeqnVC9VsNN9jHI1VYvJ+dr+YJmp rKP0qrAsD86PGeSYJDCXyfXFeC4pKFxlSPAnMrUtLbfDmtKqwVYaq/L7oT2UDNJqyTyU NV0pdIGQl8r9Tj/eUyKEUh/qGF8TT/q8U0KRPnoIo17bjC2tWvRuQx+/JvzZeXhRrgcI /rNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yUwXZ9+1; 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 q5si2096772pgb.245.2018.11.29.06.23.08; Thu, 29 Nov 2018 06:23:23 -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=yUwXZ9+1; 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 S1730150AbeK3BZr (ORCPT + 99 others); Thu, 29 Nov 2018 20:25:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:49222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729806AbeK3BZr (ORCPT ); Thu, 29 Nov 2018 20:25:47 -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 A89A220868; Thu, 29 Nov 2018 14:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501216; bh=L7mBtZQTKwdfLiC8MbkQAatAtYV5kkbn5565OAKjgc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yUwXZ9+1NHinp7/GqMFVMzi1sCscQ2czeKPWZI+u0eqoZjQydMRdVP9Efo9mTrxhJ vrfPs6DSCzO8OyV8bo3vejHhQY8SZrj816oal3WCLoJNnWCsc6hULttSKaLvTbZv+9 iM/C/R5PVM9h88jqLvHnx7N+ce9Uypzd12VIv1PY= 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.4 74/86] scsi: ufshcd: Fix race between clk scaling and ungate work Date: Thu, 29 Nov 2018 15:12:39 +0100 Message-Id: <20181129140115.897979142@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140109.832117862@linuxfoundation.org> References: <20181129140109.832117862@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.4-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 @@ -585,6 +585,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)) {