Re: [PATCH v5 1/5] x86/cacheinfo: move shared cache map definitions

From: Ingo Molnar
Date: Tue Aug 02 2022 - 07:13:16 EST



* Sander Vanheule <sander@xxxxxxxxxxxxx> wrote:

> The maps to keep track of shared caches between CPUs on SMP systems are
> declared in asm/smp.h, among them specifically cpu_llc_shared_map. These
> maps are externally defined in cpu/smpboot.c. The latter is only compiled
> on CONFIG_SMP=y, which means the declared extern symbols from asm/smp.h do
> not have a corresponding definition on uniprocessor builds.
>
> The inline cpu_llc_shared_mask() function from asm/smp.h refers to the map
> declaration mentioned above. This function is referenced in cacheinfo.c
> inside for_each_cpu() loop macros, to provide cpumask for the loop. On
> uniprocessor builds, the symbol for the cpu_llc_shared_map does not exist.
> However, the current implementation of for_each_cpu() also (wrongly)
> ignores the provided mask.
>
> By sheer luck, the compiler thus optimises out this unused reference to
> cpu_llc_shared_map, and the linker therefore does not require the
> cpu_llc_shared_mask to actually exist on uniprocessor builds. Only on SMP
> bulids does smpboot.o exist to provide the required symbols.
>
> To no longer rely on compiler optimisations for successful uniprocessor
> builds, move the definitions of cpu_llc_shared_map and cpu_l2c_shared_map
> from smpboot.c to cacheinfo.c.
>
> Signed-off-by: Sander Vanheule <sander@xxxxxxxxxxxxx>
> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Cc: Marco Elver <elver@xxxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
> Cc: Yury Norov <yury.norov@xxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> ---
> Changes since v3:
> - New patch
>
> arch/x86/kernel/cpu/cacheinfo.c | 6 ++++++
> arch/x86/kernel/smpboot.c | 4 ----
> 2 files changed, 6 insertions(+), 4 deletions(-)

Reviewed-by: Ingo Molnar <mingo@xxxxxxxxxx>

I'm also fine with you guys carrying this in the bitmap tree - the x86
impact is incidental.

Thanks,

Ingo