Skip to content

Commit

Permalink
arch: simplify several early memory allocations
Browse files Browse the repository at this point in the history
There are several early memory allocations in arch/ code that use
memblock_phys_alloc() to allocate memory, convert the returned physical
address to the virtual address and then set the allocated memory to
zero.

Exactly the same behaviour can be achieved simply by calling
memblock_alloc(): it allocates the memory in the same way as
memblock_phys_alloc(), then it performs the phys_to_virt() conversion
and clears the allocated memory.

Replace the longer sequence with a simpler call to memblock_alloc().

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Mike Rapoport <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Greentime Hu <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: Russell King <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Stefan Kristiansson <[email protected]>
Cc: Vincent Chen <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rppt authored and torvalds committed Mar 8, 2019
1 parent 1e8ffd5 commit b63a07d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 43 deletions.
4 changes: 1 addition & 3 deletions arch/arm/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@ EXPORT_SYMBOL(phys_mem_access_prot);

static void __init *early_alloc_aligned(unsigned long sz, unsigned long align)
{
void *ptr = __va(memblock_phys_alloc(sz, align));
memset(ptr, 0, sz);
return ptr;
return memblock_alloc(sz, align);
}

static void __init *early_alloc(unsigned long sz)
Expand Down
9 changes: 2 additions & 7 deletions arch/c6x/mm/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
*/
void __init coherent_mem_init(phys_addr_t start, u32 size)
{
phys_addr_t bitmap_phys;

if (!size)
return;

Expand All @@ -138,11 +136,8 @@ void __init coherent_mem_init(phys_addr_t start, u32 size)
if (dma_size & (PAGE_SIZE - 1))
++dma_pages;

bitmap_phys = memblock_phys_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
sizeof(long));

dma_bitmap = phys_to_virt(bitmap_phys);
memset(dma_bitmap, 0, dma_pages * PAGE_SIZE);
dma_bitmap = memblock_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
sizeof(long));
}

static void c6x_dma_sync(struct device *dev, phys_addr_t paddr, size_t size,
Expand Down
12 changes: 4 additions & 8 deletions arch/nds32/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ static void __init map_ram(void)
}

/* Alloc one page for holding PTE's... */
pte = (pte_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
memset(pte, 0, PAGE_SIZE);
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
set_pmd(pme, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));

