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

Thomas Gleixner
2025-03-21T13:09:00Z

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.

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);

I talk more about that struct apic_page in the context of a subsequent
patch.

Thanks,

tglx