Re: [PATCH v1] x86/smp: Set up exception handling before cr4_init()

From: Xin Li

Date: Mon Feb 09 2026 - 22:13:03 EST




> On Feb 9, 2026, at 5:13 PM, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>
> On 2/9/26 16:18, Sohil Mehta wrote:
>>
>> However, I found another location where we enable FRED in CR4 before
>> enabling the MSRs.


IIRC, it’s expected:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e5f1e8af9c9e151ecd665f6d2e36fb25fec3b110



>>
>> __restore_processor_state():
>>
>> ...
>>
>> __write_cr4(ctxt->cr4);
>>
>> ...
>>
>> if (ctxt->cr4 & X86_CR4_FRED) {
>> cpu_init_fred_exceptions();
>> cpu_init_fred_rsps();
>> }
>>
>> Due to limitations of my test platform, I couldn't verify the FRED print
>> in __restore_processor_state()'s path. But, could "restore" run into a
>> similar issue in the future?
>
> It sure looks like it. Good catch! I have the feeling there's never been
> an exception in that code anyway. The:
>
> wrmsrq(MSR_GS_BASE, ctxt->kernelmode_gs_base);
>
> is misplaced too. Exception handling leans heavily on MSR_GS_BASE.
>
> But, it doesn't hurt to be consistent about the ordering.
>
> In a perfect world, we'd probably unify all this code. Maybe the boot
> code establishes a 'saved_context' and all the APs just
> restore_processor_state() to go online normally instead of just for a
> restore. Or maybe the restore_processor_state() should be unified more
> with start_secondary() because a big chunk of the stuff its restoring is
> pretty static already.
>
> But there's no need today to do anything that drastic.
>