blob: 0804a6af4a3b7103c729a48d12d898212ecbc0ff [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * linux/arch/arm/mm/init.c
4 *
5 * Copyright (C) 1995-2005 Russell King
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7#include <linux/kernel.h>
8#include <linux/errno.h>
9#include <linux/swap.h>
10#include <linux/init.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000011#include <linux/mman.h>
12#include <linux/sched/signal.h>
13#include <linux/sched/task.h>
14#include <linux/export.h>
15#include <linux/nodemask.h>
16#include <linux/initrd.h>
17#include <linux/of_fdt.h>
18#include <linux/highmem.h>
19#include <linux/gfp.h>
20#include <linux/memblock.h>
21#include <linux/dma-contiguous.h>
22#include <linux/sizes.h>
23#include <linux/stop_machine.h>
David Brazdil0f672f62019-12-10 10:32:29 +000024#include <linux/swiotlb.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025
26#include <asm/cp15.h>
27#include <asm/mach-types.h>
28#include <asm/memblock.h>
29#include <asm/memory.h>
30#include <asm/prom.h>
31#include <asm/sections.h>
32#include <asm/setup.h>
33#include <asm/system_info.h>
34#include <asm/tlb.h>
35#include <asm/fixmap.h>
36#include <asm/ptdump.h>
37
38#include <asm/mach/arch.h>
39#include <asm/mach/map.h>
40
41#include "mm.h"
42
43#ifdef CONFIG_CPU_CP15_MMU
44unsigned long __init __clear_cr(unsigned long mask)
45{
46 cr_alignment = cr_alignment & ~mask;
47 return cr_alignment;
48}
49#endif
50
David Brazdil0f672f62019-12-10 10:32:29 +000051#ifdef CONFIG_BLK_DEV_INITRD
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000052static int __init parse_tag_initrd(const struct tag *tag)
53{
54 pr_warn("ATAG_INITRD is deprecated; "
55 "please update your bootloader.\n");
56 phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
57 phys_initrd_size = tag->u.initrd.size;
58 return 0;
59}
60
61__tagtable(ATAG_INITRD, parse_tag_initrd);
62
63static int __init parse_tag_initrd2(const struct tag *tag)
64{
65 phys_initrd_start = tag->u.initrd.start;
66 phys_initrd_size = tag->u.initrd.size;
67 return 0;
68}
69
70__tagtable(ATAG_INITRD2, parse_tag_initrd2);
David Brazdil0f672f62019-12-10 10:32:29 +000071#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000072
73static void __init find_limits(unsigned long *min, unsigned long *max_low,
74 unsigned long *max_high)
75{
76 *max_low = PFN_DOWN(memblock_get_current_limit());
77 *min = PFN_UP(memblock_start_of_DRAM());
78 *max_high = PFN_DOWN(memblock_end_of_DRAM());
79}
80
81#ifdef CONFIG_ZONE_DMA
82
83phys_addr_t arm_dma_zone_size __read_mostly;
84EXPORT_SYMBOL(arm_dma_zone_size);
85
86/*
87 * The DMA mask corresponding to the maximum bus address allocatable
88 * using GFP_DMA. The default here places no restriction on DMA
89 * allocations. This must be the smallest DMA mask in the system,
90 * so a successful GFP_DMA allocation will always satisfy this.
91 */
92phys_addr_t arm_dma_limit;
93unsigned long arm_dma_pfn_limit;
94
95static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
96 unsigned long dma_size)
97{
98 if (size[0] <= dma_size)
99 return;
100
101 size[ZONE_NORMAL] = size[0] - dma_size;
102 size[ZONE_DMA] = dma_size;
103 hole[ZONE_NORMAL] = hole[0];
104 hole[ZONE_DMA] = 0;
105}
106#endif
107
108void __init setup_dma_zone(const struct machine_desc *mdesc)
109{
110#ifdef CONFIG_ZONE_DMA
111 if (mdesc->dma_zone_size) {
112 arm_dma_zone_size = mdesc->dma_zone_size;
113 arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;
114 } else
115 arm_dma_limit = 0xffffffff;
116 arm_dma_pfn_limit = arm_dma_limit >> PAGE_SHIFT;
117#endif
118}
119
120static void __init zone_sizes_init(unsigned long min, unsigned long max_low,
121 unsigned long max_high)
122{
123 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
124 struct memblock_region *reg;
125
126 /*
127 * initialise the zones.
128 */
129 memset(zone_size, 0, sizeof(zone_size));
130
131 /*
132 * The memory size has already been determined. If we need
133 * to do anything fancy with the allocation of this memory
134 * to the zones, now is the time to do it.
135 */
136 zone_size[0] = max_low - min;
137#ifdef CONFIG_HIGHMEM
138 zone_size[ZONE_HIGHMEM] = max_high - max_low;
139#endif
140
141 /*
142 * Calculate the size of the holes.
143 * holes = node_size - sum(bank_sizes)
144 */
145 memcpy(zhole_size, zone_size, sizeof(zhole_size));
146 for_each_memblock(memory, reg) {
147 unsigned long start = memblock_region_memory_base_pfn(reg);
148 unsigned long end = memblock_region_memory_end_pfn(reg);
149
150 if (start < max_low) {
151 unsigned long low_end = min(end, max_low);
152 zhole_size[0] -= low_end - start;
153 }
154#ifdef CONFIG_HIGHMEM
155 if (end > max_low) {
156 unsigned long high_start = max(start, max_low);
157 zhole_size[ZONE_HIGHMEM] -= end - high_start;
158 }
159#endif
160 }
161
162#ifdef CONFIG_ZONE_DMA
163 /*
164 * Adjust the sizes according to any special requirements for
165 * this machine type.
166 */
167 if (arm_dma_zone_size)
168 arm_adjust_dma_zone(zone_size, zhole_size,
169 arm_dma_zone_size >> PAGE_SHIFT);
170#endif
171
172 free_area_init_node(0, zone_size, min, zhole_size);
173}
174
175#ifdef CONFIG_HAVE_ARCH_PFN_VALID
176int pfn_valid(unsigned long pfn)
177{
David Brazdil0f672f62019-12-10 10:32:29 +0000178 phys_addr_t addr = __pfn_to_phys(pfn);
179
180 if (__phys_to_pfn(addr) != pfn)
181 return 0;
182
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000183 return memblock_is_map_memory(__pfn_to_phys(pfn));
184}
185EXPORT_SYMBOL(pfn_valid);
186#endif
187
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000188static bool arm_memblock_steal_permitted = true;
189
190phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
191{
192 phys_addr_t phys;
193
194 BUG_ON(!arm_memblock_steal_permitted);
195
David Brazdil0f672f62019-12-10 10:32:29 +0000196 phys = memblock_phys_alloc(size, align);
197 if (!phys)
198 panic("Failed to steal %pa bytes at %pS\n",
199 &size, (void *)_RET_IP_);
200
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000201 memblock_free(phys, size);
202 memblock_remove(phys, size);
203
204 return phys;
205}
206
207static void __init arm_initrd_init(void)
208{
209#ifdef CONFIG_BLK_DEV_INITRD
210 phys_addr_t start;
211 unsigned long size;
212
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000213 initrd_start = initrd_end = 0;
214
215 if (!phys_initrd_size)
216 return;
217
218 /*
219 * Round the memory region to page boundaries as per free_initrd_mem()
220 * This allows us to detect whether the pages overlapping the initrd
221 * are in use, but more importantly, reserves the entire set of pages
222 * as we don't want these pages allocated for other purposes.
223 */
224 start = round_down(phys_initrd_start, PAGE_SIZE);
225 size = phys_initrd_size + (phys_initrd_start - start);
226 size = round_up(size, PAGE_SIZE);
227
228 if (!memblock_is_region_memory(start, size)) {
229 pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
230 (u64)start, size);
231 return;
232 }
233
234 if (memblock_is_region_reserved(start, size)) {
235 pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n",
236 (u64)start, size);
237 return;
238 }
239
240 memblock_reserve(start, size);
241
242 /* Now convert initrd to virtual addresses */
243 initrd_start = __phys_to_virt(phys_initrd_start);
244 initrd_end = initrd_start + phys_initrd_size;
245#endif
246}
247
David Brazdil0f672f62019-12-10 10:32:29 +0000248#ifdef CONFIG_CPU_ICACHE_MISMATCH_WORKAROUND
249void check_cpu_icache_size(int cpuid)
250{
251 u32 size, ctr;
252
253 asm("mrc p15, 0, %0, c0, c0, 1" : "=r" (ctr));
254
255 size = 1 << ((ctr & 0xf) + 2);
256 if (cpuid != 0 && icache_size != size)
257 pr_info("CPU%u: detected I-Cache line size mismatch, workaround enabled\n",
258 cpuid);
259 if (icache_size > size)
260 icache_size = size;
261}
262#endif
263
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000264void __init arm_memblock_init(const struct machine_desc *mdesc)
265{
266 /* Register the kernel text, kernel data and initrd with memblock. */
267 memblock_reserve(__pa(KERNEL_START), KERNEL_END - KERNEL_START);
268
269 arm_initrd_init();
270
271 arm_mm_memblock_reserve();
272
273 /* reserve any platform specific memblock areas */
274 if (mdesc->reserve)
275 mdesc->reserve();
276
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000277 early_init_fdt_scan_reserved_mem();
278
279 /* reserve memory for DMA contiguous allocations */
280 dma_contiguous_reserve(arm_dma_limit);
281
282 arm_memblock_steal_permitted = false;
283 memblock_dump_all();
284}
285
286void __init bootmem_init(void)
287{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000288 memblock_allow_resize();
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000289
David Brazdil0f672f62019-12-10 10:32:29 +0000290 find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000291
David Brazdil0f672f62019-12-10 10:32:29 +0000292 early_memtest((phys_addr_t)min_low_pfn << PAGE_SHIFT,
293 (phys_addr_t)max_low_pfn << PAGE_SHIFT);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000294
295 /*
296 * Sparsemem tries to allocate bootmem in memory_present(),
297 * so must be done after the fixed reservations
298 */
David Brazdil0f672f62019-12-10 10:32:29 +0000299 memblocks_present();
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000300
301 /*
302 * sparse_init() needs the bootmem allocator up and running.
303 */
304 sparse_init();
305
306 /*
307 * Now free the memory - free_area_init_node needs
308 * the sparse mem_map arrays initialized by sparse_init()
309 * for memmap_init_zone(), otherwise all PFNs are invalid.
310 */
David Brazdil0f672f62019-12-10 10:32:29 +0000311 zone_sizes_init(min_low_pfn, max_low_pfn, max_pfn);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000312}
313
314/*
315 * Poison init memory with an undefined instruction (ARM) or a branch to an
316 * undefined instruction (Thumb).
317 */
318static inline void poison_init_mem(void *s, size_t count)
319{
320 u32 *p = (u32 *)s;
321 for (; count != 0; count -= 4)
322 *p++ = 0xe7fddef0;
323}
324
Olivier Deprez0e641232021-09-23 10:07:05 +0200325static inline void __init
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000326free_memmap(unsigned long start_pfn, unsigned long end_pfn)
327{
328 struct page *start_pg, *end_pg;
329 phys_addr_t pg, pgend;
330
331 /*
332 * Convert start_pfn/end_pfn to a struct page pointer.
333 */
334 start_pg = pfn_to_page(start_pfn - 1) + 1;
335 end_pg = pfn_to_page(end_pfn - 1) + 1;
336
337 /*
338 * Convert to physical addresses, and
339 * round start upwards and end downwards.
340 */
341 pg = PAGE_ALIGN(__pa(start_pg));
342 pgend = __pa(end_pg) & PAGE_MASK;
343
344 /*
345 * If there are free pages between these,
346 * free the section of the memmap array.
347 */
348 if (pg < pgend)
349 memblock_free_early(pg, pgend - pg);
350}
351
352/*
353 * The mem_map array can get very big. Free the unused area of the memory map.
354 */
355static void __init free_unused_memmap(void)
356{
357 unsigned long start, prev_end = 0;
358 struct memblock_region *reg;
359
360 /*
361 * This relies on each bank being in address order.
362 * The banks are sorted previously in bootmem_init().
363 */
364 for_each_memblock(memory, reg) {
365 start = memblock_region_memory_base_pfn(reg);
366
367#ifdef CONFIG_SPARSEMEM
368 /*
369 * Take care not to free memmap entries that don't exist
370 * due to SPARSEMEM sections which aren't present.
371 */
372 start = min(start,
373 ALIGN(prev_end, PAGES_PER_SECTION));
374#else
375 /*
376 * Align down here since the VM subsystem insists that the
377 * memmap entries are valid from the bank start aligned to
378 * MAX_ORDER_NR_PAGES.
379 */
380 start = round_down(start, MAX_ORDER_NR_PAGES);
381#endif
382 /*
383 * If we had a previous bank, and there is a space
384 * between the current bank and the previous, free it.
385 */
386 if (prev_end && prev_end < start)
387 free_memmap(prev_end, start);
388
389 /*
390 * Align up here since the VM subsystem insists that the
391 * memmap entries are valid from the bank end aligned to
392 * MAX_ORDER_NR_PAGES.
393 */
394 prev_end = ALIGN(memblock_region_memory_end_pfn(reg),
395 MAX_ORDER_NR_PAGES);
396 }
397
398#ifdef CONFIG_SPARSEMEM
399 if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
400 free_memmap(prev_end,
401 ALIGN(prev_end, PAGES_PER_SECTION));
402#endif
403}
404
405#ifdef CONFIG_HIGHMEM
406static inline void free_area_high(unsigned long pfn, unsigned long end)
407{
408 for (; pfn < end; pfn++)
409 free_highmem_page(pfn_to_page(pfn));
410}
411#endif
412
413static void __init free_highpages(void)
414{
415#ifdef CONFIG_HIGHMEM
416 unsigned long max_low = max_low_pfn;
417 struct memblock_region *mem, *res;
418
419 /* set highmem page free */
420 for_each_memblock(memory, mem) {
421 unsigned long start = memblock_region_memory_base_pfn(mem);
422 unsigned long end = memblock_region_memory_end_pfn(mem);
423
424 /* Ignore complete lowmem entries */
425 if (end <= max_low)
426 continue;
427
428 if (memblock_is_nomap(mem))
429 continue;
430
431 /* Truncate partial highmem entries */
432 if (start < max_low)
433 start = max_low;
434
435 /* Find and exclude any reserved regions */
436 for_each_memblock(reserved, res) {
437 unsigned long res_start, res_end;
438
439 res_start = memblock_region_reserved_base_pfn(res);
440 res_end = memblock_region_reserved_end_pfn(res);
441
442 if (res_end < start)
443 continue;
444 if (res_start < start)
445 res_start = start;
446 if (res_start > end)
447 res_start = end;
448 if (res_end > end)
449 res_end = end;
450 if (res_start != start)
451 free_area_high(start, res_start);
452 start = res_end;
453 if (start == end)
454 break;
455 }
456
457 /* And now free anything which remains */
458 if (start < end)
459 free_area_high(start, end);
460 }
461#endif
462}
463
464/*
465 * mem_init() marks the free areas in the mem_map and tells us how much
466 * memory is free. This is done after various parts of the system have
467 * claimed their memory after the kernel image.
468 */
469void __init mem_init(void)
470{
David Brazdil0f672f62019-12-10 10:32:29 +0000471#ifdef CONFIG_ARM_LPAE
472 swiotlb_init(1);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000473#endif
474
475 set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
476
477 /* this will put all unused low memory onto the freelists */
478 free_unused_memmap();
David Brazdil0f672f62019-12-10 10:32:29 +0000479 memblock_free_all();
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000480
481#ifdef CONFIG_SA1111
482 /* now that our DMA memory is actually so designated, we can free it */
483 free_reserved_area(__va(PHYS_OFFSET), swapper_pg_dir, -1, NULL);
484#endif
485
486 free_highpages();
487
488 mem_init_print_info(NULL);
489
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000490 /*
491 * Check boundaries twice: Some fundamental inconsistencies can
492 * be detected at build time already.
493 */
494#ifdef CONFIG_MMU
495 BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR);
496 BUG_ON(TASK_SIZE > MODULES_VADDR);
497#endif
498
499#ifdef CONFIG_HIGHMEM
500 BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
501 BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
502#endif
503}
504
505#ifdef CONFIG_STRICT_KERNEL_RWX
506struct section_perm {
507 const char *name;
508 unsigned long start;
509 unsigned long end;
510 pmdval_t mask;
511 pmdval_t prot;
512 pmdval_t clear;
513};
514
515/* First section-aligned location at or after __start_rodata. */
516extern char __start_rodata_section_aligned[];
517
518static struct section_perm nx_perms[] = {
519 /* Make pages tables, etc before _stext RW (set NX). */
520 {
521 .name = "pre-text NX",
522 .start = PAGE_OFFSET,
523 .end = (unsigned long)_stext,
524 .mask = ~PMD_SECT_XN,
525 .prot = PMD_SECT_XN,
526 },
527 /* Make init RW (set NX). */
528 {
529 .name = "init NX",
530 .start = (unsigned long)__init_begin,
531 .end = (unsigned long)_sdata,
532 .mask = ~PMD_SECT_XN,
533 .prot = PMD_SECT_XN,
534 },
535 /* Make rodata NX (set RO in ro_perms below). */
536 {
537 .name = "rodata NX",
538 .start = (unsigned long)__start_rodata_section_aligned,
539 .end = (unsigned long)__init_begin,
540 .mask = ~PMD_SECT_XN,
541 .prot = PMD_SECT_XN,
542 },
543};
544
545static struct section_perm ro_perms[] = {
546 /* Make kernel code and rodata RX (set RO). */
547 {
548 .name = "text/rodata RO",
549 .start = (unsigned long)_stext,
550 .end = (unsigned long)__init_begin,
551#ifdef CONFIG_ARM_LPAE
552 .mask = ~(L_PMD_SECT_RDONLY | PMD_SECT_AP2),
553 .prot = L_PMD_SECT_RDONLY | PMD_SECT_AP2,
554#else
555 .mask = ~(PMD_SECT_APX | PMD_SECT_AP_WRITE),
556 .prot = PMD_SECT_APX | PMD_SECT_AP_WRITE,
557 .clear = PMD_SECT_AP_WRITE,
558#endif
559 },
560};
561
562/*
563 * Updates section permissions only for the current mm (sections are
564 * copied into each mm). During startup, this is the init_mm. Is only
565 * safe to be called with preemption disabled, as under stop_machine().
566 */
567static inline void section_update(unsigned long addr, pmdval_t mask,
568 pmdval_t prot, struct mm_struct *mm)
569{
570 pmd_t *pmd;
571
572 pmd = pmd_offset(pud_offset(pgd_offset(mm, addr), addr), addr);
573
574#ifdef CONFIG_ARM_LPAE
575 pmd[0] = __pmd((pmd_val(pmd[0]) & mask) | prot);
576#else
577 if (addr & SECTION_SIZE)
578 pmd[1] = __pmd((pmd_val(pmd[1]) & mask) | prot);
579 else
580 pmd[0] = __pmd((pmd_val(pmd[0]) & mask) | prot);
581#endif
582 flush_pmd_entry(pmd);
583 local_flush_tlb_kernel_range(addr, addr + SECTION_SIZE);
584}
585
586/* Make sure extended page tables are in use. */
587static inline bool arch_has_strict_perms(void)
588{
589 if (cpu_architecture() < CPU_ARCH_ARMv6)
590 return false;
591
592 return !!(get_cr() & CR_XP);
593}
594
595void set_section_perms(struct section_perm *perms, int n, bool set,
596 struct mm_struct *mm)
597{
598 size_t i;
599 unsigned long addr;
600
601 if (!arch_has_strict_perms())
602 return;
603
604 for (i = 0; i < n; i++) {
605 if (!IS_ALIGNED(perms[i].start, SECTION_SIZE) ||
606 !IS_ALIGNED(perms[i].end, SECTION_SIZE)) {
607 pr_err("BUG: %s section %lx-%lx not aligned to %lx\n",
608 perms[i].name, perms[i].start, perms[i].end,
609 SECTION_SIZE);
610 continue;
611 }
612
613 for (addr = perms[i].start;
614 addr < perms[i].end;
615 addr += SECTION_SIZE)
616 section_update(addr, perms[i].mask,
617 set ? perms[i].prot : perms[i].clear, mm);
618 }
619
620}
621
622/**
623 * update_sections_early intended to be called only through stop_machine
624 * framework and executed by only one CPU while all other CPUs will spin and
625 * wait, so no locking is required in this function.
626 */
627static void update_sections_early(struct section_perm perms[], int n)
628{
629 struct task_struct *t, *s;
630
631 for_each_process(t) {
632 if (t->flags & PF_KTHREAD)
633 continue;
634 for_each_thread(t, s)
David Brazdil0f672f62019-12-10 10:32:29 +0000635 if (s->mm)
636 set_section_perms(perms, n, true, s->mm);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000637 }
638 set_section_perms(perms, n, true, current->active_mm);
639 set_section_perms(perms, n, true, &init_mm);
640}
641
642static int __fix_kernmem_perms(void *unused)
643{
644 update_sections_early(nx_perms, ARRAY_SIZE(nx_perms));
645 return 0;
646}
647
648static void fix_kernmem_perms(void)
649{
650 stop_machine(__fix_kernmem_perms, NULL, NULL);
651}
652
653static int __mark_rodata_ro(void *unused)
654{
655 update_sections_early(ro_perms, ARRAY_SIZE(ro_perms));
656 return 0;
657}
658
659static int kernel_set_to_readonly __read_mostly;
660
661void mark_rodata_ro(void)
662{
663 kernel_set_to_readonly = 1;
664 stop_machine(__mark_rodata_ro, NULL, NULL);
665 debug_checkwx();
666}
667
668void set_kernel_text_rw(void)
669{
670 if (!kernel_set_to_readonly)
671 return;
672
673 set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false,
674 current->active_mm);
675}
676
677void set_kernel_text_ro(void)
678{
679 if (!kernel_set_to_readonly)
680 return;
681
682 set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true,
683 current->active_mm);
684}
685
686#else
687static inline void fix_kernmem_perms(void) { }
688#endif /* CONFIG_STRICT_KERNEL_RWX */
689
690void free_initmem(void)
691{
692 fix_kernmem_perms();
693
694 poison_init_mem(__init_begin, __init_end - __init_begin);
695 if (!machine_is_integrator() && !machine_is_cintegrator())
696 free_initmem_default(-1);
697}
698
699#ifdef CONFIG_BLK_DEV_INITRD
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000700void free_initrd_mem(unsigned long start, unsigned long end)
701{
David Brazdil0f672f62019-12-10 10:32:29 +0000702 if (start == initrd_start)
703 start = round_down(start, PAGE_SIZE);
704 if (end == initrd_end)
705 end = round_up(end, PAGE_SIZE);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000706
David Brazdil0f672f62019-12-10 10:32:29 +0000707 poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
708 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000709}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000710#endif