Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] cpufreq: Limit resolving a frequency to policy min/max
@ 2024-02-22  8:35 Shivnandan Kumar
  2024-02-22  8:37 ` kernel test robot
  2024-02-22 19:22 ` Rafael J. Wysocki
  0 siblings, 2 replies; 4+ messages in thread
From: Shivnandan Kumar @ 2024-02-22  8:35 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar
  Cc: linux-pm, linux-kernel, kernel, quic_pkondeti, quic_namajain,
	stable, Shivnandan Kumar

Resolving a frequency to an efficient one should not transgress policy->max
(which can be set for thermal reason) and policy->min. Currently there is
possibility where scaling_cur_freq can exceed scaling_max_freq when
scaling_max_freq is inefficient frequency. Add additional check to ensure
that resolving a frequency will respect policy->min/max.

Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E")
Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
---
 include/linux/cpufreq.h | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index afda5f24d3dd..42d98b576a36 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
 						   efficiencies);
 }
 
+static inline bool cpufreq_table_index_is_in_limits(struct cpufreq_policy *policy,
+						    int idx)
+{
+	unsigned int freq;
+
+	if (idx < 0)
+		return false;
+
+	freq = policy->freq_table[idx].frequency;
+
+	return (freq == clamp_val(freq, policy->min, policy->max));
+}
+
 static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
 						 unsigned int target_freq,
 						 unsigned int relation)
@@ -1054,7 +1067,10 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
 		return 0;
 	}
 
-	if (idx < 0 && efficiencies) {
+	/*
+	 * Limit frequency index to honor policy->min/max
+	 */
+	if (!cpufreq_table_index_is_in_limits(policy, idx) && efficiencies) {
 		efficiencies = false;
 		goto retry;
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: Limit resolving a frequency to policy min/max
  2024-02-22  8:35 [PATCH] cpufreq: Limit resolving a frequency to policy min/max Shivnandan Kumar
@ 2024-02-22  8:37 ` kernel test robot
  2024-02-22 19:22 ` Rafael J. Wysocki
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2024-02-22  8:37 UTC (permalink / raw)
  To: Shivnandan Kumar; +Cc: stable, oe-kbuild-all

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: stable@vger.kernel.org" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH] cpufreq: Limit resolving a frequency to policy min/max
Link: https://lore.kernel.org/stable/20240222083515.1065025-1-quic_kshivnan%40quicinc.com

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: Limit resolving a frequency to policy min/max
  2024-02-22  8:35 [PATCH] cpufreq: Limit resolving a frequency to policy min/max Shivnandan Kumar
  2024-02-22  8:37 ` kernel test robot
@ 2024-02-22 19:22 ` Rafael J. Wysocki
  2024-02-24 15:23   ` Shivnandan Kumar
  1 sibling, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2024-02-22 19:22 UTC (permalink / raw)
  To: Shivnandan Kumar
  Cc: Rafael J . Wysocki, Viresh Kumar, linux-pm, linux-kernel, kernel,
	quic_pkondeti, quic_namajain, stable

On Thu, Feb 22, 2024 at 9:35 AM Shivnandan Kumar
<quic_kshivnan@quicinc.com> wrote:
>
> Resolving a frequency to an efficient one should not transgress policy->max
> (which can be set for thermal reason) and policy->min. Currently there is
> possibility where scaling_cur_freq can exceed scaling_max_freq when
> scaling_max_freq is inefficient frequency. Add additional check to ensure
> that resolving a frequency will respect policy->min/max.
>
> Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E")
> Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
> ---
>  include/linux/cpufreq.h | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index afda5f24d3dd..42d98b576a36 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
>                                                    efficiencies);
>  }
>
> +static inline bool cpufreq_table_index_is_in_limits(struct cpufreq_policy *policy,
> +                                                   int idx)

This is not really about the index only, but about the frequency at
that index too, so I'd call the function differently.

> +{
> +       unsigned int freq;
> +
> +       if (idx < 0)
> +               return false;
> +
> +       freq = policy->freq_table[idx].frequency;
> +
> +       return (freq == clamp_val(freq, policy->min, policy->max));

Redundant outer parens.

> +}
> +
>  static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
>                                                  unsigned int target_freq,
>                                                  unsigned int relation)
> @@ -1054,7 +1067,10 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
>                 return 0;
>         }
>
> -       if (idx < 0 && efficiencies) {
> +       /*
> +        * Limit frequency index to honor policy->min/max
> +        */

This comment need not be multi-line.

> +       if (!cpufreq_table_index_is_in_limits(policy, idx) && efficiencies) {
>                 efficiencies = false;
>                 goto retry;
>         }
> --

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq: Limit resolving a frequency to policy min/max
  2024-02-22 19:22 ` Rafael J. Wysocki
@ 2024-02-24 15:23   ` Shivnandan Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Shivnandan Kumar @ 2024-02-24 15:23 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, linux-kernel, kernel, quic_pkondeti,
	quic_namajain, stable, quic_rgottimu

Hi Rafael,

Thanks for reviewing the change.

On 2/23/2024 12:52 AM, Rafael J. Wysocki wrote:
> On Thu, Feb 22, 2024 at 9:35 AM Shivnandan Kumar
> <quic_kshivnan@quicinc.com> wrote:
>>
>> Resolving a frequency to an efficient one should not transgress policy->max
>> (which can be set for thermal reason) and policy->min. Currently there is
>> possibility where scaling_cur_freq can exceed scaling_max_freq when
>> scaling_max_freq is inefficient frequency. Add additional check to ensure
>> that resolving a frequency will respect policy->min/max.
>>
>> Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E")
>> Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
>> ---
>>   include/linux/cpufreq.h | 18 +++++++++++++++++-
>>   1 file changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
>> index afda5f24d3dd..42d98b576a36 100644
>> --- a/include/linux/cpufreq.h
>> +++ b/include/linux/cpufreq.h
>> @@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy,
>>                                                     efficiencies);
>>   }
>>
>> +static inline bool cpufreq_table_index_is_in_limits(struct cpufreq_policy *policy,
>> +                                                   int idx)
> 
> This is not really about the index only, but about the frequency at
> that index too, so I'd call the function differently.
> 

ACK

>> +{
>> +       unsigned int freq;
>> +
>> +       if (idx < 0)
>> +               return false;
>> +
>> +       freq = policy->freq_table[idx].frequency;
>> +
>> +       return (freq == clamp_val(freq, policy->min, policy->max));
> 
> Redundant outer parens.
> 

ACK


>> +}
>> +
>>   static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
>>                                                   unsigned int target_freq,
>>                                                   unsigned int relation)
>> @@ -1054,7 +1067,10 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
>>                  return 0;
>>          }
>>
>> -       if (idx < 0 && efficiencies) {
>> +       /*
>> +        * Limit frequency index to honor policy->min/max
>> +        */
> 
> This comment need not be multi-line.
> 

ACK
I will make the changes in next patch set.

Thanks
Shivnandan

>> +       if (!cpufreq_table_index_is_in_limits(policy, idx) && efficiencies) {
>>                  efficiencies = false;
>>                  goto retry;
>>          }
>> --
> 
> Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-24 15:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22  8:35 [PATCH] cpufreq: Limit resolving a frequency to policy min/max Shivnandan Kumar
2024-02-22  8:37 ` kernel test robot
2024-02-22 19:22 ` Rafael J. Wysocki
2024-02-24 15:23   ` Shivnandan Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox