Re: x86, possible bug in __memmove() alternatives patching

From: Dave Hansen
Date: Tue Mar 29 2022 - 18:34:47 EST


On 3/26/22 01:27, Borislav Petkov wrote:
> So, more to the point, it is about this chunk:
>
> /*
> * If fast string is not enabled in IA32_MISC_ENABLE for any reason,
> * clear the fast string and enhanced fast string CPU capabilities.
> */
> if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
> rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
> if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
> pr_info("Disabled fast string operations\n");
> setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
> setup_clear_cpu_cap(X86_FEATURE_ERMS);
> }
> }
>
> we already check whether fast strings was disabled, regardless of HV or
> not. Question is, should we clear X86_FEATURE_FSRM there too. I wanna
> say yes.

I don't think it would hurt to clear it.

> Or is it that, *if* MSR_IA32_MISC_ENABLE_FAST_STRING is clear, the FSRM
> CPUID bit was not set either so nothing to clear...

I don't think there's really any direct connection between the CPUID bit
and MSR_IA32_MISC_ENABLE_FAST_STRING. The CPUID bit definitely doesn't
appear to be cleared by the CPU if MSR_IA32_MISC_ENABLE_FAST_STRING is
clear.