Skip to content

Commit 7278914

Browse files
rppttorvalds
authored andcommitted
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>
1 parent fc2a6b8 commit 7278914

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

‎arch/xtensa/include/asm/pgalloc.h‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
#ifndef _XTENSA_PGALLOC_H
99
#define _XTENSA_PGALLOC_H
1010

11+
#ifdef CONFIG_MMU
1112
#include <linux/highmem.h>
1213
#include <linux/slab.h>
1314

15+
#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
16+
#define __HAVE_ARCH_PTE_ALLOC_ONE
17+
#include <asm-generic/pgalloc.h>
18+
1419
/*
1520
* Allocating and freeing a pmd is trivial: the 1-entry pmd is
1621
* inside the pgd, so has no extra memory associated with it.
@@ -33,45 +38,37 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3338
free_page((unsigned long)pgd);
3439
}
3540

41+
static inline void ptes_clear(pte_t *ptep)
42+
{
43+
int i;
44+
45+
for (i = 0; i < PTRS_PER_PTE; i++)
46+
pte_clear(NULL, 0, ptep + i);
47+
}
48+
3649
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
3750
{
3851
pte_t *ptep;
39-
int i;
4052

41-
ptep = (pte_t *)__get_free_page(GFP_KERNEL);
53+
ptep = (pte_t *)__pte_alloc_one_kernel(mm);
4254
if (!ptep)
4355
return NULL;
44-
for (i = 0; i < 1024; i++)
45-
pte_clear(NULL, 0, ptep + i);
56+
ptes_clear(ptep);
4657
return ptep;
4758
}
4859

4960
static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
5061
{
51-
pte_t *pte;
5262
struct page *page;
5363

54-
pte = pte_alloc_one_kernel(mm);
55-
if (!pte)
56-
return NULL;
57-
page = virt_to_page(pte);
58-
if (!pgtable_pte_page_ctor(page)) {
59-
__free_page(page);
64+
page = __pte_alloc_one(mm, GFP_PGTABLE_USER);
65+
if (!page)
6066
return NULL;
61-
}
67+
ptes_clear(page_address(page));
6268
return page;
6369
}
6470

65-
static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
66-
{
67-
free_page((unsigned long)pte);
68-
}
69-
70-
static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
71-
{
72-
pgtable_pte_page_dtor(pte);
73-
__free_page(pte);
74-
}
7571
#define pmd_pgtable(pmd) pmd_page(pmd)
72+
#endif /* CONFIG_MMU */
7673

7774
#endif /* _XTENSA_PGALLOC_H */

0 commit comments

Comments
 (0)