powerpc/ptdump: Handle hugepd at PGD level
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 19 May 2020 05:48:55 +0000 (05:48 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 26 May 2020 12:22:19 +0000 (22:22 +1000)
The 8xx is about to map kernel linear space and IMMR using huge
pages.

In order to display those pages properly, ptdump needs to handle
hugepd tables at PGD level.

For the time being do it only at PGD level. Further patches may
add handling of hugepd tables at lower level for other platforms
when needed in the future.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/630728289158dcfeb06b14d40ed7c4c4e7148cf1.1589866984.git.christophe.leroy@csgroup.eu
arch/powerpc/mm/ptdump/ptdump.c

index 98d82dcf6f0b9f57533e0c234981de461152dbf2..5fc880e301756bce09a3def3695c26c24807e038 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/const.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
+#include <asm/hugetlb.h>
 
 #include <mm/mmu_decl.h>
 
@@ -269,6 +270,26 @@ static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
        }
 }
 
+static void walk_hugepd(struct pg_state *st, hugepd_t *phpd, unsigned long start,
+                       int pdshift, int level)
+{
+#ifdef CONFIG_ARCH_HAS_HUGEPD
+       unsigned int i;
+       int shift = hugepd_shift(*phpd);
+       int ptrs_per_hpd = pdshift - shift > 0 ? 1 << (pdshift - shift) : 1;
+
+       if (start & ((1 << shift) - 1))
+               return;
+
+       for (i = 0; i < ptrs_per_hpd; i++) {
+               unsigned long addr = start + (i << shift);
+               pte_t *pte = hugepte_offset(*phpd, addr, pdshift);
+
+               note_page(st, addr, level + 1, pte_val(*pte), 1 << shift);
+       }
+#endif
+}
+
 static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
 {
        pmd_t *pmd = pmd_offset(pud, 0);
@@ -312,11 +333,13 @@ static void walk_pagetables(struct pg_state *st)
         * the hash pagetable.
         */
        for (i = pgd_index(addr); i < PTRS_PER_PGD; i++, pgd++, addr += PGDIR_SIZE) {
-               if (!pgd_none(*pgd) && !pgd_is_leaf(*pgd))
+               if (pgd_none(*pgd) || pgd_is_leaf(*pgd))
+                       note_page(st, addr, 1, pgd_val(*pgd), PGDIR_SIZE);
+               else if (is_hugepd(__hugepd(pgd_val(*pgd))))
+                       walk_hugepd(st, (hugepd_t *)pgd, addr, PGDIR_SHIFT, 1);
+               else
                        /* pgd exists */
                        walk_pud(st, pgd, addr);
-               else
-                       note_page(st, addr, 1, pgd_val(*pgd), PGDIR_SIZE);
        }
 }