Re: [PATCH] x86/cacheinfo: Don't use cpu_llc_shared_map for !CONFIG_SMP

From: Saurabh Singh Sengar
Date: Fri Aug 19 2022 - 14:01:34 EST


On Fri, Aug 19, 2022 at 07:16:13PM +0200, Borislav Petkov wrote:
> On Thu, Aug 18, 2022 at 05:29:25AM -0700, Saurabh Singh Sengar wrote:
> > Boot latest linux kernel on AMD CPU, having CONGIG_SMP=n. Once booted
> > execute lscpu (just lscpu without any argument ), this will cause
> > segfault. Please make a note issue is observed with 2.34 version
> > (default lscpu version with Ubuntu 20.04.4) of lscpu.
>
> Does that fix it?

Yes, this patch fixes this segfault.

- Saurabh

>
> ---
> diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
> index 81a0211a372d..a73bced40e24 100644
> --- a/arch/x86/include/asm/smp.h
> +++ b/arch/x86/include/asm/smp.h
> @@ -21,16 +21,6 @@ DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
> DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id);
> DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
>
> -static inline struct cpumask *cpu_llc_shared_mask(int cpu)
> -{
> - return per_cpu(cpu_llc_shared_map, cpu);
> -}
> -
> -static inline struct cpumask *cpu_l2c_shared_mask(int cpu)
> -{
> - return per_cpu(cpu_l2c_shared_map, cpu);
> -}
> -
> DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
> DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
> DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
> @@ -172,6 +162,16 @@ extern int safe_smp_processor_id(void);
> # define safe_smp_processor_id() smp_processor_id()
> #endif
>
> +static inline struct cpumask *cpu_llc_shared_mask(int cpu)
> +{
> + return per_cpu(cpu_llc_shared_map, cpu);
> +}
> +
> +static inline struct cpumask *cpu_l2c_shared_mask(int cpu)
> +{
> + return per_cpu(cpu_l2c_shared_map, cpu);
> +}
> +
> #else /* !CONFIG_SMP */
> #define wbinvd_on_cpu(cpu) wbinvd()
> static inline int wbinvd_on_all_cpus(void)
> @@ -179,6 +179,11 @@ static inline int wbinvd_on_all_cpus(void)
> wbinvd();
> return 0;
> }
> +
> +static inline struct cpumask *cpu_llc_shared_mask(int cpu)
> +{
> + return (struct cpumask *)cpumask_of(0);
> +}
> #endif /* CONFIG_SMP */
>
> extern unsigned disabled_cpus;
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette