Re: [PATCH v2 1/2] cacheinfo: Add arch specific early level initializer

From: Radu Rendec
Date: Thu Apr 06 2023 - 17:22:44 EST


Hello Pierre,

On Thu, 2023-04-06 at 10:17 +0200, Pierre Gondois wrote:
> [start]
> > +       unsigned int early_leaves = cache_leaves(cpu);
> >         int ret;
> >  
> >         /* Since early initialization/allocation of the cacheinfo is allowed
> >          * via fetch_cache_info() and this also gets called as CPU hotplug
> >          * callbacks via cacheinfo_cpu_online, the init/alloc can be skipped
> >          * as it will happen only once (the cacheinfo memory is never freed).
> > -        * Just populate the cacheinfo.
> > +        * Just populate the cacheinfo. However, if the cacheinfo has been
> > +        * allocated early through the arch-specific early_cache_level() call,
> > +        * there is a chance the info is wrong (this can happen on arm64). In
> > +        * that case, call init_cache_level() anyway to give the arch-specific
> > +        * code a chance to make things right.
> >          */
> > -       if (per_cpu_cacheinfo(cpu))
> > +       if (per_cpu_cacheinfo(cpu) && !ci_cacheinfo(cpu)->early_arch_info)
> >                 goto populate_leaves;
> >  
> >         if (init_cache_level(cpu) || !cache_leaves(cpu))
> >                 return -ENOENT;
> >  
> > +       if (cache_leaves(cpu) <= early_leaves)
> > +               goto populate_leaves;
> > +
> > +       kfree(per_cpu_cacheinfo(cpu))
> >
> >         ret = allocate_cache_info(cpu);
> >         if (ret)
> >                 return ret;
> [stop]
>
> Maybe this would be the occasion to put the code between the start/stop in a separate
> function and remove the 'populate_leaves' label. The code seems correct, but it was
> already a bit complex to read before the patch.

Yes, that makes sense. I will address this (and your other comment
about the braces) and post v3 shortly. Thanks for reviewing the patch
and for the feedback!

After I had sent v2, I realized there was something missing from that
code between start/stop. I think we should also set the early_arch_info
flag back to false to prevent another detection/reallocation in case
detect_cache_attributes() is called again (I'm thinking CPU hotplug).
I will address this as well in v3.

Best regards,
Radu