Re: [PATCH v2 2/5] x86/bugs: Use early_param for spectre_v2
From: Borislav Petkov
Date: Fri Aug 22 2025 - 07:49:57 EST
On Tue, Aug 19, 2025 at 02:21:57PM -0500, David Kaplan wrote:
> +static void __init spectre_v2_check_cmd(void)
Why the separate function?
This can simply go in spectre_v2_select_mitigation() before the switch-case
like with all the others *_select_mitigation() functions...
> +{
> + if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_GENERIC ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
> + !IS_ENABLED(CONFIG_MITIGATION_RETPOLINE)) {
> + pr_err("RETPOLINE selected but not compiled in. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if ((spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) &&
> + !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) {
> + pr_err("EIBRS selected but CPU doesn't have Enhanced or Automatic IBRS. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if ((spectre_v2_cmd == SPECTRE_V2_CMD_RETPOLINE_LFENCE ||
> + spectre_v2_cmd == SPECTRE_V2_CMD_EIBRS_LFENCE) &&
> + !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
> + pr_err("LFENCE selected, but CPU doesn't have a serializing LFENCE. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !IS_ENABLED(CONFIG_MITIGATION_IBRS_ENTRY)) {
> + pr_err("IBRS selected but not compiled in. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
> + pr_err("IBRS selected but not Intel CPU. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && !boot_cpu_has(X86_FEATURE_IBRS)) {
> + pr_err("IBRS selected but CPU doesn't have IBRS. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +
> + if (spectre_v2_cmd == SPECTRE_V2_CMD_IBRS && cpu_feature_enabled(X86_FEATURE_XENPV)) {
> + pr_err("IBRS selected but running as XenPV guest. Switching to AUTO select\n");
> + spectre_v2_cmd = SPECTRE_V2_CMD_AUTO;
> + }
> +}
> +
> static void __init spectre_v2_select_mitigation(void)
> {
> - spectre_v2_cmd = spectre_v2_parse_cmdline();
> + spectre_v2_check_cmd();
>
> if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2) &&
> (spectre_v2_cmd == SPECTRE_V2_CMD_NONE || spectre_v2_cmd == SPECTRE_V2_CMD_AUTO))
> --
> 2.34.1
>
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette