All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Shivnandan Kumar <quic_kshivnan@quicinc.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	Linux PM <linux-pm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PM: QoS: Add check to make sure CPU freq is non-negative
Date: Tue, 12 Jul 2022 20:37:03 +0200	[thread overview]
Message-ID: <CAJZ5v0hX6H1Z-2bAJvV92YO95N_D=uNotVxJRcA9cmGQwsr1fQ@mail.gmail.com> (raw)
In-Reply-To: <20220623064605.2538969-1-quic_kshivnan@quicinc.com>

On Thu, Jun 23, 2022 at 8:47 AM Shivnandan Kumar
<quic_kshivnan@quicinc.com> wrote:
>
>         CPU frequency should never be non-negative.

Do you mean "always be non-negative"?

>         If some client driver calls freq_qos_update_request with some
>         value greater than INT_MAX, then it will set max CPU freq at
>         fmax but it will add plist node with some negative priority.
>         plist node has priority from INT_MIN (highest) to INT_MAX
>         (lowest). Once priority is set as negative, another client
>         will not be able to reduce max CPU frequency. Adding check
>         to make sure CPU freq is non-negative will fix this problem.
> Signed-off-by: Shivnandan Kumar <quic_kshivnan@quicinc.com>
>
> ---
>  kernel/power/qos.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/power/qos.c b/kernel/power/qos.c
> index ec7e1e85923e..41e96fe34bfd 100644
> --- a/kernel/power/qos.c
> +++ b/kernel/power/qos.c
> @@ -531,7 +531,8 @@ int freq_qos_add_request(struct freq_constraints *qos,
>  {
>         int ret;
>
> -       if (IS_ERR_OR_NULL(qos) || !req)
> +       if (IS_ERR_OR_NULL(qos) || !req || value < FREQ_QOS_MIN_DEFAULT_VALUE
> +               || value > FREQ_QOS_MAX_DEFAULT_VALUE)

Why do you check against the defaults?

>                 return -EINVAL;
>
>         if (WARN(freq_qos_request_active(req),
> @@ -563,7 +564,8 @@ EXPORT_SYMBOL_GPL(freq_qos_add_request);
>   */
>  int freq_qos_update_request(struct freq_qos_request *req, s32 new_value)
>  {
> -       if (!req)
> +       if (!req || new_value < FREQ_QOS_MIN_DEFAULT_VALUE ||
> +               new_value > FREQ_QOS_MAX_DEFAULT_VALUE)
>                 return -EINVAL;
>
>         if (WARN(!freq_qos_request_active(req),
> --

I agree that it should guard against adding negative values, but I
don't see why s32 can be greater than INT_MAX.

Also why don't you put the guard into freq_qos_apply() instead of
duplicating it in the callers of that function?

  parent reply	other threads:[~2022-07-12 18:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23  6:46 [PATCH] PM: QoS: Add check to make sure CPU freq is non-negative Shivnandan Kumar
2022-07-06  6:30 ` Shivnandan Kumar
2022-07-12 18:37 ` Rafael J. Wysocki [this message]
2022-07-13  8:37   ` Shivnandan Kumar
2022-07-13 17:50     ` Rafael J. Wysocki

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='CAJZ5v0hX6H1Z-2bAJvV92YO95N_D=uNotVxJRcA9cmGQwsr1fQ@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=quic_kshivnan@quicinc.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 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.