]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
x86: Use better #define for FEATURE_ENABLE_IBRS and 0
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 5 Jan 2018 03:34:14 +0000 (22:34 -0500)
committerKirtikar Kashyap <kirtikar.kashyap@oracle.com>
Fri, 12 Jan 2018 18:20:12 +0000 (10:20 -0800)
Upstream patches use:
 SPEC_CTRL_FEATURE_DISABLE_IBRS for 0
 SPEC_CTRL_FEATURE_ENABLE_IBRS for  1

Lets use those fancy names so that it is easier to look
in the code and compare to upstream.

Orabug: 27344012
CVE: CVE-2017-5715

Reviewed-by: Todd Vierling <todd.vierling@oracle.com>
Acked-by: John Haxby <john.haxby@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Kirtikar Kashyap <kirtikar.kashyap@oracle.com>
arch/x86/include/asm/mwait.h
arch/x86/include/asm/spec_ctrl.h
arch/x86/include/uapi/asm/msr-index.h
arch/x86/kernel/process.c
arch/x86/kernel/smpboot.c
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
include/linux/smp.h
kernel/sysctl.c

index 72f8fcd65ec17bc49d8fedb212d8b55317e7d07c..7d1df6d36eab4c8b31077c81d8b5d8c9033b2a46 100644 (file)
@@ -60,14 +60,14 @@ static inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
                }
 
                if (ibrs_inuse)
-                       native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+                       native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
 
                __monitor((void *)&current_thread_info()->flags, 0, 0);
                if (!need_resched())
                        __mwait(eax, ecx);
 
                if (ibrs_inuse)
-                       native_wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+                       native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
        }
        current_clr_polling();
 }
index 5204336841a173c2713639032919543c2d930a39..d4df538ce72da9480512d9b5b0596f75b799540e 100644 (file)
@@ -21,7 +21,7 @@
        pushq %rdx;                             \
        movl $MSR_IA32_SPEC_CTRL, %ecx;         \
        movl $0, %edx;                          \
-       movl $FEATURE_ENABLE_IBRS, %eax;        \
+       movl $SPEC_CTRL_FEATURE_ENABLE_IBRS, %eax;      \
        wrmsr;                                  \
        popq %rdx;                              \
        popq %rcx;                              \
@@ -29,7 +29,7 @@
 #define __ASM_ENABLE_IBRS_CLOBBER              \
        movl $MSR_IA32_SPEC_CTRL, %ecx;         \
        movl $0, %edx;                          \
-       movl $FEATURE_ENABLE_IBRS, %eax;        \
+       movl $SPEC_CTRL_FEATURE_ENABLE_IBRS, %eax;      \
        wrmsr;
 #define __ASM_DISABLE_IBRS                     \
        pushq %rax;                             \
@@ -147,7 +147,7 @@ ALTERNATIVE "", __stringify(__ASM_ENABLE_IBRS), X86_FEATURE_SPEC_CTRL
        movl    %eax, \save_reg
 
        movl    $0, %edx
-       movl    $FEATURE_ENABLE_IBRS, %eax
+       movl    $SPEC_CTRL_FEATURE_ENABLE_IBRS, %eax
        wrmsr
        jmp 22f
 12:
@@ -159,7 +159,7 @@ ALTERNATIVE "", __stringify(__ASM_ENABLE_IBRS), X86_FEATURE_SPEC_CTRL
        testl   $SPEC_CTRL_IBRS_INUSE, use_ibrs
        jz      13f
 
-       cmpl    $FEATURE_ENABLE_IBRS, \save_reg
+       cmpl    $SPEC_CTRL_FEATURE_ENABLE_IBRS, \save_reg
        je      13f
 
        movl    $MSR_IA32_SPEC_CTRL, %ecx
index a4d88b896b55e8da6c432d724e481fc37abb4370..eb183c40dff20bc5ef2161214bf97caf31d6ac82 100644 (file)
 #define MSR_IA32_LASTINTFROMIP         0x000001dd
 #define MSR_IA32_LASTINTTOIP           0x000001de
 
+#define SPEC_CTRL_FEATURE_DISABLE_IBRS (0 << 0)
+#define SPEC_CTRL_FEATURE_ENABLE_IBRS  (1 << 0)
+
 #define MSR_IA32_SPEC_CTRL             0x00000048
 #define MSR_IA32_PRED_CMD              0x00000049
 
 #define PACKAGE_THERM_INT_LOW_ENABLE           (1 << 1)
 #define PACKAGE_THERM_INT_PLN_ENABLE           (1 << 24)
 
-#define FEATURE_ENABLE_IBRS                    (1<<0)
 #define FEATURE_SET_IBPB                       (1<<0)
 
 /* Thermal Thresholds Support */
