Skip to content

Commit 2bb20d2

Browse files
bibo-maochenhuacai
authored andcommitted
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 <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent f33efa9 commit 2bb20d2

File tree

3 files changed

+23
-57
lines changed

3 files changed

+23
-57
lines changed

arch/loongarch/include/asm/pgalloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
9191

9292
#endif /* __PAGETABLE_PUD_FOLDED */
9393

94+
extern pte_t * __init populate_kernel_pte(unsigned long addr);
9495
#endif /* _ASM_PGALLOC_H */

arch/loongarch/kernel/numa.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,7 @@ static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
6767

6868
void __init pcpu_populate_pte(unsigned long addr)
6969
{
70-
pgd_t *pgd = pgd_offset_k(addr);
71-
p4d_t *p4d = p4d_offset(pgd, addr);
72-
pud_t *pud;
73-
pmd_t *pmd;
74-
75-
if (p4d_none(*p4d)) {
76-
pud = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
77-
if (!pud)
78-
panic("%s: Failed to allocate memory\n", __func__);
79-
p4d_populate(&init_mm, p4d, pud);
80-
#ifndef __PAGETABLE_PUD_FOLDED
81-
pud_init(pud);
82-
#endif
83-
}
84-
85-
pud = pud_offset(p4d, addr);
86-
if (pud_none(*pud)) {
87-
pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
88-
if (!pmd)
89-
panic("%s: Failed to allocate memory\n", __func__);
90-
pud_populate(&init_mm, pud, pmd);
91-
#ifndef __PAGETABLE_PMD_FOLDED
92-
pmd_init(pmd);
93-
#endif
94-
}
95-
96-
pmd = pmd_offset(pud, addr);
97-
if (!pmd_present(*pmd)) {
98-
pte_t *pte;
99-
100-
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
101-
if (!pte)
102-
panic("%s: Failed to allocate memory\n", __func__);
103-
pmd_populate_kernel(&init_mm, pmd, pte);
104-
}
70+
populate_kernel_pte(addr);
10571
}
10672

10773
void __init setup_per_cpu_areas(void)

arch/loongarch/mm/init.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,43 +191,42 @@ void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *al
191191
#endif
192192
#endif
193193

194-
static pte_t *fixmap_pte(unsigned long addr)
194+
pte_t * __init populate_kernel_pte(unsigned long addr)
195195
{
196-
pgd_t *pgd;
197-
p4d_t *p4d;
196+
pgd_t *pgd = pgd_offset_k(addr);
197+
p4d_t *p4d = p4d_offset(pgd, addr);
198198
pud_t *pud;
199199
pmd_t *pmd;
200200

201-
pgd = pgd_offset_k(addr);
202-
p4d = p4d_offset(pgd, addr);
203-
204-
if (pgd_none(*pgd)) {
205-
pud_t *new __maybe_unused;
206-
207-
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
208-
pgd_populate(&init_mm, pgd, new);
201+
if (p4d_none(*p4d)) {
202+
pud = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
203+
if (!pud)
204+
panic("%s: Failed to allocate memory\n", __func__);
205+
p4d_populate(&init_mm, p4d, pud);
209206
#ifndef __PAGETABLE_PUD_FOLDED
210-
pud_init(new);
207+
pud_init(pud);
211208
#endif
212209
}
213210

214211
pud = pud_offset(p4d, addr);
215212
if (pud_none(*pud)) {
216-
pmd_t *new __maybe_unused;
217-
218-
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
219-
pud_populate(&init_mm, pud, new);
213+
pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
214+
if (!pmd)
215+
panic("%s: Failed to allocate memory\n", __func__);
216+
pud_populate(&init_mm, pud, pmd);
220217
#ifndef __PAGETABLE_PMD_FOLDED
221-
pmd_init(new);
218+
pmd_init(pmd);
222219
#endif
223220
}
224221

225222
pmd = pmd_offset(pud, addr);
226-
if (pmd_none(*pmd)) {
227-
pte_t *new __maybe_unused;
223+
if (!pmd_present(*pmd)) {
224+
pte_t *pte;
228225

229-
new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
230-
pmd_populate_kernel(&init_mm, pmd, new);
226+
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
227+
if (!pte)
228+
panic("%s: Failed to allocate memory\n", __func__);
229+
pmd_populate_kernel(&init_mm, pmd, pte);
231230
}
232231

233232
return pte_offset_kernel(pmd, addr);
@@ -241,7 +240,7 @@ void __init __set_fixmap(enum fixed_addresses idx,
241240

242241
BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
243242

244-
ptep = fixmap_pte(addr);
243+
ptep = populate_kernel_pte(addr);
245244
if (!pte_none(*ptep)) {
246245
pte_ERROR(*ptep);
247246
return;

0 commit comments

Comments
 (0)