Commit 5323922f authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

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: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20240304005104.513181735@linutronix.de
parent 154fcf3a
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include <uapi/asm/msr.h> #include <uapi/asm/msr.h>
#include <asm/shared/msr.h> #include <asm/shared/msr.h>
#include <linux/percpu.h>
struct msr_info { struct msr_info {
u32 msr_no; u32 msr_no;
struct msr reg; struct msr reg;
struct msr *msrs; struct msr __percpu *msrs;
int err; int err;
}; };
struct msr_regs_info { struct msr_regs_info {
...@@ -305,8 +307,8 @@ static inline int wrmsrl_safe(u32 msr, u64 val) ...@@ -305,8 +307,8 @@ static inline int wrmsrl_safe(u32 msr, u64 val)
return wrmsr_safe(msr, (u32)val, (u32)(val >> 32)); return wrmsr_safe(msr, (u32)val, (u32)(val >> 32));
} }
struct msr *msrs_alloc(void); struct msr __percpu *msrs_alloc(void);
void msrs_free(struct msr *msrs); void msrs_free(struct msr __percpu *msrs);
int msr_set_bit(u32 msr, u8 bit); int msr_set_bit(u32 msr, u8 bit);
int msr_clear_bit(u32 msr, u8 bit); int msr_clear_bit(u32 msr, u8 bit);
...@@ -315,8 +317,8 @@ int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); ...@@ -315,8 +317,8 @@ int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q); int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q);
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs);
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs);
int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
...@@ -345,14 +347,14 @@ static inline int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q) ...@@ -345,14 +347,14 @@ static inline int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
return 0; return 0;
} }
static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no, static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no,
struct msr *msrs) struct msr __percpu *msrs)
{ {
rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h)); rdmsr_on_cpu(0, msr_no, raw_cpu_ptr(&msrs->l), raw_cpu_ptr(&msrs->h));
} }
static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no, static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no,
struct msr *msrs) struct msr __percpu *msrs)
{ {
wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h); wrmsr_on_cpu(0, msr_no, raw_cpu_read(msrs->l), raw_cpu_read(msrs->h));
} }
static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no,
u32 *l, u32 *h) u32 *l, u32 *h)
......
...@@ -20,7 +20,6 @@ struct vm86; ...@@ -20,7 +20,6 @@ struct vm86;
#include <asm/page.h> #include <asm/page.h>
#include <asm/pgtable_types.h> #include <asm/pgtable_types.h>
#include <asm/percpu.h> #include <asm/percpu.h>
#include <asm/msr.h>
#include <asm/desc_defs.h> #include <asm/desc_defs.h>
#include <asm/nops.h> #include <asm/nops.h>
#include <asm/special_insns.h> #include <asm/special_insns.h>
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#ifndef _ASM_X86_TSC_H #ifndef _ASM_X86_TSC_H
#define _ASM_X86_TSC_H #define _ASM_X86_TSC_H
#include <asm/processor.h>
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
#include <asm/processor.h>
#include <asm/msr.h>
/* /*
* Standard way to access the cycle counter. * Standard way to access the cycle counter.
......
...@@ -9,10 +9,9 @@ static void __rdmsr_on_cpu(void *info) ...@@ -9,10 +9,9 @@ static void __rdmsr_on_cpu(void *info)
{ {
struct msr_info *rv = info; struct msr_info *rv = info;
struct msr *reg; struct msr *reg;
int this_cpu = raw_smp_processor_id();
if (rv->msrs) if (rv->msrs)
reg = per_cpu_ptr(rv->msrs, this_cpu); reg = this_cpu_ptr(rv->msrs);
else else
reg = &rv->reg; reg = &rv->reg;
...@@ -23,10 +22,9 @@ static void __wrmsr_on_cpu(void *info) ...@@ -23,10 +22,9 @@ static void __wrmsr_on_cpu(void *info)
{ {
struct msr_info *rv = info; struct msr_info *rv = info;
struct msr *reg; struct msr *reg;
int this_cpu = raw_smp_processor_id();
if (rv->msrs) if (rv->msrs)
reg = per_cpu_ptr(rv->msrs, this_cpu); reg = this_cpu_ptr(rv->msrs);
else else
reg = &rv->reg; reg = &rv->reg;
...@@ -97,7 +95,7 @@ int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q) ...@@ -97,7 +95,7 @@ int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
EXPORT_SYMBOL(wrmsrl_on_cpu); EXPORT_SYMBOL(wrmsrl_on_cpu);
static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no, static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
struct msr *msrs, struct msr __percpu *msrs,
void (*msr_func) (void *info)) void (*msr_func) (void *info))
{ {
struct msr_info rv; struct msr_info rv;
...@@ -124,7 +122,7 @@ static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no, ...@@ -124,7 +122,7 @@ static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
* @msrs: array of MSR values * @msrs: array of MSR values
* *
*/ */
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs) void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs)
{ {
__rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu); __rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
} }
...@@ -138,7 +136,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus); ...@@ -138,7 +136,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
* @msrs: array of MSR values * @msrs: array of MSR values
* *
*/ */
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs) void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs)
{ {
__rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu); __rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
} }
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
#include <asm/msr-trace.h> #include <asm/msr-trace.h>
struct msr *msrs_alloc(void) struct msr __percpu *msrs_alloc(void)
{ {
struct msr *msrs = NULL; struct msr __percpu *msrs = NULL;
msrs = alloc_percpu(struct msr); msrs = alloc_percpu(struct msr);
if (!msrs) { if (!msrs) {
...@@ -20,7 +20,7 @@ struct msr *msrs_alloc(void) ...@@ -20,7 +20,7 @@ struct msr *msrs_alloc(void)
} }
EXPORT_SYMBOL(msrs_alloc); EXPORT_SYMBOL(msrs_alloc);
void msrs_free(struct msr *msrs) void msrs_free(struct msr __percpu *msrs)
{ {
free_percpu(msrs); free_percpu(msrs);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment