Skip to contentSkip to conversation

x86: update comment about pgd_list

PATCH Applied Brendan Jackman 4 participants 5 messages Mar 23 – May 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: update comment about pgd_list

This venerable comment got detached from its context when the code moved in commit 394158559d4c ("x86: move all the pgd_list handling to one place"). Put it back next to its context. It was originally on pgd_list_add() but it actually describes pgd_list so put it there.

While moving it, update it to strip away stale and superfluous info. pageattr.c doesn't exist any more. pgd_list is now required for all x86 architectures. Also be slightly more precise about what PGDs are in this list.

---
Changes in v2:
- Moved it next to pgd_list instead of back to old location
- Strip away stale bits from the comment
- Added note about PGDs that _aren't_ in this list
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 arch/x86/mm/fault.c   |  6 ++++++
 arch/x86/mm/pgtable.c | 11 -----------
 2 files changed, 6 insertions(+), 11 deletions(-)
arch/x86/mm/fault.c +6 -0
index f0e77e0844820..cf7144d386b87 100644
@@ -169,6 +169,12 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
 }
 
 DEFINE_SPINLOCK(pgd_lock);
+/*
+ * List of all process' PGD pages (excluding init_mm and some other special
+ * system-wide PGDs); for kernel addresses the lower level pages are mostly
+ * shared but the PGD itself is local to each mm. This list is mainly used to
+ * keep those in sync.
+ */
 LIST_HEAD(pgd_list);
 
 #ifdef CONFIG_X86_32
arch/x86/mm/pgtable.c +0 -11
index 2e5ecfdce73c3..2a84fdeca8874 100644
@@ -99,17 +99,6 @@ static void pgd_dtor(pgd_t *pgd)
 	spin_unlock(&pgd_lock);
 }
 
-/*
- * List of all pgd's needed for non-PAE so it can invalidate entries
- * in both cached and uncached pgd's; not needed for PAE since the
- * kernel pmd is shared. If PAE were not to share the pmd a similar
- * tactic would be needed. This is essentially codepath-based locking
- * against pageattr.c; it is the unique case in which a valid change
- * of kernel pagetables can't be lazily synchronized by vmalloc faults.
- * vmalloc faults work because attached pagetables are never freed.
- * -- nyc
- */
-
 #ifdef CONFIG_X86_PAE
 /*
  * In PAE mode, we need to do a cr3 reload (=tlb flush) when

---
base-commit: 2ca26dad836fb4cd18694ef85af7a71d2878b239
change-id: 20260311-pgd_list-comment-2ee97876c552

Best regards,

Signature · 1 line
Brendan Jackman <[email protected]>
#1 lore raw
Quoted 10 lines · Brendan Jackman

This venerable comment got detached from its context when the code moved in commit 394158559d4c ("x86: move all the pgd_list handling to one place"). Put it back next to its context. It was originally on pgd_list_add() but it actually describes pgd_list so put it there.

While moving it, update it to strip away stale and superfluous info. pageattr.c doesn't exist any more. pgd_list is now required for all x86 architectures. Also be slightly more precise about what PGDs are in this list.

Quoted 7 lines

---
Changes in v2:
- Moved it next to pgd_list instead of back to old location
- Strip away stale bits from the comment
- Added note about PGDs that _aren't_ in this list
- Link to v1: https://lore.kernel.org/r/[email protected]

Hi Dave,

I think this is ready?

(I don't see it in tip/master, apologies if I'm looking in the wrong place).

#2 lore raw
Quoted 19 lines · Brendan Jackman
Quoted 10 lines · Brendan Jackman

This venerable comment got detached from its context when the code moved in commit 394158559d4c ("x86: move all the pgd_list handling to one place"). Put it back next to its context. It was originally on pgd_list_add() but it actually describes pgd_list so put it there.

While moving it, update it to strip away stale and superfluous info. pageattr.c doesn't exist any more. pgd_list is now required for all x86 architectures. Also be slightly more precise about what PGDs are in this list.

Quoted 7 lines

---
Changes in v2:
- Moved it next to pgd_list instead of back to old location
- Strip away stale bits from the comment
- Added note about PGDs that _aren't_ in this list
- Link to v1: https://lore.kernel.org/r/[email protected]

Quoted 6 lines

Hi Dave,

I think this is ready?

(I don't see it in tip/master, apologies if I'm looking in the wrong place).

The PAE code comment should still remain.

I don't know if the 32-bit PAE code is still suffering from Xen-induced drain bramage (using a whole page to store 32 bytes), but it is nevertheless true in a fashion -- as there are a maximum of 3 kernel PDE pages, they are considered the de facto top level of the kernel page tables.

-hpa

#3 lore raw
Quoted 4 lines · H. Peter Anvin

The PAE code comment should still remain.

I don't know if the 32-bit PAE code is still suffering from Xen-induced drain bramage (using a whole page to store 32 bytes),

Actually, I think I recently spread the brain damage even further. The kmalloc()'d PGDs are completely gone now. PGDs all directly out of the page allocator. It actually simplified the 32-bit code quite a bit.

Quoted 3 lines

but it is nevertheless true in a fashion -- as there are a maximum of 3 kernel PDE pages, they are considered the de facto top level of the kernel page tables.

Here's what I ended up with:

Quoted 5 lines

+/*
+ * List of all process' PGD pages (excluding init_mm and some other special
+ * system-wide PGDs). Mainly used to keep the kernel portion of the address
+ * space in sync across mms.
+ */

