Re: [PATCH 1/3] powerpc/book3s: Use config independent helpers for page table walk

2019-07-07 Thread Michael Ellerman
On Tue, 2019-05-14 at 06:03:00 UTC, "Aneesh Kumar K.V" wrote:
> Even when we have HugeTLB and THP disabled, kernel linear map can still be
> mapped with hugepages. This is only an issue with radix translation because 
> hash
> MMU doesn't map kernel linear range in linux page table and other kernel
> map areas are not mapped using hugepage.
> 
> Add config independent helpers and put WARN_ON() when we don't expect things
> to be mapped via hugepages.
> 
> Signed-off-by: Aneesh Kumar K.V 

Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/d6eacedd1f0ebf00bdf1c77715d194f7c1036fd4

cheers


[PATCH 1/3] powerpc/book3s: Use config independent helpers for page table walk

2019-05-14 Thread Aneesh Kumar K.V
Even when we have HugeTLB and THP disabled, kernel linear map can still be
mapped with hugepages. This is only an issue with radix translation because hash
MMU doesn't map kernel linear range in linux page table and other kernel
map areas are not mapped using hugepage.

Add config independent helpers and put WARN_ON() when we don't expect things
to be mapped via hugepages.

Signed-off-by: Aneesh Kumar K.V 
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 21 +++
 arch/powerpc/include/asm/pgtable.h   | 24 +
 arch/powerpc/include/asm/pte-walk.h  | 28 ++--
 arch/powerpc/kvm/book3s_64_mmu_radix.c   | 12 +++--
 arch/powerpc/mm/book3s64/radix_pgtable.c | 10 +++
 arch/powerpc/mm/pgtable.c| 16 +--
 arch/powerpc/mm/pgtable_64.c | 12 ++---
 arch/powerpc/mm/ptdump/ptdump.c  |  6 ++---
 arch/powerpc/xmon/xmon.c |  6 ++---
 9 files changed, 102 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 7dede2e34b70..f402b2a96ef3 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1313,5 +1313,26 @@ static inline bool is_pte_rw_upgrade(unsigned long 
old_val, unsigned long new_va
return false;
 }
 
+/*
+ * Like pmd_huge() and pmd_large(), but works regardless of config options
+ */
+#define pmd_is_leaf pmd_is_leaf
+static inline bool pmd_is_leaf(pmd_t pmd)
+{
+   return !!(pmd_raw(pmd) & cpu_to_be64(_PAGE_PTE));
+}
+
+#define pud_is_leaf pud_is_leaf
+static inline bool pud_is_leaf(pud_t pud)
+{
+   return !!(pud_raw(pud) & cpu_to_be64(_PAGE_PTE));
+}
+
+#define pgd_is_leaf pgd_is_leaf
+static inline bool pgd_is_leaf(pgd_t pgd)
+{
+   return !!(pgd_raw(pgd) & cpu_to_be64(_PAGE_PTE));
+}
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 3f53be60fb01..bf7d771f342e 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -140,6 +140,30 @@ static inline void pte_frag_set(mm_context_t *ctx, void *p)
 }
 #endif
 
+#ifndef pmd_is_leaf
+#define pmd_is_leaf pmd_is_leaf
+static inline bool pmd_is_leaf(pmd_t pmd)
+{
+   return false;
+}
+#endif
+
+#ifndef pud_is_leaf
+#define pud_is_leaf pud_is_leaf
+static inline bool pud_is_leaf(pud_t pud)
+{
+   return false;
+}
+#endif
+
+#ifndef pgd_is_leaf
+#define pgd_is_leaf pgd_is_leaf
+static inline bool pgd_is_leaf(pgd_t pgd)
+{
+   return false;
+}
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_PGTABLE_H */
diff --git a/arch/powerpc/include/asm/pte-walk.h 
b/arch/powerpc/include/asm/pte-walk.h
index 2d633e9d686c..33fa5dd8ee6a 100644
--- a/arch/powerpc/include/asm/pte-walk.h
+++ b/arch/powerpc/include/asm/pte-walk.h
@@ -10,8 +10,20 @@ extern pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long 
ea,
 static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea,
bool *is_thp, unsigned *hshift)
 {
+   pte_t *pte;
+
VM_WARN(!arch_irqs_disabled(), "%s called with irq enabled\n", 
__func__);
-   return __find_linux_pte(pgdir, ea, is_thp, hshift);
+   pte = __find_linux_pte(pgdir, ea, is_thp, hshift);
+
+#if defined(CONFIG_DEBUG_VM) &&
\
+   !(defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE))
+   /*
+* We should not find huge page if these configs are not enabled.
+*/
+   if (hshift)
+   WARN_ON(*hshift);
+#endif
+   return pte;
 }
 
 static inline pte_t *find_init_mm_pte(unsigned long ea, unsigned *hshift)
@@ -26,10 +38,22 @@ static inline pte_t *find_init_mm_pte(unsigned long ea, 
unsigned *hshift)
 static inline pte_t *find_current_mm_pte(pgd_t *pgdir, unsigned long ea,
 bool *is_thp, unsigned *hshift)
 {
+   pte_t *pte;
+
VM_WARN(!arch_irqs_disabled(), "%s called with irq enabled\n", 
__func__);
VM_WARN(pgdir != current->mm->pgd,
"%s lock less page table lookup called on wrong mm\n", 
__func__);
-   return __find_linux_pte(pgdir, ea, is_thp, hshift);
+   pte = __find_linux_pte(pgdir, ea, is_thp, hshift);
+
+#if defined(CONFIG_DEBUG_VM) &&
\
+   !(defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE))
+   /*
+* We should not find huge page if these configs are not enabled.
+*/
+   if (hshift)
+   WARN_ON(*hshift);
+#endif
+   return pte;
 }
 
 #endif /* _ASM_POWERPC_PTE_WALK_H */
diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c 
b/arch/powerpc/kvm/book3s_64_mmu_radix.c
index f55ef071883f..91efee7f0329 100644
---