Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xtensa: switch to generic version of pte allocation

xtensa clears PTEs during allocation of the page tables and pte_clear()
sets the PTE to a non-zero value. Splitting ptes_clear() helper out of
pte_alloc_one() and pte_alloc_one_kernel() allows reuse of base generic
allocation methods (__pte_alloc_one() and __pte_alloc_one_kernel()) and
the common GFP mask for page table allocations.

The pte_free() and pte_free_kernel() implementations on xtensa are
identical to the generic ones and can be dropped.

[jcmvbkbc@gmail.com: xtensa: fix closing endif comment]
Link: http://lkml.kernel.org/r/20200721024751.1257-1-jcmvbkbc@gmail.com

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Cc: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Joerg Roedel <jroedel@suse.de>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Matthew Wilcox <willy@infradead.org>
Link: http://lkml.kernel.org/r/20200627143453.31835-4-rppt@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mike Rapoport and committed by
Linus Torvalds
7278914c fc2a6b83

+19 -22
+19 -22
arch/xtensa/include/asm/pgalloc.h
··· 8 8 #ifndef _XTENSA_PGALLOC_H 9 9 #define _XTENSA_PGALLOC_H 10 10 11 + #ifdef CONFIG_MMU 11 12 #include <linux/highmem.h> 12 13 #include <linux/slab.h> 14 + 15 + #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL 16 + #define __HAVE_ARCH_PTE_ALLOC_ONE 17 + #include <asm-generic/pgalloc.h> 13 18 14 19 /* 15 20 * Allocating and freeing a pmd is trivial: the 1-entry pmd is ··· 38 33 free_page((unsigned long)pgd); 39 34 } 40 35 36 + static inline void ptes_clear(pte_t *ptep) 37 + { 38 + int i; 39 + 40 + for (i = 0; i < PTRS_PER_PTE; i++) 41 + pte_clear(NULL, 0, ptep + i); 42 + } 43 + 41 44 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) 42 45 { 43 46 pte_t *ptep; 44 - int i; 45 47 46 - ptep = (pte_t *)__get_free_page(GFP_KERNEL); 48 + ptep = (pte_t *)__pte_alloc_one_kernel(mm); 47 49 if (!ptep) 48 50 return NULL; 49 - for (i = 0; i < 1024; i++) 50 - pte_clear(NULL, 0, ptep + i); 51 + ptes_clear(ptep); 51 52 return ptep; 52 53 } 53 54 54 55 static inline pgtable_t pte_alloc_one(struct mm_struct *mm) 55 56 { 56 - pte_t *pte; 57 57 struct page *page; 58 58 59 - pte = pte_alloc_one_kernel(mm); 60 - if (!pte) 59 + page = __pte_alloc_one(mm, GFP_PGTABLE_USER); 60 + if (!page) 61 61 return NULL; 62 - page = virt_to_page(pte); 63 - if (!pgtable_pte_page_ctor(page)) { 64 - __free_page(page); 65 - return NULL; 66 - } 62 + ptes_clear(page_address(page)); 67 63 return page; 68 64 } 69 65 70 - static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) 71 - { 72 - free_page((unsigned long)pte); 73 - } 74 - 75 - static inline void pte_free(struct mm_struct *mm, pgtable_t pte) 76 - { 77 - pgtable_pte_page_dtor(pte); 78 - __free_page(pte); 79 - } 80 66 #define pmd_pgtable(pmd) pmd_page(pmd) 67 + #endif /* CONFIG_MMU */ 81 68 82 69 #endif /* _XTENSA_PGALLOC_H */