Path: blob/master/arch/powerpc/include/asm/book3s/64/pgalloc.h
26519 views
/* SPDX-License-Identifier: GPL-2.0-or-later */1#ifndef _ASM_POWERPC_BOOK3S_64_PGALLOC_H2#define _ASM_POWERPC_BOOK3S_64_PGALLOC_H3/*4*/56#include <linux/slab.h>7#include <linux/cpumask.h>8#include <linux/kmemleak.h>9#include <linux/percpu.h>1011struct vmemmap_backing {12struct vmemmap_backing *list;13unsigned long phys;14unsigned long virt_addr;15};16extern struct vmemmap_backing *vmemmap_list;1718extern pmd_t *pmd_fragment_alloc(struct mm_struct *, unsigned long);19extern void pmd_fragment_free(unsigned long *);20extern void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift);21extern void __tlb_remove_table(void *_table);22void pte_frag_destroy(void *pte_frag);2324static inline pgd_t *radix__pgd_alloc(struct mm_struct *mm)25{26#ifdef CONFIG_PPC_64K_PAGES27return (pgd_t *)__get_free_page(pgtable_gfp_flags(mm, PGALLOC_GFP));28#else29struct page *page;30page = alloc_pages(pgtable_gfp_flags(mm, PGALLOC_GFP | __GFP_RETRY_MAYFAIL),314);32if (!page)33return NULL;34return (pgd_t *) page_address(page);35#endif36}3738static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)39{40#ifdef CONFIG_PPC_64K_PAGES41free_page((unsigned long)pgd);42#else43free_pages((unsigned long)pgd, 4);44#endif45}4647static inline pgd_t *pgd_alloc(struct mm_struct *mm)48{49pgd_t *pgd;5051if (radix_enabled())52return radix__pgd_alloc(mm);5354pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),55pgtable_gfp_flags(mm, GFP_KERNEL));56if (unlikely(!pgd))57return pgd;5859/*60* Don't scan the PGD for pointers, it contains references to PUDs but61* those references are not full pointers and so can't be recognised by62* kmemleak.63*/64kmemleak_no_scan(pgd);6566/*67* With hugetlb, we don't clear the second half of the page table.68* If we share the same slab cache with the pmd or pud level table,69* we need to make sure we zero out the full table on alloc.70* With 4K we don't store slot in the second half. Hence we don't71* need to do this for 4k.72*/73#if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_PPC_64K_PAGES) && \74(H_PGD_INDEX_SIZE == H_PUD_CACHE_INDEX)75memset(pgd, 0, PGD_TABLE_SIZE);76#endif77return pgd;78}7980static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)81{82if (radix_enabled())83return radix__pgd_free(mm, pgd);84kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);85}8687static inline void p4d_populate(struct mm_struct *mm, p4d_t *pgd, pud_t *pud)88{89*pgd = __p4d(__pgtable_ptr_val(pud) | PGD_VAL_BITS);90}9192static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)93{94pud_t *pud;9596pud = kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX),97pgtable_gfp_flags(mm, GFP_KERNEL));98/*99* Tell kmemleak to ignore the PUD, that means don't scan it for100* pointers and don't consider it a leak. PUDs are typically only101* referred to by their PGD, but kmemleak is not able to recognise those102* as pointers, leading to false leak reports.103*/104kmemleak_ignore(pud);105106return pud;107}108109static inline void __pud_free(pud_t *pud)110{111struct page *page = virt_to_page(pud);112113/*114* Early pud pages allocated via memblock allocator115* can't be directly freed to slab. KFENCE pages have116* both reserved and slab flags set so need to be freed117* kmem_cache_free.118*/119if (PageReserved(page) && !PageSlab(page))120free_reserved_page(page);121else122kmem_cache_free(PGT_CACHE(PUD_CACHE_INDEX), pud);123}124125static inline void pud_free(struct mm_struct *mm, pud_t *pud)126{127return __pud_free(pud);128}129130static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)131{132*pud = __pud(__pgtable_ptr_val(pmd) | PUD_VAL_BITS);133}134135static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,136unsigned long address)137{138pgtable_free_tlb(tlb, pud, PUD_INDEX);139}140141static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)142{143return pmd_fragment_alloc(mm, addr);144}145146static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)147{148pmd_fragment_free((unsigned long *)pmd);149}150151static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,152unsigned long address)153{154return pgtable_free_tlb(tlb, pmd, PMD_INDEX);155}156157static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,158pte_t *pte)159{160*pmd = __pmd(__pgtable_ptr_val(pte) | PMD_VAL_BITS);161}162163static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,164pgtable_t pte_page)165{166*pmd = __pmd(__pgtable_ptr_val(pte_page) | PMD_VAL_BITS);167}168169static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,170unsigned long address)171{172pgtable_free_tlb(tlb, table, PTE_INDEX);173}174175extern atomic_long_t direct_pages_count[MMU_PAGE_COUNT];176static inline void update_page_count(int psize, long count)177{178if (IS_ENABLED(CONFIG_PROC_FS))179atomic_long_add(count, &direct_pages_count[psize]);180}181182#endif /* _ASM_POWERPC_BOOK3S_64_PGALLOC_H */183184185