Re: [RFC PATCH 2/3] x86/boot: Set __pgtable_l5_enabled correctly before calling into C code

From: David Laight
Date: Sat May 10 2025 - 09:55:00 EST


On Tue, 6 May 2025 17:45:35 +0200
Ard Biesheuvel <ardb+git@xxxxxxxxxx> wrote:

> From: Ard Biesheuvel <ardb@xxxxxxxxxx>
>
> Ensure that __pgtable_l5_enabled() is set to its permanent value before
> calling into any C code that may manipulate page tables or reference any
> global variable or object that may be dimensioned differently based on
> whether 5-level paging is in use.
...
> #ifdef CONFIG_X86_5LEVEL
> -/* __pgtable_l5_enabled needs to be in .data to avoid being cleared along with .bss */
> -unsigned int __section(".data") __pgtable_l5_enabled;
> +unsigned int __pgtable_l5_enabled = 1;
> +
> +/* These need to be in .data to avoid being cleared along with .bss */
> unsigned int __section(".data") pgdir_shift = 39;
> unsigned int __section(".data") ptrs_per_p4d = 1;

Is that comment (and the section assignment) relevant given that they
are initialised non-zero?

I'd guess that __pgtable_l5_enabled was getting set before .bss was cleared?

David