Message ID | 20230207161256.271613-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2936932wrn; Tue, 7 Feb 2023 08:15:54 -0800 (PST) X-Google-Smtp-Source: AK7set9RsctEKXDPP2W3pg+aZdEIZAG517svar1cBu6VVPtxi+sZevh5O9LB+13ysgb/qx+z+lCr X-Received: by 2002:a05:6a21:29c1:b0:bf:e6c:758b with SMTP id tv1-20020a056a2129c100b000bf0e6c758bmr3123897pzb.4.1675786554240; Tue, 07 Feb 2023 08:15:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675786554; cv=none; d=google.com; s=arc-20160816; b=Ou+6pvfGXOWi8B5OPl4PgQCUiBs8VKcq/T7/tb49Kxp2EKso2mQDW9MRs4McexwGJL +u9NJ3IZwp2dcVwoPBGCQYjRJD6hqVTaW4HocEPDCrfZEmVybt0icImTPJ0tECQykAQ7 eT1OE+jGM6QB8lG02eyH/h9qDF310hD+tOiiAF38wQoHVTJJFieaAswWOqUxbEoIaOis +gFaBct+QR4P5aJv7VMUBf8INCiFm1NJugQNIzAXRYYWAWEiHP/9aKnkY6/nJhPFd/6a vZx6pPxb1XXZOphaXdCeoyEETBa3/XnGs/bOxWsGRZ9bFraWlTNUDngD4z6kWzLDOLnM 9blg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Dbg7/E0MSqqw0rgiQ+IE/hYOdXYDVcIZKP16Y/lz6fE=; b=S+IUDG433F0taVo/2yTaGPQMZqju67yaZwSeJR2Kd6xhDblVUGTtPVvaH44CJReylV mYJblUAlcQ8k8FSrLKenYzdBNwYMqdfGcgzOMh8vtUSffDkTAqMNjPTzjvirxd40dfTo pOSeeP9jdo/5lW3L/QHV+PE2fTu/3UnV01SzTOVYjKCZqPW/Z9LGxBnvFCq3h87twPS0 YNmkatr2vt3/OS4aa+XUKnqmLE5nXniekDRl+AOx830Sp6CeF0evQ+Zk8b/K5FfD6gKU KXzYu2WEjidiyAj1HfnGUtC6SvmDjAYIGvkC1qtsUsLyBxZLRwkw3wj32ibNoizQJEFG qfrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f6UuGFSL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b004ae2bd6b8casi14846266pgw.808.2023.02.07.08.15.41; Tue, 07 Feb 2023 08:15:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f6UuGFSL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232450AbjBGQNH (ORCPT <rfc822;kmanaouilinux@gmail.com> + 99 others); Tue, 7 Feb 2023 11:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbjBGQND (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 7 Feb 2023 11:13:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED98DBEF; Tue, 7 Feb 2023 08:13:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ECA1060F16; Tue, 7 Feb 2023 16:13:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A13AC433D2; Tue, 7 Feb 2023 16:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675786380; bh=cC2tkzskefDBrZsRvMNSczr6SitbzsKg7wGCqoUStHs=; h=From:To:Cc:Subject:Date:From; b=f6UuGFSLOAa3/jEqTL8xCu752LB/v8U3T4/n7H7TP+DnA7MHVJ5Vo5N6wy95yp83P 3RzDdYgxP0osFCxQoOpBVQ6QBH2x9upd1ijSxseNfiXM2jyY23tInRrYN/inEEjIEG GPvz+k1Z1MlR7IVEt67M5aTJrybyZw5jDsUOkUFymVJjX/SlCwn7n24j6Vx5Dctp4F YNCXUtoEGBQ1XJt914hG+MgsBiPcZ5bSnpnmdS6Gtknc5EOYbsBxUAljNC75gS2rh8 CMmRnOw9YU/dCZC6ACchSa1JcLgx1HKsBsJwkEtVF8w3aPEVcwndJ12mLguLm7M7wO ZuWqcudZxdoyQ== From: Arnd Bergmann <arnd@kernel.org> To: Huang Rui <ray.huang@amd.com>, "Rafael J. Wysocki" <rafael@kernel.org>, Viresh Kumar <viresh.kumar@linaro.org>, Wyes Karny <wyes.karny@amd.com>, Perry Yuan <Perry.Yuan@amd.com>, Mario Limonciello <Mario.Limonciello@amd.com> Cc: Arnd Bergmann <arnd@arndb.de>, Perry Yuan <perry.yuan@amd.com>, Mario Limonciello <mario.limonciello@amd.com>, Jinzhou Su <Jinzhou.Su@amd.com>, Meng Li <li.meng@amd.com>, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use Date: Tue, 7 Feb 2023 17:12:51 +0100 Message-Id: <20230207161256.271613-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757189561683356760?= X-GMAIL-MSGID: =?utf-8?q?1757189561683356760?= |
Series |
cpufreq: amd-pstate: avoid uninitialized variable use
|
|
Commit Message
Arnd Bergmann
Feb. 7, 2023, 4:12 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The new epp support causes warnings about three separate but related bugs: 1) failing before allocation should just return an error: drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (!dev) ^~~~ drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here return ret; ^~~ 2) wrong variable to store return code: drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (rc) ^~ drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here return ret; ^~~ drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false if (rc) ^~~~~~~ 3) calling amd_pstate_set_epp() in cleanup path after determining that it should not be called: drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (cpudata->epp_policy == cpudata->policy) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here amd_pstate_set_epp(cpudata, epp); ^~~ All three are trivial to fix, but most likely there are additional bugs in this function when the error handling was not really tested. Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- drivers/cpufreq/amd-pstate.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Comments
On 07 Feb 17:12, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The new epp support causes warnings about three separate > but related bugs: > > 1) failing before allocation should just return an error: > > drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (!dev) > ^~~~ > drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here > return ret; > ^~~ > > 2) wrong variable to store return code: > > drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (rc) > ^~ > drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here > return ret; > ^~~ > drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false > if (rc) > ^~~~~~~ > > 3) calling amd_pstate_set_epp() in cleanup path after determining > that it should not be called: > > drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (cpudata->epp_policy == cpudata->policy) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here > amd_pstate_set_epp(cpudata, epp); > ^~~ > > All three are trivial to fix, but most likely there are additional bugs > in this function when the error handling was not really tested. > > Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > drivers/cpufreq/amd-pstate.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index 168a28bed6ee..847f5f31396d 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; > struct amd_cpudata *cpudata; > struct device *dev; > - int rc; > u64 value; > > /* > @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > amd_perf_ctl_reset(policy->cpu); > dev = get_cpu_device(policy->cpu); > if (!dev) > - goto free_cpudata1; > + return -ENODEV; > > cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); > if (!cpudata) > @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > cpudata->cpu = policy->cpu; > cpudata->epp_policy = 0; > > - rc = amd_pstate_init_perf(cpudata); > - if (rc) > + ret = amd_pstate_init_perf(cpudata); > + if (ret) > goto free_cpudata1; > > min_freq = amd_get_min_freq(cpudata); > @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) > value |= (u64)epp << 24; > } > > + amd_pstate_set_epp(cpudata, epp); > skip_epp: > WRITE_ONCE(cpudata->cppc_req_cached, value); > - amd_pstate_set_epp(cpudata, epp); > cpufreq_cpu_put(policy); > } > Tested this on AMD Milan (Zen 3) system. Tested-by: Wyes Karny <wyes.karny@amd.com> > -- > 2.39.1 >
[AMD Official Use Only - General] Hi Arnd, > -----Original Message----- > From: Arnd Bergmann <arnd@kernel.org> > Sent: Wednesday, February 8, 2023 12:13 AM > To: Huang, Ray <Ray.Huang@amd.com>; Rafael J. Wysocki > <rafael@kernel.org>; Viresh Kumar <viresh.kumar@linaro.org>; Karny, Wyes > <Wyes.Karny@amd.com>; Yuan, Perry <Perry.Yuan@amd.com>; Limonciello, > Mario <Mario.Limonciello@amd.com> > Cc: Arnd Bergmann <arnd@arndb.de>; Yuan, Perry <Perry.Yuan@amd.com>; > Limonciello, Mario <Mario.Limonciello@amd.com>; Jinzhou Su > <Jinzhou.Su@amd.com>; Meng, Li (Jassmine) <Li.Meng@amd.com>; linux- > pm@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use > > From: Arnd Bergmann <arnd@arndb.de> > > The new epp support causes warnings about three separate but related bugs: > > 1) failing before allocation should just return an error: > > drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized > whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (!dev) > ^~~~ > drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here > return ret; > ^~~ > > 2) wrong variable to store return code: > > drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized > whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (rc) > ^~ > drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here > return ret; > ^~~ > drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is > always false > if (rc) > ^~~~~~~ > > 3) calling amd_pstate_set_epp() in cleanup path after determining that it > should not be called: > > drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used > uninitialized whenever 'if' condition is true [-Werror,-Wsometimes- > uninitialized] > if (cpudata->epp_policy == cpudata->policy) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here > amd_pstate_set_epp(cpudata, epp); > ^~~ > > All three are trivial to fix, but most likely there are additional bugs in this > function when the error handling was not really tested. > > Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support > for the AMD processors") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > drivers/cpufreq/amd-pstate.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index 168a28bed6ee..847f5f31396d 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct > cpufreq_policy *policy) > int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; > struct amd_cpudata *cpudata; > struct device *dev; > - int rc; > u64 value; > > /* > @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct > cpufreq_policy *policy) > amd_perf_ctl_reset(policy->cpu); > dev = get_cpu_device(policy->cpu); > if (!dev) > - goto free_cpudata1; > + return -ENODEV; > > cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); > if (!cpudata) > @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct > cpufreq_policy *policy) > cpudata->cpu = policy->cpu; > cpudata->epp_policy = 0; > > - rc = amd_pstate_init_perf(cpudata); > - if (rc) > + ret = amd_pstate_init_perf(cpudata); > + if (ret) > goto free_cpudata1; > > min_freq = amd_get_min_freq(cpudata); > @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) > value |= (u64)epp << 24; > } > > + amd_pstate_set_epp(cpudata, epp); > skip_epp: > WRITE_ONCE(cpudata->cppc_req_cached, value); > - amd_pstate_set_epp(cpudata, epp); > cpufreq_cpu_put(policy); > } > > -- > 2.39.1 Thanks for your quick fix patch. Reviewed-by: Yuan Perry <Perry.Yuan@amd.com>
On Wed, Feb 08, 2023 at 12:12:51AM +0800, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The new epp support causes warnings about three separate > but related bugs: > > 1) failing before allocation should just return an error: > > drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (!dev) > ^~~~ > drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here > return ret; > ^~~ > > 2) wrong variable to store return code: > > drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (rc) > ^~ > drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here > return ret; > ^~~ > drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false > if (rc) > ^~~~~~~ > > 3) calling amd_pstate_set_epp() in cleanup path after determining > that it should not be called: > > drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > if (cpudata->epp_policy == cpudata->policy) > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here > amd_pstate_set_epp(cpudata, epp); > ^~~ > > All three are trivial to fix, but most likely there are additional bugs > in this function when the error handling was not really tested. > > Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> Thanks! Acked-by: Huang Rui <ray.huang@amd.com> > --- > drivers/cpufreq/amd-pstate.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index 168a28bed6ee..847f5f31396d 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; > struct amd_cpudata *cpudata; > struct device *dev; > - int rc; > u64 value; > > /* > @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > amd_perf_ctl_reset(policy->cpu); > dev = get_cpu_device(policy->cpu); > if (!dev) > - goto free_cpudata1; > + return -ENODEV; > > cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); > if (!cpudata) > @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > cpudata->cpu = policy->cpu; > cpudata->epp_policy = 0; > > - rc = amd_pstate_init_perf(cpudata); > - if (rc) > + ret = amd_pstate_init_perf(cpudata); > + if (ret) > goto free_cpudata1; > > min_freq = amd_get_min_freq(cpudata); > @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) > value |= (u64)epp << 24; > } > > + amd_pstate_set_epp(cpudata, epp); > skip_epp: > WRITE_ONCE(cpudata->cppc_req_cached, value); > - amd_pstate_set_epp(cpudata, epp); > cpufreq_cpu_put(policy); > } > > -- > 2.39.1 >
Hi Arnd, Ray, Perry, On 07 Feb 17:12, Arnd Bergmann wrote: > @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) > value |= (u64)epp << 24; > } > > + amd_pstate_set_epp(cpudata, epp); > skip_epp: > WRITE_ONCE(cpudata->cppc_req_cached, value); > - amd_pstate_set_epp(cpudata, epp); > cpufreq_cpu_put(policy); > } I see an issue here with MSR-based systems. Here EPP is being set before updating `cppc_req_cached` and for MSR based systems while updating EPP value, MIN_PERF and MAX_PERF also updated. So, here whatever value MSR_AMD_CPPC_REQ had for min and max perf that will be rewritten instead of highest and lowest perf from MSR_AMD_CPPC_CAP1. Can we do something like this: @@ -1053,32 +1052,34 @@ static void amd_pstate_epp_init(unsigned int cpu) value &= ~AMD_CPPC_DES_PERF(~0L); value |= AMD_CPPC_DES_PERF(0); + /* No need to set epp again if previous and current policy is same */ if (cpudata->epp_policy == cpudata->policy) goto skip_epp; cpudata->epp_policy = cpudata->policy; - if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { - epp = amd_pstate_get_epp(cpudata, value); - if (epp < 0) - goto skip_epp; - /* force the epp value to be zero for performance policy */ - epp = 0; - } else { - /* Get BIOS pre-defined epp value */ - epp = amd_pstate_get_epp(cpudata, value); - if (epp) - goto skip_epp; + /* Get BIOS pre-defined epp value */ + epp = amd_pstate_get_epp(cpudata, value); + if (epp < 0) { + /** + * This return value can only be negative for shared_memory + * systems where EPP register read/write not supported. + */ + goto skip_epp; } + + if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) + epp = 0; + /* Set initial EPP value */ if (boot_cpu_has(X86_FEATURE_CPPC)) { value &= ~GENMASK_ULL(31, 24); value |= (u64)epp << 24; } -skip_epp: WRITE_ONCE(cpudata->cppc_req_cached, value); amd_pstate_set_epp(cpudata, epp); +skip_epp: cpufreq_cpu_put(policy); } > > -- > 2.39.1 >
On Thu, Feb 9, 2023 at 6:04 AM Huang Rui <ray.huang@amd.com> wrote: > > On Wed, Feb 08, 2023 at 12:12:51AM +0800, Arnd Bergmann wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > The new epp support causes warnings about three separate > > but related bugs: > > > > 1) failing before allocation should just return an error: > > > > drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > > if (!dev) > > ^~~~ > > drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here > > return ret; > > ^~~ > > > > 2) wrong variable to store return code: > > > > drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > > if (rc) > > ^~ > > drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here > > return ret; > > ^~~ > > drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is always false > > if (rc) > > ^~~~~~~ > > > > 3) calling amd_pstate_set_epp() in cleanup path after determining > > that it should not be called: > > > > drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] > > if (cpudata->epp_policy == cpudata->policy) > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here > > amd_pstate_set_epp(cpudata, epp); > > ^~~ > > > > All three are trivial to fix, but most likely there are additional bugs > > in this function when the error handling was not really tested. > > > > Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors") > > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > > Thanks! > > Acked-by: Huang Rui <ray.huang@amd.com> > > > --- > > drivers/cpufreq/amd-pstate.c | 9 ++++----- > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > > index 168a28bed6ee..847f5f31396d 100644 > > --- a/drivers/cpufreq/amd-pstate.c > > +++ b/drivers/cpufreq/amd-pstate.c > > @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > > int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; > > struct amd_cpudata *cpudata; > > struct device *dev; > > - int rc; > > u64 value; > > > > /* > > @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > > amd_perf_ctl_reset(policy->cpu); > > dev = get_cpu_device(policy->cpu); > > if (!dev) > > - goto free_cpudata1; > > + return -ENODEV; > > > > cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); > > if (!cpudata) > > @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) > > cpudata->cpu = policy->cpu; > > cpudata->epp_policy = 0; > > > > - rc = amd_pstate_init_perf(cpudata); > > - if (rc) > > + ret = amd_pstate_init_perf(cpudata); > > + if (ret) > > goto free_cpudata1; > > > > min_freq = amd_get_min_freq(cpudata); > > @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) > > value |= (u64)epp << 24; > > } > > > > + amd_pstate_set_epp(cpudata, epp); > > skip_epp: > > WRITE_ONCE(cpudata->cppc_req_cached, value); > > - amd_pstate_set_epp(cpudata, epp); > > cpufreq_cpu_put(policy); > > } > > > > -- Applied, thanks!
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 168a28bed6ee..847f5f31396d 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret; struct amd_cpudata *cpudata; struct device *dev; - int rc; u64 value; /* @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) amd_perf_ctl_reset(policy->cpu); dev = get_cpu_device(policy->cpu); if (!dev) - goto free_cpudata1; + return -ENODEV; cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL); if (!cpudata) @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) cpudata->cpu = policy->cpu; cpudata->epp_policy = 0; - rc = amd_pstate_init_perf(cpudata); - if (rc) + ret = amd_pstate_init_perf(cpudata); + if (ret) goto free_cpudata1; min_freq = amd_get_min_freq(cpudata); @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu) value |= (u64)epp << 24; } + amd_pstate_set_epp(cpudata, epp); skip_epp: WRITE_ONCE(cpudata->cppc_req_cached, value); - amd_pstate_set_epp(cpudata, epp); cpufreq_cpu_put(policy); }