Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp491264pxu; Thu, 3 Dec 2020 05:40:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVVXd8I75oy72v5JwRX2/dxPfIs4vQH3KdZqKaXAV1rpFpeWstu0DlrjZjyJJtaIB5Bi1f X-Received: by 2002:a17:906:1450:: with SMTP id q16mr2582187ejc.524.1607002804575; Thu, 03 Dec 2020 05:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607002804; cv=none; d=google.com; s=arc-20160816; b=xykjyfFlMCWPOGGXxcvyoS2Pmj3U9EtfPnUQOVOGWQjZpOIeb0wciH2C1pS6jqtjz7 VpKdX9qzSpMg6BezFaSyYsO6PXpqDC8q+mTDcICvw0ZRsphf2TlPHjx8/TubWmHSsStZ +df+o5bWfmMG+cQStWsy6sIHwx3jh+bRTRm4evHZP/VQVvD+XVUOERzlFyed1TH9gMF6 lliMQdkSmpviSa6qOSF87iXrhD5xTUgKaRQ1jFO/b3N5nDw1yqSlaP7Q2DomS1muFcIm tAILADJqPTvVdLaMQne/WsaI/Aav00bwmO/NZa7HQopLn4ZarKpD1/gFDcdH8/AOsfit SATw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mJrXKeDm9N0QUY8q4TxtZg9VhOTP8YseRrBrXMCOp3g=; b=kvxe3AmiCxGf7fFstDozVR4fgXSTEQ6hEworUBfdvXmgwADZRRajbngoutuNAEuuM6 HqIQ+VutIOXAMasIbNFv/hb+NsprmfhPdymYZLGKYz5CIamXgdsZhTROwnk0pGp7RfL0 9BnbhMslQfAYpn+LjV5vAYlxmM4WA5UMZDqQbPUEdWaGfVlAZ5aJp6gop0xPRitLtSxH 3hZrwmf6daTM6NzaPcX8VZ9cPVUS1HCAcsvA2k738DZx7ZZRVZXkdmK+DNDxhiCyN57l 18AvnyxU2iw/gGvQfBAsedeCTd6lds9IPz3+75/AFiWwF+RIEfNL7OYq/hhvszI4kqrS GRig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c22si1082220ejx.290.2020.12.03.05.39.34; Thu, 03 Dec 2020 05:40:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437054AbgLCNh6 (ORCPT + 99 others); Thu, 3 Dec 2020 08:37:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:47986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436464AbgLCNaD (ORCPT ); Thu, 3 Dec 2020 08:30:03 -0500 From: Sasha Levin Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Can Guo , Stanley Chu , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 5.9 13/39] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Date: Thu, 3 Dec 2020 08:28:07 -0500 Message-Id: <20201203132834.930999-13-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201203132834.930999-1-sashal@kernel.org> References: <20201203132834.930999-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Can Guo [ Upstream commit 73cc291c270248567245f084dcdf5078069af6b5 ] If someone plays with the UFS clk scaling devfreq governor through sysfs, ufshcd_devfreq_scale may be called even when HBA is not runtime ACTIVE. This can lead to unexpected error. We cannot just protect it by calling pm_runtime_get_sync() because that may cause a race condition since HBA runtime suspend ops need to suspend clk scaling. To fix this call pm_runtime_get_noresume() and check HBA's runtime status. Only proceed if HBA is runtime ACTIVE, otherwise just bail. governor_store devfreq_performance_handler update_devfreq devfreq_set_target ufshcd_devfreq_target ufshcd_devfreq_scale Link: https://lore.kernel.org/r/1600758548-28576-1-git-send-email-cang@codeaurora.org Reviewed-by: Stanley Chu Signed-off-by: Can Guo Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/ufs/ufshcd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index cbcdd79a1f76f..18326eb772aeb 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1279,8 +1279,15 @@ static int ufshcd_devfreq_target(struct device *dev, } spin_unlock_irqrestore(hba->host->host_lock, irq_flags); + pm_runtime_get_noresume(hba->dev); + if (!pm_runtime_active(hba->dev)) { + pm_runtime_put_noidle(hba->dev); + ret = -EAGAIN; + goto out; + } start = ktime_get(); ret = ufshcd_devfreq_scale(hba, scale_up); + pm_runtime_put(hba->dev); trace_ufshcd_profile_clk_scaling(dev_name(hba->dev), (scale_up ? "up" : "down"), -- 2.27.0