Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/msr: Add missing __percpu annotations

Sparse rightfully complains about using a plain pointer for per CPU
accessors:

msr-smp.c:15:23: sparse: warning: incorrect type in initializer (different address spaces)
msr-smp.c:15:23: sparse: expected void const [noderef] __percpu *__vpp_verify
msr-smp.c:15:23: sparse: got struct msr *

Add __percpu annotations to the related datastructure and function
arguments to cure this. This also cures the related sparse warnings at the
callsites in drivers/edac/amd64_edac.c.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240304005104.513181735@linutronix.de

authored by

Thomas Gleixner and committed by
Ingo Molnar
5323922f 154fcf3a

+24 -24
+14 -12
arch/x86/include/asm/msr.h
··· 12 12 #include <uapi/asm/msr.h> 13 13 #include <asm/shared/msr.h> 14 14 15 + #include <linux/percpu.h> 16 + 15 17 struct msr_info { 16 - u32 msr_no; 17 - struct msr reg; 18 - struct msr *msrs; 19 - int err; 18 + u32 msr_no; 19 + struct msr reg; 20 + struct msr __percpu *msrs; 21 + int err; 20 22 }; 21 23 22 24 struct msr_regs_info { ··· 307 305 return wrmsr_safe(msr, (u32)val, (u32)(val >> 32)); 308 306 } 309 307 310 - struct msr *msrs_alloc(void); 311 - void msrs_free(struct msr *msrs); 308 + struct msr __percpu *msrs_alloc(void); 309 + void msrs_free(struct msr __percpu *msrs); 312 310 int msr_set_bit(u32 msr, u8 bit); 313 311 int msr_clear_bit(u32 msr, u8 bit); 314 312 ··· 317 315 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); 318 316 int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); 319 317 int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q); 320 - void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); 321 - void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); 318 + void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs); 319 + void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs); 322 320 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); 323 321 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); 324 322 int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); ··· 347 345 return 0; 348 346 } 349 347 static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no, 350 - struct msr *msrs) 348 + struct msr __percpu *msrs) 351 349 { 352 - rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h)); 350 + rdmsr_on_cpu(0, msr_no, raw_cpu_ptr(&msrs->l), raw_cpu_ptr(&msrs->h)); 353 351 } 354 352 static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no, 355 - struct msr *msrs) 353 + struct msr __percpu *msrs) 356 354 { 357 - wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h); 355 + wrmsr_on_cpu(0, msr_no, raw_cpu_read(msrs->l), raw_cpu_read(msrs->h)); 358 356 } 359 357 static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, 360 358 u32 *l, u32 *h)
-1
arch/x86/include/asm/processor.h
··· 20 20 #include <asm/page.h> 21 21 #include <asm/pgtable_types.h> 22 22 #include <asm/percpu.h> 23 - #include <asm/msr.h> 24 23 #include <asm/desc_defs.h> 25 24 #include <asm/nops.h> 26 25 #include <asm/special_insns.h>
+2 -1
arch/x86/include/asm/tsc.h
··· 5 5 #ifndef _ASM_X86_TSC_H 6 6 #define _ASM_X86_TSC_H 7 7 8 - #include <asm/processor.h> 9 8 #include <asm/cpufeature.h> 9 + #include <asm/processor.h> 10 + #include <asm/msr.h> 10 11 11 12 /* 12 13 * Standard way to access the cycle counter.
+5 -7
arch/x86/lib/msr-smp.c
··· 9 9 { 10 10 struct msr_info *rv = info; 11 11 struct msr *reg; 12 - int this_cpu = raw_smp_processor_id(); 13 12 14 13 if (rv->msrs) 15 - reg = per_cpu_ptr(rv->msrs, this_cpu); 14 + reg = this_cpu_ptr(rv->msrs); 16 15 else 17 16 reg = &rv->reg; 18 17 ··· 22 23 { 23 24 struct msr_info *rv = info; 24 25 struct msr *reg; 25 - int this_cpu = raw_smp_processor_id(); 26 26 27 27 if (rv->msrs) 28 - reg = per_cpu_ptr(rv->msrs, this_cpu); 28 + reg = this_cpu_ptr(rv->msrs); 29 29 else 30 30 reg = &rv->reg; 31 31 ··· 95 97 EXPORT_SYMBOL(wrmsrl_on_cpu); 96 98 97 99 static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no, 98 - struct msr *msrs, 100 + struct msr __percpu *msrs, 99 101 void (*msr_func) (void *info)) 100 102 { 101 103 struct msr_info rv; ··· 122 124 * @msrs: array of MSR values 123 125 * 124 126 */ 125 - void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs) 127 + void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs) 126 128 { 127 129 __rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu); 128 130 } ··· 136 138 * @msrs: array of MSR values 137 139 * 138 140 */ 139 - void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs) 141 + void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs) 140 142 { 141 143 __rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu); 142 144 }
+3 -3
arch/x86/lib/msr.c
··· 6 6 #define CREATE_TRACE_POINTS 7 7 #include <asm/msr-trace.h> 8 8 9 - struct msr *msrs_alloc(void) 9 + struct msr __percpu *msrs_alloc(void) 10 10 { 11 - struct msr *msrs = NULL; 11 + struct msr __percpu *msrs = NULL; 12 12 13 13 msrs = alloc_percpu(struct msr); 14 14 if (!msrs) { ··· 20 20 } 21 21 EXPORT_SYMBOL(msrs_alloc); 22 22 23 - void msrs_free(struct msr *msrs) 23 + void msrs_free(struct msr __percpu *msrs) 24 24 { 25 25 free_percpu(msrs); 26 26 }