Received: by 10.223.176.46 with SMTP id f43csp2532086wra; Thu, 25 Jan 2018 11:17:08 -0800 (PST) X-Google-Smtp-Source: AH8x2259NUqBlvOwN4LZxKnsunh2PdUyVUElOPYryuUhrv4aa3DL/LGk11cVJZ4qFELFCnvKrZR9 X-Received: by 2002:a17:902:8a97:: with SMTP id p23-v6mr12233864plo.74.1516907827973; Thu, 25 Jan 2018 11:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516907827; cv=none; d=google.com; s=arc-20160816; b=yzMDMD3eQzksZc/jf0Jwh3DYhe54618y5bqs9fb/yrRmkDihVO4PuOXr0DestVke32 RdnDhKTvrRj3rh/123XopLJmRRJprLe3pY2gS1E+N0+KtYezyF3/S3wc9//lZihDUOnB zdHjJBpODb9ZdNV7yKk4Cn4C6ndbuBf0nmaNunisUn69mnb/xe9SatEjc0yzNOqSn/X5 yEtmL4hU+wd9nuTaAIW7XVi6HQhMuiYZeoRaFG5zTMHhtYLSge6/N6OjKMHCVqHXA4ZZ lfpj1CKwJVonGIHFwUIYucQnM92wBHmT5Y6fBkJNSI8QnEY0+ibe/VyXlly1MilM38y8 TbHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=szF+qTSki+TPlI1ZGHplrSSWerdGNpHxhG9p7Ix/pCE=; b=dtZcj7pG3lBAu7N+PwcwUF81GAsjk5A2jlENcmnKZN8klgOUBJJYuz4AtL5xEIn6QJ H8/gDAhF4IhvpkpfLz3bCqRK93YgukjUhecqd49zYs+1AeQ4fVLqeP0LowqUNjko5VEr cOYg36k+ilnr00Vf9E+pVRbMtYlqhKmnU6kpfJ+9n+ZkDbAHpiclIWGvbf3SqvSZQV2K hhxl1fu8mZPc7Rex1Qr+oI7kmLu2j0xrWgDsigF1itFyqGckdKVDl9p+ukOkA4ai5Oz+ PJQpcLGJgzwgYp3ixj/dRLPdwBqwlWWngdDbBbARLtk/rize4Y6uEcFG0omBGIL8Qu4N Hi7Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t88si5022057pfj.196.2018.01.25.11.16.53; Thu, 25 Jan 2018 11:17:07 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751306AbeAYTPw (ORCPT + 99 others); Thu, 25 Jan 2018 14:15:52 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:17444 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751108AbeAYTPu (ORCPT ); Thu, 25 Jan 2018 14:15:50 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Thu, 25 Jan 2018 11:15:53 -0800 Received: from HQMAIL108.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Thu, 25 Jan 2018 11:15:50 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Thu, 25 Jan 2018 11:15:50 -0800 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 25 Jan 2018 19:15:50 +0000 Received: from byan-linux.NVIDIA.COM (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2 via Frontend Transport; Thu, 25 Jan 2018 19:15:50 +0000 From: Bo Yan To: , , CC: , , Bo Yan Subject: [PATCH v2] cpufreq: skip cpufreq resume if it's not suspended Date: Thu, 25 Jan 2018 11:15:45 -0800 Message-ID: <1516907745-13508-1-git-send-email-byan@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1744712.rO4QOLozun@aspire.rjw.lan> References: <1744712.rO4QOLozun@aspire.rjw.lan> X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; Ideally, suspend should succeed, then things will be fine. But even in case of suspend failure, system should not crash. The fix is to check the pm_transition status in dpm_resume. if pm_transition.event == PMSG_ON, we know for sure dpm_suspend has not been called, so do not call cpufreq_resume. Signed-off-by: Bo Yan --- drivers/base/power/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 08744b572af6..39829d7a9311 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -921,6 +921,7 @@ static void async_resume(void *data, async_cookie_t cookie) void dpm_resume(pm_message_t state) { struct device *dev; + bool suspended = (pm_transition.event != PM_EVENT_ON); ktime_t starttime = ktime_get(); trace_suspend_resume(TPS("dpm_resume"), state.event, true); @@ -964,7 +965,8 @@ void dpm_resume(pm_message_t state) async_synchronize_full(); dpm_show_time(starttime, state, 0, NULL); - cpufreq_resume(); + if (likely(suspended)) + cpufreq_resume(); trace_suspend_resume(TPS("dpm_resume"), state.event, false); } -- 2.7.4