x86/tsx: Use MSR_TSX_CTRL to clear CPUID bits
tsx_clear_cpuid() uses MSR_TSX_FORCE_ABORT to clear CPUID.RTM and CPUID.HLE. Not all CPUs support MSR_TSX_FORCE_ABORT, alternatively use MSR_IA32_TSX_CTRL when supported. [ bp: Document how and why TSX gets disabled. ] Fixes: 293649307ef9 ("x86/tsx: Clear CPUID bits when TSX always force aborts") Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Tested-by: Neelima Krishnan <neelima.krishnan@intel.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/5b323e77e251a9c8bcdda498c5cc0095be1e1d3c.1646943780.git.pawan.kumar.gupta@linux.intel.com
This commit is contained in:
parent
ce522ba9ef
commit
258f3b8c32
@ -722,6 +722,7 @@ static void init_intel(struct cpuinfo_x86 *c)
|
|||||||
else if (tsx_ctrl_state == TSX_CTRL_DISABLE)
|
else if (tsx_ctrl_state == TSX_CTRL_DISABLE)
|
||||||
tsx_disable();
|
tsx_disable();
|
||||||
else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT)
|
else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT)
|
||||||
|
/* See comment over that function for more details. */
|
||||||
tsx_clear_cpuid();
|
tsx_clear_cpuid();
|
||||||
|
|
||||||
split_lock_init();
|
split_lock_init();
|
||||||
|
@ -58,7 +58,7 @@ void tsx_enable(void)
|
|||||||
wrmsrl(MSR_IA32_TSX_CTRL, tsx);
|
wrmsrl(MSR_IA32_TSX_CTRL, tsx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __init tsx_ctrl_is_supported(void)
|
static bool tsx_ctrl_is_supported(void)
|
||||||
{
|
{
|
||||||
u64 ia32_cap = x86_read_arch_cap_msr();
|
u64 ia32_cap = x86_read_arch_cap_msr();
|
||||||
|
|
||||||
@ -84,6 +84,44 @@ static enum tsx_ctrl_states x86_get_tsx_auto_mode(void)
|
|||||||
return TSX_CTRL_ENABLE;
|
return TSX_CTRL_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disabling TSX is not a trivial business.
|
||||||
|
*
|
||||||
|
* First of all, there's a CPUID bit: X86_FEATURE_RTM_ALWAYS_ABORT
|
||||||
|
* which says that TSX is practically disabled (all transactions are
|
||||||
|
* aborted by default). When that bit is set, the kernel unconditionally
|
||||||
|
* disables TSX.
|
||||||
|
*
|
||||||
|
* In order to do that, however, it needs to dance a bit:
|
||||||
|
*
|
||||||
|
* 1. The first method to disable it is through MSR_TSX_FORCE_ABORT and
|
||||||
|
* the MSR is present only when *two* CPUID bits are set:
|
||||||
|
*
|
||||||
|
* - X86_FEATURE_RTM_ALWAYS_ABORT
|
||||||
|
* - X86_FEATURE_TSX_FORCE_ABORT
|
||||||
|
*
|
||||||
|
* 2. The second method is for CPUs which do not have the above-mentioned
|
||||||
|
* MSR: those use a different MSR - MSR_IA32_TSX_CTRL and disable TSX
|
||||||
|
* through that one. Those CPUs can also have the initially mentioned
|
||||||
|
* CPUID bit X86_FEATURE_RTM_ALWAYS_ABORT set and for those the same strategy
|
||||||
|
* applies: TSX gets disabled unconditionally.
|
||||||
|
*
|
||||||
|
* When either of the two methods are present, the kernel disables TSX and
|
||||||
|
* clears the respective RTM and HLE feature flags.
|
||||||
|
*
|
||||||
|
* An additional twist in the whole thing presents late microcode loading
|
||||||
|
* which, when done, may cause for the X86_FEATURE_RTM_ALWAYS_ABORT CPUID
|
||||||
|
* bit to be set after the update.
|
||||||
|
*
|
||||||
|
* A subsequent hotplug operation on any logical CPU except the BSP will
|
||||||
|
* cause for the supported CPUID feature bits to get re-detected and, if
|
||||||
|
* RTM and HLE get cleared all of a sudden, but, userspace did consult
|
||||||
|
* them before the update, then funny explosions will happen. Long story
|
||||||
|
* short: the kernel doesn't modify CPUID feature bits after booting.
|
||||||
|
*
|
||||||
|
* That's why, this function's call in init_intel() doesn't clear the
|
||||||
|
* feature flags.
|
||||||
|
*/
|
||||||
void tsx_clear_cpuid(void)
|
void tsx_clear_cpuid(void)
|
||||||
{
|
{
|
||||||
u64 msr;
|
u64 msr;
|
||||||
@ -97,6 +135,10 @@ void tsx_clear_cpuid(void)
|
|||||||
rdmsrl(MSR_TSX_FORCE_ABORT, msr);
|
rdmsrl(MSR_TSX_FORCE_ABORT, msr);
|
||||||
msr |= MSR_TFA_TSX_CPUID_CLEAR;
|
msr |= MSR_TFA_TSX_CPUID_CLEAR;
|
||||||
wrmsrl(MSR_TSX_FORCE_ABORT, msr);
|
wrmsrl(MSR_TSX_FORCE_ABORT, msr);
|
||||||
|
} else if (tsx_ctrl_is_supported()) {
|
||||||
|
rdmsrl(MSR_IA32_TSX_CTRL, msr);
|
||||||
|
msr |= TSX_CTRL_CPUID_CLEAR;
|
||||||
|
wrmsrl(MSR_IA32_TSX_CTRL, msr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +148,11 @@ void __init tsx_init(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hardware will always abort a TSX transaction if both CPUID bits
|
* Hardware will always abort a TSX transaction when the CPUID bit
|
||||||
* RTM_ALWAYS_ABORT and TSX_FORCE_ABORT are set. In this case, it is
|
* RTM_ALWAYS_ABORT is set. In this case, it is better not to enumerate
|
||||||
* better not to enumerate CPUID.RTM and CPUID.HLE bits. Clear them
|
* CPUID.RTM and CPUID.HLE bits. Clear them here.
|
||||||
* here.
|
|
||||||
*/
|
*/
|
||||||
if (boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT) &&
|
if (boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)) {
|
||||||
boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)) {
|
|
||||||
tsx_ctrl_state = TSX_CTRL_RTM_ALWAYS_ABORT;
|
tsx_ctrl_state = TSX_CTRL_RTM_ALWAYS_ABORT;
|
||||||
tsx_clear_cpuid();
|
tsx_clear_cpuid();
|
||||||
setup_clear_cpu_cap(X86_FEATURE_RTM);
|
setup_clear_cpu_cap(X86_FEATURE_RTM);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user