init.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Based on arch/arm/mm/init.c
  3. *
  4. * Copyright (C) 1995-2005 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/export.h>
  21. #include <linux/errno.h>
  22. #include <linux/swap.h>
  23. #include <linux/init.h>
  24. #include <linux/bootmem.h>
  25. #include <linux/cache.h>
  26. #include <linux/mman.h>
  27. #include <linux/nodemask.h>
  28. #include <linux/initrd.h>
  29. #include <linux/gfp.h>
  30. #include <linux/memblock.h>
  31. #include <linux/sort.h>
  32. #include <linux/of.h>
  33. #include <linux/of_fdt.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/dma-contiguous.h>
  36. #include <linux/efi.h>
  37. #include <linux/swiotlb.h>
  38. #include <linux/vmalloc.h>
  39. #include <linux/kexec.h>
  40. #include <linux/crash_dump.h>
  41. #include <asm/boot.h>
  42. #include <asm/fixmap.h>
  43. #include <asm/kasan.h>
  44. #include <asm/kernel-pgtable.h>
  45. #include <asm/memory.h>
  46. #include <asm/numa.h>
  47. #include <asm/sections.h>
  48. #include <asm/setup.h>
  49. #include <asm/sizes.h>
  50. #include <asm/tlb.h>
  51. #include <asm/alternative.h>
  52. /*
  53. * We need to be able to catch inadvertent references to memstart_addr
  54. * that occur (potentially in generic code) before arm64_memblock_init()
  55. * executes, which assigns it its actual value. So use a default value
  56. * that cannot be mistaken for a real physical address.
  57. */
  58. s64 memstart_addr __ro_after_init = -1;
  59. phys_addr_t arm64_dma_phys_limit __ro_after_init;
  60. #ifdef CONFIG_BLK_DEV_INITRD
  61. static int __init early_initrd(char *p)
  62. {
  63. unsigned long start, size;
  64. char *endp;
  65. start = memparse(p, &endp);
  66. if (*endp == ',') {
  67. size = memparse(endp + 1, NULL);
  68. initrd_start = start;
  69. initrd_end = start + size;
  70. }
  71. return 0;
  72. }
  73. early_param("initrd", early_initrd);
  74. #endif
  75. #ifdef CONFIG_KEXEC_CORE
  76. /*
  77. * reserve_crashkernel() - reserves memory for crash kernel
  78. *
  79. * This function reserves memory area given in "crashkernel=" kernel command
  80. * line parameter. The memory reserved is used by dump capture kernel when
  81. * primary kernel is crashing.
  82. */
  83. static void __init reserve_crashkernel(void)
  84. {
  85. unsigned long long crash_base, crash_size;
  86. int ret;
  87. ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
  88. &crash_size, &crash_base);
  89. /* no crashkernel= or invalid value specified */
  90. if (ret || !crash_size)
  91. return;
  92. crash_size = PAGE_ALIGN(crash_size);
  93. if (crash_base == 0) {
  94. /* Current arm64 boot protocol requires 2MB alignment */
  95. crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT,
  96. crash_size, SZ_2M);
  97. if (crash_base == 0) {
  98. pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
  99. crash_size);
  100. return;
  101. }
  102. } else {
  103. /* User specifies base address explicitly. */
  104. if (!memblock_is_region_memory(crash_base, crash_size)) {
  105. pr_warn("cannot reserve crashkernel: region is not memory\n");
  106. return;
  107. }
  108. if (memblock_is_region_reserved(crash_base, crash_size)) {
  109. pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n");
  110. return;
  111. }
  112. if (!IS_ALIGNED(crash_base, SZ_2M)) {
  113. pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n");
  114. return;
  115. }
  116. }
  117. memblock_reserve(crash_base, crash_size);
  118. pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n",
  119. crash_base, crash_base + crash_size, crash_size >> 20);
  120. crashk_res.start = crash_base;
  121. crashk_res.end = crash_base + crash_size - 1;
  122. }
  123. static void __init kexec_reserve_crashkres_pages(void)
  124. {
  125. #ifdef CONFIG_HIBERNATION
  126. phys_addr_t addr;
  127. struct page *page;
  128. if (!crashk_res.end)
  129. return;
  130. /*
  131. * To reduce the size of hibernation image, all the pages are
  132. * marked as Reserved initially.
  133. */
  134. for (addr = crashk_res.start; addr < (crashk_res.end + 1);
  135. addr += PAGE_SIZE) {
  136. page = phys_to_page(addr);
  137. SetPageReserved(page);
  138. }
  139. #endif
  140. }
  141. #else
  142. static void __init reserve_crashkernel(void)
  143. {
  144. }
  145. static void __init kexec_reserve_crashkres_pages(void)
  146. {
  147. }
  148. #endif /* CONFIG_KEXEC_CORE */
  149. #ifdef CONFIG_CRASH_DUMP
  150. static int __init early_init_dt_scan_elfcorehdr(unsigned long node,
  151. const char *uname, int depth, void *data)
  152. {
  153. const __be32 *reg;
  154. int len;
  155. if (depth != 1 || strcmp(uname, "chosen") != 0)
  156. return 0;
  157. reg = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len);
  158. if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
  159. return 1;
  160. elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &reg);
  161. elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &reg);
  162. return 1;
  163. }
  164. /*
  165. * reserve_elfcorehdr() - reserves memory for elf core header
  166. *
  167. * This function reserves the memory occupied by an elf core header
  168. * described in the device tree. This region contains all the
  169. * information about primary kernel's core image and is used by a dump
  170. * capture kernel to access the system memory on primary kernel.
  171. */
  172. static void __init reserve_elfcorehdr(void)
  173. {
  174. of_scan_flat_dt(early_init_dt_scan_elfcorehdr, NULL);
  175. if (!elfcorehdr_size)
  176. return;
  177. if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) {
  178. pr_warn("elfcorehdr is overlapped\n");
  179. return;
  180. }
  181. memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
  182. pr_info("Reserving %lldKB of memory at 0x%llx for elfcorehdr\n",
  183. elfcorehdr_size >> 10, elfcorehdr_addr);
  184. }
  185. #else
  186. static void __init reserve_elfcorehdr(void)
  187. {
  188. }
  189. #endif /* CONFIG_CRASH_DUMP */
  190. /*
  191. * Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It
  192. * currently assumes that for memory starting above 4G, 32-bit devices will
  193. * use a DMA offset.
  194. */
  195. static phys_addr_t __init max_zone_dma_phys(void)
  196. {
  197. phys_addr_t offset = memblock_start_of_DRAM() & GENMASK_ULL(63, 32);
  198. return min(offset + (1ULL << 32), memblock_end_of_DRAM());
  199. }
  200. #ifdef CONFIG_NUMA
  201. static void __init zone_sizes_init(unsigned long min, unsigned long max)
  202. {
  203. unsigned long max_zone_pfns[MAX_NR_ZONES] = {0};
  204. if (IS_ENABLED(CONFIG_ZONE_DMA))
  205. max_zone_pfns[ZONE_DMA] = PFN_DOWN(max_zone_dma_phys());
  206. max_zone_pfns[ZONE_NORMAL] = max;
  207. free_area_init_nodes(max_zone_pfns);
  208. }
  209. #else
  210. static void __init zone_sizes_init(unsigned long min, unsigned long max)
  211. {
  212. struct memblock_region *reg;
  213. unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
  214. unsigned long max_dma = min;
  215. memset(zone_size, 0, sizeof(zone_size));
  216. /* 4GB maximum for 32-bit only capable devices */
  217. #ifdef CONFIG_ZONE_DMA
  218. max_dma = PFN_DOWN(arm64_dma_phys_limit);
  219. zone_size[ZONE_DMA] = max_dma - min;
  220. #endif
  221. zone_size[ZONE_NORMAL] = max - max_dma;
  222. memcpy(zhole_size, zone_size, sizeof(zhole_size));
  223. for_each_memblock(memory, reg) {
  224. unsigned long start = memblock_region_memory_base_pfn(reg);
  225. unsigned long end = memblock_region_memory_end_pfn(reg);
  226. if (start >= max)
  227. continue;
  228. #ifdef CONFIG_ZONE_DMA
  229. if (start < max_dma) {
  230. unsigned long dma_end = min(end, max_dma);
  231. zhole_size[ZONE_DMA] -= dma_end - start;
  232. }
  233. #endif
  234. if (end > max_dma) {
  235. unsigned long normal_end = min(end, max);
  236. unsigned long normal_start = max(start, max_dma);
  237. zhole_size[ZONE_NORMAL] -= normal_end - normal_start;
  238. }
  239. }
  240. free_area_init_node(0, zone_size, min, zhole_size);
  241. }
  242. #endif /* CONFIG_NUMA */
  243. #ifdef CONFIG_HAVE_ARCH_PFN_VALID
  244. int pfn_valid(unsigned long pfn)
  245. {
  246. return memblock_is_map_memory(pfn << PAGE_SHIFT);
  247. }
  248. EXPORT_SYMBOL(pfn_valid);
  249. #endif
  250. #ifndef CONFIG_SPARSEMEM
  251. static void __init arm64_memory_present(void)
  252. {
  253. }
  254. #else
  255. static void __init arm64_memory_present(void)
  256. {
  257. struct memblock_region *reg;
  258. for_each_memblock(memory, reg) {
  259. int nid = memblock_get_region_node(reg);
  260. memory_present(nid, memblock_region_memory_base_pfn(reg),
  261. memblock_region_memory_end_pfn(reg));
  262. }
  263. }
  264. #endif
  265. static phys_addr_t memory_limit = (phys_addr_t)ULLONG_MAX;
  266. /*
  267. * Limit the memory size that was specified via FDT.
  268. */
  269. static int __init early_mem(char *p)
  270. {
  271. if (!p)
  272. return 1;
  273. memory_limit = memparse(p, &p) & PAGE_MASK;
  274. pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
  275. return 0;
  276. }
  277. early_param("mem", early_mem);
  278. static int __init early_init_dt_scan_usablemem(unsigned long node,
  279. const char *uname, int depth, void *data)
  280. {
  281. struct memblock_region *usablemem = data;
  282. const __be32 *reg;
  283. int len;
  284. if (depth != 1 || strcmp(uname, "chosen") != 0)
  285. return 0;
  286. reg = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
  287. if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells)))
  288. return 1;
  289. usablemem->base = dt_mem_next_cell(dt_root_addr_cells, &reg);
  290. usablemem->size = dt_mem_next_cell(dt_root_size_cells, &reg);
  291. return 1;
  292. }
  293. static void __init fdt_enforce_memory_region(void)
  294. {
  295. struct memblock_region reg = {
  296. .size = 0,
  297. };
  298. of_scan_flat_dt(early_init_dt_scan_usablemem, &reg);
  299. if (reg.size)
  300. memblock_cap_memory_range(reg.base, reg.size);
  301. }
  302. void __init arm64_memblock_init(void)
  303. {
  304. const s64 linear_region_size = -(s64)PAGE_OFFSET;
  305. /* Handle linux,usable-memory-range property */
  306. fdt_enforce_memory_region();
  307. /*
  308. * Ensure that the linear region takes up exactly half of the kernel
  309. * virtual address space. This way, we can distinguish a linear address
  310. * from a kernel/module/vmalloc address by testing a single bit.
  311. */
  312. BUILD_BUG_ON(linear_region_size != BIT(VA_BITS - 1));
  313. /*
  314. * Select a suitable value for the base of physical memory.
  315. */
  316. memstart_addr = round_down(memblock_start_of_DRAM(),
  317. ARM64_MEMSTART_ALIGN);
  318. /*
  319. * Remove the memory that we will not be able to cover with the
  320. * linear mapping. Take care not to clip the kernel which may be
  321. * high in memory.
  322. */
  323. memblock_remove(max_t(u64, memstart_addr + linear_region_size, __pa(_end)),
  324. ULLONG_MAX);
  325. if (memstart_addr + linear_region_size < memblock_end_of_DRAM()) {
  326. /* ensure that memstart_addr remains sufficiently aligned */
  327. memstart_addr = round_up(memblock_end_of_DRAM() - linear_region_size,
  328. ARM64_MEMSTART_ALIGN);
  329. memblock_remove(0, memstart_addr);
  330. }
  331. /*
  332. * Apply the memory limit if it was set. Since the kernel may be loaded
  333. * high up in memory, add back the kernel region that must be accessible
  334. * via the linear mapping.
  335. */
  336. if (memory_limit != (phys_addr_t)ULLONG_MAX) {
  337. memblock_mem_limit_remove_map(memory_limit);
  338. memblock_add(__pa(_text), (u64)(_end - _text));
  339. }
  340. if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_start) {
  341. /*
  342. * Add back the memory we just removed if it results in the
  343. * initrd to become inaccessible via the linear mapping.
  344. * Otherwise, this is a no-op
  345. */
  346. u64 base = initrd_start & PAGE_MASK;
  347. u64 size = PAGE_ALIGN(initrd_end) - base;
  348. /*
  349. * We can only add back the initrd memory if we don't end up
  350. * with more memory than we can address via the linear mapping.
  351. * It is up to the bootloader to position the kernel and the
  352. * initrd reasonably close to each other (i.e., within 32 GB of
  353. * each other) so that all granule/#levels combinations can
  354. * always access both.
  355. */
  356. if (WARN(base < memblock_start_of_DRAM() ||
  357. base + size > memblock_start_of_DRAM() +
  358. linear_region_size,
  359. "initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) {
  360. initrd_start = 0;
  361. } else {
  362. memblock_remove(base, size); /* clear MEMBLOCK_ flags */
  363. memblock_add(base, size);
  364. memblock_reserve(base, size);
  365. }
  366. }
  367. if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
  368. extern u16 memstart_offset_seed;
  369. u64 range = linear_region_size -
  370. (memblock_end_of_DRAM() - memblock_start_of_DRAM());
  371. /*
  372. * If the size of the linear region exceeds, by a sufficient
  373. * margin, the size of the region that the available physical
  374. * memory spans, randomize the linear region as well.
  375. */
  376. if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) {
  377. range = range / ARM64_MEMSTART_ALIGN + 1;
  378. memstart_addr -= ARM64_MEMSTART_ALIGN *
  379. ((range * memstart_offset_seed) >> 16);
  380. }
  381. }
  382. /*
  383. * Register the kernel text, kernel data, initrd, and initial
  384. * pagetables with memblock.
  385. */
  386. memblock_reserve(__pa(_text), _end - _text);
  387. #ifdef CONFIG_BLK_DEV_INITRD
  388. if (initrd_start) {
  389. memblock_reserve(initrd_start, initrd_end - initrd_start);
  390. /* the generic initrd code expects virtual addresses */
  391. initrd_start = __phys_to_virt(initrd_start);
  392. initrd_end = __phys_to_virt(initrd_end);
  393. }
  394. #endif
  395. early_init_fdt_scan_reserved_mem();
  396. /* 4GB maximum for 32-bit only capable devices */
  397. if (IS_ENABLED(CONFIG_ZONE_DMA))
  398. arm64_dma_phys_limit = max_zone_dma_phys();
  399. else
  400. arm64_dma_phys_limit = PHYS_MASK + 1;
  401. reserve_crashkernel();
  402. reserve_elfcorehdr();
  403. dma_contiguous_reserve(arm64_dma_phys_limit);
  404. memblock_allow_resize();
  405. }
  406. void __init bootmem_init(void)
  407. {
  408. unsigned long min, max;
  409. min = PFN_UP(memblock_start_of_DRAM());
  410. max = PFN_DOWN(memblock_end_of_DRAM());
  411. early_memtest(min << PAGE_SHIFT, max << PAGE_SHIFT);
  412. max_pfn = max_low_pfn = max;
  413. arm64_numa_init();
  414. /*
  415. * Sparsemem tries to allocate bootmem in memory_present(), so must be
  416. * done after the fixed reservations.
  417. */
  418. arm64_memory_present();
  419. sparse_init();
  420. zone_sizes_init(min, max);
  421. high_memory = __va((max << PAGE_SHIFT) - 1) + 1;
  422. memblock_dump_all();
  423. }
  424. #ifndef CONFIG_SPARSEMEM_VMEMMAP
  425. static inline void free_memmap(unsigned long start_pfn, unsigned long end_pfn)
  426. {
  427. struct page *start_pg, *end_pg;
  428. unsigned long pg, pgend;
  429. /*
  430. * Convert start_pfn/end_pfn to a struct page pointer.
  431. */
  432. start_pg = pfn_to_page(start_pfn - 1) + 1;
  433. end_pg = pfn_to_page(end_pfn - 1) + 1;
  434. /*
  435. * Convert to physical addresses, and round start upwards and end
  436. * downwards.
  437. */
  438. pg = (unsigned long)PAGE_ALIGN(__pa(start_pg));
  439. pgend = (unsigned long)__pa(end_pg) & PAGE_MASK;
  440. /*
  441. * If there are free pages between these, free the section of the
  442. * memmap array.
  443. */
  444. if (pg < pgend)
  445. free_bootmem(pg, pgend - pg);
  446. }
  447. /*
  448. * The mem_map array can get very big. Free the unused area of the memory map.
  449. */
  450. static void __init free_unused_memmap(void)
  451. {
  452. unsigned long start, prev_end = 0;
  453. struct memblock_region *reg;
  454. for_each_memblock(memory, reg) {
  455. start = __phys_to_pfn(reg->base);
  456. #ifdef CONFIG_SPARSEMEM
  457. /*
  458. * Take care not to free memmap entries that don't exist due
  459. * to SPARSEMEM sections which aren't present.
  460. */
  461. start = min(start, ALIGN(prev_end, PAGES_PER_SECTION));
  462. #endif
  463. /*
  464. * If we had a previous bank, and there is a space between the
  465. * current bank and the previous, free it.
  466. */
  467. if (prev_end && prev_end < start)
  468. free_memmap(prev_end, start);
  469. /*
  470. * Align up here since the VM subsystem insists that the
  471. * memmap entries are valid from the bank end aligned to
  472. * MAX_ORDER_NR_PAGES.
  473. */
  474. prev_end = ALIGN(__phys_to_pfn(reg->base + reg->size),
  475. MAX_ORDER_NR_PAGES);
  476. }
  477. #ifdef CONFIG_SPARSEMEM
  478. if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
  479. free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
  480. #endif
  481. }
  482. #endif /* !CONFIG_SPARSEMEM_VMEMMAP */
  483. /*
  484. * mem_init() marks the free areas in the mem_map and tells us how much memory
  485. * is free. This is done after various parts of the system have claimed their
  486. * memory after the kernel image.
  487. */
  488. void __init mem_init(void)
  489. {
  490. if (swiotlb_force == SWIOTLB_FORCE ||
  491. max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
  492. swiotlb_init(1);
  493. else
  494. swiotlb_force = SWIOTLB_NO_FORCE;
  495. set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
  496. #ifndef CONFIG_SPARSEMEM_VMEMMAP
  497. free_unused_memmap();
  498. #endif
  499. /* this will put all unused low memory onto the freelists */
  500. free_all_bootmem();
  501. kexec_reserve_crashkres_pages();
  502. mem_init_print_info(NULL);
  503. #define MLK(b, t) b, t, ((t) - (b)) >> 10
  504. #define MLM(b, t) b, t, ((t) - (b)) >> 20
  505. #define MLG(b, t) b, t, ((t) - (b)) >> 30
  506. #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
  507. pr_notice("Virtual kernel memory layout:\n");
  508. #ifdef CONFIG_KASAN
  509. pr_notice(" kasan : 0x%16lx - 0x%16lx (%6ld GB)\n",
  510. MLG(KASAN_SHADOW_START, KASAN_SHADOW_END));
  511. #endif
  512. pr_notice(" modules : 0x%16lx - 0x%16lx (%6ld MB)\n",
  513. MLM(MODULES_VADDR, MODULES_END));
  514. pr_notice(" vmalloc : 0x%16lx - 0x%16lx (%6ld GB)\n",
  515. MLG(VMALLOC_START, VMALLOC_END));
  516. pr_notice(" .text : 0x%p" " - 0x%p" " (%6ld KB)\n",
  517. MLK_ROUNDUP(_text, _etext));
  518. pr_notice(" .rodata : 0x%p" " - 0x%p" " (%6ld KB)\n",
  519. MLK_ROUNDUP(__start_rodata, __init_begin));
  520. pr_notice(" .init : 0x%p" " - 0x%p" " (%6ld KB)\n",
  521. MLK_ROUNDUP(__init_begin, __init_end));
  522. pr_notice(" .data : 0x%p" " - 0x%p" " (%6ld KB)\n",
  523. MLK_ROUNDUP(_sdata, _edata));
  524. pr_notice(" .bss : 0x%p" " - 0x%p" " (%6ld KB)\n",
  525. MLK_ROUNDUP(__bss_start, __bss_stop));
  526. pr_notice(" fixed : 0x%16lx - 0x%16lx (%6ld KB)\n",
  527. MLK(FIXADDR_START, FIXADDR_TOP));
  528. pr_notice(" PCI I/O : 0x%16lx - 0x%16lx (%6ld MB)\n",
  529. MLM(PCI_IO_START, PCI_IO_END));
  530. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  531. pr_notice(" vmemmap : 0x%16lx - 0x%16lx (%6ld GB maximum)\n",
  532. MLG(VMEMMAP_START, VMEMMAP_START + VMEMMAP_SIZE));
  533. pr_notice(" 0x%16lx - 0x%16lx (%6ld MB actual)\n",
  534. MLM((unsigned long)phys_to_page(memblock_start_of_DRAM()),
  535. (unsigned long)virt_to_page(high_memory)));
  536. #endif
  537. pr_notice(" memory : 0x%16lx - 0x%16lx (%6ld MB)\n",
  538. MLM(__phys_to_virt(memblock_start_of_DRAM()),
  539. (unsigned long)high_memory));
  540. #undef MLK
  541. #undef MLM
  542. #undef MLK_ROUNDUP
  543. /*
  544. * Check boundaries twice: Some fundamental inconsistencies can be
  545. * detected at build time already.
  546. */
  547. #ifdef CONFIG_COMPAT
  548. BUILD_BUG_ON(TASK_SIZE_32 > TASK_SIZE_64);
  549. #endif
  550. /*
  551. * Make sure we chose the upper bound of sizeof(struct page)
  552. * correctly.
  553. */
  554. BUILD_BUG_ON(sizeof(struct page) > (1 << STRUCT_PAGE_MAX_SHIFT));
  555. if (PAGE_SIZE >= 16384 && get_num_physpages() <= 128) {
  556. extern int sysctl_overcommit_memory;
  557. /*
  558. * On a machine this small we won't get anywhere without
  559. * overcommit, so turn it on by default.
  560. */
  561. sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
  562. }
  563. }
  564. void free_initmem(void)
  565. {
  566. free_reserved_area(__va(__pa(__init_begin)), __va(__pa(__init_end)),
  567. 0, "unused kernel");
  568. /*
  569. * Unmap the __init region but leave the VM area in place. This
  570. * prevents the region from being reused for kernel modules, which
  571. * is not supported by kallsyms.
  572. */
  573. unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
  574. }
  575. #ifdef CONFIG_BLK_DEV_INITRD
  576. static int keep_initrd __initdata;
  577. void __init free_initrd_mem(unsigned long start, unsigned long end)
  578. {
  579. if (!keep_initrd)
  580. free_reserved_area((void *)start, (void *)end, 0, "initrd");
  581. }
  582. static int __init keepinitrd_setup(char *__unused)
  583. {
  584. keep_initrd = 1;
  585. return 1;
  586. }
  587. __setup("keepinitrd", keepinitrd_setup);
  588. #endif
  589. /*
  590. * Dump out memory limit information on panic.
  591. */
  592. static int dump_mem_limit(struct notifier_block *self, unsigned long v, void *p)
  593. {
  594. if (memory_limit != (phys_addr_t)ULLONG_MAX) {
  595. pr_emerg("Memory Limit: %llu MB\n", memory_limit >> 20);
  596. } else {
  597. pr_emerg("Memory Limit: none\n");
  598. }
  599. return 0;
  600. }
  601. static struct notifier_block mem_limit_notifier = {
  602. .notifier_call = dump_mem_limit,
  603. };
  604. static int __init register_mem_limit_dumper(void)
  605. {
  606. atomic_notifier_chain_register(&panic_notifier_list,
  607. &mem_limit_notifier);
  608. return 0;
  609. }
  610. __initcall(register_mem_limit_dumper);