init.c 18 KB

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