Re: [PATCH v3 13/35] x86/bugs: Restructure spectre_v2_user mitigation

From: Josh Poimboeuf
Date: Mon Feb 10 2025 - 19:53:50 EST


On Wed, Jan 08, 2025 at 02:24:53PM -0600, David Kaplan wrote:
> - if (retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
> - retbleed_mitigation == RETBLEED_MITIGATION_IBPB) {
> - if (mode != SPECTRE_V2_USER_STRICT &&
> - mode != SPECTRE_V2_USER_STRICT_PREFERRED)
> + if (spectre_v2_user_stibp != SPECTRE_V2_USER_NONE &&
> + (retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
> + retbleed_mitigation == RETBLEED_MITIGATION_IBPB)) {

This adds a hidden dependency on retbleed_update_mitigation()?

Also, that last line should be aligned one more space to the right:

if (spectre_v2_user_stibp != SPECTRE_V2_USER_NONE &&
(retbleed_mitigation == RETBLEED_MITIGATION_UNRET ||
retbleed_mitigation == RETBLEED_MITIGATION_IBPB)) {

> +static void __init spectre_v2_user_apply_mitigation(void)
> +{
> + /* Initialize Indirect Branch Prediction Barrier */
> + if (boot_cpu_has(X86_FEATURE_IBPB) &&
> + spectre_v2_user_ibpb != SPECTRE_V2_USER_NONE) {
> + setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
>
> -set_mode:
> - pr_info("%s\n", spectre_v2_user_strings[mode]);
> + switch (spectre_v2_user_ibpb) {
> + case SPECTRE_V2_USER_NONE:
> + break;

This case can't happen, spectre_v2_user_ibpb was already checked for
!SPECTRE_V2_USER_NONE above.

--
Josh