Skip to content

Commit 15b7ddc

Browse files
sohilmehIngo Molnar
authored andcommitted
x86/cpu/intel: Fix fast string initialization for extended Families
X86_FEATURE_REP_GOOD is a linux defined feature flag to track whether fast string operations should be used for copy_page(). It is also used as a second alternative for clear_page() if enhanced fast string operations (ERMS) are not available. X86_FEATURE_ERMS is an Intel-specific hardware-defined feature flag that tracks hardware support for Enhanced Fast strings. It is used to track whether Fast strings should be used for similar memory copy and memory clearing operations. On top of these, there is a FAST_STRING enable bit in the IA32_MISC_ENABLE MSR. It is typically controlled by the BIOS to provide a hint to the hardware and the OS on whether fast string operations are preferred. Commit: 161ec53 ("x86, mem, intel: Initialize Enhanced REP MOVSB/STOSB") introduced a mechanism to honor the BIOS preference for fast string operations and clear the above feature flags if needed. Unfortunately, the current initialization code for Intel to set and clear these bits is confusing at best and likely incorrect. X86_FEATURE_REP_GOOD is cleared in early_init_intel() if MISC_ENABLE.FAST_STRING is 0. But it gets set later on unconditionally for all Family 6 processors in init_intel(). This not only overrides the BIOS preference but also contradicts the earlier check. Fix this by combining the related checks and always relying on the BIOS provided preference for fast string operations. This simplification makes sure the upcoming Intel Family 18 and 19 models are covered as well. Signed-off-by: Sohil Mehta <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Juergen Gross <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7a2ad75 commit 15b7ddc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

arch/x86/kernel/cpu/intel.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,19 @@ static void early_init_intel(struct cpuinfo_x86 *c)
289289
clear_cpu_cap(c, X86_FEATURE_PAT);
290290

291291
/*
292-
* If fast string is not enabled in IA32_MISC_ENABLE for any reason,
293-
* clear the fast string and enhanced fast string CPU capabilities.
292+
* Modern CPUs are generally expected to have a sane fast string
293+
* implementation. However, BIOSes typically have a knob to tweak
294+
* the architectural MISC_ENABLE.FAST_STRING enable bit.
295+
*
296+
* Adhere to the preference and program the Linux-defined fast
297+
* string flag and enhanced fast string capabilities accordingly.
294298
*/
295-
if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
299+
if (c->x86_vfm >= INTEL_PENTIUM_M_DOTHAN) {
296300
rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
297-
if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
301+
if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) {
302+
/* X86_FEATURE_ERMS is set based on CPUID */
303+
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
304+
} else {
298305
pr_info("Disabled fast string operations\n");
299306
setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
300307
setup_clear_cpu_cap(X86_FEATURE_ERMS);
@@ -545,8 +552,6 @@ static void init_intel(struct cpuinfo_x86 *c)
545552
#ifdef CONFIG_X86_64
546553
if (c->x86 == 15)
547554
c->x86_cache_alignment = c->x86_clflush_size * 2;
548-
if (c->x86 == 6)
549-
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
550555
#else
551556
/*
552557
* Names for the Pentium II/Celeron processors

0 commit comments

Comments
 (0)