The memory size calculation in cma_early_percent_memory() traverses memblock.memory rather than simply call memblock_phys_mem_size(). The comment in that function suggests that at some point there should have been call to memblock_analyze() before memblock_phys_mem_size() could be used. As of now, there is no memblock_analyze() at all and memblock_phys_mem_size() can be used as soon as cold-plug memory is registered with memblock. Replace loop over memblock.memory with a call to memblock_phys_mem_size().
Unified · Split
| @@ -73,16 +73,7 @@ early_param("cma", early_cma); · 72 unmodified lines | ||
| 73 | 73 | |
| 74 | 74 | static phys_addr_t __init __maybe_unused cma_early_percent_memory(void) |
| 75 | 75 | { |
| 76 | − struct memblock_region *reg; | |
| 77 | − unsigned long total_pages = 0; | |
| 78 | − | |
| 79 | − /* | |
| 80 | − * We cannot use memblock_phys_mem_size() here, because | |
| 81 | − * memblock_analyze() has not been called yet. | |
| 82 | − */ | |
| 83 | − for_each_memblock(memory, reg) | |
| 84 | − total_pages += memblock_region_memory_end_pfn(reg) - | |
| 85 | − memblock_region_memory_base_pfn(reg); | |
| 76 | + unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size()); | |
| 86 | 77 | |
| 87 | 78 | return (total_pages * CONFIG_CMA_SIZE_PERCENTAGE / 100) << PAGE_SHIFT; |
| 88 | 79 | } |