Re: [RFC v2 02/17] x86/apic: Initialize Secure AVIC APIC backing page

From: Neeraj Upadhyay
Date: Fri Mar 21 2025 - 09:49:56 EST




On 3/21/2025 6:38 PM, Thomas Gleixner wrote:
> On Wed, Feb 26 2025 at 14:35, Neeraj Upadhyay wrote:
>> @@ -1504,6 +1504,8 @@ static void setup_local_APIC(void)
>> return;
>> }
>>
>> + if (apic->setup)
>> + apic->setup();
>
> That's broken for AP bringup. This is invoked from ap_starting()
> _before_ anything of the CPU is populated. You _CANNOT_
>
>> +static void x2apic_savic_setup(void)
>> +{
>> + void *backing_page;
>> + enum es_result ret;
>> + unsigned long gpa;
>> +
>> + if (this_cpu_read(apic_backing_page))
>> + return;
>> +
>> + backing_page = kzalloc(PAGE_SIZE, GFP_KERNEL);
>
> allocate memory at that point. This was clearly never tested with any
> debugging enabled. And no GFP_ATOMIC is not the right thing either.
>
> This allocation has to happen on the control CPU before the AP is kicked
> into life.
>

I see. I missed this. I now see warnings with CONFIG_DEBUG_ATOMIC_SLEEP
enabled.

> But the right thing to do is:
>
> struct apic_page __percpu *backing_page __ro_after_init;
>
> and do once on the boot CPU:
>
> backing_page = alloc_percpu(struct apic_page);
>

Ok, got it. Thanks for providing the correct way to do it!


- Neeraj

> I talk more about that struct apic_page in the context of a subsequent
> patch.
>
> Thanks,
>
> tglx