Skip to content

Commit

Permalink
asm-generic: pgalloc: provide generic pgd_free()
Browse files Browse the repository at this point in the history
Most architectures define pgd_free() as a wrapper for free_page().

Provide a generic version in asm-generic/pgalloc.h and enable its use for
most architectures.

Signed-off-by: Mike Rapoport <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Pekka Enberg <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>	[m68k]
Cc: Abdul Haleem <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Peter Zijlstra (Intel) <[email protected]>
Cc: Satheesh Rajendran <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Stephen Rothwell <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rppt authored and torvalds committed Aug 7, 2020
1 parent d9e8b92 commit f9cb654
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 62 deletions.
6 changes: 0 additions & 6 deletions arch/alpha/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)

extern pgd_t *pgd_alloc(struct mm_struct *mm);

static inline void
pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long)pgd);
}

#endif /* _ALPHA_PGALLOC_H */
1 change: 1 addition & 0 deletions arch/arm/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static inline void clean_pte_table(pte_t *pte)

#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
#define __HAVE_ARCH_PTE_ALLOC_ONE
#define __HAVE_ARCH_PGD_FREE
#include <asm-generic/pgalloc.h>

static inline pte_t *
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>

#define __HAVE_ARCH_PGD_FREE
#include <asm-generic/pgalloc.h>

#define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
Expand Down
7 changes: 1 addition & 6 deletions arch/csky/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <linux/sched.h>

#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
#include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */
#include <asm-generic/pgalloc.h>

static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
pte_t *pte)
Expand Down Expand Up @@ -42,11 +42,6 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
return pte;
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_pages((unsigned long)pgd, PGD_ORDER);
}

static inline pgd_t *pgd_alloc(struct mm_struct *mm)
{
pgd_t *ret;
Expand Down
7 changes: 1 addition & 6 deletions arch/hexagon/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <asm/mem-layout.h>
#include <asm/atomic.h>

#include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */
#include <asm-generic/pgalloc.h>

extern unsigned long long kmap_generation;

Expand Down Expand Up @@ -41,11 +41,6 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
return pgd;
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long) pgd);
}

static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
pgtable_t pte)
{
Expand Down
5 changes: 0 additions & 5 deletions arch/ia64/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
return (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long)pgd);
}

#if CONFIG_PGTABLE_LEVELS == 4
static inline void
p4d_populate(struct mm_struct *mm, p4d_t * p4d_entry, pud_t * pud)
Expand Down
7 changes: 1 addition & 6 deletions arch/m68k/include/asm/sun3_pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <asm/tlb.h>

#include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */
#include <asm-generic/pgalloc.h>

extern const char bad_pmd_string[];

Expand All @@ -40,11 +40,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page
*/
#define pmd_free(mm, x) do { } while (0)

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long) pgd);
}

static inline pgd_t * pgd_alloc(struct mm_struct *mm)
{
pgd_t *new_pgd;
Expand Down
6 changes: 0 additions & 6 deletions arch/microblaze/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ static inline pgd_t *get_pgd(void)
return (pgd_t *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, 0);
}

static inline void free_pgd(pgd_t *pgd)
{
free_page((unsigned long)pgd);
}

#define pgd_free(mm, pgd) free_pgd(pgd)
#define pgd_alloc(mm) get_pgd()

#define pmd_pgtable(pmd) pmd_page(pmd)
Expand Down
5 changes: 0 additions & 5 deletions arch/mips/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
extern void pgd_init(unsigned long page);
extern pgd_t *pgd_alloc(struct mm_struct *mm);

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_pages((unsigned long)pgd, PGD_ORDER);
}

#define __pte_free_tlb(tlb,pte,address) \
do { \
pgtable_pte_page_dtor(pte); \
Expand Down
2 changes: 2 additions & 0 deletions arch/nds32/mm/mm-nds32.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (C) 2005-2017 Andes Technology Corporation

#include <linux/init_task.h>

#define __HAVE_ARCH_PGD_FREE
#include <asm/pgalloc.h>

#define FIRST_KERNEL_PGD_NR (USER_PTRS_PER_PGD)
Expand Down
7 changes: 1 addition & 6 deletions arch/nios2/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <linux/mm.h>

#include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */
#include <asm-generic/pgalloc.h>

static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
pte_t *pte)
Expand All @@ -34,11 +34,6 @@ extern void pmd_init(unsigned long page, unsigned long pagetable);

extern pgd_t *pgd_alloc(struct mm_struct *mm);

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_pages((unsigned long)pgd, PGD_ORDER);
}

#define __pte_free_tlb(tlb, pte, addr) \
do { \
pgtable_pte_page_dtor(pte); \
Expand Down
1 change: 1 addition & 0 deletions arch/parisc/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <asm/cache.h>

#define __HAVE_ARCH_PMD_FREE
#define __HAVE_ARCH_PGD_FREE
#include <asm-generic/pgalloc.h>

/* Allocate the top level pgd (page directory)
Expand Down
5 changes: 0 additions & 5 deletions arch/riscv/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
return pgd;
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long)pgd);
}

#ifndef __PAGETABLE_PMD_FOLDED

#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
Expand Down
1 change: 1 addition & 0 deletions arch/sh/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define __HAVE_ARCH_PMD_ALLOC_ONE
#define __HAVE_ARCH_PMD_FREE
#define __HAVE_ARCH_PGD_FREE
#include <asm-generic/pgalloc.h>

extern pgd_t *pgd_alloc(struct mm_struct *);
Expand Down
1 change: 0 additions & 1 deletion arch/um/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* Allocate and free page tables.
*/
extern pgd_t *pgd_alloc(struct mm_struct *);
extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);

#define __pte_free_tlb(tlb,pte, address) \
do { \
Expand Down
5 changes: 0 additions & 5 deletions arch/um/kernel/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
return pgd;
}

void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long) pgd);
}

void *uml_kmalloc(int size, int flags)
{
return kmalloc(size, flags);
Expand Down
1 change: 1 addition & 0 deletions arch/x86/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/pagemap.h>

#define __HAVE_ARCH_PTE_ALLOC_ONE
#define __HAVE_ARCH_PGD_FREE
#include <asm-generic/pgalloc.h>

static inline int __paravirt_pgd_alloc(struct mm_struct *mm) { return 0; }
Expand Down
5 changes: 0 additions & 5 deletions arch/xtensa/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ pgd_alloc(struct mm_struct *mm)
return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER);
}

static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long)pgd);
}

static inline void ptes_clear(pte_t *ptep)
{
int i;
Expand Down
7 changes: 7 additions & 0 deletions include/asm-generic/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)

#endif /* CONFIG_PGTABLE_LEVELS > 3 */

#ifndef __HAVE_ARCH_PGD_FREE
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
free_page((unsigned long)pgd);
}
#endif

#endif /* CONFIG_MMU */

#endif /* __ASM_GENERIC_PGALLOC_H */

0 comments on commit f9cb654

Please sign in to comment.