LoongArch: mm: Introduce unified function populate_kernel_pte()

Function pcpu_populate_pte() and fixmap_pte() are similar, they populate
one page from kernel address space. And there is confusion between pgd
and p4d in the function fixmap_pte(), such as pgd_none() always returns
zero. This patch introduces a unified function populate_kernel_pte() and
then replaces pcpu_populate_pte() and fixmap_pte().

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
This commit is contained in:
Bibo Mao 2023-09-06 22:53:09 +08:00 committed by Huacai Chen
parent f33efa905c
commit 2bb20d2926
3 changed files with 23 additions and 57 deletions

View file

@ -91,4 +91,5 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
#endif /* __PAGETABLE_PUD_FOLDED */ #endif /* __PAGETABLE_PUD_FOLDED */
extern pte_t * __init populate_kernel_pte(unsigned long addr);
#endif /* _ASM_PGALLOC_H */ #endif /* _ASM_PGALLOC_H */

View file

@ -67,41 +67,7 @@ static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
void __init pcpu_populate_pte(unsigned long addr) void __init pcpu_populate_pte(unsigned long addr)
{ {
pgd_t *pgd = pgd_offset_k(addr); populate_kernel_pte(addr);
p4d_t *p4d = p4d_offset(pgd, addr);
pud_t *pud;
pmd_t *pmd;
if (p4d_none(*p4d)) {
pud = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
if (!pud)
panic("%s: Failed to allocate memory\n", __func__);
p4d_populate(&init_mm, p4d, pud);
#ifndef __PAGETABLE_PUD_FOLDED
pud_init(pud);
#endif
}
pud = pud_offset(p4d, addr);
if (pud_none(*pud)) {
pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
if (!pmd)
panic("%s: Failed to allocate memory\n", __func__);
pud_populate(&init_mm, pud, pmd);
#ifndef __PAGETABLE_PMD_FOLDED
pmd_init(pmd);
#endif
}
pmd = pmd_offset(pud, addr);
if (!pmd_present(*pmd)) {
pte_t *pte;
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
if (!pte)
panic("%s: Failed to allocate memory\n", __func__);
pmd_populate_kernel(&init_mm, pmd, pte);
}
} }
void __init setup_per_cpu_areas(void) void __init setup_per_cpu_areas(void)

View file

@ -191,43 +191,42 @@ void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *al
#endif #endif
#endif #endif
static pte_t *fixmap_pte(unsigned long addr) pte_t * __init populate_kernel_pte(unsigned long addr)
{ {
pgd_t *pgd; pgd_t *pgd = pgd_offset_k(addr);
p4d_t *p4d; p4d_t *p4d = p4d_offset(pgd, addr);
pud_t *pud; pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pgd = pgd_offset_k(addr); if (p4d_none(*p4d)) {
p4d = p4d_offset(pgd, addr); pud = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
if (!pud)
if (pgd_none(*pgd)) { panic("%s: Failed to allocate memory\n", __func__);
pud_t *new __maybe_unused; p4d_populate(&init_mm, p4d, pud);
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
pgd_populate(&init_mm, pgd, new);
#ifndef __PAGETABLE_PUD_FOLDED #ifndef __PAGETABLE_PUD_FOLDED
pud_init(new); pud_init(pud);
#endif #endif
} }
pud = pud_offset(p4d, addr); pud = pud_offset(p4d, addr);
if (pud_none(*pud)) { if (pud_none(*pud)) {
pmd_t *new __maybe_unused; pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
if (!pmd)
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); panic("%s: Failed to allocate memory\n", __func__);
pud_populate(&init_mm, pud, new); pud_populate(&init_mm, pud, pmd);
#ifndef __PAGETABLE_PMD_FOLDED #ifndef __PAGETABLE_PMD_FOLDED
pmd_init(new); pmd_init(pmd);
#endif #endif
} }
pmd = pmd_offset(pud, addr); pmd = pmd_offset(pud, addr);
if (pmd_none(*pmd)) { if (!pmd_present(*pmd)) {
pte_t *new __maybe_unused; pte_t *pte;
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE); pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
pmd_populate_kernel(&init_mm, pmd, new); if (!pte)
panic("%s: Failed to allocate memory\n", __func__);
pmd_populate_kernel(&init_mm, pmd, pte);
} }
return pte_offset_kernel(pmd, addr); return pte_offset_kernel(pmd, addr);
@ -241,7 +240,7 @@ void __init __set_fixmap(enum fixed_addresses idx,
BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses); BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
ptep = fixmap_pte(addr); ptep = populate_kernel_pte(addr);
if (!pte_none(*ptep)) { if (!pte_none(*ptep)) {
pte_ERROR(*ptep); pte_ERROR(*ptep);
return; return;