From: Wyes Karny <wyes.karny@amd.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Huang Rui <ray.huang@amd.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Perry Yuan <Perry.Yuan@amd.com>,
Mario Limonciello <Mario.Limonciello@amd.com>,
Arnd Bergmann <arnd@arndb.de>, Jinzhou Su <Jinzhou.Su@amd.com>,
Meng Li <li.meng@amd.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use
Date: Thu, 9 Feb 2023 09:58:18 +0000 [thread overview]
Message-ID: <Y+TDurLjotH2WWxL@beas> (raw)
In-Reply-To: <20230207161256.271613-1-arnd@kernel.org>
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
>
prev parent reply other threads:[~2023-02-09 9:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-07 16:12 [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use Arnd Bergmann
2023-02-08 14:28 ` Wyes Karny
2023-02-09 2:02 ` Yuan, Perry
2023-02-09 5:03 ` Huang Rui
2023-02-09 19:22 ` Rafael J. Wysocki
2023-02-09 9:58 ` Wyes Karny [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y+TDurLjotH2WWxL@beas \
--to=wyes.karny@amd.com \
--cc=Jinzhou.Su@amd.com \
--cc=Mario.Limonciello@amd.com \
--cc=Perry.Yuan@amd.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=li.meng@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).