x86/srso: Add IBPB_BRTYPE support
[platform/kernel/linux-starfive.git] / arch / x86 / kernel / cpu / bugs.c
index d691abd..137565e 100644 (file)
@@ -2356,10 +2356,20 @@ static void __init srso_select_mitigation(void)
        if (!boot_cpu_has_bug(X86_BUG_SRSO) || cpu_mitigations_off())
                return;
 
-       has_microcode = cpu_has_ibpb_brtype_microcode();
+       /*
+        * The first check is for the kernel running as a guest in order
+        * for guests to verify whether IBPB is a viable mitigation.
+        */
+       has_microcode = boot_cpu_has(X86_FEATURE_IBPB_BRTYPE) || cpu_has_ibpb_brtype_microcode();
        if (!has_microcode) {
                pr_warn("IBPB-extending microcode not applied!\n");
                pr_warn(SRSO_NOTICE);
+       } else {
+               /*
+                * Enable the synthetic (even if in a real CPUID leaf)
+                * flag for guests.
+                */
+               setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE);
        }
 
        switch (srso_cmd) {