Skip to content

Commit 60639f7

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
asm-generic: Prepare for riscv use of pud_alloc_one and pud_free
In the following commits, riscv will almost use the generic versions of pud_alloc_one and pud_free but an additional check is required since those functions are only relevant when using at least a 4-level page table, which will be determined at runtime on riscv. So move the content of those functions into other functions that riscv can use without duplicating code. Signed-off-by: Alexandre Ghiti <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 3270bfd commit 60639f7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

include/asm-generic/pgalloc.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
147147

148148
#if CONFIG_PGTABLE_LEVELS > 3
149149

150+
static inline pud_t *__pud_alloc_one(struct mm_struct *mm, unsigned long addr)
151+
{
152+
gfp_t gfp = GFP_PGTABLE_USER;
153+
154+
if (mm == &init_mm)
155+
gfp = GFP_PGTABLE_KERNEL;
156+
return (pud_t *)get_zeroed_page(gfp);
157+
}
158+
150159
#ifndef __HAVE_ARCH_PUD_ALLOC_ONE
151160
/**
152161
* pud_alloc_one - allocate a page for PUD-level page table
@@ -159,20 +168,23 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
159168
*/
160169
static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
161170
{
162-
gfp_t gfp = GFP_PGTABLE_USER;
163-
164-
if (mm == &init_mm)
165-
gfp = GFP_PGTABLE_KERNEL;
166-
return (pud_t *)get_zeroed_page(gfp);
171+
return __pud_alloc_one(mm, addr);
167172
}
168173
#endif
169174

170-
static inline void pud_free(struct mm_struct *mm, pud_t *pud)
175+
static inline void __pud_free(struct mm_struct *mm, pud_t *pud)
171176
{
172177
BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
173178
free_page((unsigned long)pud);
174179
}
175180

181+
#ifndef __HAVE_ARCH_PUD_FREE
182+
static inline void pud_free(struct mm_struct *mm, pud_t *pud)
183+
{
184+
__pud_free(mm, pud);
185+
}
186+
#endif
187+
176188
#endif /* CONFIG_PGTABLE_LEVELS > 3 */
177189

178190
#ifndef __HAVE_ARCH_PGD_FREE

0 commit comments

Comments
 (0)