/* Fill the newly allocated page with PTE'S */
Expand Down Expand Up @@ -111,8 +110,7 @@ static void __init fixedrange_init(void)
pgd = swapper_pg_dir + pgd_index(vaddr);
pud = pud_offset(pgd, vaddr);
pmd = pmd_offset(pud, vaddr);
fixmap_pmd_p = (pmd_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
memset(fixmap_pmd_p, 0, PAGE_SIZE);
fixmap_pmd_p = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
set_pmd(pmd, __pmd(__pa(fixmap_pmd_p) + _PAGE_KERNEL_TABLE));

#ifdef CONFIG_HIGHMEM
Expand All @@ -124,8 +122,7 @@ static void __init fixedrange_init(void)
pgd = swapper_pg_dir + pgd_index(vaddr);
pud = pud_offset(pgd, vaddr);
pmd = pmd_offset(pud, vaddr);
pte = (pte_t *) __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
memset(pte, 0, PAGE_SIZE);
pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
set_pmd(pmd, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
pkmap_page_table = pte;
#endif /* CONFIG_HIGHMEM */
Expand All @@ -150,8 +147,7 @@ void __init paging_init(void)
fixedrange_init();

/* allocate space for empty_zero_page */
zero_page = __va(memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE));
memset(zero_page, 0, PAGE_SIZE);
zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
zone_sizes_init();

empty_zero_page = virt_to_page(zero_page);
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/kernel/setup-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ void __init smp_setup_cpu_maps(void)

DBG("smp_setup_cpu_maps()\n");

cpu_to_phys_id = __va(memblock_phys_alloc(nr_cpu_ids * sizeof(u32), __alignof__(u32)));
memset(cpu_to_phys_id, 0, nr_cpu_ids * sizeof(u32));
cpu_to_phys_id = memblock_alloc(nr_cpu_ids * sizeof(u32),
__alignof__(u32));

for_each_node_by_type(dn, "cpu") {
const __be32 *intserv;
Expand Down
3 changes: 1 addition & 2 deletions arch/powerpc/mm/ppc_mmu_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ void __init MMU_init_hw(void)
* Find some memory for the hash table.
*/
if ( ppc_md.progress ) ppc_md.progress("hash:find piece", 0x322);
Hash = __va(memblock_phys_alloc(Hash_size, Hash_size));
memset(Hash, 0, Hash_size);
Hash = memblock_alloc(Hash_size, Hash_size);
_SDR1 = __pa(Hash) | SDR1_LOW_BITS;

Hash_end = (struct hash_pte *) ((unsigned long)Hash + Hash_size);
Expand Down
3 changes: 1 addition & 2 deletions arch/powerpc/platforms/powernv/opal.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ int __init early_init_dt_scan_recoverable_ranges(unsigned long node,
/*
* Allocate a buffer to hold the MC recoverable ranges.
*/
mc_recoverable_range =__va(memblock_phys_alloc(size, __alignof__(u64)));
memset(mc_recoverable_range, 0, size);
mc_recoverable_range = memblock_alloc(size, __alignof__(u64));

for (i = 0; i < mc_recoverable_range_len; i++) {
mc_recoverable_range[i].start_addr =
Expand Down
6 changes: 1 addition & 5 deletions arch/s390/numa/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ int numa_debug_enabled;
*/
static __init pg_data_t *alloc_node_data(void)
{
pg_data_t *res;

res = (pg_data_t *) memblock_phys_alloc(sizeof(pg_data_t), 8);
memset(res, 0, sizeof(pg_data_t));
return res;
return memblock_alloc(sizeof(pg_data_t), 8);
}

/*
Expand Down
7 changes: 2 additions & 5 deletions arch/sparc/kernel/prom_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@

void * __init prom_early_alloc(unsigned long size)
{
unsigned long paddr = memblock_phys_alloc(size, SMP_CACHE_BYTES);
void *ret;
void *ret = memblock_alloc(size, SMP_CACHE_BYTES);

if (!paddr) {
if (!ret) {
prom_printf("prom_early_alloc(%lu) failed\n", size);
prom_halt();
}

ret = __va(paddr);
memset(ret, 0, size);
prom_early_allocated += size;

return ret;
Expand Down
9 changes: 3 additions & 6 deletions arch/sparc/mm/init_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,16 +1089,13 @@ static void __init allocate_node_data(int nid)
struct pglist_data *p;
unsigned long start_pfn, end_pfn;
#ifdef CONFIG_NEED_MULTIPLE_NODES
unsigned long paddr;

paddr = memblock_phys_alloc_try_nid(sizeof(struct pglist_data),
SMP_CACHE_BYTES, nid);
if (!paddr) {
NODE_DATA(nid) = memblock_alloc_node(sizeof(struct pglist_data),
SMP_CACHE_BYTES, nid);
if (!NODE_DATA(nid)) {
prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
prom_halt();
}
NODE_DATA(nid) = __va(paddr);
memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));

NODE_DATA(nid)->node_id = nid;
#endif
Expand Down
4 changes: 1 addition & 3 deletions arch/unicore32/mm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ static void __init build_mem_type_table(void)

static void __init *early_alloc(unsigned long sz)
{
void *ptr = __va(memblock_phys_alloc(sz, sz));
memset(ptr, 0, sz);
return ptr;
return memblock_alloc(sz, sz);
}

static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr,
Expand Down

0 comments on commit b63a07d

Please sign in to comment.