Skip to content

Commit e1e5e10

Browse files
labbottAlex Shi
authored andcommitted
arm64: Drop alloc function from create_mapping
create_mapping is only used in fixmap_remap_fdt. All the create_mapping calls need to happen on existing translation table pages without additional allocations. Rather than have an alloc function be called and fail, just set it to NULL and catch its use. Also change the name to create_mapping_noalloc to better capture what exactly is going on. Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Laura Abbott <labbott@fedoraproject.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> (cherry picked from commit 132233a759580f5ce9b1bfaac9073e47d03c460d) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent a916d13 commit e1e5e10

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

arch/arm64/mm/mmu.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ static void alloc_init_pte(pmd_t *pmd, unsigned long addr,
116116
pte_t *pte;
117117

118118
if (pmd_none(*pmd) || pmd_sect(*pmd)) {
119-
phys_addr_t pte_phys = pgtable_alloc();
119+
phys_addr_t pte_phys;
120+
BUG_ON(!pgtable_alloc);
121+
pte_phys = pgtable_alloc();
120122
pte = pte_set_fixmap(pte_phys);
121123
if (pmd_sect(*pmd))
122124
split_pmd(pmd, pte);
@@ -158,7 +160,9 @@ static void alloc_init_pmd(pud_t *pud, unsigned long addr, unsigned long end,
158160
* Check for initial section mappings in the pgd/pud and remove them.
159161
*/
160162
if (pud_none(*pud) || pud_sect(*pud)) {
161-
phys_addr_t pmd_phys = pgtable_alloc();
163+
phys_addr_t pmd_phys;
164+
BUG_ON(!pgtable_alloc);
165+
pmd_phys = pgtable_alloc();
162166
pmd = pmd_set_fixmap(pmd_phys);
163167
if (pud_sect(*pud)) {
164168
/*
@@ -223,7 +227,9 @@ static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
223227
unsigned long next;
224228

225229
if (pgd_none(*pgd)) {
226-
phys_addr_t pud_phys = pgtable_alloc();
230+
phys_addr_t pud_phys;
231+
BUG_ON(!pgtable_alloc);
232+
pud_phys = pgtable_alloc();
227233
__pgd_populate(pgd, pud_phys, PUD_TYPE_TABLE);
228234
}
229235
BUG_ON(pgd_bad(*pgd));
@@ -304,7 +310,12 @@ static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
304310
init_pgd(pgd_offset_raw(pgdir, virt), phys, virt, size, prot, alloc);
305311
}
306312

307-
static void __init create_mapping(phys_addr_t phys, unsigned long virt,
313+
/*
314+
* This function can only be used to modify existing table entries,
315+
* without allocating new levels of table. Note that this permits the
316+
* creation of new section or page entries.
317+
*/
318+
static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt,
308319
phys_addr_t size, pgprot_t prot)
309320
{
310321
if (virt < VMALLOC_START) {
@@ -313,7 +324,7 @@ static void __init create_mapping(phys_addr_t phys, unsigned long virt,
313324
return;
314325
}
315326
__create_pgd_mapping(init_mm.pgd, phys, virt, size, prot,
316-
early_pgtable_alloc);
327+
NULL);
317328
}
318329

319330
void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
@@ -670,7 +681,7 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
670681
/*
671682
* Make sure that the FDT region can be mapped without the need to
672683
* allocate additional translation table pages, so that it is safe
673-
* to call create_mapping() this early.
684+
* to call create_mapping_noalloc() this early.
674685
*
675686
* On 64k pages, the FDT will be mapped using PTEs, so we need to
676687
* be in the same PMD as the rest of the fixmap.
@@ -686,8 +697,8 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
686697
dt_virt = (void *)dt_virt_base + offset;
687698

688699
/* map the first chunk so we can read the size from the header */
689-
create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
690-
SWAPPER_BLOCK_SIZE, prot);
700+
create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE),
701+
dt_virt_base, SWAPPER_BLOCK_SIZE, prot);
691702

692703
if (fdt_magic(dt_virt) != FDT_MAGIC)
693704
return NULL;
@@ -697,7 +708,7 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
697708
return NULL;
698709

699710
if (offset + size > SWAPPER_BLOCK_SIZE)
700-
create_mapping(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
711+
create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
701712
round_up(offset + size, SWAPPER_BLOCK_SIZE), prot);
702713

703714
memblock_reserve(dt_phys, size);

0 commit comments

Comments
 (0)