Re: [PATCH v10 05/15] x86/cpu: Defer CR pinning enforcement until late_initcall()

From: Sohil Mehta

Date: Tue Oct 07 2025 - 19:05:45 EST


On 10/7/2025 10:23 AM, Edgecombe, Rick P wrote:

>
> Why is only set_virtual_address_map problematic? Some of the other ones get
> called after boot by a bunch of modules by the looks of it.
>

AFAIU, efi_enter_virtual_mode()->set_virtual_address_map maps the
runtime services from physical mode into virtual mode.

After that, all the other runtime services can get called using virtual
addressing. I can find out more if you still have concerns.

>> @@ -476,8 +476,8 @@ void cr4_init(void)
>>
>> if (boot_cpu_has(X86_FEATURE_PCID))
>> cr4 |= X86_CR4_PCIDE;
>> - if (static_branch_likely(&cr_pinning))
>> - cr4 = (cr4 & ~cr4_pinned_mask) | cr4_pinned_bits;
>> +
>> + cr4 = (cr4 & ~cr4_pinned_mask) | cr4_pinned_bits;
>
>
> Can you explain why this change is needed? It relies on cr4_pinned_bits to be
> already set, and kind of is "enforcement", but no longer depends on
> enable_cr_pinning() being called.
>

cr4_init() is only called from APs during bring up. The pinned bits are
saved on the BSP and then used to program the CR4 on the APs. It is
independent of pinning *enforcement* which warns when these bits get
modified.

>
>>
>> __write_cr4(cr4);
>>