Re: [RFC PATCH 2/3] x86/boot: Set __pgtable_l5_enabled correctly before calling into C code
From: Ard Biesheuvel
Date: Sat May 10 2025 - 10:51:28 EST
On Sat, 10 May 2025 at 15:54, David Laight <david.laight.linux@xxxxxxxxx> wrote:
>
> 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?
>
Excellent point - no, they are not.
> I'd guess that __pgtable_l5_enabled was getting set before .bss was cleared?
>
Yes.