Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9218845pxu; Mon, 28 Dec 2020 09:35:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxP5aQjRj/PV6IAxpXEa0sOLypFoLafSf8MUuFGYmgm8wO6nXlJKKT8hjMPH0Oi9DF1X/qA X-Received: by 2002:a17:907:447d:: with SMTP id oo21mr42618280ejb.367.1609176941048; Mon, 28 Dec 2020 09:35:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609176941; cv=none; d=google.com; s=arc-20160816; b=Ib5qOFkEgL84YSg4XGsAmVkra5AYXN0aGdEAXw79nCTMymR5Q+UyozLcGjmwyXkMQH DyDK2uh1CbyRWTm/SL17Q8KeTvjc0FeUl7XXXqzpm6Ia87i9B+oVN/HY1XCOTnYpKZW7 E4kT6RBBR81xOe++DdtKYqTJGDW3sQotWnS8QUswNyk4tdWPu/fJE0uflftNwhLQNlz6 K6uK2sC1i6UATg9g3vnkI3IhuLweTMKk7PA1lFtnl3STqCfhrZPETLSnOwcjXVcvaSOL 2oejAXKbx0UYSXZS8ETEoitr+CygaHVcjctfKWE/IBl0rSGCN7MnhHT0YWQ+FlRwkJSq wHAw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jQ83exShKY4V7l2epdjYKw3UqY0ww2lUXiEJBnyMAHw=; b=lNoTHQvlyhtlCD8zi8WIW6DvJA0VnCJePEomlul8QJO5P/kgz8jOID2U31gJRakD1o JENMvWxVBzb8nOT/n61kDqnG/MLiWJvS3mZbDXpLypAJsDbyhT3+v+NSvy2O8z81JbUp R1CKf8ng4VqDVJAw57tLUPY+tDgDA3//DNrMJupaAheYPEWUoL7qedwOvKl/OcMgVH1H mMlbzXiJuaUN30K/dxGfZRASs7FL5q1/f5URH9tfn7bz656CUhJNmtkfFf7z/KjHKQit l7pVlfsGeMR4vLjakWrOdwHsSmsPYBSYF0UJfwrd8hiPA5YY9YPdsBtzrKYAmkzEZHmg qnVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K+owcmLk; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si19003887ejz.630.2020.12.28.09.35.19; Mon, 28 Dec 2020 09:35:41 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K+owcmLk; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730911AbgL1NIV (ORCPT + 99 others); Mon, 28 Dec 2020 08:08:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:35772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730833AbgL1NIH (ORCPT ); Mon, 28 Dec 2020 08:08:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F31EC21D94; Mon, 28 Dec 2020 13:07:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160846; bh=/1r65JJhn6hoBJ6i3zDSlyOlxoR3zPYHt81bEy4DIXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K+owcmLkXk8CLUuGKHKx/8PiAsYBS5oBeEiTNF1OCyy8ZwY/bKGR/7sdU/8q7aP5K cggiHli53aT7f62TeN4R4U2F+stxIIRo2HR2UwyvRoTANa1S9gyP0k/ZjFZgDdFmrW BYNsF4w8+vcpZUAvym3Dk5KJ49tzGFb9rFcUxMGk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stanley Chu , Can Guo , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 007/242] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Date: Mon, 28 Dec 2020 13:46:52 +0100 Message-Id: <20201228124905.026990042@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 a3a3ee6e2a002..342e086e41991 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1215,8 +1215,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