From: Wyes Karny <wyes.karny@amd.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: ray.huang@amd.com, rafael@kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, gautham.shenoy@amd.com
Subject: Re: [PATCH v3 2/2] cpufreq: Warn if fast_switch is not set
Date: Tue, 16 May 2023 11:19:06 +0530 [thread overview]
Message-ID: <ZGMZUhWCU18Wn/47@BLR-5CG13462PL.amd.com> (raw)
In-Reply-To: <20230516011001.epa4xlvbiimu6ai3@vireshk-i7>
Hi Viresh,
Thanks for looking into this patch.
On 16 May 06:40, Viresh Kumar wrote:
> On 15-05-23, 11:34, Wyes Karny wrote:
> > If fast_switch_possible flag is set by the scaling driver, the governor
> > is free to select fast_switch function even if adjust_perf is set. When
> > the frequency invariance is disabled due to some reason governor
> > fallbacks to fast_switch if fast_switch_possible is set. This could
> > crash the kernel if the driver didn't set the fast_switch function
> > pointer.
> >
> > This issue becomes apparent when aperf/mperf overflow occurs with
> > amd_pstate (passive) + schedutil. When this happens, kernel disables
> > frequency invariance calculation which causes schedutil to fallback to
> > sugov_update_single_freq which currently relies on the fast_switch
> > callback.
> >
> > Normal flow:
> > sugov_update_single_perf
> > cpufreq_driver_adjust_perf
> > cpufreq_driver->adjust_perf
> >
> > Error case flow:
> > sugov_update_single_perf
> > sugov_update_single_freq <-- This is chosen because the freq invariant is disabled due to aperf/mperf overflow
> > cpufreq_driver_fast_switch
> > cpufreq_driver->fast_switch <-- Here NULL pointer dereference is happening, because fast_switch is not set
>
> Not sure if all these details are required for this patch or not. It
> is logically incorrect to set fast_switch_possible, while fast_switch
> isn't set. That's a reason enough.
Sure, I'll remove this if it's unnecessary.
>
> > Put up a warning message if the driver sets fast_switch_possible flag
> > but not fast_switch.
> >
> > Signed-off-by: Wyes Karny <wyes.karny@amd.com>
> > ---
> > drivers/cpufreq/cpufreq.c | 18 ++++++++++++++++++
> > include/linux/cpufreq.h | 5 ++++-
> > 2 files changed, 22 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index 6b52ebe5a890..180be9235b08 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -501,6 +501,13 @@ void cpufreq_enable_fast_switch(struct cpufreq_policy *policy)
> > if (!policy->fast_switch_possible)
> > return;
> >
> > + /**
>
> Doc style comments aren't required here I guess.
Okay.
>
> > + * It's not expected driver's fast_switch callback is not set
> > + * even fast_switch_possible is true.
> > + */
> > + if (!cpufreq_driver_has_fast_switch())
> > + pr_alert_once("fast_switch callback is not set\n");
> > +
> > mutex_lock(&cpufreq_fast_switch_lock);
> > if (cpufreq_fast_switch_count >= 0) {
> > cpufreq_fast_switch_count++;
> > @@ -2143,6 +2150,17 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
> > }
> > EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);
> >
> > +/**
> > + * cpufreq_driver_has_fast_switch - Check "fast switch" callback.
> > + *
> > + * Return 'true' if the ->fast_switch callback is present for the
> > + * current driver or 'false' otherwise.
> > + */
> > +bool cpufreq_driver_has_fast_switch(void)
>
> Why create a routine for this, when no one else is going to use it ?
>
> > +{
> > + return !!cpufreq_driver->fast_switch;
> > +}
>
> I think you should add the required check in cpufreq_online(), after
> cpufreq_driver->init() is called, and return failure if fast_switch
> isn't set and fast_switch_possible is.
Sure, I'll do that. But one caution if we return failure, the drivers which
has the above conditions won't load.
Thanks,
Wyes
>
> --
> viresh
next prev parent reply other threads:[~2023-05-16 5:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 11:34 [PATCH v3 0/2] cpufreq/amd-pstate: Fix null pointer dereference when frequency invariance is disabled Wyes Karny
2023-05-15 11:34 ` [PATCH v3 1/2] amd_pstate: Add ->fast_switch() callback Wyes Karny
2023-05-15 11:34 ` [PATCH v3 2/2] cpufreq: Warn if fast_switch is not set Wyes Karny
2023-05-16 1:10 ` Viresh Kumar
2023-05-16 5:49 ` Wyes Karny [this message]
2023-05-16 5:52 ` Viresh Kumar
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=ZGMZUhWCU18Wn/47@BLR-5CG13462PL.amd.com \
--to=wyes.karny@amd.com \
--cc=gautham.shenoy@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
all inboxes | Powered by JetHome®