From 3f680a602fa204f4a24a68af0487e0b4e9d4ae23 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Thu, 4 Jan 2018 21:33:07 -0500 Subject: [PATCH] x86: Instead of 0x2, 0x4, and 0x1 use #defines. This mirrors what the posted upstream patches are doing. Orabug: 27344012 CVE: CVE-2017-5715 Reviewed-by: Todd Vierling Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Kirtikar Kashyap --- arch/x86/include/asm/spec_ctrl.h | 12 ++++++++---- include/linux/smp.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/spec_ctrl.h b/arch/x86/include/asm/spec_ctrl.h index ba1c51058b62..5204336841a1 100644 --- a/arch/x86/include/asm/spec_ctrl.h +++ b/arch/x86/include/asm/spec_ctrl.h @@ -6,6 +6,10 @@ #include #include +#define SPEC_CTRL_IBRS_INUSE (1<<0) /* OS enables IBRS usage */ +#define SPEC_CTRL_IBRS_SUPPORTED (1<<1) /* System supports IBRS */ +#define SPEC_CTRL_IBRS_ADMIN_DISABLED (1<<2) /* Admin disables IBRS */ + #ifdef __ASSEMBLY__ .extern use_ibrs @@ -128,14 +132,14 @@ ALTERNATIVE "", __stringify(__ASM_ENABLE_IBRS), X86_FEATURE_SPEC_CTRL .endm .macro ENABLE_IBRS_CLOBBER - testl $1, use_ibrs + testl $SPEC_CTRL_IBRS_INUSE, use_ibrs jz 11f __ASM_ENABLE_IBRS_CLOBBER 11: .endm .macro ENABLE_IBRS_SAVE_AND_CLOBBER save_reg:req - testl $1, use_ibrs + testl $SPEC_CTRL_IBRS_INUSE, use_ibrs jz 12f movl $MSR_IA32_SPEC_CTRL, %ecx @@ -152,7 +156,7 @@ ALTERNATIVE "", __stringify(__ASM_ENABLE_IBRS), X86_FEATURE_SPEC_CTRL .endm .macro RESTORE_IBRS_CLOBBER save_reg:req - testl $1, use_ibrs + testl $SPEC_CTRL_IBRS_INUSE, use_ibrs jz 13f cmpl $FEATURE_ENABLE_IBRS, \save_reg @@ -169,7 +173,7 @@ ALTERNATIVE "", __stringify(__ASM_ENABLE_IBRS), X86_FEATURE_SPEC_CTRL .endm .macro DISABLE_IBRS - testl $1, use_ibrs + testl $SPEC_CTRL_IBRS_INUSE, use_ibrs jz 9f __ASM_DISABLE_IBRS 9: diff --git a/include/linux/smp.h b/include/linux/smp.h index 3689de249d0c..3701f451f12a 100644 --- a/include/linux/smp.h +++ b/include/linux/smp.h @@ -55,20 +55,20 @@ int smp_call_function_single_async(int cpu, struct call_single_data *csd); extern int use_ibrs; extern u32 sysctl_ibrs_enabled; extern struct mutex spec_ctrl_mutex; -#define ibrs_supported (use_ibrs & 0x2) -#define ibrs_disabled (use_ibrs & 0x4) +#define ibrs_supported (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED) +#define ibrs_disabled (use_ibrs & SPEC_CTRL_IBRS_ADMIN_DISABLED) static inline void set_ibrs_inuse(void) { if (ibrs_supported) - use_ibrs |= 0x1; + use_ibrs |= SPEC_CTRL_IBRS_INUSE; } static inline void clear_ibrs_inuse(void) { - use_ibrs &= ~0x1; + use_ibrs &= ~SPEC_CTRL_IBRS_INUSE; } static inline int check_ibrs_inuse(void) { - if (use_ibrs & 0x1) + if (use_ibrs & SPEC_CTRL_IBRS_INUSE) return 1; else /* rmb to prevent wrong speculation for security */ @@ -77,19 +77,19 @@ static inline int check_ibrs_inuse(void) } static inline void set_ibrs_supported(void) { - use_ibrs |= 0x2; + use_ibrs |= SPEC_CTRL_IBRS_SUPPORTED; if (!ibrs_disabled) set_ibrs_inuse(); } static inline void set_ibrs_disabled(void) { - use_ibrs |= 0x4; + use_ibrs |= SPEC_CTRL_IBRS_ADMIN_DISABLED; if (check_ibrs_inuse()) clear_ibrs_inuse(); } static inline void clear_ibrs_disabled(void) { - use_ibrs &= ~0x4; + use_ibrs &= ~SPEC_CTRL_IBRS_ADMIN_DISABLED; set_ibrs_inuse(); } #define ibrs_inuse (check_ibrs_inuse()) -- 2.50.1