Skip to contentSkip to conversation

powerpc/mm/hash64: memset the pagetable pages on allocation.

PATCH Applied Aneesh Kumar K.V 3 participants 3 messages Feb 13, 2018 – Feb 14, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 powerpc/mm/hash64: memset the pagetable pages on allocation.

On powerpc we allocate page table pages from slab cache of different sizes. For now we have a constructor that zero out the objects when we allocate then for the first time. We expect the objects to be zeroed out when we free the the object back to slab cache. This happens in the unmap path. For hugetlb pages we call huge_pte_get_and_clear to do that. With the current configuration of page table size, both pud and pgd level tables get allocated from the same slab cache. At the pud level, we use the second half of the table to store the slot information. But never clear that when unmapping. When such an freed object get allocated at pgd level, we will have part of the page table page not initlaized correctly. This result in kernel crash

Simplify this by calling the object initialization after kmem_cache_alloc

---
 arch/powerpc/include/asm/book3s/64/pgalloc.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/book3s/64/pgalloc.h +5 -2
index 53df86d3cfce..e4d154a4d114 100644
@@ -73,10 +73,13 @@ static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
+	pgd_t *pgd;
 	if (radix_enabled())
 		return radix__pgd_alloc(mm);
-	return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
-		pgtable_gfp_flags(mm, GFP_KERNEL));
+	pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
+			       pgtable_gfp_flags(mm, GFP_KERNEL));
+	memset(pgd, 0, PGD_TABLE_SIZE);
+	return pgd;
 }
 
 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Signature · 1 line
2.14.3
#1 lore raw
Quoted 23 lines · Aneesh Kumar K.V

On powerpc we allocate page table pages from slab cache of different sizes. For now we have a constructor that zero out the objects when we allocate then for the first time. We expect the objects to be zeroed out when we free the the object back to slab cache. This happens in the unmap path. For hugetlb pages we call huge_pte_get_and_clear to do that. With the current configuration of page table size, both pud and pgd level tables get allocated from the same slab cache. At the pud level, we use the second half of the table to store the slot information. But never clear that when unmapping. When such an freed object get allocated at pgd level, we will have part of the page table page not initlaized correctly. This result in kernel crash

Simplify this by calling the object initialization after kmem_cache_alloc

---
 arch/powerpc/include/asm/book3s/64/pgalloc.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/book3s/64/pgalloc.h +0 -0
index 53df86d3cfce..e4d154a4d114 100644

arch/powerpc/include/asm/book3s/64/pgalloc.h static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd) · line 79

Quoted 8 lines
arch/powerpc/include/asm/book3s/64/pgalloc.h +1 -2
@@ -73,10 +73,13 @@ static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
+	pgd_t *pgd;
 	if (radix_enabled())
 		return radix__pgd_alloc(mm);
-	return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
-		pgtable_gfp_flags(mm, GFP_KERNEL));

kmem_cache_zalloc() wont work?

RP

Quoted 9 lines
arch/powerpc/include/asm/book3s/64/pgalloc.h +4 -0
+	pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
+			       pgtable_gfp_flags(mm, GFP_KERNEL));
+	memset(pgd, 0, PGD_TABLE_SIZE);
+	return pgd;
 }
 
 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Signature · 1 line
2.14.3
Signature · 1 line
Ram Pai
#2 lore raw
In reply to Aneesh Kumar K.V
Quoted 11 lines · Aneesh Kumar K.V

On powerpc we allocate page table pages from slab cache of different sizes. For now we have a constructor that zero out the objects when we allocate then for the first time. We expect the objects to be zeroed out when we free the the object back to slab cache. This happens in the unmap path. For hugetlb pages we call huge_pte_get_and_clear to do that. With the current configuration of page table size, both pud and pgd level tables get allocated from the same slab cache. At the pud level, we use the second half of the table to store the slot information. But never clear that when unmapping. When such an freed object get allocated at pgd level, we will have part of the page table page not initlaized correctly. This result in kernel crash

Quoted 3 lines

Simplify this by calling the object initialization after kmem_cache_alloc

Applied to powerpc fixes, thanks.

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

cheers