Skip to content

Commit aaa65d1

Browse files
pa1guptasuryasaimadhu
authored andcommitted
x86/tsx: Add a feature bit for TSX control MSR support
Support for the TSX control MSR is enumerated in MSR_IA32_ARCH_CAPABILITIES. This is different from how other CPU features are enumerated i.e. via CPUID. Currently, a call to tsx_ctrl_is_supported() is required for enumerating the feature. In the absence of a feature bit for TSX control, any code that relies on checking feature bits directly will not work. In preparation for adding a feature bit check in MSR save/restore during suspend/resume, set a new feature bit X86_FEATURE_TSX_CTRL when MSR_IA32_TSX_CTRL is present. Also make tsx_ctrl_is_supported() use the new feature bit to avoid any overhead of reading the MSR. [ bp: Remove tsx_ctrl_is_supported(), add room for two more feature bits in word 11 which are coming up in the next merge window. ] Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: <stable@kernel.org> Link: https://lore.kernel.org/r/de619764e1d98afbb7a5fa58424f1278ede37b45.1668539735.git.pawan.kumar.gupta@linux.intel.com
1 parent 47894e0 commit aaa65d1

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@
305305
#define X86_FEATURE_USE_IBPB_FW (11*32+16) /* "" Use IBPB during runtime firmware calls */
306306
#define X86_FEATURE_RSB_VMEXIT_LITE (11*32+17) /* "" Fill RSB on VM exit when EIBRS is enabled */
307307

308+
309+
#define X86_FEATURE_MSR_TSX_CTRL (11*32+20) /* "" MSR IA32_TSX_CTRL (Intel) implemented */
310+
308311
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
309312
#define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */
310313
#define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* AVX512 BFLOAT16 instructions */

arch/x86/kernel/cpu/tsx.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,6 @@ static void tsx_enable(void)
5858
wrmsrl(MSR_IA32_TSX_CTRL, tsx);
5959
}
6060

61-
static bool tsx_ctrl_is_supported(void)
62-
{
63-
u64 ia32_cap = x86_read_arch_cap_msr();
64-
65-
/*
66-
* TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this
67-
* MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES.
68-
*
69-
* TSX control (aka MSR_IA32_TSX_CTRL) is only available after a
70-
* microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES
71-
* bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get
72-
* MSR_IA32_TSX_CTRL support even after a microcode update. Thus,
73-
* tsx= cmdline requests will do nothing on CPUs without
74-
* MSR_IA32_TSX_CTRL support.
75-
*/
76-
return !!(ia32_cap & ARCH_CAP_TSX_CTRL_MSR);
77-
}
78-
7961
static enum tsx_ctrl_states x86_get_tsx_auto_mode(void)
8062
{
8163
if (boot_cpu_has_bug(X86_BUG_TAA))
@@ -135,7 +117,7 @@ static void tsx_clear_cpuid(void)
135117
rdmsrl(MSR_TSX_FORCE_ABORT, msr);
136118
msr |= MSR_TFA_TSX_CPUID_CLEAR;
137119
wrmsrl(MSR_TSX_FORCE_ABORT, msr);
138-
} else if (tsx_ctrl_is_supported()) {
120+
} else if (cpu_feature_enabled(X86_FEATURE_MSR_TSX_CTRL)) {
139121
rdmsrl(MSR_IA32_TSX_CTRL, msr);
140122
msr |= TSX_CTRL_CPUID_CLEAR;
141123
wrmsrl(MSR_IA32_TSX_CTRL, msr);
@@ -158,7 +140,8 @@ static void tsx_dev_mode_disable(void)
158140
u64 mcu_opt_ctrl;
159141

160142
/* Check if RTM_ALLOW exists */
161-
if (!boot_cpu_has_bug(X86_BUG_TAA) || !tsx_ctrl_is_supported() ||
143+
if (!boot_cpu_has_bug(X86_BUG_TAA) ||
144+
!cpu_feature_enabled(X86_FEATURE_MSR_TSX_CTRL) ||
162145
!cpu_feature_enabled(X86_FEATURE_SRBDS_CTRL))
163146
return;
164147

@@ -191,7 +174,20 @@ void __init tsx_init(void)
191174
return;
192175
}
193176

194-
if (!tsx_ctrl_is_supported()) {
177+
/*
178+
* TSX is controlled via MSR_IA32_TSX_CTRL. However, support for this
179+
* MSR is enumerated by ARCH_CAP_TSX_MSR bit in MSR_IA32_ARCH_CAPABILITIES.
180+
*
181+
* TSX control (aka MSR_IA32_TSX_CTRL) is only available after a
182+
* microcode update on CPUs that have their MSR_IA32_ARCH_CAPABILITIES
183+
* bit MDS_NO=1. CPUs with MDS_NO=0 are not planned to get
184+
* MSR_IA32_TSX_CTRL support even after a microcode update. Thus,
185+
* tsx= cmdline requests will do nothing on CPUs without
186+
* MSR_IA32_TSX_CTRL support.
187+
*/
188+
if (x86_read_arch_cap_msr() & ARCH_CAP_TSX_CTRL_MSR) {
189+
setup_force_cpu_cap(X86_FEATURE_MSR_TSX_CTRL);
190+
} else {
195191
tsx_ctrl_state = TSX_CTRL_NOT_SUPPORTED;
196192
return;
197193
}

0 commit comments

Comments
 (0)