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

From: Dave Hansen

Date: Mon Feb 09 2026 - 20:13:54 EST


On 2/9/26 16:18, Sohil Mehta wrote:
>
> However, I found another location where we enable FRED in CR4 before
> enabling the MSRs.
>
> __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.