Skip to content

Commit 989b5cf

Browse files
xinli-intelKAGA-KOKO
authored andcommitted
x86/fred: Parse cmdline param "fred=" in cpu_parse_early_param()
Depending on whether FRED is enabled, sysvec_install() installs a system interrupt handler into either into FRED's system vector dispatch table or into the IDT. However FRED can be disabled later in trap_init(), after sysvec_install() has been invoked already; e.g., the HYPERVISOR_CALLBACK_VECTOR handler is registered with sysvec_install() in kvm_guest_init(), which is called in setup_arch() but way before trap_init(). IOW, there is a gap between FRED is available and available but disabled. As a result, when FRED is available but disabled, early sysvec_install() invocations fail to install the IDT handler resulting in spurious interrupts. Fix it by parsing cmdline param "fred=" in cpu_parse_early_param() to ensure that FRED is disabled before the first sysvec_install() incovations. Fixes: 3810da1 ("x86/fred: Add a fred= cmdline param") Reported-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Xin Li (Intel) <xin@zytor.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20240709154048.3543361-2-xin@zytor.com
1 parent 7c626ce commit 989b5cf

2 files changed

Lines changed: 5 additions & 26 deletions

File tree

arch/x86/kernel/cpu/common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,11 @@ static void __init cpu_parse_early_param(void)
15101510
if (cmdline_find_option_bool(boot_command_line, "nousershstk"))
15111511
setup_clear_cpu_cap(X86_FEATURE_USER_SHSTK);
15121512

1513+
/* Minimize the gap between FRED is available and available but disabled. */
1514+
arglen = cmdline_find_option(boot_command_line, "fred", arg, sizeof(arg));
1515+
if (arglen != 2 || strncmp(arg, "on", 2))
1516+
setup_clear_cpu_cap(X86_FEATURE_FRED);
1517+
15131518
arglen = cmdline_find_option(boot_command_line, "clearcpuid", arg, sizeof(arg));
15141519
if (arglen <= 0)
15151520
return;

arch/x86/kernel/traps.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,34 +1402,8 @@ DEFINE_IDTENTRY_SW(iret_error)
14021402
}
14031403
#endif
14041404

1405-
/* Do not enable FRED by default yet. */
1406-
static bool enable_fred __ro_after_init = false;
1407-
1408-
#ifdef CONFIG_X86_FRED
1409-
static int __init fred_setup(char *str)
1410-
{
1411-
if (!str)
1412-
return -EINVAL;
1413-
1414-
if (!cpu_feature_enabled(X86_FEATURE_FRED))
1415-
return 0;
1416-
1417-
if (!strcmp(str, "on"))
1418-
enable_fred = true;
1419-
else if (!strcmp(str, "off"))
1420-
enable_fred = false;
1421-
else
1422-
pr_warn("invalid FRED option: 'fred=%s'\n", str);
1423-
return 0;
1424-
}
1425-
early_param("fred", fred_setup);
1426-
#endif
1427-
14281405
void __init trap_init(void)
14291406
{
1430-
if (cpu_feature_enabled(X86_FEATURE_FRED) && !enable_fred)
1431-
setup_clear_cpu_cap(X86_FEATURE_FRED);
1432-
14331407
/* Init cpu_entry_area before IST entries are set up */
14341408
setup_cpu_entry_areas();
14351409

0 commit comments

Comments
 (0)