[PATCH 1/3] x86/msr: Pass a single MSR value to __rwmsr_on_cpus() too

Borislav Petkov
2020-06-10T11:00:52Z

__rwmsr_on_cpus() is the low-level worker function which is called by
the exported {rd,wr}msr_on_cpus() when an MSR is supposed to be set with
values for CPUs or an MSR is supposed to be read from CPUs into an array
of percpu variables in @msrs.

The low-level machinery supports also passing a single MSR value for the
single CPU {rd,wr}msr_on_cpu() handlers.

Pass that value to __rwmsr_on_cpus() too and enforce a mutually
exclusive either a single MSR value "XOR" an array of per-CPU MSR
values.

This is the prerequisite for supporting writing the same MSR value on
multiple CPUs.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/lib/msr-smp.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/lib/msr-smp.c b/arch/x86/lib/msr-smp.c
index fee8b9c0520c..15e1157d6b29 100644
--- a/arch/x86/lib/msr-smp.c
+++ b/arch/x86/lib/msr-smp.c
@@ -97,7 +97,7 @@ int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
EXPORT_SYMBOL(wrmsrl_on_cpu);

static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
- struct msr *msrs,
+ struct msr *msrs, u64 reg_val,
void (*msr_func) (void *info))
{
struct msr_info rv;
@@ -105,8 +105,13 @@ static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,

memset(&rv, 0, sizeof(rv));

+ /* Can't have both. */
+ if (WARN_ON(msrs && reg_val))
+ return;
+
rv.msrs = msrs;
rv.msr_no = msr_no;
+ rv.reg.q = reg_val;

this_cpu = get_cpu();

@@ -126,7 +131,7 @@ static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no,
*/
void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
{
- __rwmsr_on_cpus(mask, msr_no, msrs, __rdmsr_on_cpu);
+ __rwmsr_on_cpus(mask, msr_no, msrs, 0, __rdmsr_on_cpu);
}
EXPORT_SYMBOL(rdmsr_on_cpus);

@@ -140,7 +145,7 @@ EXPORT_SYMBOL(rdmsr_on_cpus);
*/
void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
{
- __rwmsr_on_cpus(mask, msr_no, msrs, __wrmsr_on_cpu);
+ __rwmsr_on_cpus(mask, msr_no, msrs, 0, __wrmsr_on_cpu);
}
EXPORT_SYMBOL(wrmsr_on_cpus);

--
2.21.0