[PATCH 2/3] x86/msr: Add wrmsrl_val_on_cpus()

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

Add a helper which writes the same MSR value on a set of CPUs.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/include/asm/msr.h | 8 ++++++++
arch/x86/lib/msr-smp.c | 15 +++++++++++++++
2 files changed, 23 insertions(+)

diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index 86f20d520a07..71393a4c2104 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -342,6 +342,7 @@ int rdmsrl_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 wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
+void wrmsrl_val_on_cpus(const struct cpumask *mask, u32 msr_no, u64 reg_val);
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 rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
@@ -379,6 +380,13 @@ static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no,
{
wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h);
}
+
+static inline void wrmsrl_val_on_cpus(const struct cpumask *mask, u32 msr_no,
+ u64 reg_val)
+{
+ wrmsrl(msr_no, reg_val);
+}
+
static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no,
u32 *l, u32 *h)
{
diff --git a/arch/x86/lib/msr-smp.c b/arch/x86/lib/msr-smp.c
index 15e1157d6b29..f67ee2fdec69 100644
--- a/arch/x86/lib/msr-smp.c
+++ b/arch/x86/lib/msr-smp.c
@@ -149,6 +149,21 @@ void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs)
}
EXPORT_SYMBOL(wrmsr_on_cpus);

+/*
+ * wrmsr a single MSR value on a bunch of CPUs. To be used for MSRs which are
+ * the same on each core.
+ *
+ * @mask: which CPUs
+ * @msr_no: which MSR
+ * @reg_val: MSR value
+ *
+ */
+void wrmsrl_val_on_cpus(const struct cpumask *mask, u32 msr_no, u64 reg_val)
+{
+ __rwmsr_on_cpus(mask, msr_no, NULL, reg_val, __wrmsr_on_cpu);
+}
+EXPORT_SYMBOL(wrmsrl_val_on_cpus);
+
struct msr_info_completion {
struct msr_info msr;
struct completion done;
--
2.21.0