x86/cacheinfo: Add a cpu_llc_shared_mask() UP variant

On a CONFIG_SMP=n kernel, the LLC shared mask is 0, which prevents
__cache_amd_cpumap_setup() from doing the L3 masks setup, and more
specifically from setting up the shared_cpu_map and shared_cpu_list
files in sysfs, leading to lscpu from util-linux getting confused and
segfaulting.

Add a cpu_llc_shared_mask() UP variant which returns a mask with a
single bit set, i.e., for CPU0.

Fixes: 2b83809a5e6d ("x86/cpu/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask")
Reported-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1660148115-302-1-git-send-email-ssengar@linux.microsoft.com

Changed files
+15 -10
arch
x86
include
asm
+15 -10
arch/x86/include/asm/smp.h
··· 21 21 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id); 22 22 DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number); 23 23 24 - static inline struct cpumask *cpu_llc_shared_mask(int cpu) 25 - { 26 - return per_cpu(cpu_llc_shared_map, cpu); 27 - } 28 - 29 - static inline struct cpumask *cpu_l2c_shared_mask(int cpu) 30 - { 31 - return per_cpu(cpu_l2c_shared_map, cpu); 32 - } 33 - 34 24 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); 35 25 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); 36 26 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid); ··· 162 172 # define safe_smp_processor_id() smp_processor_id() 163 173 #endif 164 174 175 + static inline struct cpumask *cpu_llc_shared_mask(int cpu) 176 + { 177 + return per_cpu(cpu_llc_shared_map, cpu); 178 + } 179 + 180 + static inline struct cpumask *cpu_l2c_shared_mask(int cpu) 181 + { 182 + return per_cpu(cpu_l2c_shared_map, cpu); 183 + } 184 + 165 185 #else /* !CONFIG_SMP */ 166 186 #define wbinvd_on_cpu(cpu) wbinvd() 167 187 static inline int wbinvd_on_all_cpus(void) 168 188 { 169 189 wbinvd(); 170 190 return 0; 191 + } 192 + 193 + static inline struct cpumask *cpu_llc_shared_mask(int cpu) 194 + { 195 + return (struct cpumask *)cpumask_of(0); 171 196 } 172 197 #endif /* CONFIG_SMP */ 173 198