On new microcode write, check whether IBRS
is present by rescanning IBRS feature.

Signed-off-by: Tim Chen <tim.c.c...@linux.intel.com>
---
 arch/x86/include/asm/spec_ctrl.h     |  1 +
 arch/x86/kernel/cpu/microcode/core.c |  4 ++++
 arch/x86/kernel/cpu/spec_ctrl.c      | 18 ++++++++++--------
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h
index 62c5dc8..be08ae7 100644
--- a/arch/x86/include/asm/spec_ctrl.h
+++ b/arch/x86/include/asm/spec_ctrl.h
@@ -8,6 +8,7 @@
 #include <asm/microcode.h>
 
 void scan_spec_ctrl_feature(struct cpuinfo_x86 *c);
+void rescan_spec_ctrl_feature(struct cpuinfo_x86 *c);
 bool ibrs_inuse(void);
 
 extern unsigned int dynamic_ibrs;
diff --git a/arch/x86/kernel/cpu/microcode/core.c 
b/arch/x86/kernel/cpu/microcode/core.c
index c4fa4a8..848c3e9 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -40,6 +40,7 @@
 #include <asm/processor.h>
 #include <asm/cmdline.h>
 #include <asm/setup.h>
+#include <asm/spec_ctrl.h>
 
 #define DRIVER_VERSION "2.2"
 
@@ -444,6 +445,9 @@ static ssize_t microcode_write(struct file *file, const 
char __user *buf,
        if (ret > 0)
                perf_check_microcode();
 
+       /* check spec_ctrl capabilities */
+       rescan_spec_ctrl_feature(&boot_cpu_data);
+
        mutex_unlock(&microcode_mutex);
        put_online_cpus();
 
diff --git a/arch/x86/kernel/cpu/spec_ctrl.c b/arch/x86/kernel/cpu/spec_ctrl.c
index 1641bec..28107a2 100644
--- a/arch/x86/kernel/cpu/spec_ctrl.c
+++ b/arch/x86/kernel/cpu/spec_ctrl.c
@@ -24,13 +24,18 @@ static bool ibrs_admin_disabled;
 /* mutex to serialize IBRS control changes */
 DEFINE_MUTEX(spec_ctrl_mutex);
 
+static inline void set_ibrs_feature(void)
+{
+       if (!ibrs_admin_disabled) {
+               dynamic_ibrs = 1;
+               ibrs_enabled = IBRS_ENABLED;
+       }
+}
+
 void scan_spec_ctrl_feature(struct cpuinfo_x86 *c)
 {
        if ((!c->cpu_index) && (boot_cpu_has(X86_FEATURE_SPEC_CTRL))) {
-               if (!ibrs_admin_disabled) {
-                       dynamic_ibrs = 1;
-                       ibrs_enabled = IBRS_ENABLED;
-               }
+               set_ibrs_feature();
        }
 }
 EXPORT_SYMBOL_GPL(scan_spec_ctrl_feature);
@@ -43,10 +48,7 @@ void rescan_spec_ctrl_feature(struct cpuinfo_x86 *c)
 {
        mutex_lock(&spec_ctrl_mutex);
        if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
-               if (!ibrs_admin_disabled) {
-                       dynamic_ibrs = 1;
-                       ibrs_enabled = IBRS_ENABLED;
-               }
+               set_ibrs_feature();
        }
        mutex_unlock(&spec_ctrl_mutex);
 }
-- 
2.9.4

Reply via email to