I think what you're saying is that those (max) 3 kernel PDE pages are static and all PGDs always have the same value in there. So, there's no synchronizing necessary on PAE. That was definitely true for a long time.

But we actually also moved away from that:

Quoted 1 line

https://lore.kernel.org/all/[email protected]/

PTI forced some PMD unsharing. So I just moved 32-bit over to not share kernel PMDs at all. It made the 32-bit code quite a bit simpler, although it wastes memory when PTI is disabled.

#4 lore raw

[tip: x86/mm] x86: Update comment about pgd_list

In reply to Brendan Jackman
The following commit has been merged into the x86/mm branch of tip:

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     952ac097ce98901c608cdced012f89a90367401e
Gitweb:        https://git.kernel.org/tip/952ac097ce98901c608cdced012f89a90367401e
Author:        Brendan Jackman <[email protected]>
AuthorDate:    Mon, 23 Mar 2026 14:25:07 
Committer:     Dave Hansen <[email protected]>
CommitterDate: Mon, 11 May 2026 11:26:33 -07:00

x86: Update comment about pgd_list

This venerable comment got detached from its context when the code moved in commit 394158559d4c ("x86: move all the pgd_list handling to one place"). Put it back next to its context. It was originally on pgd_list_add() but it actually describes pgd_list so put it there.

While moving it, update it to strip away stale and superfluous info. pageattr.c doesn't exist any more. pgd_list is now required for all x86 architectures. Also be slightly more precise about what PGDs are in this list.

[ dhansen: tweak and trim the updated comment a bit ]

---
 arch/x86/mm/fault.c   |  5 +++++
 arch/x86/mm/pgtable.c | 11 -----------
 2 files changed, 5 insertions(+), 11 deletions(-)
arch/x86/mm/fault.c +5 -0
index 63de8e8..250942e 100644
@@ -169,6 +169,11 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
 }
 
 DEFINE_SPINLOCK(pgd_lock);
+/*
+ * List of all process' PGD pages (excluding init_mm and some other special
+ * system-wide PGDs). Mainly used to keep the kernel portion of the address
+ * space in sync across mms.
+ */
 LIST_HEAD(pgd_list);
 
 #ifdef CONFIG_X86_32
arch/x86/mm/pgtable.c +0 -11
index da7f0a0..f32facd 100644
@@ -99,17 +99,6 @@ static void pgd_dtor(pgd_t *pgd)
 	spin_unlock(&pgd_lock);
 }
 
-/*
- * List of all pgd's needed for non-PAE so it can invalidate entries
- * in both cached and uncached pgd's; not needed for PAE since the
- * kernel pmd is shared. If PAE were not to share the pmd a similar
- * tactic would be needed. This is essentially codepath-based locking
- * against pageattr.c; it is the unique case in which a valid change
- * of kernel pagetables can't be lazily synchronized by vmalloc faults.
- * vmalloc faults work because attached pagetables are never freed.
- * -- nyc
- */
-
 #ifdef CONFIG_X86_PAE
 /*
  * In PAE mode, we need to do a cr3 reload (=tlb flush) when