x86/fred: Add a fred= cmdline param
authorXin Li <xin3.li@intel.com>
Tue, 5 Dec 2023 10:49:57 +0000 (02:49 -0800)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 30 Jan 2024 17:19:20 +0000 (18:19 +0100)
Let command line option "fred" accept multiple options to make it
easier to tweak its behavior.

Currently, two options 'on' and 'off' are allowed, and the default
behavior is to disable FRED. To enable FRED, append "fred=on" to the
kernel command line.

  [ bp: Use cpu_feature_enabled(), touch ups. ]

Signed-off-by: Xin Li <xin3.li@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Shan Kang <shan.kang@intel.com>
Link: https://lore.kernel.org/r/20231205105030.8698-9-xin3.li@intel.com
Documentation/admin-guide/kernel-parameters.txt
arch/x86/kernel/traps.c

index 31b3a25680d08cfac3603d58b3d3783bbf1e34bb..d6ea4f42127cfa0b41907051ab3a1e30c334cd4f 100644 (file)
                        Warning: use of this parameter will taint the kernel
                        and may cause unknown problems.
 
+       fred=           [X86-64]
+                       Enable/disable Flexible Return and Event Delivery.
+                       Format: { on | off }
+                       on: enable FRED when it's present.
+                       off: disable FRED, the default setting.
+
        ftrace=[tracer]
                        [FTRACE] will set and start the specified tracer
                        as early as possible in order to facilitate early
index c3b2f863acf0f3f28c7402c86de8cbaa47eb930c..3c37489018256f189ba7839f80518cd2520e4079 100644 (file)
@@ -1369,8 +1369,34 @@ DEFINE_IDTENTRY_SW(iret_error)
 }
 #endif
 
+/* Do not enable FRED by default yet. */
+static bool enable_fred __ro_after_init = false;
+
+#ifdef CONFIG_X86_FRED
+static int __init fred_setup(char *str)
+{
+       if (!str)
+               return -EINVAL;
+
+       if (!cpu_feature_enabled(X86_FEATURE_FRED))
+               return 0;
+
+       if (!strcmp(str, "on"))
+               enable_fred = true;
+       else if (!strcmp(str, "off"))
+               enable_fred = false;
+       else
+               pr_warn("invalid FRED option: 'fred=%s'\n", str);
+       return 0;
+}
+early_param("fred", fred_setup);
+#endif
+
 void __init trap_init(void)
 {
+       if (cpu_feature_enabled(X86_FEATURE_FRED) && !enable_fred)
+               setup_clear_cpu_cap(X86_FEATURE_FRED);
+
        /* Init cpu_entry_area before IST entries are set up */
        setup_cpu_entry_areas();