All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org,
	kernel test robot <lkp@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	x86@kernel.org
Subject: Re: [tip: x86/mm] x86/mm: Check if PTRS_PER_PMD is defined before use
Date: Thu, 6 Mar 2025 22:22:09 +0100	[thread overview]
Message-ID: <Z8oSAQiBvVJ_METQ@gmail.com> (raw)
In-Reply-To: <CAHk-=whTGVy1aaEashu3K49wuG7-hARh02xbAr_hMm3844Ec7Q@mail.gmail.com>


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Thu, 6 Mar 2025 at 00:13, tip-bot2 for Andy Shevchenko
> <tip-bot2@linutronix.de> 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.

Yeah, so <asm/pgtable-2level_types.h> hasn't defined it historically, 
because 2-level paging only has PGDs and PTE tables - and it relies on 
<asm-generic/pgtable-nopmd.h> doing it:

 #define PTRS_PER_PMD    1

<asm/pgtable_types.h> includes <asm-generic/pgtable-nopmd.h>, and with 
it most of the MM headers.

But:

> 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.

Yeah, so the MM headers cover the C case - but the bugreport was about 
the assembly side (head_32.S):

  In file included from arch/x86/kernel/head_32.S:29:
  arch/x86/include/asm/pgtable_32.h:59:5: error: "PTRS_PER_PMD" is not defined, evaluates to 0 [-Werror=undef]
     59 | #if PTRS_PER_PMD > 1

and AFAICS the assembly version of these headers doesn't define 
PTRS_PER_PMD.

Separating out the assembler-compatible defines from the types headers 
appears to be a bigger patch, since it's all mixed in with C syntax:

<=-----------------------------------===============================
typedef struct { pud_t pud; } pmd_t;

#define PMD_SHIFT       PUD_SHIFT
#define PTRS_PER_PMD    1
#define PMD_SIZE        (1UL << PMD_SHIFT)
#define PMD_MASK        (~(PMD_SIZE-1))

/*
 * The "pud_xxx()" functions here are trivial for a folded two-level
 * setup: the pmd is never bad, and a pmd always exists (as it's folded
 * into the pud entry)
 */
static inline int pud_none(pud_t pud)           { return 0; }
static inline int pud_bad(pud_t pud)            { return 0; }
static inline int pud_present(pud_t pud)        { return 1; }
================================================================>

In any case I've removed the commit for the time being until this all 
is cleared up.

Thanks,

	Ingo

  reply	other threads:[~2025-03-06 21:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06  9:25 [PATCH v2 1/1] x86/mm: Check if PTRS_PER_PMD is defined before use Andy Shevchenko
2025-03-06 10:13 ` [tip: x86/mm] " tip-bot2 for Andy Shevchenko
2025-03-06 19:49   ` Linus Torvalds
2025-03-06 21:22     ` Ingo Molnar [this message]
2025-03-06 22:00       ` [PATCH] x86/mm: Define PTRS_PER_PMD for assembly code too Ingo Molnar
2025-03-07 16:51         ` Andy Shevchenko
2025-03-07 23:09           ` Ingo Molnar
2025-03-07 23:21         ` [tip: x86/urgent] " tip-bot2 for Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z8oSAQiBvVJ_METQ@gmail.com \
    --to=mingo@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.