Re: [tip: x86/mm] x86/mm: Check if PTRS_PER_PMD is defined before use

From: Linus Torvalds
Date: Thu Mar 06 2025 - 14:50:19 EST


On Thu, 6 Mar 2025 at 00:13, tip-bot2 for Andy Shevchenko
<tip-bot2@xxxxxxxxxxxxx> wrote:
>
> x86/mm: Check if PTRS_PER_PMD is defined before use

I'm not at all happy with this one.

> -#if PTRS_PER_PMD > 1
> +#if defined(PTRS_PER_PMD) && (PTRS_PER_PMD > 1)

Honestly, I feel that if PTRS_PER_PMD isn't defined, we've missed some
include, and now the code is making random decisions based on lack of
information.

That's not correct. You can't say "I don't know the size, so I'm just
assuming it's 1".

It should always be defined, because it's normally used
unconditionally (just grep for it in mm code, eg mm/pagewalk.c:
real_depth()).

So the undefined case really is broken.

It should be defined either by the architecture pgtable_types.h
header, or if the PMD is folded away, the architecture should have
included <asm-generic/pgtable-nopmd.h>.

So I'm *really* thinking this patch is completely bogus and is hiding
a serious problem, and making PAGE_TABLE_SIZE() have random values.

Linus