1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/export.h>
3 #include <linux/preempt.h>
7 static void __rdmsr_on_cpu(void *info
)
9 struct msr_info
*rv
= info
;
11 int this_cpu
= raw_smp_processor_id();
14 reg
= per_cpu_ptr(rv
->msrs
, this_cpu
);
18 rdmsr(rv
->msr_no
, reg
->l
, reg
->h
);
21 static void __wrmsr_on_cpu(void *info
)
23 struct msr_info
*rv
= info
;
25 int this_cpu
= raw_smp_processor_id();
28 reg
= per_cpu_ptr(rv
->msrs
, this_cpu
);
32 wrmsr(rv
->msr_no
, reg
->l
, reg
->h
);
35 int rdmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
40 memset(&rv
, 0, sizeof(rv
));
43 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
49 EXPORT_SYMBOL(rdmsr_on_cpu
);
51 int rdmsrl_on_cpu(unsigned int cpu
, u32 msr_no
, u64
*q
)
56 memset(&rv
, 0, sizeof(rv
));
59 err
= smp_call_function_single(cpu
, __rdmsr_on_cpu
, &rv
, 1);
64 EXPORT_SYMBOL(rdmsrl_on_cpu
);
66 int wrmsr_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
71 memset(&rv
, 0, sizeof(rv
));
76 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
80 EXPORT_SYMBOL(wrmsr_on_cpu
);
82 int wrmsrl_on_cpu(unsigned int cpu
, u32 msr_no
, u64 q
)
87 memset(&rv
, 0, sizeof(rv
));
92 err
= smp_call_function_single(cpu
, __wrmsr_on_cpu
, &rv
, 1);
96 EXPORT_SYMBOL(wrmsrl_on_cpu
);
98 static void __rwmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
,
100 void (*msr_func
) (void *info
))
105 memset(&rv
, 0, sizeof(rv
));
110 this_cpu
= get_cpu();
112 if (cpumask_test_cpu(this_cpu
, mask
))
115 smp_call_function_many(mask
, msr_func
, &rv
, 1);
119 /* rdmsr on a bunch of CPUs
123 * @msrs: array of MSR values
126 void rdmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
128 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __rdmsr_on_cpu
);
130 EXPORT_SYMBOL(rdmsr_on_cpus
);
133 * wrmsr on a bunch of CPUs
137 * @msrs: array of MSR values
140 void wrmsr_on_cpus(const struct cpumask
*mask
, u32 msr_no
, struct msr
*msrs
)
142 __rwmsr_on_cpus(mask
, msr_no
, msrs
, __wrmsr_on_cpu
);
144 EXPORT_SYMBOL(wrmsr_on_cpus
);
146 /* These "safe" variants are slower and should be used when the target MSR
147 may not actually exist. */
148 static void __rdmsr_safe_on_cpu(void *info
)
150 struct msr_info
*rv
= info
;
152 rv
->err
= rdmsr_safe(rv
->msr_no
, &rv
->reg
.l
, &rv
->reg
.h
);
155 static void __wrmsr_safe_on_cpu(void *info
)
157 struct msr_info
*rv
= info
;
159 rv
->err
= wrmsr_safe(rv
->msr_no
, rv
->reg
.l
, rv
->reg
.h
);
162 int rdmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32
*l
, u32
*h
)
167 memset(&rv
, 0, sizeof(rv
));
170 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
174 return err
? err
: rv
.err
;
176 EXPORT_SYMBOL(rdmsr_safe_on_cpu
);
178 int wrmsr_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u32 l
, u32 h
)
183 memset(&rv
, 0, sizeof(rv
));
188 err
= smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
, &rv
, 1);
190 return err
? err
: rv
.err
;
192 EXPORT_SYMBOL(wrmsr_safe_on_cpu
);
194 int wrmsrl_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u64 q
)
199 memset(&rv
, 0, sizeof(rv
));
204 err
= smp_call_function_single(cpu
, __wrmsr_safe_on_cpu
, &rv
, 1);
206 return err
? err
: rv
.err
;
208 EXPORT_SYMBOL(wrmsrl_safe_on_cpu
);
210 int rdmsrl_safe_on_cpu(unsigned int cpu
, u32 msr_no
, u64
*q
)
215 memset(&rv
, 0, sizeof(rv
));
218 err
= smp_call_function_single(cpu
, __rdmsr_safe_on_cpu
, &rv
, 1);
221 return err
? err
: rv
.err
;
223 EXPORT_SYMBOL(rdmsrl_safe_on_cpu
);
226 * These variants are significantly slower, but allows control over
227 * the entire 32-bit GPR set.
229 static void __rdmsr_safe_regs_on_cpu(void *info
)
231 struct msr_regs_info
*rv
= info
;
233 rv
->err
= rdmsr_safe_regs(rv
->regs
);
236 static void __wrmsr_safe_regs_on_cpu(void *info
)
238 struct msr_regs_info
*rv
= info
;
240 rv
->err
= wrmsr_safe_regs(rv
->regs
);
243 int rdmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
246 struct msr_regs_info rv
;
250 err
= smp_call_function_single(cpu
, __rdmsr_safe_regs_on_cpu
, &rv
, 1);
252 return err
? err
: rv
.err
;
254 EXPORT_SYMBOL(rdmsr_safe_regs_on_cpu
);
256 int wrmsr_safe_regs_on_cpu(unsigned int cpu
, u32
*regs
)
259 struct msr_regs_info rv
;
263 err
= smp_call_function_single(cpu
, __wrmsr_safe_regs_on_cpu
, &rv
, 1);
265 return err
? err
: rv
.err
;
267 EXPORT_SYMBOL(wrmsr_safe_regs_on_cpu
);