index f6c1cea968d9e2927771cd0a0352316b8978b3f1..b47511b91de0f131d7b1402729c99e32978aca7f 100644 (file)
@@ -464,17 +464,17 @@ static __cpuidle void mwait_idle(void)
                }
 
                if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
-                       native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+                       native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
 
                __monitor((void *)&current_thread_info()->flags, 0, 0);
                if (!need_resched()) {
                        __sti_mwait(0, 0);
                        if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
                                native_wrmsrl(MSR_IA32_SPEC_CTRL,
-                                   FEATURE_ENABLE_IBRS);
+                                   SPEC_CTRL_FEATURE_ENABLE_IBRS);
                } else {
                        if (boot_cpu_has(X86_FEATURE_SPEC_CTRL))
-                               native_wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+                               native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
                        local_irq_enable();
                }
                trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
index 240cd2b73ed840da5bf0740ebf25d8593ca9d346..15c27ffaa4c56145426766685e295a1126c08e1c 100644 (file)
@@ -1504,14 +1504,14 @@ void native_play_dead(void)
        tboot_shutdown(TB_SHUTDOWN_WFS);
 
        if (ibrs_inuse)
-               native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
+               native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
 
        mwait_play_dead();      /* Only returns on failure */
        if (cpuidle_play_dead())
                hlt_play_dead();
 
        if (ibrs_inuse)
-               native_wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+               native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
 }
 
 #else /* ... !CONFIG_HOTPLUG_CPU */
index 8cc1f5347d75d45a25f2e93270687b68d7856a5b..fa2cb89c5403044f3d1d2b871bd5c24e4ca8f008 100644 (file)
@@ -3931,7 +3931,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
        local_irq_enable();
 
        if (ibrs_inuse &&
-           svm->spec_ctrl != FEATURE_ENABLE_IBRS)
+           svm->spec_ctrl != SPEC_CTRL_FEATURE_ENABLE_IBRS)
                wrmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
 
        asm volatile (
@@ -4028,8 +4028,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 
        if (ibrs_inuse) {
                rdmsrl(MSR_IA32_SPEC_CTRL, svm->spec_ctrl);
-               if (svm->spec_ctrl != FEATURE_ENABLE_IBRS)
-                       wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+               if (svm->spec_ctrl != SPEC_CTRL_FEATURE_ENABLE_IBRS)
+                       wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
        }
        stuff_RSB();
 
index db38e33cc2015ff7689b04bda6a7ab69057a756c..4a60333d322c2e2bbdc3c18d845b64cd819e7b95 100644 (file)
@@ -8188,7 +8188,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
                vmx_set_interrupt_shadow(vcpu, 0);
 
        if (ibpb_inuse &&
-           vmx->spec_ctrl != FEATURE_ENABLE_IBRS)
+           vmx->spec_ctrl != SPEC_CTRL_FEATURE_ENABLE_IBRS)
                wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
 
        atomic_switch_perf_msrs(vmx);
@@ -8320,7 +8320,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
        if (ibpb_inuse) {
                rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl);
                if (vmx->spec_ctrl)
-                       wrmsrl(MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+                       wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
        }
        stuff_RSB();
 
index 3701f451f12a67226d253f49f9c043612d34b0e2..ed927292713bf60ecdace31520b9925971675c7e 100644 (file)
@@ -51,6 +51,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
 int smp_call_function_single_async(int cpu, struct call_single_data *csd);
 
 #ifdef CONFIG_X86
+#include <asm/spec_ctrl.h>
 /* indicate usage of IBRS to control execution speculation */
 extern int use_ibrs;
 extern u32 sysctl_ibrs_enabled;
index 71bcdd0854b41f2ffe9ff29ff02a40c2aa767935..5428d939b693308a6ac4453021802220d476d211 100644 (file)
@@ -2847,14 +2847,14 @@ int proc_dointvec_ibrs_ctrl(struct ctl_table *table, int write,
                set_ibrs_disabled();
                if (ibrs_supported) {
                        for_each_online_cpu(cpu)
-                               wrmsrl_on_cpu(cpu, MSR_IA32_SPEC_CTRL, 0x0);
+                               wrmsrl_on_cpu(cpu, MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
                }
        } else if (sysctl_ibrs_enabled == 2) {
                /* always set IBRS on, even in user space */
                clear_ibrs_disabled();
                if (ibrs_supported) {
                        for_each_online_cpu(cpu)
-                               wrmsrl_on_cpu(cpu, MSR_IA32_SPEC_CTRL, FEATURE_ENABLE_IBRS);
+                               wrmsrl_on_cpu(cpu, MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
                } else {
                        sysctl_ibrs_enabled = 0;
                }