Linux-mm Archive on
 help / color / Atom feed
* [patch 046/158] mm: add generic p?d_leaf() macros
@ 2019-12-01  1:51 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2019-12-01  1:51 UTC (permalink / raw)
  To: akpm, alex, aou, ard.biesheuvel, arnd, aryabinin, benh,
	borntraeger, bp, catalin.marinas, dave.hansen, dave.jiang, davem,
	dvyukov, glider, gor, heiko.carstens, hpa, james.morse, jhogan,
	kan.liang, linux-mm, linux, luto, Mark.Rutland, mawilcox, mingo,
	mm-commits, mpe, n-horiguchi, palmer, paul.burton, paul.walmsley,
	paulus, peterz, ralf, shashim, steven.price, tglx, torvalds,
	vgupta, will,

From: Steven Price <>
Subject: mm: add generic p?d_leaf() macros

Patch series "Generic page walk and ptdump", v15.

Many architectures current have a debugfs file for dumping the kernel page
tables.  Currently each architecture has to implement custom functions for
this because the details of walking the page tables used by the kernel are
different between architectures.

This series extends the capabilities of walk_page_range() so that it can
deal with the page tables of the kernel (which have no VMAs and can
contain larger huge pages than exist for user space).  A generic PTDUMP
implementation is the implemented making use of the new functionality of
walk_page_range() and finally arm64 and x86 are switch to using it,
removing the custom table walkers.

To enable a generic page table walker to walk the unusual mappings of the
kernel we need to implement a set of functions which let us know when the
walker has reached the leaf entry.  After a suggestion from Will Deacon
I've chosen the name p?d_leaf() as this (hopefully) describes the purpose
(and is a new name so has no historic baggage).  Some architectures have
p?d_large macros but this is easily confused with "large pages".

This series ends with a generic PTDUMP implemention for arm64 and x86.

Mostly this is a clean up and there should be very little functional
change. The exceptions are:

* arm64 PTDUMP debugfs now displays pages which aren't present (patch 22).

* arm64 has the ability to efficiently process KASAN pages (which
  previously only x86 implemented). This means that the combination of
  KASAN and DEBUG_WX is now useable.

This patch (of 23):

Exposing the pud/pgd levels of the page tables to walk_page_range() means
we may come across the exotic large mappings that come with large areas of
contiguous memory (such as the kernel's linear map).

For architectures that don't provide all p?d_leaf() macros, provide
generic do nothing default that are suitable where there cannot be leaf
pages at that level.  Futher patches will add implementations for
individual architectures.

The name p?d_leaf() is chosen to minimize the confusion with existing uses
of "large" pages and "huge" pages which do not necessary mean that the
entry is a leaf (for example it may be a set of contiguous entries that
only take 1 TLB slot).  For the purpose of walking the page tables we
don't need to know how it will be represented in the TLB, but we do need
to know for sure if it is a leaf of the tree.

Signed-off-by: Steven Price <>
Acked-by: Mark Rutland <>
Cc: Albert Ou <>
Cc: Alexandre Ghiti <>
Cc: Andy Lutomirski <>
Cc: Ard Biesheuvel <>
Cc: Arnd Bergmann <>
Cc: Benjamin Herrenschmidt <>
Cc: Borislav Petkov <>
Cc: Catalin Marinas <>
Cc: Christian Borntraeger <>
Cc: Dave Hansen <>
Cc: Heiko Carstens <>
Cc: "H. Peter Anvin" <>
Cc: James Hogan <>
Cc: James Morse <>
Cc: "Liang, Kan" <>
Cc: Mark Rutland <>
Cc: Michael Ellerman <>
Cc: Palmer Dabbelt <>
Cc: Paul Burton <>
Cc: Paul Mackerras <>
Cc: Paul Walmsley <>
Cc: Peter Zijlstra <>
Cc: Ralf Baechle <>
Cc: Russell King <>
Cc: Thomas Gleixner <>
Cc: Vasily Gorbik <>
Cc: Vineet Gupta <>
Cc: Will Deacon <>
Cc: Zong Li <>
Cc: Alexander Potapenko <>
Cc: Andrey Ryabinin <>
Cc: Dave Jiang <>
Cc: David S. Miller <>
Cc: Dmitry Vyukov <>
Cc: Ingo Molnar <>
Cc: Matthew Wilcox <>
Cc: Naoya Horiguchi <>
Cc: Shiraz Hashim <>
Signed-off-by: Andrew Morton <>

 include/asm-generic/pgtable.h |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- a/include/asm-generic/pgtable.h~mm-add-generic-pd_leaf-macros
+++ a/include/asm-generic/pgtable.h
@@ -1238,4 +1238,24 @@ static inline bool arch_has_pfn_modify_c
 #define mm_pmd_folded(mm)	__is_defined(__PAGETABLE_PMD_FOLDED)
+ * p?d_leaf() - true if this entry is a final mapping to a physical address.
+ * This differs from p?d_huge() by the fact that they are always available (if
+ * the architecture supports large pages at the appropriate level) even
+ * if CONFIG_HUGETLB_PAGE is not defined.
+ * Only meaningful when called on a valid entry.
+ */
+#ifndef pgd_leaf
+#define pgd_leaf(x)	0
+#ifndef p4d_leaf
+#define p4d_leaf(x)	0
+#ifndef pud_leaf
+#define pud_leaf(x)	0
+#ifndef pmd_leaf
+#define pmd_leaf(x)	0
 #endif /* _ASM_GENERIC_PGTABLE_H */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-01  1:51 [patch 046/158] mm: add generic p?d_leaf() macros akpm

Linux-mm Archive on

Archives are clonable:
	git clone --mirror linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ \
	public-inbox-index linux-mm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone