Re: [PATCH v3 08/26] x86/mm: move LDT remap into mm-local region

Yosry Ahmed <[email protected]> Mon, 3 Aug 2026 22:33:15 +0000
Newsgroups org.kvack.linux-mm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Sun, Jul 26, 2026 at 10:22:41PM +0000, Brendan Jackman wrote:
> Now that x86 processes have a general mm-local region, the LDT-specific
> management of the higher-level pagetables can mostly be replaced by just
> using the generic mm-local API.
> 
> Drop all management of pagetable allocation and freeing; that is now
> handled automatically by virtue of the pagetables being in the mm-local
> region.
> 
> Drop explicit logic to map LDTs into the user pagetables under PTI; that
> also happens automatically for this region.
> 
> Unify the sanity-checking logic between x86_64 and PAE: use the generic
> set_memory.c mechanism to walk pagetables. This means the
> sanity-checking is slightly more relaxed, since lookup_address_in_pgd()
> is more flexible than pgd_to_pmd_walk(), but this seems to be worth it
> for the simplified code. It means that ldt.c doesn't have to know about
> the exact structure of the mm-local region's pagetables.
> 
> Signed-off-by: Brendan Jackman <[email protected]>
> ---
[..]
> diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
> index 40c5bf97dd5cc..685664c1ee770 100644
> --- a/arch/x86/kernel/ldt.c
> +++ b/arch/x86/kernel/ldt.c
> @@ -186,10 +186,16 @@ static struct ldt_struct *alloc_ldt_struct(unsigned int num_entries)
>  
>  #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
>  
> -static void do_sanity_check(struct mm_struct *mm,
> -			    bool had_kernel_mapping,
> -			    bool had_user_mapping)
> +static void sanity_check_ldt_mapping(struct mm_struct *mm)
>  {
> +	pgd_t *k_pgd = pgd_offset(mm, LDT_BASE_ADDR);
> +	pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd);
> +	unsigned int k_level, u_level;
> +	bool had_kernel_mapping, had_user_mapping;
> +
> +	had_kernel_mapping = lookup_address_in_pgd(k_pgd, LDT_BASE_ADDR, &k_level);
> +	had_user_mapping   = lookup_address_in_pgd(u_pgd, LDT_BASE_ADDR, &u_level);
> +

As mentioned in the previous patch, this patch is difficult to review
with the current arrangement and patches 7 and 8 can probably be
structured in a better way.

The unification of sanity_check_ldt_mapping() by using
lookup_address_in_pgd() can also be done separately as part of that.

>  	if (mm->context.ldt) {
>  		/*
>  		 * We already had an LDT.  The top-level entry should already