From: Dan Carpenter <dan.carpenter@oracle.com>
To: Giovanni Gherdovich <ggherdovich@suse.cz>
Cc: kernel-janitors@vger.kernel.org
Subject: Re: [bug report] x86, sched: Bail out of frequency invariance if turbo frequency is unknown
Date: Fri, 13 May 2022 17:05:49 +0300 [thread overview]
Message-ID: <20220513140549.GF29930@kadam> (raw)
In-Reply-To: <aed5505a1ae9ec9aab1978ad36c46b1e0acd2aeb.camel@suse.cz>
On Fri, May 13, 2022 at 03:17:24PM +0200, Giovanni Gherdovich wrote:
> On Thu, 2022-05-05 at 10:05 +0300, Dan Carpenter wrote:
> > Hello Giovanni Gherdovich,
> >
> > The patch 51beea8862a3: "x86, sched: Bail out of frequency invariance
> > if turbo frequency is unknown" from May 31, 2020, leads to the
> > following Smatch static checker warning:
> >
> > arch/x86/kernel/cpu/aperfmperf.c:274 intel_set_max_freq_ratio()
> > error: uninitialized symbol 'turbo_freq'.
> >
> > arch/x86/kernel/cpu/aperfmperf.c
> > 242 static bool __init intel_set_max_freq_ratio(void)
> > 243 {
> > 244 u64 base_freq, turbo_freq;
> > 245 u64 turbo_ratio;
> > 246
> > 247 if (slv_set_max_freq_ratio(&base_freq, &turbo_freq))
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > Imagine this fails.
> >
> > 248 goto out;
>
> I think this is a false positive of the static checker; I'll send the patch
> to initialize the variables anyway as it looks better.
>
> When slv_set_max_freq_ratio() fails, it returns false, and we move on to the
> next "if" statement. "goto out" is executed only if slv_set_max_freq_ratio()
> succeeds (returns true), and writes data in its input parameters.
>
> I give you that the code looks wrong, because apparently when people (and
> static analyzers) read that, they think "if (problem) goto error;" but this
> function is written like "if (it_works) goto the_end;".
I read this wrong. But looking at it closer, I think the static analyzer is
actually correct (definitely correct-ish for sure). Smatch is complaining about
knl_set_max_freq_ratio().
149 static bool __init knl_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq,
150 int num_delta_fratio)
151 {
152 int fratio, delta_fratio, found;
153 int err, i;
154 u64 msr;
155
156 err = rdmsrl_safe(MSR_PLATFORM_INFO, base_freq);
157 if (err)
158 return false;
159
160 *base_freq = (*base_freq >> 8) & 0xFF; /* max P state */
161
162 err = rdmsrl_safe(MSR_TURBO_RATIO_LIMIT, &msr);
163 if (err)
164 return false;
165
166 fratio = (msr >> 8) & 0xFF;
167 i = 16;
168 found = 0;
169 do {
170 if (found >= num_delta_fratio) {
171 *turbo_freq = fratio;
172 return true;
173 }
174
175 delta_fratio = (msr >> (i + 5)) & 0x7;
176
177 if (delta_fratio) {
178 found += 1;
179 fratio -= delta_fratio;
180 }
181
182 i += 8;
183 } while (i < 64);
184
185 return true;
If we reach this "return true" then turbo_freq is not set. This may not be
reachable in real life. Should it be return false?
186 }
regards,
dan carpenter
next prev parent reply other threads:[~2022-05-13 14:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 7:05 [bug report] x86, sched: Bail out of frequency invariance if turbo frequency is unknown Dan Carpenter
2022-05-13 8:15 ` Giovanni Gherdovich
2022-05-13 13:17 ` Giovanni Gherdovich
2022-05-13 14:05 ` Dan Carpenter [this message]
2022-05-13 14:40 ` Giovanni Gherdovich
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=20220513140549.GF29930@kadam \
--to=dan.carpenter@oracle.com \
--cc=ggherdovich@suse.cz \
--cc=kernel-janitors@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.