From patchwork Wed Nov 28 14:40:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 152297 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1170951ljp; Wed, 28 Nov 2018 06:40:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/UtHoOOO6eqpWxI1cxj5Yd/kY1sQ+QtUM6fC2vlhTdIoPhxtJmxfNU/Q9SSSX06sPdd0EmI X-Received: by 2002:a17:902:a03:: with SMTP id 3mr24934291plo.112.1543416031468; Wed, 28 Nov 2018 06:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543416031; cv=none; d=google.com; s=arc-20160816; b=t2ztDHy1H/l9uVHIsQ/aVlo9w3GoilhcvTSnl2O9eCeo/eSovyHReFPnzlA7DYWacU x/qqKfc9PPosdtuTxartQp9LH/TQl8IFiSDotA3C6l4u0uBrn3mYPRSSUFo4gohG33wB naqdKMJWxdheEDhGnNLbBPchhnugkxzV1rrdSAHHevdoFPhK/5Y7N9DAqP86yjlm6Rqi 3VPONC+vS1tjzwFX48s0Z3o/xJG35CR0e+Wq6H+uJSzYJ50xIuy7UBwnDlfcNNlKXFd5 pZODI5oI6oNl5vadYrBG6Fy3MnXY/QZn+KCBhl++y9h4TjZ84Zx7W7H3Llnx6IaDiKsd tU/g== 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:dkim-signature; bh=8/oszXCEEU9n8169o7c5KKdnJY4IbNKiR1WhSfUs5xo=; b=D/FunhPwyxrsnobd4AG9+lPVVcy6roMDrT6LhPiz9V3c/cvHDb/+1AaBeNPVw4Jzq1 Ggv1qbd8UJb10h2Im8G2JZFofE5vp2kE7dWKmlA5TdhKIp2DFn022DxL7ssgAN34/8IO Pu64sUFrTOUfYsevctoZzEasyI+ao1miYL1WedbnFjxpj0Y7c5YwZpziFDaQ5TKv6/5E eAgITUFL9+yutAzkjHGYXKWBg6oJO2VlZaWLtKu4V7VLlLC0j6gedWRBlFMVpv6nCHUW MVaFqpvWYLbncuYpTZirUCGm+aRhf4rCjt+o+XXzFh3kdMGjZOOu0cz8+sD1+Fa1ou9q NDoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YkzJZcBa; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si7489048pgh.533.2018.11.28.06.40.31; Wed, 28 Nov 2018 06:40:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=YkzJZcBa; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728572AbeK2BmX (ORCPT + 15 others); Wed, 28 Nov 2018 20:42:23 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36401 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbeK2BmX (ORCPT ); Wed, 28 Nov 2018 20:42:23 -0500 Received: by mail-pg1-f196.google.com with SMTP id n2so9598818pgm.3 for ; Wed, 28 Nov 2018 06:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8/oszXCEEU9n8169o7c5KKdnJY4IbNKiR1WhSfUs5xo=; b=YkzJZcBaummHcKcechzc7ScUDLZRrwU3woscO6c593ZjcnUK8uNda0cIQlcThYPMcc 1MEIQh1tVXbz0hlabuXxVCI/P7GXdNOdk2N+ENi+rWWxvoRJ+2ervYXhhpL/Qiyg0/HQ 0j5MQilDiVFCmDPOOI7l0BEhgN+t8vKSwpSys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8/oszXCEEU9n8169o7c5KKdnJY4IbNKiR1WhSfUs5xo=; b=B8sdbHMahaPvli14+/rCQiqcwMBWVq+2tcW4eJcw0QP/oFI4y323D54I24nxB8oU4d MspcwswQ1sQFh+yaQpyZ/Ua/2B6T2MPzpCrR6t0Yy2mmqqn7wUfjol1Z7jZQ6ho3+/gg lJ/+whdpz1WzrILpfmv7aLULCHyYmbpLw0xfGU5jxw4j8KzLi5rfzey4YOIXsT6Hr4lO gdFmOqF7+jUqyloBq+G5qtfrzpR6Zhi8VbXpCtccMSkKaNlfgHOByR4iurJ9JyfXxBN/ X5qqJCn/ckcffBO452v0iP8yDSILEj7os/aDGwhXHVhOj4eV7FeTBv/oQknBzSzr09Gz FVvw== X-Gm-Message-State: AA+aEWZtim/sblE0rjsXlwhIcvjgIIjryTsYnAYZTEkkiJ68It9IN37M QG4R9XmGE0bPTVX9v5Br4tGk3A== X-Received: by 2002:a63:1c09:: with SMTP id c9mr32970190pgc.200.1543416029472; Wed, 28 Nov 2018 06:40:29 -0800 (PST) Received: from localhost.localdomain ([49.207.53.6]) by smtp.gmail.com with ESMTPSA id b26sm24227637pfe.91.2018.11.28.06.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Nov 2018 06:40:28 -0800 (PST) From: Amit Pundir To: Greg KH Cc: Stable , Venkat Gopalakrishnan , Subhash Jadavani , "Martin K . Petersen" Subject: [PATCH for-4.9.y 08/10] scsi: ufshcd: Fix race between clk scaling and ungate work Date: Wed, 28 Nov 2018 20:10:02 +0530 Message-Id: <1543416004-1547-9-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543416004-1547-1-git-send-email-amit.pundir@linaro.org> References: <1543416004-1547-1-git-send-email-amit.pundir@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 --- drivers/scsi/ufs/ufshcd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.7.4 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 5a1ea5aa799e..6130e10145b5 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -672,6 +672,21 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) 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)) {