[PATCH 2/2] x86/CPU/Intel: Do the MSR_IA32_FEAT_CTL setup before alternatives

From: Borislav Petkov
Date: Sat May 04 2024 - 08:51:00 EST


From: "Borislav Petkov (AMD)" <bp@xxxxxxxxx>
Date: Thu, 2 May 2024 15:15:41 +0200

init_ia32_feat_ctl() goes through the MSR_IA32_FEAT_CTL settings and
sanity-checks the configuration on each logical CPU, while setting or
clearing X86_FEATURE flags in the process.

However, it does that after alternatives have run, leading to settings
which have been patched by the alternatives to become invalid and
irreversible.

Move the settings detection to an earlier path, before the alternatives.

Reported-by: kernel test robot <oliver.sang@xxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Link: https://lore.kernel.org/oe-lkp/202404302233.f27f91b2-oliver.sang@xxxxxxxxx
---
arch/x86/kernel/cpu/intel.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index be30d7fa2e66..d8575511a143 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -406,6 +406,8 @@ static void early_init_intel(struct cpuinfo_x86 *c)
*/
if (cpu_has(c, X86_FEATURE_TME))
detect_tme_early(c);
+
+ init_ia32_feat_ctl(c);
}

static void bsp_init_intel(struct cpuinfo_x86 *c)
@@ -682,8 +684,6 @@ static void init_intel(struct cpuinfo_x86 *c)
/* Work around errata */
srat_detect_node(c);

- init_ia32_feat_ctl(c);
-
init_intel_misc_features(c);

split_lock_init();
--
2.43.0

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette