lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJZ5v0jcsYnKW=WwXs7tvd-dy9vp_pCT2KDWOEsTELUJonmYYQ@mail.gmail.com>
Date: Thu, 24 Oct 2024 17:38:29 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: liwei <liwei728@...wei.com>
Cc: rafael@...nel.org, lenb@...nel.org, viresh.kumar@...aro.org, 
	Pierre.Gondois@....com, vincent.guittot@...aro.org, mingo@...nel.org, 
	linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org, 
	bobo.shaobowang@...wei.com
Subject: Re: [PATCH v3] cpufreq/cppc: fix perf_to_khz/khz_to_perf conversion exception

On Thu, Oct 24, 2024 at 4:16 AM liwei <liwei728@...wei.com> wrote:
>
> When the nominal_freq recorded by the kernel is equal to the lowest_freq,
> and the frequency adjustment operation is triggered externally, there is
> a logic error in cppc_perf_to_khz()/cppc_khz_to_perf(), resulting in perf
> and khz conversion errors.
>
> Fix this by adding the branch processing logic when nominal_freq is equal
> to lowest_freq.
>
> Fixes: ec1c7ad47664 ("cpufreq: CPPC: Fix performance/frequency conversion")
> Signed-off-by: liwei <liwei728@...wei.com>
> Acked-by: Viresh Kumar <viresh.kumar@...aro.org>
> ---
> v2:
>     - Fix similar issue in cppc_khz_to_perf()
> ---
> v3:
>     - Add acked-by tag
> ---
>  drivers/acpi/cppc_acpi.c | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index b73b3aa92f3f..c3fc2c05d868 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -1916,9 +1916,15 @@ unsigned int cppc_perf_to_khz(struct cppc_perf_caps *caps, unsigned int perf)
>         u64 mul, div;
>
>         if (caps->lowest_freq && caps->nominal_freq) {
> -               mul = caps->nominal_freq - caps->lowest_freq;
> +               /* Avoid special case when nominal_freq is equal to lowest_freq */
> +               if (caps->lowest_freq == caps->nominal_freq) {
> +                       mul = caps->nominal_freq;
> +                       div = caps->nominal_perf;
> +               } else {
> +                       mul = caps->nominal_freq - caps->lowest_freq;
> +                       div = caps->nominal_perf - caps->lowest_perf;
> +               }
>                 mul *= KHZ_PER_MHZ;
> -               div = caps->nominal_perf - caps->lowest_perf;
>                 offset = caps->nominal_freq * KHZ_PER_MHZ -
>                          div64_u64(caps->nominal_perf * mul, div);
>         } else {
> @@ -1939,11 +1945,17 @@ unsigned int cppc_khz_to_perf(struct cppc_perf_caps *caps, unsigned int freq)
>  {
>         s64 retval, offset = 0;
>         static u64 max_khz;
> -       u64  mul, div;
> +       u64 mul, div;
>
>         if (caps->lowest_freq && caps->nominal_freq) {
> -               mul = caps->nominal_perf - caps->lowest_perf;
> -               div = caps->nominal_freq - caps->lowest_freq;
> +               /* Avoid special case when nominal_freq is equal to lowest_freq */
> +               if (caps->lowest_freq == caps->nominal_freq) {
> +                       mul = caps->nominal_perf;
> +                       div = caps->nominal_freq;
> +               } else {
> +                       mul = caps->nominal_perf - caps->lowest_perf;
> +                       div = caps->nominal_freq - caps->lowest_freq;
> +               }
>                 /*
>                  * We don't need to convert to kHz for computing offset and can
>                  * directly use nominal_freq and lowest_freq as the div64_u64
> --

Applied as 6.12-rc material, thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