Re: [PATCH v5 04/16] x86/bugs: Restructure RFDS mitigation

Borislav Petkov
2025-04-27T15:08:28Z

On Fri, Apr 18, 2025 at 11:17:09AM -0500, David Kaplan wrote:
> +static bool __init rfds_has_ucode(void)
> +{
> + return (x86_arch_cap_msr & ARCH_CAP_RFDS_CLEAR);
> +}

Might as well call it what the bit means and then the code reads a bit better:

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index e668ccccd8c7..2705105d9a5e 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -630,7 +630,7 @@ static const char * const rfds_strings[] = {
[RFDS_MITIGATION_UCODE_NEEDED] = "Vulnerable: No microcode",
};

-static bool __init rfds_has_ucode(void)
+static inline bool __init verw_clears_cpu_reg_file(void)
{
return (x86_arch_cap_msr & ARCH_CAP_RFDS_CLEAR);
}
@@ -648,7 +648,7 @@ static void __init rfds_select_mitigation(void)
if (rfds_mitigation == RFDS_MITIGATION_OFF)
return;

- if (rfds_has_ucode())
+ if (verw_clears_cpu_reg_file())
verw_clear_cpu_buf_mitigation_selected = true;
}

@@ -661,7 +661,7 @@ static void __init rfds_update_mitigation(void)
rfds_mitigation = RFDS_MITIGATION_VERW;

if (rfds_mitigation == RFDS_MITIGATION_VERW) {
- if (!rfds_has_ucode())
+ if (!verw_clears_cpu_reg_file())
rfds_mitigation = RFDS_MITIGATION_UCODE_NEEDED;
}

--
Regards/Gruss,
Boris.