Skip to content

Commit 288b373

Browse files
kvaneeshgregkh
authored andcommitted
powerpc/mm/hash64: Zero PGD pages on allocation
[ Upstream commit fc5c2f4 ] On powerpc we allocate page table pages from slab caches of different sizes. Currently we have a constructor that zeroes out the objects when we allocate them 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 are allocated from the same slab cache. At the PUD level, we use the second half of the table to store the slot information. But we never clear that when unmapping. When such a freed object is then allocated for a PGD page, the second half of the page table page will not be zeroed as expected. This results in a kernel crash. Fix it by always clearing PGD pages when they're allocated. Signed-off-by: Aneesh Kumar K.V <[email protected]> [mpe: Change log wording and formatting, add whitespace] Signed-off-by: Michael Ellerman <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f4d6e45 commit 288b373

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/powerpc/include/asm/book3s/64/pgalloc.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)
7373

7474
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
7575
{
76+
pgd_t *pgd;
77+
7678
if (radix_enabled())
7779
return radix__pgd_alloc(mm);
78-
return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
79-
pgtable_gfp_flags(mm, GFP_KERNEL));
80+
81+
pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
82+
pgtable_gfp_flags(mm, GFP_KERNEL));
83+
memset(pgd, 0, PGD_TABLE_SIZE);
84+
85+
return pgd;
8086
}
8187

8288
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)

0 commit comments

Comments
 (0)