Re: [PATCH] x86/fred: Fix early boot failures on SEV-ES/SNP guests

From: H. Peter Anvin

Date: Thu Feb 05 2026 - 12:45:29 EST


On February 5, 2026 9:20:20 AM PST, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>On 2/5/26 08:10, Dave Hansen wrote:
>> Shouldn't we flip the FRED CR4 bit _last_, once all the MSRs are set up?
>> Why is it backwards in the first place? Why can't it be fixed?
>
>Ahhh, it was done by CR4 pinning. It's the first thing in C code for
>booting secondaries:
>
>static void notrace __noendbr start_secondary(void *unused)
>{
> cr4_init();
>
>Since FRED is set in 'cr4_pinned_mask', cr4_init() sets the FRED bit far
>before the FRED MSRs are ready. Anyone else doing native_write_cr4()
>will do the same thing. That's obviously not what was intended from the
>pinning code or the FRED init code.
>
>Shouldn't we fix this properly rather than moving printk()'s around?
>
>One idea is just to turn off all the CR-pinning logic while bringing
>CPUs up. That way, nothing before:
>
> set_cpu_online(smp_processor_id(), true);
>
>can get tripped up by CR pinning. I've attached a completely untested
>patch to do that.
>
>The other thing would be to make pinning actually per-cpu:
>'cr4_pinned_bits' could be per-cpu and we'd just keep it empty until the
>CPU is actually booted and everything is fully set up.
>
>Either way, this is looking like it'll be a bit more than one patch to
>do properly.
We could initialize the FRED MSRs much earlier, like we do during S3 resume.