From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78BC5C432C0 for ; Wed, 27 Nov 2019 20:53:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BC6821850 for ; Wed, 27 Nov 2019 20:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887997; bh=gwRA3QBinyJ+pfEuPlUuA24oReQRRvxYsXG9q+xeN3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k5nGRgYHWK/cqgXKuHTtXMATodrdBPEab8dlDuFPzCKEImR+TQoVOSsv1TxjCy0E6 SKhXycQ6enmdCmtWJAr/TEBY9voi8AvFbhPTFATR2+aWp5V+NU0h0r/ZQ5ggoSMNez itRetqQf6wUzFgfJ/kxlgK57JWePnTal3jfTb6oI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730699AbfK0UxP (ORCPT ); Wed, 27 Nov 2019 15:53:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:41644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729593AbfK0UxO (ORCPT ); Wed, 27 Nov 2019 15:53:14 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 1D8BF218A3; Wed, 27 Nov 2019 20:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887993; bh=gwRA3QBinyJ+pfEuPlUuA24oReQRRvxYsXG9q+xeN3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkYutljHPcVsOHFFV7dipWMGsjeNaJh911v+kBZy8KbgGfA36DV+P3fh1c77ghiNy XGlgekemkUtlU+yckFz/srmufQsnvvQ+sZbpx6WyDjnSM4E4dD9jeo/oDViHL5k8wi wRFi3VLXsQA3aVefW0hJK11x//PkSLTE1gCPtsrA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bo Yan , Viresh Kumar , "Rafael J. Wysocki" , Lee Jones Subject: [PATCH 4.14 173/211] cpufreq: Skip cpufreq resume if its not suspended Date: Wed, 27 Nov 2019 21:31:46 +0100 Message-Id: <20191127203110.209602527@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Bo Yan commit 703cbaa601ff3fb554d1246c336ba727cc083ea0 upstream. cpufreq_resume can be called even without preceding cpufreq_suspend. This can happen in following scenario: suspend_devices_and_enter --> dpm_suspend_start --> dpm_prepare --> device_prepare : this function errors out --> dpm_suspend: this is skipped due to dpm_prepare failure this means cpufreq_suspend is skipped over --> goto Recover_platform, due to previous error --> goto Resume_devices --> dpm_resume_end --> dpm_resume --> cpufreq_resume In case schedutil is used as frequency governor, cpufreq_resume will eventually call sugov_start, which does following: memset(sg_cpu, 0, sizeof(*sg_cpu)); .... This effectively erases function pointer for frequency update, causing crash later on. The function pointer would have been set correctly if subsequent cpufreq_add_update_util_hook runs successfully, but that function returns earlier because cpufreq_suspend was not called: if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu))) return; The fix is to check cpufreq_suspended first, if it's false, that means cpufreq_suspend was not called in the first place, so do not resume cpufreq. Signed-off-by: Bo Yan Acked-by: Viresh Kumar [ rjw: Dropped printing a message ] Signed-off-by: Rafael J. Wysocki Signed-off-by: Lee Jones Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1673,6 +1673,9 @@ void cpufreq_resume(void) if (!cpufreq_driver) return; + if (unlikely(!cpufreq_suspended)) + return; + cpufreq_suspended = false; if (!has_target() && !cpufreq_driver->resume)