From patchwork Fri Jun 2 00:41:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 9761389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 683FF6038E for ; Fri, 2 Jun 2017 00:48:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7014B284BD for ; Fri, 2 Jun 2017 00:48:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6468F2852E; Fri, 2 Jun 2017 00:48:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CA0F284BD for ; Fri, 2 Jun 2017 00:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751225AbdFBAsB convert rfc822-to-8bit (ORCPT ); Thu, 1 Jun 2017 20:48:01 -0400 Received: from cloudserver094114.home.net.pl ([79.96.170.134]:59998 "EHLO cloudserver094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750851AbdFBAsA (ORCPT ); Thu, 1 Jun 2017 20:48:00 -0400 Received: from 79.184.252.2.ipv4.supernova.orange.pl (79.184.252.2) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.82) id 86bde7a5a681c01f; Fri, 2 Jun 2017 02:48:01 +0200 From: "Rafael J. Wysocki" To: jongman.heo@samsung.com Cc: Linux PM , LKML , Srinivas Pandruvada Subject: Re: FW: [4.12 regression] "cpufreq: intel_pstate: Active mode P-state limits rework" Date: Fri, 02 Jun 2017 02:41:04 +0200 Message-ID: <1531609.n2MRKDRlk2@aspire.rjw.lan> User-Agent: KMail/4.14.10 (Linux/4.12.0-rc1+; KDE/4.14.9; x86_64; ; ) In-Reply-To: <20170601010816epcms1p16cded9ef0657a694c5a7a73ab723ecd7@epcms1p1> References: <3772609.tskOqDLWI3@aspire.rjw.lan> <20170601010816epcms1p16cded9ef0657a694c5a7a73ab723ecd7@epcms1p1> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thursday, June 01, 2017 01:08:16 AM Jongman Heo wrote: > > > >--------- Original Message --------- > >Sender : Rafael J. Wysocki > >Date : 2017-06-01 08:58 (GMT+9) > >Title : Re: FW: [4.12 regression] "cpufreq: intel_pstate: Active mode P-state limits rework" > > > >On Monday, May 29, 2017 02:18:52 AM Jongman Heo wrote: > >> > >> Hi, > >> > >> FYI, 4.12-rc3 still has this issue. > >> > >> > >> --------- Original Message --------- > >> Sender : 허종만 > >> Date : 2017-05-16 13:25 (GMT+9) > >> Title : [4.12 regression] "cpufreq: intel_pstate: Active mode P-state limits rework" > >> > >> > >> Hi, > >> > >> With 4.12-rc1 (Linus git), booting fails due to kernel panic, at intel_pstate_register_driver+0x56/0x110. > >> I can't copy the whole trace from the graphic console, it looks like below. > >> > >> Call Trace: > >> intel_pstate_init > >> intel_pstate_setup > >> do_one_initcall > >> set_debug_rodata > >> kernel_init_freeable > >> rest_init > >> kernel_init > >> ret_from_fork > >> Code: ... > >> RIP: intel_pstate_register_driver+0x56/0x110 RSP: ffffa3a98000bd80 > >> ... > > > >I guess this is a division by 0 due to the unmet assumption that the denominator > >in min_perf_pct_min() will always be nonzero. > > > >If this guess is correct, the patch below should help, so can you please test it? > > > >Thanks, > >Rafael > > > > > >--- > > drivers/cpufreq/intel_pstate.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > >Index: linux-pm/drivers/cpufreq/intel_pstate.c > >=================================================================== > >--- linux-pm.orig/drivers/cpufreq/intel_pstate.c > >+++ linux-pm/drivers/cpufreq/intel_pstate.c > >@@ -571,9 +571,10 @@ static inline void update_turbo_state(vo > > static int min_perf_pct_min(void) > > { > > struct cpudata *cpu = all_cpu_data[0]; > >+ int turbo_pstate = cpu->pstate.turbo_pstate; > > > >- return DIV_ROUND_UP(cpu->pstate.min_pstate * 100, > >- cpu->pstate.turbo_pstate); > >+ return turbo_pstate ? > >+ DIV_ROUND_UP(cpu->pstate.min_pstate * 100, turbo_pstate) : 0; > > } > > > > static s16 intel_pstate_get_epb(struct cpudata *cpu_data) > > > > > > > > Hi, > > Your patch fixes the issue. OK, thanks for the confirmation. Here it goes again with a changelog and all. --- From: Rafael J. Wysocki Subject: [PATCH] cpufreq: intel_pstate: Avoid division by 0 in min_perf_pct_min() Commit c5a2ee7dde89 (cpufreq: intel_pstate: Active mode P-state limits rework) incorrectly assumed that pstate.turbo_pstate will always be nonzero for CPU0 in min_perf_pct_min() if cpufreq_register_driver() has succeeded which may not be the case in virtualized environments. If that is not the case, it leads to an early crash on boot in intel_pstate_register_driver(), so add a sanity check to min_perf_pct_min() to prevent the crash from happening. Fixes: c5a2ee7dde89 (cpufreq: intel_pstate: Active mode P-state limits rework) Reported-and-tested-by: Jongman Heo Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/intel_pstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -571,9 +571,10 @@ static inline void update_turbo_state(vo static int min_perf_pct_min(void) { struct cpudata *cpu = all_cpu_data[0]; + int turbo_pstate = cpu->pstate.turbo_pstate; - return DIV_ROUND_UP(cpu->pstate.min_pstate * 100, - cpu->pstate.turbo_pstate); + return turbo_pstate ? + DIV_ROUND_UP(cpu->pstate.min_pstate * 100, turbo_pstate) : 0; } static s16 intel_pstate_get_epb(struct cpudata *cpu_data)