blob: 32e4845af2b66fe1af4c1b43601b05b1fd1c51f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/init.c
3 *
Russell King90072052005-10-28 14:48:37 +01004 * Copyright (C) 1995-2005 Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
11#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/swap.h>
13#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/mman.h>
Ingo Molnar3f07c012017-02-08 18:51:30 +010015#include <linux/sched/signal.h>
Ingo Molnar29930022017-02-08 18:51:36 +010016#include <linux/sched/task.h>
Paul Gortmakerdc280942011-07-31 16:17:29 -040017#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/nodemask.h>
19#include <linux/initrd.h>
Grant Likely9eb8f672011-04-28 14:27:20 -060020#include <linux/of_fdt.h>
Nicolas Pitre3835f6c2008-09-17 15:21:55 -040021#include <linux/highmem.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
Russell King2778f622010-07-09 16:27:52 +010023#include <linux/memblock.h>
Marek Szyprowskic7909502011-12-29 13:09:51 +010024#include <linux/dma-contiguous.h>
Alessandro Rubini158e8bf2012-06-24 12:46:26 +010025#include <linux/sizes.h>
Laura Abbott08925c22015-11-30 19:36:28 +010026#include <linux/stop_machine.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Russell Kingb4b20ad82014-04-13 18:57:29 +010028#include <asm/cp15.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/mach-types.h>
Russell King716a3dc2012-01-13 15:00:51 +000030#include <asm/memblock.h>
Afzal Mohammedd2ca5f22017-01-29 17:31:32 +010031#include <asm/memory.h>
Grant Likely93c02ab2011-04-28 14:27:21 -060032#include <asm/prom.h>
Russell King37efe642008-12-01 11:53:07 +000033#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/setup.h>
Kees Cook1e6b4812014-04-03 17:28:11 -070035#include <asm/system_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/tlb.h>
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +010037#include <asm/fixmap.h>
Jinbum Parka8e53c12017-12-12 01:43:57 +010038#include <asm/ptdump.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/mach/arch.h>
41#include <asm/mach/map.h>
42
Russell King1b2e2b732006-08-21 17:06:38 +010043#include "mm.h"
44
Russell Kingb4b20ad82014-04-13 18:57:29 +010045#ifdef CONFIG_CPU_CP15_MMU
46unsigned long __init __clear_cr(unsigned long mask)
47{
Russell Kingb4b20ad82014-04-13 18:57:29 +010048 cr_alignment = cr_alignment & ~mask;
49 return cr_alignment;
50}
51#endif
52
Vitaly Andrianovde22cc6e2012-06-22 14:26:04 -040053static phys_addr_t phys_initrd_start __initdata = 0;
Russell King012d1f42008-09-06 10:57:03 +010054static unsigned long phys_initrd_size __initdata = 0;
55
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010056static int __init early_initrd(char *p)
Russell King012d1f42008-09-06 10:57:03 +010057{
Vitaly Andrianovde22cc6e2012-06-22 14:26:04 -040058 phys_addr_t start;
59 unsigned long size;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010060 char *endp;
Russell King012d1f42008-09-06 10:57:03 +010061
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010062 start = memparse(p, &endp);
63 if (*endp == ',') {
64 size = memparse(endp + 1, NULL);
Russell King012d1f42008-09-06 10:57:03 +010065
66 phys_initrd_start = start;
67 phys_initrd_size = size;
68 }
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010069 return 0;
Russell King012d1f42008-09-06 10:57:03 +010070}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +010071early_param("initrd", early_initrd);
Russell King012d1f42008-09-06 10:57:03 +010072
73static int __init parse_tag_initrd(const struct tag *tag)
74{
Russell King4ed89f22282014-10-28 11:26:42 +000075 pr_warn("ATAG_INITRD is deprecated; "
Russell King012d1f42008-09-06 10:57:03 +010076 "please update your bootloader.\n");
77 phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
78 phys_initrd_size = tag->u.initrd.size;
79 return 0;
80}
81
82__tagtable(ATAG_INITRD, parse_tag_initrd);
83
84static int __init parse_tag_initrd2(const struct tag *tag)
85{
86 phys_initrd_start = tag->u.initrd.start;
87 phys_initrd_size = tag->u.initrd.size;
88 return 0;
89}
90
91__tagtable(ATAG_INITRD2, parse_tag_initrd2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Russell Kingf25b4b42010-10-27 19:49:33 +010093static void __init find_limits(unsigned long *min, unsigned long *max_low,
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -040094 unsigned long *max_high)
Russell Kingdde58282009-08-15 12:36:00 +010095{
Laura Abbott1c2f87c2014-04-13 22:54:58 +010096 *max_low = PFN_DOWN(memblock_get_current_limit());
97 *min = PFN_UP(memblock_start_of_DRAM());
98 *max_high = PFN_DOWN(memblock_end_of_DRAM());
Russell Kingdde58282009-08-15 12:36:00 +010099}
100
Russell Kingbe209022011-05-11 15:39:00 +0100101#ifdef CONFIG_ZONE_DMA
Nicolas Pitre65032012011-07-18 15:05:10 -0400102
Rob Herring364230b2013-08-01 15:29:29 -0500103phys_addr_t arm_dma_zone_size __read_mostly;
Nicolas Pitre65032012011-07-18 15:05:10 -0400104EXPORT_SYMBOL(arm_dma_zone_size);
105
Russell King022ae532011-07-08 21:26:59 +0100106/*
107 * The DMA mask corresponding to the maximum bus address allocatable
108 * using GFP_DMA. The default here places no restriction on DMA
109 * allocations. This must be the smallest DMA mask in the system,
110 * so a successful GFP_DMA allocation will always satisfy this.
111 */
Marek Szyprowski4986e5c2012-06-06 12:05:01 +0200112phys_addr_t arm_dma_limit;
Russell King4dcfa602013-07-09 12:14:49 +0100113unsigned long arm_dma_pfn_limit;
Russell King022ae532011-07-08 21:26:59 +0100114
Russell Kingbe209022011-05-11 15:39:00 +0100115static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
116 unsigned long dma_size)
117{
118 if (size[0] <= dma_size)
119 return;
120
121 size[ZONE_NORMAL] = size[0] - dma_size;
122 size[ZONE_DMA] = dma_size;
123 hole[ZONE_NORMAL] = hole[0];
124 hole[ZONE_DMA] = 0;
125}
126#endif
127
Russell Kingff69a4c2013-07-26 14:55:59 +0100128void __init setup_dma_zone(const struct machine_desc *mdesc)
Marek Szyprowskic7909502011-12-29 13:09:51 +0100129{
130#ifdef CONFIG_ZONE_DMA
131 if (mdesc->dma_zone_size) {
132 arm_dma_zone_size = mdesc->dma_zone_size;
Russell King6bcac802014-01-07 17:53:54 +0000133 arm_dma_limit = PHYS_OFFSET + arm_dma_zone_size - 1;
Marek Szyprowskic7909502011-12-29 13:09:51 +0100134 } else
135 arm_dma_limit = 0xffffffff;
Russell King4dcfa602013-07-09 12:14:49 +0100136 arm_dma_pfn_limit = arm_dma_limit >> PAGE_SHIFT;
Marek Szyprowskic7909502011-12-29 13:09:51 +0100137#endif
138}
139
Santosh Shilimkar84f452b2013-06-30 00:28:46 -0400140static void __init zone_sizes_init(unsigned long min, unsigned long max_low,
Russell Kinga2c54d22010-10-27 19:17:31 +0100141 unsigned long max_high)
Russell Kingb7a69ac2008-10-01 16:58:32 +0100142{
143 unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
Russell Kinga2c54d22010-10-27 19:17:31 +0100144 struct memblock_region *reg;
Russell Kingb7a69ac2008-10-01 16:58:32 +0100145
Russell King90072052005-10-28 14:48:37 +0100146 /*
Russell Kingbe370302010-05-07 17:40:33 +0100147 * initialise the zones.
Russell King90072052005-10-28 14:48:37 +0100148 */
149 memset(zone_size, 0, sizeof(zone_size));
Russell King90072052005-10-28 14:48:37 +0100150
151 /*
Russell Kingbe370302010-05-07 17:40:33 +0100152 * The memory size has already been determined. If we need
153 * to do anything fancy with the allocation of this memory
154 * to the zones, now is the time to do it.
Russell King90072052005-10-28 14:48:37 +0100155 */
Russell Kingdde58282009-08-15 12:36:00 +0100156 zone_size[0] = max_low - min;
157#ifdef CONFIG_HIGHMEM
158 zone_size[ZONE_HIGHMEM] = max_high - max_low;
159#endif
Russell King90072052005-10-28 14:48:37 +0100160
161 /*
Russell Kingbe370302010-05-07 17:40:33 +0100162 * Calculate the size of the holes.
163 * holes = node_size - sum(bank_sizes)
Russell King90072052005-10-28 14:48:37 +0100164 */
Russell Kingdde58282009-08-15 12:36:00 +0100165 memcpy(zhole_size, zone_size, sizeof(zhole_size));
Russell Kinga2c54d22010-10-27 19:17:31 +0100166 for_each_memblock(memory, reg) {
167 unsigned long start = memblock_region_memory_base_pfn(reg);
168 unsigned long end = memblock_region_memory_end_pfn(reg);
169
170 if (start < max_low) {
171 unsigned long low_end = min(end, max_low);
172 zhole_size[0] -= low_end - start;
173 }
Russell Kingdde58282009-08-15 12:36:00 +0100174#ifdef CONFIG_HIGHMEM
Russell Kinga2c54d22010-10-27 19:17:31 +0100175 if (end > max_low) {
176 unsigned long high_start = max(start, max_low);
177 zhole_size[ZONE_HIGHMEM] -= end - high_start;
178 }
Russell Kingdde58282009-08-15 12:36:00 +0100179#endif
Russell Kingdde58282009-08-15 12:36:00 +0100180 }
Russell King90072052005-10-28 14:48:37 +0100181
Nicolas Pitre65032012011-07-18 15:05:10 -0400182#ifdef CONFIG_ZONE_DMA
Russell King90072052005-10-28 14:48:37 +0100183 /*
184 * Adjust the sizes according to any special requirements for
185 * this machine type.
186 */
Marek Szyprowskic7909502011-12-29 13:09:51 +0100187 if (arm_dma_zone_size)
Nicolas Pitre65032012011-07-18 15:05:10 -0400188 arm_adjust_dma_zone(zone_size, zhole_size,
189 arm_dma_zone_size >> PAGE_SHIFT);
Russell Kingbe209022011-05-11 15:39:00 +0100190#endif
Russell King90072052005-10-28 14:48:37 +0100191
Russell Kingbe370302010-05-07 17:40:33 +0100192 free_area_init_node(0, zone_size, min, zhole_size);
Russell King90072052005-10-28 14:48:37 +0100193}
194
Will Deacon7b7bf492011-05-19 13:21:14 +0100195#ifdef CONFIG_HAVE_ARCH_PFN_VALID
Russell Kingb7cfda92009-09-07 15:06:42 +0100196int pfn_valid(unsigned long pfn)
197{
Ard Biesheuvel09414d02015-10-01 17:58:11 +0200198 return memblock_is_map_memory(__pfn_to_phys(pfn));
Russell Kingb7cfda92009-09-07 15:06:42 +0100199}
200EXPORT_SYMBOL(pfn_valid);
Will Deacon7b7bf492011-05-19 13:21:14 +0100201#endif
Russell King657e12f2009-10-29 17:06:17 +0000202
Will Deacon7b7bf492011-05-19 13:21:14 +0100203#ifndef CONFIG_SPARSEMEM
Stephen Boyd14904922012-04-27 01:40:10 +0100204static void __init arm_memory_present(void)
Russell King657e12f2009-10-29 17:06:17 +0000205{
206}
207#else
Stephen Boyd14904922012-04-27 01:40:10 +0100208static void __init arm_memory_present(void)
Russell King657e12f2009-10-29 17:06:17 +0000209{
Benjamin Herrenschmidt719c15142010-08-05 12:55:55 +1000210 struct memblock_region *reg;
Benjamin Herrenschmidt719c15142010-08-05 12:55:55 +1000211
Yinghai Lu7c996362010-09-16 00:20:36 -0700212 for_each_memblock(memory, reg)
Yinghai Luc7fc2de2010-10-12 14:07:09 -0700213 memory_present(0, memblock_region_memory_base_pfn(reg),
214 memblock_region_memory_end_pfn(reg));
Russell King657e12f2009-10-29 17:06:17 +0000215}
Russell Kingb7cfda92009-09-07 15:06:42 +0100216#endif
217
Russell King716a3dc2012-01-13 15:00:51 +0000218static bool arm_memblock_steal_permitted = true;
219
Russell Kingbc2827d2012-01-19 14:35:19 +0000220phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
Russell King716a3dc2012-01-13 15:00:51 +0000221{
222 phys_addr_t phys;
223
224 BUG_ON(!arm_memblock_steal_permitted);
225
Russell King7ac68a42012-08-13 00:22:28 +0100226 phys = memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ANYWHERE);
Russell King716a3dc2012-01-13 15:00:51 +0000227 memblock_free(phys, size);
228 memblock_remove(phys, size);
229
230 return phys;
231}
232
Russell King39286242017-01-16 15:11:10 +0000233static void __init arm_initrd_init(void)
Russell King2778f622010-07-09 16:27:52 +0100234{
Russell King2778f622010-07-09 16:27:52 +0100235#ifdef CONFIG_BLK_DEV_INITRD
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000236 phys_addr_t start;
237 unsigned long size;
238
Rob Herring65939302013-08-30 10:54:26 -0500239 /* FDT scan will populate initrd_start */
Ben Peddell4c235cb2014-01-13 23:25:18 +0100240 if (initrd_start && !phys_initrd_size) {
Rob Herring65939302013-08-30 10:54:26 -0500241 phys_initrd_start = __virt_to_phys(initrd_start);
242 phys_initrd_size = initrd_end - initrd_start;
243 }
Russell King2778f622010-07-09 16:27:52 +0100244
Russell King2778f622010-07-09 16:27:52 +0100245 initrd_start = initrd_end = 0;
Russell King68b32f32017-01-16 15:13:25 +0000246
247 if (!phys_initrd_size)
248 return;
249
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000250 /*
251 * Round the memory region to page boundaries as per free_initrd_mem()
252 * This allows us to detect whether the pages overlapping the initrd
253 * are in use, but more importantly, reserves the entire set of pages
254 * as we don't want these pages allocated for other purposes.
255 */
256 start = round_down(phys_initrd_start, PAGE_SIZE);
257 size = phys_initrd_size + (phys_initrd_start - start);
258 size = round_up(size, PAGE_SIZE);
259
260 if (!memblock_is_region_memory(start, size)) {
Russell King2778f622010-07-09 16:27:52 +0100261 pr_err("INITRD: 0x%08llx+0x%08lx is not a memory region - disabling initrd\n",
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000262 (u64)start, size);
Russell King68b32f32017-01-16 15:13:25 +0000263 return;
Russell King2778f622010-07-09 16:27:52 +0100264 }
Russell King68b32f32017-01-16 15:13:25 +0000265
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000266 if (memblock_is_region_reserved(start, size)) {
Russell King2778f622010-07-09 16:27:52 +0100267 pr_err("INITRD: 0x%08llx+0x%08lx overlaps in-use memory region - disabling initrd\n",
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000268 (u64)start, size);
Russell King68b32f32017-01-16 15:13:25 +0000269 return;
Russell King2778f622010-07-09 16:27:52 +0100270 }
Russell King2778f622010-07-09 16:27:52 +0100271
Russell Kingcdcc5fa2017-01-16 15:21:05 +0000272 memblock_reserve(start, size);
Russell King68b32f32017-01-16 15:13:25 +0000273
274 /* Now convert initrd to virtual addresses */
275 initrd_start = __phys_to_virt(phys_initrd_start);
276 initrd_end = initrd_start + phys_initrd_size;
Russell King2778f622010-07-09 16:27:52 +0100277#endif
Russell King39286242017-01-16 15:11:10 +0000278}
279
280void __init arm_memblock_init(const struct machine_desc *mdesc)
281{
282 /* Register the kernel text, kernel data and initrd with memblock. */
283 memblock_reserve(__pa(KERNEL_START), KERNEL_END - KERNEL_START);
284
285 arm_initrd_init();
Russell King2778f622010-07-09 16:27:52 +0100286
287 arm_mm_memblock_reserve();
288
Russell King8d717a52010-05-22 19:47:18 +0100289 /* reserve any platform specific memblock areas */
290 if (mdesc->reserve)
291 mdesc->reserve();
292
Ard Biesheuvel24bbd922015-06-01 13:40:31 +0200293 early_init_fdt_reserve_self();
Marek Szyprowskibcedb5f2014-02-28 14:42:54 +0100294 early_init_fdt_scan_reserved_mem();
295
George G. Davis99a468d2015-01-16 11:21:05 +0100296 /* reserve memory for DMA contiguous allocations */
Marek Szyprowski95b0e652014-10-09 15:26:49 -0700297 dma_contiguous_reserve(arm_dma_limit);
Marek Szyprowskic7909502011-12-29 13:09:51 +0100298
Russell King716a3dc2012-01-13 15:00:51 +0000299 arm_memblock_steal_permitted = false;
Russell King2778f622010-07-09 16:27:52 +0100300 memblock_dump_all();
301}
302
Russell King8d717a52010-05-22 19:47:18 +0100303void __init bootmem_init(void)
Russell King90072052005-10-28 14:48:37 +0100304{
Russell Kingdde58282009-08-15 12:36:00 +0100305 unsigned long min, max_low, max_high;
Russell King90072052005-10-28 14:48:37 +0100306
Grygorii Strashko8e58cae2013-11-23 14:42:18 -0500307 memblock_allow_resize();
Russell Kingdde58282009-08-15 12:36:00 +0100308 max_low = max_high = 0;
309
Russell Kingf25b4b42010-10-27 19:49:33 +0100310 find_limits(&min, &max_low, &max_high);
Russell Kingbe370302010-05-07 17:40:33 +0100311
Vladimir Murzind30eae42015-04-14 15:48:37 -0700312 early_memtest((phys_addr_t)min << PAGE_SHIFT,
313 (phys_addr_t)max_low << PAGE_SHIFT);
314
Russell Kingbe370302010-05-07 17:40:33 +0100315 /*
Russell Kingbe370302010-05-07 17:40:33 +0100316 * Sparsemem tries to allocate bootmem in memory_present(),
317 * so must be done after the fixed reservations
318 */
Russell Kingeda2e5dc2010-07-01 12:00:57 +0100319 arm_memory_present();
Russell King90072052005-10-28 14:48:37 +0100320
Russell Kingb7a69ac2008-10-01 16:58:32 +0100321 /*
322 * sparse_init() needs the bootmem allocator up and running.
323 */
324 sparse_init();
325
326 /*
Russell Kingbe370302010-05-07 17:40:33 +0100327 * Now free the memory - free_area_init_node needs
Russell Kingb7a69ac2008-10-01 16:58:32 +0100328 * the sparse mem_map arrays initialized by sparse_init()
329 * for memmap_init_zone(), otherwise all PFNs are invalid.
330 */
Santosh Shilimkar84f452b2013-06-30 00:28:46 -0400331 zone_sizes_init(min, max_low, max_high);
Russell Kingb7a69ac2008-10-01 16:58:32 +0100332
Russell King90072052005-10-28 14:48:37 +0100333 /*
334 * This doesn't seem to be used by the Linux memory manager any
335 * more, but is used by ll_rw_block. If we can get rid of it, we
336 * also get rid of some of the stuff above as well.
Russell King90072052005-10-28 14:48:37 +0100337 */
Santosh Shilimkar26ba47b2013-08-01 03:12:01 +0100338 min_low_pfn = min;
339 max_low_pfn = max_low;
340 max_pfn = max_high;
Russell King90072052005-10-28 14:48:37 +0100341}
342
Stephen Boyd54d52572011-07-07 18:43:36 +0100343/*
344 * Poison init memory with an undefined instruction (ARM) or a branch to an
345 * undefined instruction (Thumb).
346 */
347static inline void poison_init_mem(void *s, size_t count)
348{
349 u32 *p = (u32 *)s;
Jamie Ilesbf912d92011-08-04 09:39:31 +0100350 for (; count != 0; count -= 4)
Stephen Boyd54d52572011-07-07 18:43:36 +0100351 *p++ = 0xe7fddef0;
352}
353
Russell Kinga0130532005-06-27 14:16:47 +0100354static inline void
Russell Kingbe370302010-05-07 17:40:33 +0100355free_memmap(unsigned long start_pfn, unsigned long end_pfn)
Russell Kinga0130532005-06-27 14:16:47 +0100356{
357 struct page *start_pg, *end_pg;
Vitaly Andrianov56bc6282012-06-21 08:09:05 -0400358 phys_addr_t pg, pgend;
Russell Kinga0130532005-06-27 14:16:47 +0100359
360 /*
361 * Convert start_pfn/end_pfn to a struct page pointer.
362 */
Catalin Marinas3257f432009-10-06 17:57:22 +0100363 start_pg = pfn_to_page(start_pfn - 1) + 1;
Will Deacon9af386c2011-04-28 18:44:31 +0100364 end_pg = pfn_to_page(end_pfn - 1) + 1;
Russell Kinga0130532005-06-27 14:16:47 +0100365
366 /*
367 * Convert to physical addresses, and
368 * round start upwards and end downwards.
369 */
Vitaly Andrianov56bc6282012-06-21 08:09:05 -0400370 pg = PAGE_ALIGN(__pa(start_pg));
371 pgend = __pa(end_pg) & PAGE_MASK;
Russell Kinga0130532005-06-27 14:16:47 +0100372
373 /*
374 * If there are free pages between these,
375 * free the section of the memmap array.
376 */
377 if (pg < pgend)
Santosh Shilimkarcfb665862014-01-21 15:50:49 -0800378 memblock_free_early(pg, pgend - pg);
Russell Kinga0130532005-06-27 14:16:47 +0100379}
380
381/*
382 * The mem_map array can get very big. Free the unused area of the memory map.
383 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100384static void __init free_unused_memmap(void)
Russell Kinga0130532005-06-27 14:16:47 +0100385{
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100386 unsigned long start, prev_end = 0;
387 struct memblock_region *reg;
Russell Kinga0130532005-06-27 14:16:47 +0100388
389 /*
Michael Bohan3260e522010-06-14 13:06:56 -0700390 * This relies on each bank being in address order.
391 * The banks are sorted previously in bootmem_init().
Russell Kinga0130532005-06-27 14:16:47 +0100392 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100393 for_each_memblock(memory, reg) {
394 start = memblock_region_memory_base_pfn(reg);
Russell Kinga0130532005-06-27 14:16:47 +0100395
Will Deacon9af386c2011-04-28 18:44:31 +0100396#ifdef CONFIG_SPARSEMEM
397 /*
398 * Take care not to free memmap entries that don't exist
399 * due to SPARSEMEM sections which aren't present.
400 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100401 start = min(start,
402 ALIGN(prev_end, PAGES_PER_SECTION));
Linus Walleij002ea9eef2011-09-29 09:37:23 +0100403#else
404 /*
405 * Align down here since the VM subsystem insists that the
406 * memmap entries are valid from the bank start aligned to
407 * MAX_ORDER_NR_PAGES.
408 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100409 start = round_down(start, MAX_ORDER_NR_PAGES);
Will Deacon9af386c2011-04-28 18:44:31 +0100410#endif
Russell Kinga0130532005-06-27 14:16:47 +0100411 /*
412 * If we had a previous bank, and there is a space
413 * between the current bank and the previous, free it.
414 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100415 if (prev_end && prev_end < start)
416 free_memmap(prev_end, start);
Russell Kinga0130532005-06-27 14:16:47 +0100417
Michael Bohan3260e522010-06-14 13:06:56 -0700418 /*
419 * Align up here since the VM subsystem insists that the
420 * memmap entries are valid from the bank end aligned to
421 * MAX_ORDER_NR_PAGES.
422 */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100423 prev_end = ALIGN(memblock_region_memory_end_pfn(reg),
424 MAX_ORDER_NR_PAGES);
Russell Kinga0130532005-06-27 14:16:47 +0100425 }
Will Deacon9af386c2011-04-28 18:44:31 +0100426
427#ifdef CONFIG_SPARSEMEM
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100428 if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
429 free_memmap(prev_end,
430 ALIGN(prev_end, PAGES_PER_SECTION));
Will Deacon9af386c2011-04-28 18:44:31 +0100431#endif
Russell Kinga0130532005-06-27 14:16:47 +0100432}
433
Jiang Liu83db0382013-04-29 15:06:26 -0700434#ifdef CONFIG_HIGHMEM
435static inline void free_area_high(unsigned long pfn, unsigned long end)
436{
Jiang Liudd6911e2013-04-29 15:07:03 -0700437 for (; pfn < end; pfn++)
438 free_highmem_page(pfn_to_page(pfn));
Jiang Liu83db0382013-04-29 15:06:26 -0700439}
440#endif
441
Russell Kingd0e775a2010-10-27 19:37:06 +0100442static void __init free_highpages(void)
443{
444#ifdef CONFIG_HIGHMEM
Santosh Shilimkar26ba47b2013-08-01 03:12:01 +0100445 unsigned long max_low = max_low_pfn;
Russell Kingdf4f14c2010-10-27 19:45:49 +0100446 struct memblock_region *mem, *res;
Russell Kingd0e775a2010-10-27 19:37:06 +0100447
448 /* set highmem page free */
Russell Kingdf4f14c2010-10-27 19:45:49 +0100449 for_each_memblock(memory, mem) {
450 unsigned long start = memblock_region_memory_base_pfn(mem);
451 unsigned long end = memblock_region_memory_end_pfn(mem);
452
453 /* Ignore complete lowmem entries */
454 if (end <= max_low)
455 continue;
456
Ard Biesheuvel09414d02015-10-01 17:58:11 +0200457 if (memblock_is_nomap(mem))
458 continue;
459
Russell Kingdf4f14c2010-10-27 19:45:49 +0100460 /* Truncate partial highmem entries */
461 if (start < max_low)
462 start = max_low;
463
464 /* Find and exclude any reserved regions */
465 for_each_memblock(reserved, res) {
466 unsigned long res_start, res_end;
467
468 res_start = memblock_region_reserved_base_pfn(res);
469 res_end = memblock_region_reserved_end_pfn(res);
470
471 if (res_end < start)
472 continue;
473 if (res_start < start)
474 res_start = start;
475 if (res_start > end)
476 res_start = end;
477 if (res_end > end)
478 res_end = end;
479 if (res_start != start)
Jiang Liu83db0382013-04-29 15:06:26 -0700480 free_area_high(start, res_start);
Russell Kingdf4f14c2010-10-27 19:45:49 +0100481 start = res_end;
482 if (start == end)
483 break;
484 }
485
486 /* And now free anything which remains */
487 if (start < end)
Jiang Liu83db0382013-04-29 15:06:26 -0700488 free_area_high(start, end);
Russell Kingd0e775a2010-10-27 19:37:06 +0100489 }
Russell Kingd0e775a2010-10-27 19:37:06 +0100490#endif
491}
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493/*
494 * mem_init() marks the free areas in the mem_map and tells us how much
495 * memory is free. This is done after various parts of the system have
496 * claimed their memory after the kernel image.
497 */
498void __init mem_init(void)
499{
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100500#ifdef CONFIG_HAVE_TCM
501 /* These pointers are filled in on TCM detection */
502 extern u32 dtcm_end;
503 extern u32 itcm_end;
504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Santosh Shilimkarb3ba41f2013-11-23 14:36:42 -0500506 set_max_mapnr(pfn_to_page(max_pfn) - mem_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /* this will put all unused low memory onto the freelists */
Laura Abbott1c2f87c2014-04-13 22:54:58 +0100509 free_unused_memmap();
Mike Rapoportc6ffc5c2018-10-30 15:09:30 -0700510 memblock_free_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512#ifdef CONFIG_SA1111
513 /* now that our DMA memory is actually so designated, we can free it */
Linus Torvaldsbfd65dd2013-07-13 14:58:36 -0700514 free_reserved_area(__va(PHYS_OFFSET), swapper_pg_dir, -1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#endif
516
Russell Kingd0e775a2010-10-27 19:37:06 +0100517 free_highpages();
Nicolas Pitre3835f6c2008-09-17 15:21:55 -0400518
Jiang Liu2450c972013-07-03 15:03:48 -0700519 mem_init_print_info(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100521#define MLK(b, t) b, t, ((t) - (b)) >> 10
522#define MLM(b, t) b, t, ((t) - (b)) >> 20
523#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)
524
Russell King4ed89f22282014-10-28 11:26:42 +0000525 pr_notice("Virtual kernel memory layout:\n"
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100526 " vector : 0x%08lx - 0x%08lx (%4ld kB)\n"
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100527#ifdef CONFIG_HAVE_TCM
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100528 " DTCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100529 " ITCM : 0x%08lx - 0x%08lx (%4ld kB)\n"
530#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100531 " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
532 " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
533 " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
534#ifdef CONFIG_HIGHMEM
535 " pkmap : 0x%08lx - 0x%08lx (%4ld MB)\n"
536#endif
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100537#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100538 " modules : 0x%08lx - 0x%08lx (%4ld MB)\n"
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100539#endif
Russell King178c3df2014-10-19 22:42:42 +0100540 " .text : 0x%p" " - 0x%p" " (%4td kB)\n"
541 " .init : 0x%p" " - 0x%p" " (%4td kB)\n"
542 " .data : 0x%p" " - 0x%p" " (%4td kB)\n"
543 " .bss : 0x%p" " - 0x%p" " (%4td kB)\n",
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100544
Afzal Mohammedd2ca5f22017-01-29 17:31:32 +0100545 MLK(VECTORS_BASE, VECTORS_BASE + PAGE_SIZE),
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100546#ifdef CONFIG_HAVE_TCM
Linus Walleij1dbd30e2010-07-12 21:53:28 +0100547 MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
548 MLK(ITCM_OFFSET, (unsigned long) itcm_end),
Linus Walleij07d2a5c2010-07-12 21:52:34 +0100549#endif
Mark Salterb615bbb2014-08-13 09:04:49 -0700550 MLK(FIXADDR_START, FIXADDR_END),
Fenkart/Bostandzhyanc931b4f2010-02-07 21:47:17 +0100551 MLM(VMALLOC_START, VMALLOC_END),
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100552 MLM(PAGE_OFFSET, (unsigned long)high_memory),
553#ifdef CONFIG_HIGHMEM
554 MLM(PKMAP_BASE, (PKMAP_BASE) + (LAST_PKMAP) *
555 (PAGE_SIZE)),
556#endif
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100557#ifdef CONFIG_MODULES
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100558 MLM(MODULES_VADDR, MODULES_END),
Uwe Kleine-Königd9277d52012-02-01 11:16:51 +0100559#endif
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100560
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100561 MLK_ROUNDUP(_text, _etext),
Russell King3835d692011-07-06 10:39:34 +0100562 MLK_ROUNDUP(__init_begin, __init_end),
Rabin Vincent45f6d7e2011-06-02 15:01:36 +0100563 MLK_ROUNDUP(_sdata, _edata),
564 MLK_ROUNDUP(__bss_start, __bss_stop));
Fenkart/Bostandzhyandb9ef1a2010-02-07 21:45:47 +0100565
566#undef MLK
567#undef MLM
568#undef MLK_ROUNDUP
569
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100570 /*
571 * Check boundaries twice: Some fundamental inconsistencies can
572 * be detected at build time already.
573 */
574#ifdef CONFIG_MMU
Fenkart/Bostandzhyana1839272010-02-07 21:47:58 +0100575 BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR);
576 BUG_ON(TASK_SIZE > MODULES_VADDR);
577#endif
578
579#ifdef CONFIG_HIGHMEM
580 BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
581 BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > PAGE_OFFSET);
582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
Laura Abbott0f5bf6d2017-02-06 16:31:58 -0800585#ifdef CONFIG_STRICT_KERNEL_RWX
Kees Cook1e6b4812014-04-03 17:28:11 -0700586struct section_perm {
Kees Cook25362dc2016-01-26 01:19:36 +0100587 const char *name;
Kees Cook1e6b4812014-04-03 17:28:11 -0700588 unsigned long start;
589 unsigned long end;
590 pmdval_t mask;
591 pmdval_t prot;
Kees Cook80d6b0c2014-04-03 13:29:50 -0700592 pmdval_t clear;
Kees Cook1e6b4812014-04-03 17:28:11 -0700593};
594
Kees Cook64ac2e72016-01-26 01:20:21 +0100595/* First section-aligned location at or after __start_rodata. */
596extern char __start_rodata_section_aligned[];
597
Kees Cook80d6b0c2014-04-03 13:29:50 -0700598static struct section_perm nx_perms[] = {
Kees Cook1e6b4812014-04-03 17:28:11 -0700599 /* Make pages tables, etc before _stext RW (set NX). */
600 {
Kees Cook25362dc2016-01-26 01:19:36 +0100601 .name = "pre-text NX",
Kees Cook1e6b4812014-04-03 17:28:11 -0700602 .start = PAGE_OFFSET,
603 .end = (unsigned long)_stext,
604 .mask = ~PMD_SECT_XN,
605 .prot = PMD_SECT_XN,
606 },
607 /* Make init RW (set NX). */
608 {
Kees Cook25362dc2016-01-26 01:19:36 +0100609 .name = "init NX",
Kees Cook1e6b4812014-04-03 17:28:11 -0700610 .start = (unsigned long)__init_begin,
611 .end = (unsigned long)_sdata,
612 .mask = ~PMD_SECT_XN,
613 .prot = PMD_SECT_XN,
614 },
Kees Cook80d6b0c2014-04-03 13:29:50 -0700615 /* Make rodata NX (set RO in ro_perms below). */
616 {
Kees Cook25362dc2016-01-26 01:19:36 +0100617 .name = "rodata NX",
Kees Cook64ac2e72016-01-26 01:20:21 +0100618 .start = (unsigned long)__start_rodata_section_aligned,
Kees Cook80d6b0c2014-04-03 13:29:50 -0700619 .end = (unsigned long)__init_begin,
620 .mask = ~PMD_SECT_XN,
621 .prot = PMD_SECT_XN,
622 },
Kees Cook1e6b4812014-04-03 17:28:11 -0700623};
624
Kees Cook80d6b0c2014-04-03 13:29:50 -0700625static struct section_perm ro_perms[] = {
626 /* Make kernel code and rodata RX (set RO). */
627 {
Kees Cook25362dc2016-01-26 01:19:36 +0100628 .name = "text/rodata RO",
Kees Cook80d6b0c2014-04-03 13:29:50 -0700629 .start = (unsigned long)_stext,
630 .end = (unsigned long)__init_begin,
631#ifdef CONFIG_ARM_LPAE
Philip Derrin400eeff2017-11-14 00:55:25 +0100632 .mask = ~(L_PMD_SECT_RDONLY | PMD_SECT_AP2),
633 .prot = L_PMD_SECT_RDONLY | PMD_SECT_AP2,
Kees Cook80d6b0c2014-04-03 13:29:50 -0700634#else
635 .mask = ~(PMD_SECT_APX | PMD_SECT_AP_WRITE),
636 .prot = PMD_SECT_APX | PMD_SECT_AP_WRITE,
637 .clear = PMD_SECT_AP_WRITE,
638#endif
639 },
640};
Kees Cook80d6b0c2014-04-03 13:29:50 -0700641
Kees Cook1e6b4812014-04-03 17:28:11 -0700642/*
643 * Updates section permissions only for the current mm (sections are
644 * copied into each mm). During startup, this is the init_mm. Is only
645 * safe to be called with preemption disabled, as under stop_machine().
646 */
647static inline void section_update(unsigned long addr, pmdval_t mask,
Laura Abbott08925c22015-11-30 19:36:28 +0100648 pmdval_t prot, struct mm_struct *mm)
Kees Cook1e6b4812014-04-03 17:28:11 -0700649{
Kees Cook1e6b4812014-04-03 17:28:11 -0700650 pmd_t *pmd;
651
Kees Cook1e6b4812014-04-03 17:28:11 -0700652 pmd = pmd_offset(pud_offset(pgd_offset(mm, addr), addr), addr);
653
654#ifdef CONFIG_ARM_LPAE
655 pmd[0] = __pmd((pmd_val(pmd[0]) & mask) | prot);
656#else
657 if (addr & SECTION_SIZE)
658 pmd[1] = __pmd((pmd_val(pmd[1]) & mask) | prot);
659 else
660 pmd[0] = __pmd((pmd_val(pmd[0]) & mask) | prot);
661#endif
662 flush_pmd_entry(pmd);
663 local_flush_tlb_kernel_range(addr, addr + SECTION_SIZE);
664}
665
666/* Make sure extended page tables are in use. */
667static inline bool arch_has_strict_perms(void)
668{
669 if (cpu_architecture() < CPU_ARCH_ARMv6)
670 return false;
671
672 return !!(get_cr() & CR_XP);
673}
674
Laura Abbott08925c22015-11-30 19:36:28 +0100675void set_section_perms(struct section_perm *perms, int n, bool set,
676 struct mm_struct *mm)
677{
678 size_t i;
679 unsigned long addr;
680
681 if (!arch_has_strict_perms())
682 return;
683
684 for (i = 0; i < n; i++) {
685 if (!IS_ALIGNED(perms[i].start, SECTION_SIZE) ||
686 !IS_ALIGNED(perms[i].end, SECTION_SIZE)) {
Kees Cook25362dc2016-01-26 01:19:36 +0100687 pr_err("BUG: %s section %lx-%lx not aligned to %lx\n",
688 perms[i].name, perms[i].start, perms[i].end,
Laura Abbott08925c22015-11-30 19:36:28 +0100689 SECTION_SIZE);
690 continue;
691 }
692
693 for (addr = perms[i].start;
694 addr < perms[i].end;
695 addr += SECTION_SIZE)
696 section_update(addr, perms[i].mask,
697 set ? perms[i].prot : perms[i].clear, mm);
698 }
699
Kees Cook1e6b4812014-04-03 17:28:11 -0700700}
701
Grygorii Strashko11ce4b32017-04-25 21:20:52 +0100702/**
703 * update_sections_early intended to be called only through stop_machine
704 * framework and executed by only one CPU while all other CPUs will spin and
705 * wait, so no locking is required in this function.
706 */
Laura Abbott08925c22015-11-30 19:36:28 +0100707static void update_sections_early(struct section_perm perms[], int n)
Kees Cook1e6b4812014-04-03 17:28:11 -0700708{
Laura Abbott08925c22015-11-30 19:36:28 +0100709 struct task_struct *t, *s;
710
Laura Abbott08925c22015-11-30 19:36:28 +0100711 for_each_process(t) {
712 if (t->flags & PF_KTHREAD)
713 continue;
714 for_each_thread(t, s)
715 set_section_perms(perms, n, true, s->mm);
716 }
Laura Abbott08925c22015-11-30 19:36:28 +0100717 set_section_perms(perms, n, true, current->active_mm);
718 set_section_perms(perms, n, true, &init_mm);
719}
720
Grygorii Strashko11ce4b32017-04-25 21:20:52 +0100721static int __fix_kernmem_perms(void *unused)
Laura Abbott08925c22015-11-30 19:36:28 +0100722{
723 update_sections_early(nx_perms, ARRAY_SIZE(nx_perms));
724 return 0;
725}
726
Grygorii Strashko11ce4b32017-04-25 21:20:52 +0100727static void fix_kernmem_perms(void)
Laura Abbott08925c22015-11-30 19:36:28 +0100728{
729 stop_machine(__fix_kernmem_perms, NULL, NULL);
Kees Cook1e6b4812014-04-03 17:28:11 -0700730}
Kees Cook80d6b0c2014-04-03 13:29:50 -0700731
Grygorii Strashko11ce4b32017-04-25 21:20:52 +0100732static int __mark_rodata_ro(void *unused)
Laura Abbott08925c22015-11-30 19:36:28 +0100733{
734 update_sections_early(ro_perms, ARRAY_SIZE(ro_perms));
735 return 0;
736}
737
Steven Rostedt (VMware)b4c7e2b2018-07-10 08:22:40 +0100738static int kernel_set_to_readonly __read_mostly;
739
Kees Cook80d6b0c2014-04-03 13:29:50 -0700740void mark_rodata_ro(void)
741{
Steven Rostedt (VMware)b4c7e2b2018-07-10 08:22:40 +0100742 kernel_set_to_readonly = 1;
Laura Abbott08925c22015-11-30 19:36:28 +0100743 stop_machine(__mark_rodata_ro, NULL, NULL);
Jinbum Parka8e53c12017-12-12 01:43:57 +0100744 debug_checkwx();
Kees Cook80d6b0c2014-04-03 13:29:50 -0700745}
746
747void set_kernel_text_rw(void)
748{
Steven Rostedt (VMware)b4c7e2b2018-07-10 08:22:40 +0100749 if (!kernel_set_to_readonly)
750 return;
751
Laura Abbott08925c22015-11-30 19:36:28 +0100752 set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false,
753 current->active_mm);
Kees Cook80d6b0c2014-04-03 13:29:50 -0700754}
755
756void set_kernel_text_ro(void)
757{
Steven Rostedt (VMware)b4c7e2b2018-07-10 08:22:40 +0100758 if (!kernel_set_to_readonly)
759 return;
760
Laura Abbott08925c22015-11-30 19:36:28 +0100761 set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true,
762 current->active_mm);
Kees Cook80d6b0c2014-04-03 13:29:50 -0700763}
Kees Cook80d6b0c2014-04-03 13:29:50 -0700764
Kees Cook1e6b4812014-04-03 17:28:11 -0700765#else
766static inline void fix_kernmem_perms(void) { }
Laura Abbott0f5bf6d2017-02-06 16:31:58 -0800767#endif /* CONFIG_STRICT_KERNEL_RWX */
Kees Cook1e6b4812014-04-03 17:28:11 -0700768
Kees Cook1e6b4812014-04-03 17:28:11 -0700769void free_initmem(void)
770{
771 fix_kernmem_perms();
Linus Walleijbc581772009-09-15 17:30:37 +0100772
Stephen Boyd54d52572011-07-07 18:43:36 +0100773 poison_init_mem(__init_begin, __init_end - __init_begin);
Nicolas Pitre6db015e2008-09-17 14:50:42 -0400774 if (!machine_is_integrator() && !machine_is_cintegrator())
Jiang Liudbe67df2013-07-03 15:02:51 -0700775 free_initmem_default(-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
778#ifdef CONFIG_BLK_DEV_INITRD
779
780static int keep_initrd;
781
782void free_initrd_mem(unsigned long start, unsigned long end)
783{
Stephen Boyd54d52572011-07-07 18:43:36 +0100784 if (!keep_initrd) {
Yalin Wang421520b2014-09-26 03:07:09 +0100785 if (start == initrd_start)
786 start = round_down(start, PAGE_SIZE);
787 if (end == initrd_end)
788 end = round_up(end, PAGE_SIZE);
789
Stephen Boyd54d52572011-07-07 18:43:36 +0100790 poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
Jiang Liudbe67df2013-07-03 15:02:51 -0700791 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Stephen Boyd54d52572011-07-07 18:43:36 +0100792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}
794
795static int __init keepinitrd_setup(char *__unused)
796{
797 keep_initrd = 1;
798 return 1;
799}
800
801__setup("keepinitrd", keepinitrd_setup);
802#endif