Re: [PATCH v4 13/36] x86/bugs: Restructure spectre_v2 mitigation

From: Josh Poimboeuf
Date: Thu Apr 10 2025 - 13:08:59 EST


On Mon, Mar 10, 2025 at 11:40:00AM -0500, David Kaplan wrote:
> Restructure spectre_v2 to use select/update/apply functions to create
> consistent vulnerability handling.
>
> The spectre_v2 mitigation may be updated based on the selected retbleed
> mitigation.
>
> Signed-off-by: David Kaplan <david.kaplan@xxxxxxx>
> ---
> arch/x86/kernel/cpu/bugs.c | 79 +++++++++++++++++++++++---------------
> 1 file changed, 48 insertions(+), 31 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 96cb2ac70245..b4a72ddf159c 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -56,6 +56,8 @@
> static void __init spectre_v1_select_mitigation(void);
> static void __init spectre_v1_apply_mitigation(void);
> static void __init spectre_v2_select_mitigation(void);
> +static void __init spectre_v2_update_mitigation(void);
> +static void __init spectre_v2_apply_mitigation(void);
> static void __init retbleed_select_mitigation(void);
> static void __init retbleed_update_mitigation(void);
> static void __init retbleed_apply_mitigation(void);
> @@ -212,7 +214,12 @@ void __init cpu_select_mitigations(void)
> /*
> * After mitigations are selected, some may need to update their
> * choices.
> + *
> + * Note that retbleed_update_mitigation() relies on the state set by
> + * spectre_v2_update_mitigation(); specifically it wants to know about
> + * spectre_v2=ibrs.
> */
> + spectre_v2_update_mitigation();
> retbleed_update_mitigation();

I'd suggest moving that dependency comment to above
retbleed_update_mitigaton() and making it more concise:

/*
* After mitigations are selected, some may need to update their
* choices.
*/
spectre_v2_update_mitigation();
/* retbleed_update_mitigation() depends on spectre_v2_update_mitigation() */
retbleed_update_mitigation();

--
Josh