mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kristen Carlson Accardi <kristen@linux.intel.com>
To: Chen Yu <yu.c.chen@intel.com>
Cc: rjw@rjwysocki.net, viresh.kumar@linaro.org,
	s.ikarashi@jp.fujitsu.com, rui.zhang@intel.com,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [v2] intel_pstate: Fix user input of min/max to legal policy region
Date: Wed, 9 Sep 2015 11:20:53 -0700	[thread overview]
Message-ID: <20150909112053.4123c939@kcaccard-desk.amr.corp.intel.com> (raw)
In-Reply-To: <1441794451-29979-1-git-send-email-yu.c.chen@intel.com>

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)


      parent reply	other threads:[~2015-09-09 18:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09 10:27 Chen Yu
2015-09-09 11:12 ` Seiichi Ikarashi
2015-09-09 18:20 ` Kristen Carlson Accardi [this message]

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=20150909112053.4123c939@kcaccard-desk.amr.corp.intel.com \
    --to=kristen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=s.ikarashi@jp.fujitsu.com \
    --cc=viresh.kumar@linaro.org \
    --cc=yu.c.chen@intel.com \
    /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®