* [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM @ 2022-05-20 16:10 Giovanni Gherdovich 2022-05-20 16:10 ` [PATCH 2/2] x86: fix platform info detection in frequency invariance Giovanni Gherdovich 2022-05-21 10:02 ` [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Peter Zijlstra 0 siblings, 2 replies; 6+ messages in thread From: Giovanni Gherdovich @ 2022-05-20 16:10 UTC (permalink / raw) To: Borislav Petkov, Ingo Molnar, Peter Zijlstra, Dave Hansen, Thomas Gleixner Cc: Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel, Giovanni Gherdovich knl_set_max_freq_ratio() should return true on success and false otherwise. If the last line of the function body is reached, it means no appropriate value for turbo_freq was found: the setup is unsuccessful and it should return false. Fixes: 8bea0dfb4a82 ("x86, sched: Add support for frequency invariance on XEON_PHI_KNL/KNM") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Giovanni Gherdovich <ggherdovich@suse.cz> --- arch/x86/kernel/smpboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 2ef14772dc04..225a3c31297c 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1985,7 +1985,7 @@ static bool knl_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq, i += 8; } while (i < 64); - return true; + return false; } static bool skx_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq, int size) -- 2.31.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] x86: fix platform info detection in frequency invariance 2022-05-20 16:10 [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Giovanni Gherdovich @ 2022-05-20 16:10 ` Giovanni Gherdovich 2022-05-20 16:44 ` Dave Hansen 2022-05-21 10:02 ` [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Peter Zijlstra 1 sibling, 1 reply; 6+ messages in thread From: Giovanni Gherdovich @ 2022-05-20 16:10 UTC (permalink / raw) To: Borislav Petkov, Ingo Molnar, Peter Zijlstra, Dave Hansen, Thomas Gleixner Cc: Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel, Giovanni Gherdovich Once the microarchitecture is recognized (via x86_match_cpu()), a failure in setting base_freq/turbo_freq should result in bailing out from frequency invariance, not in trying the next microarchitecture. This is because the call to core_set_max_freq_ratio() isn't guarded by x86_match_cpu(). The call to core_set_max_freq_ratio() should happen if no more specific microarch matched, but not in case of prior errors. Initializing base_freq=0 and turbo_freq=0 gives a mean for later code to check if setup failed. Fixes: db441bd9f630 ("x86, sched: Move check for CPU type to caller function") Signed-off-by: Giovanni Gherdovich <ggherdovich@suse.cz> --- arch/x86/kernel/smpboot.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 225a3c31297c..d0a692ea8294 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -2044,23 +2044,26 @@ static bool core_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq) static bool intel_set_max_freq_ratio(void) { - u64 base_freq, turbo_freq; + u64 base_freq = 0, turbo_freq = 0; u64 turbo_ratio; if (slv_set_max_freq_ratio(&base_freq, &turbo_freq)) goto out; - if (x86_match_cpu(has_glm_turbo_ratio_limits) && - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) + if (x86_match_cpu(has_glm_turbo_ratio_limits)) { + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1); goto out; + } - if (x86_match_cpu(has_knl_turbo_ratio_limits) && - knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) + if (x86_match_cpu(has_knl_turbo_ratio_limits)) { + knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1); goto out; + } - if (x86_match_cpu(has_skx_turbo_ratio_limits) && - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4)) + if (x86_match_cpu(has_skx_turbo_ratio_limits)) { + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4); goto out; + } if (core_set_max_freq_ratio(&base_freq, &turbo_freq)) goto out; -- 2.31.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] x86: fix platform info detection in frequency invariance 2022-05-20 16:10 ` [PATCH 2/2] x86: fix platform info detection in frequency invariance Giovanni Gherdovich @ 2022-05-20 16:44 ` Dave Hansen 2022-05-23 9:56 ` Giovanni Gherdovich 0 siblings, 1 reply; 6+ messages in thread From: Dave Hansen @ 2022-05-20 16:44 UTC (permalink / raw) To: Giovanni Gherdovich, Borislav Petkov, Ingo Molnar, Peter Zijlstra, Dave Hansen, Thomas Gleixner Cc: Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel On 5/20/22 09:10, Giovanni Gherdovich wrote: > if (slv_set_max_freq_ratio(&base_freq, &turbo_freq)) > goto out; > > - if (x86_match_cpu(has_glm_turbo_ratio_limits) && > - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) > + if (x86_match_cpu(has_glm_turbo_ratio_limits)) { > + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1); > goto out; > + } > > - if (x86_match_cpu(has_knl_turbo_ratio_limits) && > - knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) > + if (x86_match_cpu(has_knl_turbo_ratio_limits)) { > + knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1); > goto out; > + } > > - if (x86_match_cpu(has_skx_turbo_ratio_limits) && > - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4)) > + if (x86_match_cpu(has_skx_turbo_ratio_limits)) { > + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4); > goto out; > + } > > if (core_set_max_freq_ratio(&base_freq, &turbo_freq)) > goto out; But didn't the last patch in the series carefully change the return value for knl_set_max_freq_ratio()? Now, the only call site is ignoring the return value? That seems odd. Also, this is a mess. These constructs: static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = { X86_MATCH(XEON_PHI_KNL), X86_MATCH(XEON_PHI_KNM), {} }; static const struct x86_cpu_id has_skx_turbo_ratio_limits[] = { X86_MATCH(SKYLAKE_X), {} }; static const struct x86_cpu_id has_glm_turbo_ratio_limits[] = { X86_MATCH(ATOM_GOLDMONT), X86_MATCH(ATOM_GOLDMONT_D), X86_MATCH(ATOM_GOLDMONT_PLUS), {} }; are rather goofy. A single array like rapl_ids[] that points to the handler function would do us a lot more good here, say: static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = { X86_MATCH(XEON_PHI_KNL, &knl_set_max_freq_ratio), X86_MATCH(XEON_PHI_KNM, &knl_set_max_freq_ratio), X86_MATCH(SKYLAKE_X, &skx_set_max_freq_ratio), X86_MATCH(ATOM_GOLDMONT, &skx_set_max_freq_ratio), X86_MATCH(ATOM_GOLDMONT_D, &skx_set_max_freq_ratio), X86_MATCH(ATOM_GOLDMONT_PLUS, &skx_set_max_freq_ratio), X86_MATCH(ANY, &core_set_max_freq_ratio), {} }; That would get rid of all the goofy gotos and actually puts all the logic in one place. BTW, I'm not 100% sure about the 'ANY' line. I think that's how those work, but please double-check me on it. While it's generally best to keep bug fixes to a minimum, I think this one is worth a bit of a cleanup because it will remove a bunch of spaghetti. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] x86: fix platform info detection in frequency invariance 2022-05-20 16:44 ` Dave Hansen @ 2022-05-23 9:56 ` Giovanni Gherdovich 0 siblings, 0 replies; 6+ messages in thread From: Giovanni Gherdovich @ 2022-05-23 9:56 UTC (permalink / raw) To: Dave Hansen, Borislav Petkov, Ingo Molnar, Peter Zijlstra, Dave Hansen, Thomas Gleixner Cc: Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel On Fri, 2022-05-20 at 09:44 -0700, Dave Hansen wrote: > On 5/20/22 09:10, Giovanni Gherdovich wrote: > > if (slv_set_max_freq_ratio(&base_freq, &turbo_freq)) > > goto out; > > > > - if (x86_match_cpu(has_glm_turbo_ratio_limits) && > > - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) > > + if (x86_match_cpu(has_glm_turbo_ratio_limits)) { > > + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 1); > > goto out; > > + } > > > > - if (x86_match_cpu(has_knl_turbo_ratio_limits) && > > - knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1)) > > + if (x86_match_cpu(has_knl_turbo_ratio_limits)) { > > + knl_set_max_freq_ratio(&base_freq, &turbo_freq, 1); > > goto out; > > + } > > > > - if (x86_match_cpu(has_skx_turbo_ratio_limits) && > > - skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4)) > > + if (x86_match_cpu(has_skx_turbo_ratio_limits)) { > > + skx_set_max_freq_ratio(&base_freq, &turbo_freq, 4); > > goto out; > > + } > > > > if (core_set_max_freq_ratio(&base_freq, &turbo_freq)) > > goto out; > > But didn't the last patch in the series carefully change the return > value for knl_set_max_freq_ratio()? Now, the only call site is ignoring > the return value? That seems odd. Thanks for having a look! You're right. I need to either check these return values, or not have them at all. > > Also, this is a mess. These constructs: > > static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = { > X86_MATCH(XEON_PHI_KNL), > X86_MATCH(XEON_PHI_KNM), > {} > }; > > static const struct x86_cpu_id has_skx_turbo_ratio_limits[] = { > X86_MATCH(SKYLAKE_X), > {} > }; > > static const struct x86_cpu_id has_glm_turbo_ratio_limits[] = { > X86_MATCH(ATOM_GOLDMONT), > X86_MATCH(ATOM_GOLDMONT_D), > X86_MATCH(ATOM_GOLDMONT_PLUS), > {} > }; > > are rather goofy. A single array like rapl_ids[] that points to the > handler function would do us a lot more good here, say: > > static const struct x86_cpu_id has_knl_turbo_ratio_limits[] = { > X86_MATCH(XEON_PHI_KNL, &knl_set_max_freq_ratio), > X86_MATCH(XEON_PHI_KNM, &knl_set_max_freq_ratio), > X86_MATCH(SKYLAKE_X, &skx_set_max_freq_ratio), > X86_MATCH(ATOM_GOLDMONT, &skx_set_max_freq_ratio), > X86_MATCH(ATOM_GOLDMONT_D, &skx_set_max_freq_ratio), > X86_MATCH(ATOM_GOLDMONT_PLUS, &skx_set_max_freq_ratio), > X86_MATCH(ANY, &core_set_max_freq_ratio), > {} > }; > > That would get rid of all the goofy gotos and actually puts all the > logic in one place. BTW, I'm not 100% sure about the 'ANY' line. I > think that's how those work, but please double-check me on it. That's good advice. I'll do that consolidation. > > While it's generally best to keep bug fixes to a minimum, I think this > one is worth a bit of a cleanup because it will remove a bunch of spaghetti. Thanks, Giovanni ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM 2022-05-20 16:10 [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Giovanni Gherdovich 2022-05-20 16:10 ` [PATCH 2/2] x86: fix platform info detection in frequency invariance Giovanni Gherdovich @ 2022-05-21 10:02 ` Peter Zijlstra 2022-05-23 9:57 ` Giovanni Gherdovich 1 sibling, 1 reply; 6+ messages in thread From: Peter Zijlstra @ 2022-05-21 10:02 UTC (permalink / raw) To: Giovanni Gherdovich Cc: Borislav Petkov, Ingo Molnar, Dave Hansen, Thomas Gleixner, Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel On Fri, May 20, 2022 at 06:10:21PM +0200, Giovanni Gherdovich wrote: > knl_set_max_freq_ratio() should return true on success and false > otherwise. If the last line of the function body is reached, it means no > appropriate value for turbo_freq was found: the setup is unsuccessful and > it should return false. > > Fixes: 8bea0dfb4a82 ("x86, sched: Add support for frequency invariance on XEON_PHI_KNL/KNM") > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > Signed-off-by: Giovanni Gherdovich <ggherdovich@suse.cz> > --- > arch/x86/kernel/smpboot.c | 2 +- You seems to have missed all that code moved in tip. This no longer applies. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM 2022-05-21 10:02 ` [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Peter Zijlstra @ 2022-05-23 9:57 ` Giovanni Gherdovich 0 siblings, 0 replies; 6+ messages in thread From: Giovanni Gherdovich @ 2022-05-23 9:57 UTC (permalink / raw) To: Peter Zijlstra Cc: Borislav Petkov, Ingo Molnar, Dave Hansen, Thomas Gleixner, Rafael J . Wysocki, Dan Carpenter, Srinivas Pandruvada, x86, linux-kernel On Sat, 2022-05-21 at 12:02 +0200, Peter Zijlstra wrote: > On Fri, May 20, 2022 at 06:10:21PM +0200, Giovanni Gherdovich wrote: > > knl_set_max_freq_ratio() should return true on success and false > > otherwise. If the last line of the function body is reached, it means no > > appropriate value for turbo_freq was found: the setup is unsuccessful and > > it should return false. > > > > Fixes: 8bea0dfb4a82 ("x86, sched: Add support for frequency invariance on XEON_PHI_KNL/KNM") > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > > Signed-off-by: Giovanni Gherdovich <ggherdovich@suse.cz> > > --- > > arch/x86/kernel/smpboot.c | 2 +- > > You seems to have missed all that code moved in tip. This no longer > applies. Right. I'll rebase and resend. Plus, as per Dave Hansen's comments on the other patch, I need to have a second look at it. Giovanni ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-23 9:57 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-05-20 16:10 [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Giovanni Gherdovich 2022-05-20 16:10 ` [PATCH 2/2] x86: fix platform info detection in frequency invariance Giovanni Gherdovich 2022-05-20 16:44 ` Dave Hansen 2022-05-23 9:56 ` Giovanni Gherdovich 2022-05-21 10:02 ` [PATCH 1/2] x86: Fix return value in frequency invariance setup for XEON_PHI_KNL/KNM Peter Zijlstra 2022-05-23 9:57 ` Giovanni Gherdovich
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).