From: Wyes Karny <wyes.karny@amd.com>
To: stable@vger.kernel.org
Cc: "Gautham R. Shenoy" <gautham.shenoy@amd.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>
Subject: Re: [PATCH 6.3.y] cpufreq: amd-pstate: Add ->fast_switch() callback
Date: Tue, 30 May 2023 16:58:32 +0530 [thread overview]
Message-ID: <ZHXd4NcHZA/7AfUX@BLR-5CG13462PL.amd.com> (raw)
In-Reply-To: <20230530111653.3593-1-wyes.karny@amd.com>
On 30 May 11:16, Wyes Karny wrote:
> From: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
>
> [ Upstream commit 3bf8c6307bad5c0cc09cde982e146d847859b651 ]
>
> Schedutil normally calls the adjust_perf callback for drivers with
> adjust_perf callback available and fast_switch_possible flag set.
> However, when frequency invariance is disabled and schedutil tries to
> invoke fast_switch. So, there is a chance of kernel crash if this
> function pointer is not set. To protect against this scenario add
> fast_switch callback to amd_pstate driver.
>
> Fixes: 1d215f0319c2 ("cpufreq: amd-pstate: Add fast switch function for AMD P-State")
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Wyes Karny <wyes.karny@amd.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> (cherry picked from commit 4badf2eb1e986bdbf34dd2f5d4c979553a86fe54)
> ---
> drivers/cpufreq/amd-pstate.c | 37 +++++++++++++++++++++++++++++-------
> 1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 8dd46fad151e..7cce90d16b8d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -422,9 +422,8 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy)
> return 0;
> }
>
> -static int amd_pstate_target(struct cpufreq_policy *policy,
> - unsigned int target_freq,
> - unsigned int relation)
> +static int amd_pstate_update_freq(struct cpufreq_policy *policy,
> + unsigned int target_freq, bool fast_switch)
> {
> struct cpufreq_freqs freqs;
> struct amd_cpudata *cpudata = policy->driver_data;
> @@ -443,14 +442,36 @@ static int amd_pstate_target(struct cpufreq_policy *policy,
> des_perf = DIV_ROUND_CLOSEST(target_freq * cap_perf,
> cpudata->max_freq);
>
> - cpufreq_freq_transition_begin(policy, &freqs);
> - amd_pstate_update(cpudata, min_perf, des_perf,
> - max_perf, false);
> - cpufreq_freq_transition_end(policy, &freqs, false);
> + WARN_ON(fast_switch && !policy->fast_switch_enabled);
> + /*
> + * If fast_switch is desired, then there aren't any registered
> + * transition notifiers. See comment for
> + * cpufreq_enable_fast_switch().
> + */
> + if (!fast_switch)
> + cpufreq_freq_transition_begin(policy, &freqs);
> +
> + amd_pstate_update(cpudata, min_perf, des_perf, max_perf, fast_switch);
> +
> + if (!fast_switch)
> + cpufreq_freq_transition_end(policy, &freqs, false);
>
> return 0;
> }
>
> +static int amd_pstate_target(struct cpufreq_policy *policy,
> + unsigned int target_freq,
> + unsigned int relation)
> +{
> + return amd_pstate_update_freq(policy, target_freq, false);
> +}
> +
> +static unsigned int amd_pstate_fast_switch(struct cpufreq_policy *policy,
> + unsigned int target_freq)
> +{
> + return amd_pstate_update_freq(policy, target_freq, true);
> +}
> +
> static void amd_pstate_adjust_perf(unsigned int cpu,
> unsigned long _min_perf,
> unsigned long target_perf,
> @@ -692,6 +713,7 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)
>
> freq_qos_remove_request(&cpudata->req[1]);
> freq_qos_remove_request(&cpudata->req[0]);
> + policy->fast_switch_possible = false;
> kfree(cpudata);
>
> return 0;
> @@ -1226,6 +1248,7 @@ static struct cpufreq_driver amd_pstate_driver = {
> .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS,
> .verify = amd_pstate_verify,
> .target = amd_pstate_target,
> + .fast_switch = amd_pstate_fast_switch,
> .init = amd_pstate_cpu_init,
> .exit = amd_pstate_cpu_exit,
> .suspend = amd_pstate_cpu_suspend,
Please ignore this. Wrong patch.
Sorry for inconvenience.
Thanks,
Wyes
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-05-30 11:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-28 16:54 FAILED: patch "[PATCH] cpufreq: amd-pstate: Update policy->cur in" failed to apply to 6.3-stable tree gregkh
2023-05-30 11:16 ` [PATCH 6.3.y] cpufreq: amd-pstate: Add ->fast_switch() callback Wyes Karny
2023-05-30 11:28 ` Wyes Karny [this message]
2023-05-30 12:01 ` [PATCH 6.3.y] cpufreq: amd-pstate: Update policy->cur in amd_pstate_adjust_perf() Wyes Karny
-- strict thread matches above, loose matches on Subject: below --
2023-05-28 16:53 FAILED: patch "[PATCH] cpufreq: amd-pstate: Add ->fast_switch() callback" failed to apply to 6.3-stable tree gregkh
2023-05-30 11:55 ` [PATCH 6.3.y] cpufreq: amd-pstate: Add ->fast_switch() callback Wyes Karny
2023-06-01 10:22 ` Greg KH
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=ZHXd4NcHZA/7AfUX@BLR-5CG13462PL.amd.com \
--to=wyes.karny@amd.com \
--cc=gautham.shenoy@amd.com \
--cc=rafael.j.wysocki@intel.com \
--cc=stable@vger.kernel.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