Skip to content

Commit 400331f

Browse files
pa1guptasuryasaimadhu
authored andcommitted
x86/tsx: Disable TSX development mode at boot
A microcode update on some Intel processors causes all TSX transactions to always abort by default[*]. Microcode also added functionality to re-enable TSX for development purposes. With this microcode loaded, if tsx=on was passed on the cmdline, and TSX development mode was already enabled before the kernel boot, it may make the system vulnerable to TSX Asynchronous Abort (TAA). To be on safer side, unconditionally disable TSX development mode during boot. If a viable use case appears, this can be revisited later. [*]: Intel TSX Disable Update for Selected Processors, doc ID: 643557 [ bp: Drop unstable web link, massage heavily. ] Suggested-by: Andrew Cooper <[email protected]> Suggested-by: Borislav Petkov <[email protected]> Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Tested-by: Neelima Krishnan <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/347bd844da3a333a9793c6687d4e4eb3b2419a3e.1646943780.git.pawan.kumar.gupta@linux.intel.com
1 parent 258f3b8 commit 400331f

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@
128128
#define TSX_CTRL_RTM_DISABLE BIT(0) /* Disable RTM feature */
129129
#define TSX_CTRL_CPUID_CLEAR BIT(1) /* Disable TSX enumeration */
130130

131-
/* SRBDS support */
132131
#define MSR_IA32_MCU_OPT_CTRL 0x00000123
133-
#define RNGDS_MITG_DIS BIT(0)
132+
#define RNGDS_MITG_DIS BIT(0) /* SRBDS support */
133+
#define RTM_ALLOW BIT(1) /* TSX development mode */
134134

135135
#define MSR_IA32_SYSENTER_CS 0x00000174
136136
#define MSR_IA32_SYSENTER_ESP 0x00000175

arch/x86/kernel/cpu/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,8 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c)
18551855
validate_apic_and_package_id(c);
18561856
x86_spec_ctrl_setup_ap();
18571857
update_srbds_msr();
1858+
1859+
tsx_ap_init();
18581860
}
18591861

18601862
static __init int setup_noclflush(char *arg)

arch/x86/kernel/cpu/cpu.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ enum tsx_ctrl_states {
5555
extern __ro_after_init enum tsx_ctrl_states tsx_ctrl_state;
5656

5757
extern void __init tsx_init(void);
58-
extern void tsx_enable(void);
59-
extern void tsx_disable(void);
60-
extern void tsx_clear_cpuid(void);
58+
void tsx_ap_init(void);
6159
#else
6260
static inline void tsx_init(void) { }
61+
static inline void tsx_ap_init(void) { }
6362
#endif /* CONFIG_CPU_SUP_INTEL */
6463

6564
extern void get_cpu_cap(struct cpuinfo_x86 *c);

arch/x86/kernel/cpu/intel.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,6 @@ static void init_intel(struct cpuinfo_x86 *c)
717717

718718
init_intel_misc_features(c);
719719

720-
if (tsx_ctrl_state == TSX_CTRL_ENABLE)
721-
tsx_enable();
722-
else if (tsx_ctrl_state == TSX_CTRL_DISABLE)
723-
tsx_disable();
724-
else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT)
725-
/* See comment over that function for more details. */
726-
tsx_clear_cpuid();
727-
728720
split_lock_init();
729721
bus_lock_init();
730722

arch/x86/kernel/cpu/tsx.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
enum tsx_ctrl_states tsx_ctrl_state __ro_after_init = TSX_CTRL_NOT_SUPPORTED;
2121

22-
void tsx_disable(void)
22+
static void tsx_disable(void)
2323
{
2424
u64 tsx;
2525

@@ -39,7 +39,7 @@ void tsx_disable(void)
3939
wrmsrl(MSR_IA32_TSX_CTRL, tsx);
4040
}
4141

42-
void tsx_enable(void)
42+
static void tsx_enable(void)
4343
{
4444
u64 tsx;
4545

@@ -122,7 +122,7 @@ static enum tsx_ctrl_states x86_get_tsx_auto_mode(void)
122122
* That's why, this function's call in init_intel() doesn't clear the
123123
* feature flags.
124124
*/
125-
void tsx_clear_cpuid(void)
125+
static void tsx_clear_cpuid(void)
126126
{
127127
u64 msr;
128128

@@ -142,11 +142,42 @@ void tsx_clear_cpuid(void)
142142
}
143143
}
144144

145+
/*
146+
* Disable TSX development mode
147+
*
148+
* When the microcode released in Feb 2022 is applied, TSX will be disabled by
149+
* default on some processors. MSR 0x122 (TSX_CTRL) and MSR 0x123
150+
* (IA32_MCU_OPT_CTRL) can be used to re-enable TSX for development, doing so is
151+
* not recommended for production deployments. In particular, applying MD_CLEAR
152+
* flows for mitigation of the Intel TSX Asynchronous Abort (TAA) transient
153+
* execution attack may not be effective on these processors when Intel TSX is
154+
* enabled with updated microcode.
155+
*/
156+
static void tsx_dev_mode_disable(void)
157+
{
158+
u64 mcu_opt_ctrl;
159+
160+
/* Check if RTM_ALLOW exists */
161+
if (!boot_cpu_has_bug(X86_BUG_TAA) || !tsx_ctrl_is_supported() ||
162+
!cpu_feature_enabled(X86_FEATURE_SRBDS_CTRL))
163+
return;
164+
165+
rdmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_opt_ctrl);
166+
167+
if (mcu_opt_ctrl & RTM_ALLOW) {
168+
mcu_opt_ctrl &= ~RTM_ALLOW;
169+
wrmsrl(MSR_IA32_MCU_OPT_CTRL, mcu_opt_ctrl);
170+
setup_force_cpu_cap(X86_FEATURE_RTM_ALWAYS_ABORT);
171+
}
172+
}
173+
145174
void __init tsx_init(void)
146175
{
147176
char arg[5] = {};
148177
int ret;
149178

179+
tsx_dev_mode_disable();
180+
150181
/*
151182
* Hardware will always abort a TSX transaction when the CPUID bit
152183
* RTM_ALWAYS_ABORT is set. In this case, it is better not to enumerate
@@ -215,3 +246,16 @@ void __init tsx_init(void)
215246
setup_force_cpu_cap(X86_FEATURE_HLE);
216247
}
217248
}
249+
250+
void tsx_ap_init(void)
251+
{
252+
tsx_dev_mode_disable();
253+
254+
if (tsx_ctrl_state == TSX_CTRL_ENABLE)
255+
tsx_enable();
256+
else if (tsx_ctrl_state == TSX_CTRL_DISABLE)
257+
tsx_disable();
258+
else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT)
259+
/* See comment over that function for more details. */
260+
tsx_clear_cpuid();
261+
}

tools/arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@
128128
#define TSX_CTRL_RTM_DISABLE BIT(0) /* Disable RTM feature */
129129
#define TSX_CTRL_CPUID_CLEAR BIT(1) /* Disable TSX enumeration */
130130

131-
/* SRBDS support */
132131
#define MSR_IA32_MCU_OPT_CTRL 0x00000123
133-
#define RNGDS_MITG_DIS BIT(0)
132+
#define RNGDS_MITG_DIS BIT(0) /* SRBDS support */
133+
#define RTM_ALLOW BIT(1) /* TSX development mode */
134134

135135
#define MSR_IA32_SYSENTER_CS 0x00000174
136136
#define MSR_IA32_SYSENTER_ESP 0x00000175

0 commit comments

Comments
 (0)