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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdXPOJZJXPKbbTb9rnQ=8e1Tmj2_GCVHwSPJHrE=9+Hqhw@mail.gmail.com>
Date:   Mon, 20 Mar 2023 20:22:21 +0100
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     Rob Herring <robh@...nel.org>
Cc:     Magnus Damm <magnus.damm@...il.com>,
        Russell King <linux@...linux.org.uk>,
        linux-arm-kernel@...ts.infradead.org,
        linux-renesas-soc@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ARM: sh-mobile: Use of_cpu_node_to_id() to read CPU node 'reg'

Hi Rob,

On Sun, Mar 19, 2023 at 4:00 PM Rob Herring <robh@...nel.org> wrote:
> Replace open coded CPU nodes reading of "reg" and translation to logical
> ID with of_cpu_node_to_id().
>
> Signed-off-by: Rob Herring <robh@...nel.org>

Thanks for your patch!

> --- a/arch/arm/mach-shmobile/platsmp-apmu.c
> +++ b/arch/arm/mach-shmobile/platsmp-apmu.c
> @@ -10,6 +10,7 @@
>  #include <linux/init.h>
>  #include <linux/io.h>
>  #include <linux/ioport.h>
> +#include <linux/of.h>
>  #include <linux/of_address.h>
>  #include <linux/smp.h>
>  #include <linux/suspend.h>
> @@ -210,7 +211,6 @@ static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit))
>         struct device_node *np_apmu, *np_cpu;
>         struct resource res;
>         int bit, index;
> -       u32 id;
>
>         for_each_matching_node(np_apmu, apmu_ids) {
>                 /* only enable the cluster that includes the boot CPU */
> @@ -218,33 +218,27 @@ static void apmu_parse_dt(void (*fn)(struct resource *res, int cpu, int bit))
>
>                 for (bit = 0; bit < CONFIG_NR_CPUS; bit++) {

This loops over all CPUs....

>                         np_cpu = of_parse_phandle(np_apmu, "cpus", bit);
> -                       if (np_cpu) {
> -                               if (!of_property_read_u32(np_cpu, "reg", &id)) {
> -                                       if (id == cpu_logical_map(0)) {
> -                                               is_allowed = true;
> -                                               of_node_put(np_cpu);
> -                                               break;
> -                                       }
> -
> -                               }
> +                       if (np_cpu && of_cpu_node_to_id(np_cpu) == 0) {

As of_cpu_node_to_id() uses for_each_possible_cpu(), you're
converting an O(n) operation to O(n²).  I'm sure this can be done
more efficiently, using for_each_possible_cpu() as the outer loop?

Meh, cpu_logical_map() also loops over all CPUs, so it was already
O(n²)... Still, we should do better...

> +                               is_allowed = true;
>                                 of_node_put(np_cpu);
> +                               break;
>                         }
> +                       of_node_put(np_cpu);
>                 }
>                 if (!is_allowed)
>                         continue;
>
>                 for (bit = 0; bit < CONFIG_NR_CPUS; bit++) {
>                         np_cpu = of_parse_phandle(np_apmu, "cpus", bit);
> -                       if (np_cpu) {
> -                               if (!of_property_read_u32(np_cpu, "reg", &id)) {
> -                                       index = get_logical_index(id);
> -                                       if ((index >= 0) &&
> -                                           !of_address_to_resource(np_apmu,
> -                                                                   0, &res))
> -                                               fn(&res, index, bit);
> -                               }
> -                               of_node_put(np_cpu);
> -                       }
> +                       if (!np_cpu)
> +                               continue;
> +
> +                       index = of_cpu_node_to_id(np_cpu);

Likewise.

> +                       if ((index >= 0) &&
> +                           !of_address_to_resource(np_apmu, 0, &res))
> +                               fn(&res, index, bit);
> +
> +                       of_node_put(np_cpu);
>                 }
>         }
>  }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