aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/memblock.c')
-rw-r--r--mm/memblock.c68
1 files changed, 57 insertions, 11 deletions
diff --git a/mm/memblock.c b/mm/memblock.c
index 91205780e6b1..46aacdfa4f4d 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -533,7 +533,7 @@ repeat:
533 base = obase; 533 base = obase;
534 nr_new = 0; 534 nr_new = 0;
535 535
536 for_each_memblock_type(type, rgn) { 536 for_each_memblock_type(idx, type, rgn) {
537 phys_addr_t rbase = rgn->base; 537 phys_addr_t rbase = rgn->base;
538 phys_addr_t rend = rbase + rgn->size; 538 phys_addr_t rend = rbase + rgn->size;
539 539
@@ -637,7 +637,7 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
637 if (memblock_double_array(type, base, size) < 0) 637 if (memblock_double_array(type, base, size) < 0)
638 return -ENOMEM; 638 return -ENOMEM;
639 639
640 for_each_memblock_type(type, rgn) { 640 for_each_memblock_type(idx, type, rgn) {
641 phys_addr_t rbase = rgn->base; 641 phys_addr_t rbase = rgn->base;
642 phys_addr_t rend = rbase + rgn->size; 642 phys_addr_t rend = rbase + rgn->size;
643 643
@@ -1327,7 +1327,6 @@ again:
1327 return NULL; 1327 return NULL;
1328done: 1328done:
1329 ptr = phys_to_virt(alloc); 1329 ptr = phys_to_virt(alloc);
1330 memset(ptr, 0, size);
1331 1330
1332 /* 1331 /*
1333 * The min_count is set to 0 so that bootmem allocated blocks 1332 * The min_count is set to 0 so that bootmem allocated blocks
@@ -1341,6 +1340,45 @@ done:
1341} 1340}
1342 1341
1343/** 1342/**
1343 * memblock_virt_alloc_try_nid_raw - allocate boot memory block without zeroing
1344 * memory and without panicking
1345 * @size: size of memory block to be allocated in bytes
1346 * @align: alignment of the region and block's size
1347 * @min_addr: the lower bound of the memory region from where the allocation
1348 * is preferred (phys address)
1349 * @max_addr: the upper bound of the memory region from where the allocation
1350 * is preferred (phys address), or %BOOTMEM_ALLOC_ACCESSIBLE to
1351 * allocate only from memory limited by memblock.current_limit value
1352 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1353 *
1354 * Public function, provides additional debug information (including caller
1355 * info), if enabled. Does not zero allocated memory, does not panic if request
1356 * cannot be satisfied.
1357 *
1358 * RETURNS:
1359 * Virtual address of allocated memory block on success, NULL on failure.
1360 */
1361void * __init memblock_virt_alloc_try_nid_raw(
1362 phys_addr_t size, phys_addr_t align,
1363 phys_addr_t min_addr, phys_addr_t max_addr,
1364 int nid)
1365{
1366 void *ptr;
1367
1368 memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=0x%llx max_addr=0x%llx %pF\n",
1369 __func__, (u64)size, (u64)align, nid, (u64)min_addr,
1370 (u64)max_addr, (void *)_RET_IP_);
1371
1372 ptr = memblock_virt_alloc_internal(size, align,
1373 min_addr, max_addr, nid);
1374#ifdef CONFIG_DEBUG_VM
1375 if (ptr && size > 0)
1376 memset(ptr, 0xff, size);
1377#endif
1378 return ptr;
1379}
1380
1381/**
1344 * memblock_virt_alloc_try_nid_nopanic - allocate boot memory block 1382 * memblock_virt_alloc_try_nid_nopanic - allocate boot memory block
1345 * @size: size of memory block to be allocated in bytes 1383 * @size: size of memory block to be allocated in bytes
1346 * @align: alignment of the region and block's size 1384 * @align: alignment of the region and block's size
@@ -1351,8 +1389,8 @@ done:
1351 * allocate only from memory limited by memblock.current_limit value 1389 * allocate only from memory limited by memblock.current_limit value
1352 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node 1390 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1353 * 1391 *
1354 * Public version of _memblock_virt_alloc_try_nid_nopanic() which provides 1392 * Public function, provides additional debug information (including caller
1355 * additional debug information (including caller info), if enabled. 1393 * info), if enabled. This function zeroes the allocated memory.
1356 * 1394 *
1357 * RETURNS: 1395 * RETURNS:
1358 * Virtual address of allocated memory block on success, NULL on failure. 1396 * Virtual address of allocated memory block on success, NULL on failure.
@@ -1362,11 +1400,17 @@ void * __init memblock_virt_alloc_try_nid_nopanic(
1362 phys_addr_t min_addr, phys_addr_t max_addr, 1400 phys_addr_t min_addr, phys_addr_t max_addr,
1363 int nid) 1401 int nid)
1364{ 1402{
1403 void *ptr;
1404
1365 memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=0x%llx max_addr=0x%llx %pF\n", 1405 memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=0x%llx max_addr=0x%llx %pF\n",
1366 __func__, (u64)size, (u64)align, nid, (u64)min_addr, 1406 __func__, (u64)size, (u64)align, nid, (u64)min_addr,
1367 (u64)max_addr, (void *)_RET_IP_); 1407 (u64)max_addr, (void *)_RET_IP_);
1368 return memblock_virt_alloc_internal(size, align, min_addr, 1408
1369 max_addr, nid); 1409 ptr = memblock_virt_alloc_internal(size, align,
1410 min_addr, max_addr, nid);
1411 if (ptr)
1412 memset(ptr, 0, size);
1413 return ptr;
1370} 1414}
1371 1415
1372/** 1416/**
@@ -1380,7 +1424,7 @@ void * __init memblock_virt_alloc_try_nid_nopanic(
1380 * allocate only from memory limited by memblock.current_limit value 1424 * allocate only from memory limited by memblock.current_limit value
1381 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node 1425 * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
1382 * 1426 *
1383 * Public panicking version of _memblock_virt_alloc_try_nid_nopanic() 1427 * Public panicking version of memblock_virt_alloc_try_nid_nopanic()
1384 * which provides debug information (including caller info), if enabled, 1428 * which provides debug information (including caller info), if enabled,
1385 * and panics if the request can not be satisfied. 1429 * and panics if the request can not be satisfied.
1386 * 1430 *
@@ -1399,8 +1443,10 @@ void * __init memblock_virt_alloc_try_nid(
1399 (u64)max_addr, (void *)_RET_IP_); 1443 (u64)max_addr, (void *)_RET_IP_);
1400 ptr = memblock_virt_alloc_internal(size, align, 1444 ptr = memblock_virt_alloc_internal(size, align,
1401 min_addr, max_addr, nid); 1445 min_addr, max_addr, nid);
1402 if (ptr) 1446 if (ptr) {
1447 memset(ptr, 0, size);
1403 return ptr; 1448 return ptr;
1449 }
1404 1450
1405 panic("%s: Failed to allocate %llu bytes align=0x%llx nid=%d from=0x%llx max_addr=0x%llx\n", 1451 panic("%s: Failed to allocate %llu bytes align=0x%llx nid=%d from=0x%llx max_addr=0x%llx\n",
1406 __func__, (u64)size, (u64)align, nid, (u64)min_addr, 1452 __func__, (u64)size, (u64)align, nid, (u64)min_addr,
@@ -1715,7 +1761,7 @@ static void __init_memblock memblock_dump(struct memblock_type *type)
1715 1761
1716 pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt); 1762 pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt);
1717 1763
1718 for_each_memblock_type(type, rgn) { 1764 for_each_memblock_type(idx, type, rgn) {
1719 char nid_buf[32] = ""; 1765 char nid_buf[32] = "";
1720 1766
1721 base = rgn->base; 1767 base = rgn->base;
@@ -1739,7 +1785,7 @@ memblock_reserved_memory_within(phys_addr_t start_addr, phys_addr_t end_addr)
1739 unsigned long size = 0; 1785 unsigned long size = 0;
1740 int idx; 1786 int idx;
1741 1787
1742 for_each_memblock_type((&memblock.reserved), rgn) { 1788 for_each_memblock_type(idx, (&memblock.reserved), rgn) {
1743 phys_addr_t start, end; 1789 phys_addr_t start, end;
1744 1790
1745 if (rgn->base + rgn->size < start_addr) 1791 if (rgn->base + rgn->size < start_addr)