Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1221363 > unrolled thread

[PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region

Started byChen Yu <yu.c.chen@intel.com>
First post2015-09-09 12:30 +0200
Last post2015-09-09 20:30 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region Chen Yu <yu.c.chen@intel.com> - 2015-09-09 12:30 +0200
    Re: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal  policy region Seiichi Ikarashi <s.ikarashi@jp.fujitsu.com> - 2015-09-09 13:20 +0200
    Re: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal  policy region Kristen Carlson Accardi <kristen@linux.intel.com> - 2015-09-09 20:30 +0200

#1221363 — [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region

FromChen Yu <yu.c.chen@intel.com>
Date2015-09-09 12:30 +0200
Subject[PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region
Message-ID<q6KNB-i6-39@gated-at.bofh.it>
In current code, max_perf_pct might be smaller than min_perf_pct
by improper user input:

$ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
/sys/devices/system/cpu/intel_pstate/max_perf_pct:100
/sys/devices/system/cpu/intel_pstate/min_perf_pct:100

$ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct

$ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
/sys/devices/system/cpu/intel_pstate/max_perf_pct:80
/sys/devices/system/cpu/intel_pstate/min_perf_pct:100

Fix this problem by 2 steps:
1.Normalize the user input to [min_policy, max_policy].
2.Make sure max_perf_pct>=min_perf_pct, suggested by Seiichi Ikarashi.

Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
v2:
 - Add logic to ensure max_perf_pct>=min_perf_pct.
---
 drivers/cpufreq/intel_pstate.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index fcb929e..a0b935f 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -423,6 +423,8 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
 
 	limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
 	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
+	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
+	limits.max_perf_pct = max(limits.min_perf_pct, limits.max_perf_pct);
 	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
 
 	if (hwp_active)
@@ -442,6 +444,8 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
 
 	limits.min_sysfs_pct = clamp_t(int, input, 0 , 100);
 	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
+	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
+	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);
 	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
 
 	if (hwp_active)
@@ -985,12 +989,19 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 
 	limits.min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
 	limits.min_policy_pct = clamp_t(int, limits.min_policy_pct, 0 , 100);
-	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
-	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
-
 	limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
 	limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
+
+	/* Normalize user input to [min_policy_pct, max_policy_pct] */
+	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
+	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
 	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
+	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
+
+	/* Make sure min_perf_pct <= max_perf_pct */
+	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);
+
+	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
 	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
 
 	if (hwp_active)
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1221372 — Re: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region

FromSeiichi Ikarashi <s.ikarashi@jp.fujitsu.com>
Date2015-09-09 13:20 +0200
SubjectRe: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region
Message-ID<q6LzZ-1rQ-33@gated-at.bofh.it>
In reply to#1221363
Hi, Yu

On 2015-09-09 19:27, Chen Yu wrote:
> In current code, max_perf_pct might be smaller than min_perf_pct
> by improper user input:
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:100
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> $ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:80
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> Fix this problem by 2 steps:
> 1.Normalize the user input to [min_policy, max_policy].
> 2.Make sure max_perf_pct>=min_perf_pct, suggested by Seiichi Ikarashi.
> 
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> ---
> v2:
>  - Add logic to ensure max_perf_pct>=min_perf_pct.
> ---
>  drivers/cpufreq/intel_pstate.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index fcb929e..a0b935f 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -423,6 +423,8 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
> +	limits.max_perf_pct = max(limits.min_perf_pct, limits.max_perf_pct);
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -442,6 +444,8 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.min_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
> +	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);
>  	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -985,12 +989,19 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
>  
>  	limits.min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
>  	limits.min_policy_pct = clamp_t(int, limits.min_policy_pct, 0 , 100);
> -	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> -	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
> -
>  	limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
>  	limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
> +
> +	/* Normalize user input to [min_policy_pct, max_policy_pct] */
> +	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
> +
> +	/* Make sure min_perf_pct <= max_perf_pct */
> +	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);

You chose max_perf_pct prior to min_perf_pct here.
I agree.

> +
> +	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> 

I think this patch is what it should be. Good job.

Regards,
Seiichi

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1221612 — Re: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region

FromKristen Carlson Accardi <kristen@linux.intel.com>
Date2015-09-09 20:30 +0200
SubjectRe: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region
Message-ID<q6Si6-2Bs-7@gated-at.bofh.it>
In reply to#1221363
On Wed,  9 Sep 2015 18:27:31 +0800
Chen Yu <yu.c.chen@intel.com> wrote:

> In current code, max_perf_pct might be smaller than min_perf_pct
> by improper user input:
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:100
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> $ echo 80 > /sys/devices/system/cpu/intel_pstate/max_perf_pct
> 
> $ grep . /sys/devices/system/cpu/intel_pstate/m*_perf_pct
> /sys/devices/system/cpu/intel_pstate/max_perf_pct:80
> /sys/devices/system/cpu/intel_pstate/min_perf_pct:100
> 
> Fix this problem by 2 steps:
> 1.Normalize the user input to [min_policy, max_policy].
> 2.Make sure max_perf_pct>=min_perf_pct, suggested by Seiichi Ikarashi.
> 
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>

Acked-by: Kristen Carlson Accardi <kristen@linux.intel.com>
> ---
> v2:
>  - Add logic to ensure max_perf_pct>=min_perf_pct.
> ---
>  drivers/cpufreq/intel_pstate.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index fcb929e..a0b935f 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -423,6 +423,8 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.max_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
> +	limits.max_perf_pct = max(limits.min_perf_pct, limits.max_perf_pct);
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -442,6 +444,8 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
>  
>  	limits.min_sysfs_pct = clamp_t(int, input, 0 , 100);
>  	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
> +	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);
>  	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)
> @@ -985,12 +989,19 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
>  
>  	limits.min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
>  	limits.min_policy_pct = clamp_t(int, limits.min_policy_pct, 0 , 100);
> -	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> -	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
> -
>  	limits.max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
>  	limits.max_policy_pct = clamp_t(int, limits.max_policy_pct, 0 , 100);
> +
> +	/* Normalize user input to [min_policy_pct, max_policy_pct] */
> +	limits.min_perf_pct = max(limits.min_policy_pct, limits.min_sysfs_pct);
> +	limits.min_perf_pct = min(limits.max_policy_pct, limits.min_perf_pct);
>  	limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct);
> +	limits.max_perf_pct = max(limits.min_policy_pct, limits.max_perf_pct);
> +
> +	/* Make sure min_perf_pct <= max_perf_pct */
> +	limits.min_perf_pct = min(limits.max_perf_pct, limits.min_perf_pct);
> +
> +	limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100));
>  	limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100));
>  
>  	if (hwp_active)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web