init_32.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*
  2. *
  3. * Copyright (C) 1995 Linus Torvalds
  4. *
  5. * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  6. */
  7. #include <linux/module.h>
  8. #include <linux/signal.h>
  9. #include <linux/sched.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/string.h>
  13. #include <linux/types.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/mman.h>
  16. #include <linux/mm.h>
  17. #include <linux/hugetlb.h>
  18. #include <linux/swap.h>
  19. #include <linux/smp.h>
  20. #include <linux/init.h>
  21. #include <linux/highmem.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/pci.h>
  24. #include <linux/pfn.h>
  25. #include <linux/poison.h>
  26. #include <linux/bootmem.h>
  27. #include <linux/slab.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/memory_hotplug.h>
  30. #include <linux/initrd.h>
  31. #include <linux/cpumask.h>
  32. #include <asm/asm.h>
  33. #include <asm/bios_ebda.h>
  34. #include <asm/processor.h>
  35. #include <asm/system.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/dma.h>
  39. #include <asm/fixmap.h>
  40. #include <asm/e820.h>
  41. #include <asm/apic.h>
  42. #include <asm/bugs.h>
  43. #include <asm/tlb.h>
  44. #include <asm/tlbflush.h>
  45. #include <asm/pgalloc.h>
  46. #include <asm/sections.h>
  47. #include <asm/paravirt.h>
  48. #include <asm/setup.h>
  49. #include <asm/cacheflush.h>
  50. unsigned long max_low_pfn_mapped;
  51. unsigned long max_pfn_mapped;
  52. DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
  53. unsigned long highstart_pfn, highend_pfn;
  54. static noinline int do_test_wp_bit(void);
  55. static unsigned long __initdata table_start;
  56. static unsigned long __meminitdata table_end;
  57. static unsigned long __meminitdata table_top;
  58. static int __initdata after_init_bootmem;
  59. static __init void *alloc_low_page(void)
  60. {
  61. unsigned long pfn = table_end++;
  62. void *adr;
  63. if (pfn >= table_top)
  64. panic("alloc_low_page: ran out of memory");
  65. adr = __va(pfn * PAGE_SIZE);
  66. memset(adr, 0, PAGE_SIZE);
  67. return adr;
  68. }
  69. /*
  70. * Creates a middle page table and puts a pointer to it in the
  71. * given global directory entry. This only returns the gd entry
  72. * in non-PAE compilation mode, since the middle layer is folded.
  73. */
  74. static pmd_t * __init one_md_table_init(pgd_t *pgd)
  75. {
  76. pud_t *pud;
  77. pmd_t *pmd_table;
  78. #ifdef CONFIG_X86_PAE
  79. if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
  80. if (after_init_bootmem)
  81. pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  82. else
  83. pmd_table = (pmd_t *)alloc_low_page();
  84. paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
  85. set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
  86. pud = pud_offset(pgd, 0);
  87. BUG_ON(pmd_table != pmd_offset(pud, 0));
  88. return pmd_table;
  89. }
  90. #endif
  91. pud = pud_offset(pgd, 0);
  92. pmd_table = pmd_offset(pud, 0);
  93. return pmd_table;
  94. }
  95. /*
  96. * Create a page table and place a pointer to it in a middle page
  97. * directory entry:
  98. */
  99. static pte_t * __init one_page_table_init(pmd_t *pmd)
  100. {
  101. if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
  102. pte_t *page_table = NULL;
  103. if (after_init_bootmem) {
  104. #ifdef CONFIG_DEBUG_PAGEALLOC
  105. page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
  106. #endif
  107. if (!page_table)
  108. page_table =
  109. (pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  110. } else
  111. page_table = (pte_t *)alloc_low_page();
  112. paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
  113. set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
  114. BUG_ON(page_table != pte_offset_kernel(pmd, 0));
  115. }
  116. return pte_offset_kernel(pmd, 0);
  117. }
  118. pmd_t * __init populate_extra_pmd(unsigned long vaddr)
  119. {
  120. int pgd_idx = pgd_index(vaddr);
  121. int pmd_idx = pmd_index(vaddr);
  122. return one_md_table_init(swapper_pg_dir + pgd_idx) + pmd_idx;
  123. }
  124. pte_t * __init populate_extra_pte(unsigned long vaddr)
  125. {
  126. int pte_idx = pte_index(vaddr);
  127. pmd_t *pmd;
  128. pmd = populate_extra_pmd(vaddr);
  129. return one_page_table_init(pmd) + pte_idx;
  130. }
  131. static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd,
  132. unsigned long vaddr, pte_t *lastpte)
  133. {
  134. #ifdef CONFIG_HIGHMEM
  135. /*
  136. * Something (early fixmap) may already have put a pte
  137. * page here, which causes the page table allocation
  138. * to become nonlinear. Attempt to fix it, and if it
  139. * is still nonlinear then we have to bug.
  140. */
  141. int pmd_idx_kmap_begin = fix_to_virt(FIX_KMAP_END) >> PMD_SHIFT;
  142. int pmd_idx_kmap_end = fix_to_virt(FIX_KMAP_BEGIN) >> PMD_SHIFT;
  143. if (pmd_idx_kmap_begin != pmd_idx_kmap_end
  144. && (vaddr >> PMD_SHIFT) >= pmd_idx_kmap_begin
  145. && (vaddr >> PMD_SHIFT) <= pmd_idx_kmap_end
  146. && ((__pa(pte) >> PAGE_SHIFT) < table_start
  147. || (__pa(pte) >> PAGE_SHIFT) >= table_end)) {
  148. pte_t *newpte;
  149. int i;
  150. BUG_ON(after_init_bootmem);
  151. newpte = alloc_low_page();
  152. for (i = 0; i < PTRS_PER_PTE; i++)
  153. set_pte(newpte + i, pte[i]);
  154. paravirt_alloc_pte(&init_mm, __pa(newpte) >> PAGE_SHIFT);
  155. set_pmd(pmd, __pmd(__pa(newpte)|_PAGE_TABLE));
  156. BUG_ON(newpte != pte_offset_kernel(pmd, 0));
  157. __flush_tlb_all();
  158. paravirt_release_pte(__pa(pte) >> PAGE_SHIFT);
  159. pte = newpte;
  160. }
  161. BUG_ON(vaddr < fix_to_virt(FIX_KMAP_BEGIN - 1)
  162. && vaddr > fix_to_virt(FIX_KMAP_END)
  163. && lastpte && lastpte + PTRS_PER_PTE != pte);
  164. #endif
  165. return pte;
  166. }
  167. /*
  168. * This function initializes a certain range of kernel virtual memory
  169. * with new bootmem page tables, everywhere page tables are missing in
  170. * the given range.
  171. *
  172. * NOTE: The pagetables are allocated contiguous on the physical space
  173. * so we can cache the place of the first one and move around without
  174. * checking the pgd every time.
  175. */
  176. static void __init
  177. page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
  178. {
  179. int pgd_idx, pmd_idx;
  180. unsigned long vaddr;
  181. pgd_t *pgd;
  182. pmd_t *pmd;
  183. pte_t *pte = NULL;
  184. vaddr = start;
  185. pgd_idx = pgd_index(vaddr);
  186. pmd_idx = pmd_index(vaddr);
  187. pgd = pgd_base + pgd_idx;
  188. for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
  189. pmd = one_md_table_init(pgd);
  190. pmd = pmd + pmd_index(vaddr);
  191. for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
  192. pmd++, pmd_idx++) {
  193. pte = page_table_kmap_check(one_page_table_init(pmd),
  194. pmd, vaddr, pte);
  195. vaddr += PMD_SIZE;
  196. }
  197. pmd_idx = 0;
  198. }
  199. }
  200. static inline int is_kernel_text(unsigned long addr)
  201. {
  202. if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
  203. return 1;
  204. return 0;
  205. }
  206. /*
  207. * This maps the physical memory to kernel virtual address space, a total
  208. * of max_low_pfn pages, by creating page tables starting from address
  209. * PAGE_OFFSET:
  210. */
  211. static void __init kernel_physical_mapping_init(pgd_t *pgd_base,
  212. unsigned long start_pfn,
  213. unsigned long end_pfn,
  214. int use_pse)
  215. {
  216. int pgd_idx, pmd_idx, pte_ofs;
  217. unsigned long pfn;
  218. pgd_t *pgd;
  219. pmd_t *pmd;
  220. pte_t *pte;
  221. unsigned pages_2m, pages_4k;
  222. int mapping_iter;
  223. /*
  224. * First iteration will setup identity mapping using large/small pages
  225. * based on use_pse, with other attributes same as set by
  226. * the early code in head_32.S
  227. *
  228. * Second iteration will setup the appropriate attributes (NX, GLOBAL..)
  229. * as desired for the kernel identity mapping.
  230. *
  231. * This two pass mechanism conforms to the TLB app note which says:
  232. *
  233. * "Software should not write to a paging-structure entry in a way
  234. * that would change, for any linear address, both the page size
  235. * and either the page frame or attributes."
  236. */
  237. mapping_iter = 1;
  238. if (!cpu_has_pse)
  239. use_pse = 0;
  240. repeat:
  241. pages_2m = pages_4k = 0;
  242. pfn = start_pfn;
  243. pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
  244. pgd = pgd_base + pgd_idx;
  245. for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
  246. pmd = one_md_table_init(pgd);
  247. if (pfn >= end_pfn)
  248. continue;
  249. #ifdef CONFIG_X86_PAE
  250. pmd_idx = pmd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
  251. pmd += pmd_idx;
  252. #else
  253. pmd_idx = 0;
  254. #endif
  255. for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
  256. pmd++, pmd_idx++) {
  257. unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
  258. /*
  259. * Map with big pages if possible, otherwise
  260. * create normal page tables:
  261. */
  262. if (use_pse) {
  263. unsigned int addr2;
  264. pgprot_t prot = PAGE_KERNEL_LARGE;
  265. /*
  266. * first pass will use the same initial
  267. * identity mapping attribute + _PAGE_PSE.
  268. */
  269. pgprot_t init_prot =
  270. __pgprot(PTE_IDENT_ATTR |
  271. _PAGE_PSE);
  272. addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
  273. PAGE_OFFSET + PAGE_SIZE-1;
  274. if (is_kernel_text(addr) ||
  275. is_kernel_text(addr2))
  276. prot = PAGE_KERNEL_LARGE_EXEC;
  277. pages_2m++;
  278. if (mapping_iter == 1)
  279. set_pmd(pmd, pfn_pmd(pfn, init_prot));
  280. else
  281. set_pmd(pmd, pfn_pmd(pfn, prot));
  282. pfn += PTRS_PER_PTE;
  283. continue;
  284. }
  285. pte = one_page_table_init(pmd);
  286. pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
  287. pte += pte_ofs;
  288. for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
  289. pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
  290. pgprot_t prot = PAGE_KERNEL;
  291. /*
  292. * first pass will use the same initial
  293. * identity mapping attribute.
  294. */
  295. pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
  296. if (is_kernel_text(addr))
  297. prot = PAGE_KERNEL_EXEC;
  298. pages_4k++;
  299. if (mapping_iter == 1)
  300. set_pte(pte, pfn_pte(pfn, init_prot));
  301. else
  302. set_pte(pte, pfn_pte(pfn, prot));
  303. }
  304. }
  305. }
  306. if (mapping_iter == 1) {
  307. /*
  308. * update direct mapping page count only in the first
  309. * iteration.
  310. */
  311. update_page_count(PG_LEVEL_2M, pages_2m);
  312. update_page_count(PG_LEVEL_4K, pages_4k);
  313. /*
  314. * local global flush tlb, which will flush the previous
  315. * mappings present in both small and large page TLB's.
  316. */
  317. __flush_tlb_all();
  318. /*
  319. * Second iteration will set the actual desired PTE attributes.
  320. */
  321. mapping_iter = 2;
  322. goto repeat;
  323. }
  324. }
  325. /*
  326. * devmem_is_allowed() checks to see if /dev/mem access to a certain address
  327. * is valid. The argument is a physical page number.
  328. *
  329. *
  330. * On x86, access has to be given to the first megabyte of ram because that area
  331. * contains bios code and data regions used by X and dosemu and similar apps.
  332. * Access has to be given to non-kernel-ram areas as well, these contain the PCI
  333. * mmio resources as well as potential bios/acpi data regions.
  334. */
  335. int devmem_is_allowed(unsigned long pagenr)
  336. {
  337. if (pagenr <= 256)
  338. return 1;
  339. if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
  340. return 0;
  341. if (!page_is_ram(pagenr))
  342. return 1;
  343. return 0;
  344. }
  345. pte_t *kmap_pte;
  346. pgprot_t kmap_prot;
  347. static inline pte_t *kmap_get_fixmap_pte(unsigned long vaddr)
  348. {
  349. return pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr),
  350. vaddr), vaddr), vaddr);
  351. }
  352. static void __init kmap_init(void)
  353. {
  354. unsigned long kmap_vstart;
  355. /*
  356. * Cache the first kmap pte:
  357. */
  358. kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
  359. kmap_pte = kmap_get_fixmap_pte(kmap_vstart);
  360. kmap_prot = PAGE_KERNEL;
  361. }
  362. #ifdef CONFIG_HIGHMEM
  363. static void __init permanent_kmaps_init(pgd_t *pgd_base)
  364. {
  365. unsigned long vaddr;
  366. pgd_t *pgd;
  367. pud_t *pud;
  368. pmd_t *pmd;
  369. pte_t *pte;
  370. vaddr = PKMAP_BASE;
  371. page_table_range_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base);
  372. pgd = swapper_pg_dir + pgd_index(vaddr);
  373. pud = pud_offset(pgd, vaddr);
  374. pmd = pmd_offset(pud, vaddr);
  375. pte = pte_offset_kernel(pmd, vaddr);
  376. pkmap_page_table = pte;
  377. }
  378. static void __init add_one_highpage_init(struct page *page, int pfn)
  379. {
  380. ClearPageReserved(page);
  381. init_page_count(page);
  382. __free_page(page);
  383. totalhigh_pages++;
  384. }
  385. struct add_highpages_data {
  386. unsigned long start_pfn;
  387. unsigned long end_pfn;
  388. };
  389. static int __init add_highpages_work_fn(unsigned long start_pfn,
  390. unsigned long end_pfn, void *datax)
  391. {
  392. int node_pfn;
  393. struct page *page;
  394. unsigned long final_start_pfn, final_end_pfn;
  395. struct add_highpages_data *data;
  396. data = (struct add_highpages_data *)datax;
  397. final_start_pfn = max(start_pfn, data->start_pfn);
  398. final_end_pfn = min(end_pfn, data->end_pfn);
  399. if (final_start_pfn >= final_end_pfn)
  400. return 0;
  401. for (node_pfn = final_start_pfn; node_pfn < final_end_pfn;
  402. node_pfn++) {
  403. if (!pfn_valid(node_pfn))
  404. continue;
  405. page = pfn_to_page(node_pfn);
  406. add_one_highpage_init(page, node_pfn);
  407. }
  408. return 0;
  409. }
  410. void __init add_highpages_with_active_regions(int nid, unsigned long start_pfn,
  411. unsigned long end_pfn)
  412. {
  413. struct add_highpages_data data;
  414. data.start_pfn = start_pfn;
  415. data.end_pfn = end_pfn;
  416. work_with_active_regions(nid, add_highpages_work_fn, &data);
  417. }
  418. #else
  419. static inline void permanent_kmaps_init(pgd_t *pgd_base)
  420. {
  421. }
  422. #endif /* CONFIG_HIGHMEM */
  423. void __init native_pagetable_setup_start(pgd_t *base)
  424. {
  425. unsigned long pfn, va;
  426. pgd_t *pgd;
  427. pud_t *pud;
  428. pmd_t *pmd;
  429. pte_t *pte;
  430. /*
  431. * Remove any mappings which extend past the end of physical
  432. * memory from the boot time page table:
  433. */
  434. for (pfn = max_low_pfn + 1; pfn < 1<<(32-PAGE_SHIFT); pfn++) {
  435. va = PAGE_OFFSET + (pfn<<PAGE_SHIFT);
  436. pgd = base + pgd_index(va);
  437. if (!pgd_present(*pgd))
  438. break;
  439. pud = pud_offset(pgd, va);
  440. pmd = pmd_offset(pud, va);
  441. if (!pmd_present(*pmd))
  442. break;
  443. pte = pte_offset_kernel(pmd, va);
  444. if (!pte_present(*pte))
  445. break;
  446. pte_clear(NULL, va, pte);
  447. }
  448. paravirt_alloc_pmd(&init_mm, __pa(base) >> PAGE_SHIFT);
  449. }
  450. void __init native_pagetable_setup_done(pgd_t *base)
  451. {
  452. }
  453. /*
  454. * Build a proper pagetable for the kernel mappings. Up until this
  455. * point, we've been running on some set of pagetables constructed by
  456. * the boot process.
  457. *
  458. * If we're booting on native hardware, this will be a pagetable
  459. * constructed in arch/x86/kernel/head_32.S. The root of the
  460. * pagetable will be swapper_pg_dir.
  461. *
  462. * If we're booting paravirtualized under a hypervisor, then there are
  463. * more options: we may already be running PAE, and the pagetable may
  464. * or may not be based in swapper_pg_dir. In any case,
  465. * paravirt_pagetable_setup_start() will set up swapper_pg_dir
  466. * appropriately for the rest of the initialization to work.
  467. *
  468. * In general, pagetable_init() assumes that the pagetable may already
  469. * be partially populated, and so it avoids stomping on any existing
  470. * mappings.
  471. */
  472. static void __init early_ioremap_page_table_range_init(pgd_t *pgd_base)
  473. {
  474. unsigned long vaddr, end;
  475. /*
  476. * Fixed mappings, only the page table structure has to be
  477. * created - mappings will be set by set_fixmap():
  478. */
  479. vaddr = __fix_to_virt(__end_of_fixed_addresses - 1) & PMD_MASK;
  480. end = (FIXADDR_TOP + PMD_SIZE - 1) & PMD_MASK;
  481. page_table_range_init(vaddr, end, pgd_base);
  482. early_ioremap_reset();
  483. }
  484. static void __init pagetable_init(void)
  485. {
  486. pgd_t *pgd_base = swapper_pg_dir;
  487. permanent_kmaps_init(pgd_base);
  488. }
  489. #ifdef CONFIG_ACPI_SLEEP
  490. /*
  491. * ACPI suspend needs this for resume, because things like the intel-agp
  492. * driver might have split up a kernel 4MB mapping.
  493. */
  494. char swsusp_pg_dir[PAGE_SIZE]
  495. __attribute__ ((aligned(PAGE_SIZE)));
  496. static inline void save_pg_dir(void)
  497. {
  498. memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
  499. }
  500. #else /* !CONFIG_ACPI_SLEEP */
  501. static inline void save_pg_dir(void)
  502. {
  503. }
  504. #endif /* !CONFIG_ACPI_SLEEP */
  505. void zap_low_mappings(void)
  506. {
  507. int i;
  508. /*
  509. * Zap initial low-memory mappings.
  510. *
  511. * Note that "pgd_clear()" doesn't do it for
  512. * us, because pgd_clear() is a no-op on i386.
  513. */
  514. for (i = 0; i < KERNEL_PGD_BOUNDARY; i++) {
  515. #ifdef CONFIG_X86_PAE
  516. set_pgd(swapper_pg_dir+i, __pgd(1 + __pa(empty_zero_page)));
  517. #else
  518. set_pgd(swapper_pg_dir+i, __pgd(0));
  519. #endif
  520. }
  521. flush_tlb_all();
  522. }
  523. int nx_enabled;
  524. pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
  525. EXPORT_SYMBOL_GPL(__supported_pte_mask);
  526. #ifdef CONFIG_X86_PAE
  527. static int disable_nx __initdata;
  528. /*
  529. * noexec = on|off
  530. *
  531. * Control non executable mappings.
  532. *
  533. * on Enable
  534. * off Disable
  535. */
  536. static int __init noexec_setup(char *str)
  537. {
  538. if (!str || !strcmp(str, "on")) {
  539. if (cpu_has_nx) {
  540. __supported_pte_mask |= _PAGE_NX;
  541. disable_nx = 0;
  542. }
  543. } else {
  544. if (!strcmp(str, "off")) {
  545. disable_nx = 1;
  546. __supported_pte_mask &= ~_PAGE_NX;
  547. } else {
  548. return -EINVAL;
  549. }
  550. }
  551. return 0;
  552. }
  553. early_param("noexec", noexec_setup);
  554. static void __init set_nx(void)
  555. {
  556. unsigned int v[4], l, h;
  557. if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
  558. cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
  559. if ((v[3] & (1 << 20)) && !disable_nx) {
  560. rdmsr(MSR_EFER, l, h);
  561. l |= EFER_NX;
  562. wrmsr(MSR_EFER, l, h);
  563. nx_enabled = 1;
  564. __supported_pte_mask |= _PAGE_NX;
  565. }
  566. }
  567. }
  568. #endif
  569. /* user-defined highmem size */
  570. static unsigned int highmem_pages = -1;
  571. /*
  572. * highmem=size forces highmem to be exactly 'size' bytes.
  573. * This works even on boxes that have no highmem otherwise.
  574. * This also works to reduce highmem size on bigger boxes.
  575. */
  576. static int __init parse_highmem(char *arg)
  577. {
  578. if (!arg)
  579. return -EINVAL;
  580. highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
  581. return 0;
  582. }
  583. early_param("highmem", parse_highmem);
  584. #define MSG_HIGHMEM_TOO_BIG \
  585. "highmem size (%luMB) is bigger than pages available (%luMB)!\n"
  586. #define MSG_LOWMEM_TOO_SMALL \
  587. "highmem size (%luMB) results in <64MB lowmem, ignoring it!\n"
  588. /*
  589. * All of RAM fits into lowmem - but if user wants highmem
  590. * artificially via the highmem=x boot parameter then create
  591. * it:
  592. */
  593. void __init lowmem_pfn_init(void)
  594. {
  595. /* max_low_pfn is 0, we already have early_res support */
  596. max_low_pfn = max_pfn;
  597. if (highmem_pages == -1)
  598. highmem_pages = 0;
  599. #ifdef CONFIG_HIGHMEM
  600. if (highmem_pages >= max_pfn) {
  601. printk(KERN_ERR MSG_HIGHMEM_TOO_BIG,
  602. pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
  603. highmem_pages = 0;
  604. }
  605. if (highmem_pages) {
  606. if (max_low_pfn - highmem_pages < 64*1024*1024/PAGE_SIZE) {
  607. printk(KERN_ERR MSG_LOWMEM_TOO_SMALL,
  608. pages_to_mb(highmem_pages));
  609. highmem_pages = 0;
  610. }
  611. max_low_pfn -= highmem_pages;
  612. }
  613. #else
  614. if (highmem_pages)
  615. printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
  616. #endif
  617. }
  618. #define MSG_HIGHMEM_TOO_SMALL \
  619. "only %luMB highmem pages available, ignoring highmem size of %luMB!\n"
  620. #define MSG_HIGHMEM_TRIMMED \
  621. "Warning: only 4GB will be used. Use a HIGHMEM64G enabled kernel!\n"
  622. /*
  623. * We have more RAM than fits into lowmem - we try to put it into
  624. * highmem, also taking the highmem=x boot parameter into account:
  625. */
  626. void __init highmem_pfn_init(void)
  627. {
  628. max_low_pfn = MAXMEM_PFN;
  629. if (highmem_pages == -1)
  630. highmem_pages = max_pfn - MAXMEM_PFN;
  631. if (highmem_pages + MAXMEM_PFN < max_pfn)
  632. max_pfn = MAXMEM_PFN + highmem_pages;
  633. if (highmem_pages + MAXMEM_PFN > max_pfn) {
  634. printk(KERN_WARNING MSG_HIGHMEM_TOO_SMALL,
  635. pages_to_mb(max_pfn - MAXMEM_PFN),
  636. pages_to_mb(highmem_pages));
  637. highmem_pages = 0;
  638. }
  639. #ifndef CONFIG_HIGHMEM
  640. /* Maximum memory usable is what is directly addressable */
  641. printk(KERN_WARNING "Warning only %ldMB will be used.\n", MAXMEM>>20);
  642. if (max_pfn > MAX_NONPAE_PFN)
  643. printk(KERN_WARNING "Use a HIGHMEM64G enabled kernel.\n");
  644. else
  645. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  646. max_pfn = MAXMEM_PFN;
  647. #else /* !CONFIG_HIGHMEM */
  648. #ifndef CONFIG_HIGHMEM64G
  649. if (max_pfn > MAX_NONPAE_PFN) {
  650. max_pfn = MAX_NONPAE_PFN;
  651. printk(KERN_WARNING MSG_HIGHMEM_TRIMMED);
  652. }
  653. #endif /* !CONFIG_HIGHMEM64G */
  654. #endif /* !CONFIG_HIGHMEM */
  655. }
  656. /*
  657. * Determine low and high memory ranges:
  658. */
  659. void __init find_low_pfn_range(void)
  660. {
  661. /* it could update max_pfn */
  662. if (max_pfn <= MAXMEM_PFN)
  663. lowmem_pfn_init();
  664. else
  665. highmem_pfn_init();
  666. }
  667. #ifndef CONFIG_NEED_MULTIPLE_NODES
  668. void __init initmem_init(unsigned long start_pfn,
  669. unsigned long end_pfn)
  670. {
  671. #ifdef CONFIG_HIGHMEM
  672. highstart_pfn = highend_pfn = max_pfn;
  673. if (max_pfn > max_low_pfn)
  674. highstart_pfn = max_low_pfn;
  675. memory_present(0, 0, highend_pfn);
  676. e820_register_active_regions(0, 0, highend_pfn);
  677. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  678. pages_to_mb(highend_pfn - highstart_pfn));
  679. num_physpages = highend_pfn;
  680. high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
  681. #else
  682. memory_present(0, 0, max_low_pfn);
  683. e820_register_active_regions(0, 0, max_low_pfn);
  684. num_physpages = max_low_pfn;
  685. high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
  686. #endif
  687. #ifdef CONFIG_FLATMEM
  688. max_mapnr = num_physpages;
  689. #endif
  690. printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
  691. pages_to_mb(max_low_pfn));
  692. setup_bootmem_allocator();
  693. }
  694. #endif /* !CONFIG_NEED_MULTIPLE_NODES */
  695. static void __init zone_sizes_init(void)
  696. {
  697. unsigned long max_zone_pfns[MAX_NR_ZONES];
  698. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  699. max_zone_pfns[ZONE_DMA] =
  700. virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  701. max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
  702. #ifdef CONFIG_HIGHMEM
  703. max_zone_pfns[ZONE_HIGHMEM] = highend_pfn;
  704. #endif
  705. free_area_init_nodes(max_zone_pfns);
  706. }
  707. void __init setup_bootmem_allocator(void)
  708. {
  709. int i;
  710. unsigned long bootmap_size, bootmap;
  711. /*
  712. * Initialize the boot-time allocator (with low memory only):
  713. */
  714. bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
  715. bootmap = find_e820_area(min_low_pfn<<PAGE_SHIFT,
  716. max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
  717. PAGE_SIZE);
  718. if (bootmap == -1L)
  719. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  720. reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
  721. /* don't touch min_low_pfn */
  722. bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap >> PAGE_SHIFT,
  723. min_low_pfn, max_low_pfn);
  724. printk(KERN_INFO " mapped low ram: 0 - %08lx\n",
  725. max_pfn_mapped<<PAGE_SHIFT);
  726. printk(KERN_INFO " low ram: %08lx - %08lx\n",
  727. min_low_pfn<<PAGE_SHIFT, max_low_pfn<<PAGE_SHIFT);
  728. printk(KERN_INFO " bootmap %08lx - %08lx\n",
  729. bootmap, bootmap + bootmap_size);
  730. for_each_online_node(i)
  731. free_bootmem_with_active_regions(i, max_low_pfn);
  732. early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
  733. after_init_bootmem = 1;
  734. }
  735. static void __init find_early_table_space(unsigned long end, int use_pse)
  736. {
  737. unsigned long puds, pmds, ptes, tables, start;
  738. puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
  739. tables = roundup(puds * sizeof(pud_t), PAGE_SIZE);
  740. pmds = (end + PMD_SIZE - 1) >> PMD_SHIFT;
  741. tables += roundup(pmds * sizeof(pmd_t), PAGE_SIZE);
  742. if (use_pse) {
  743. unsigned long extra;
  744. extra = end - ((end>>PMD_SHIFT) << PMD_SHIFT);
  745. extra += PMD_SIZE;
  746. ptes = (extra + PAGE_SIZE - 1) >> PAGE_SHIFT;
  747. } else
  748. ptes = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
  749. tables += roundup(ptes * sizeof(pte_t), PAGE_SIZE);
  750. /* for fixmap */
  751. tables += roundup(__end_of_fixed_addresses * sizeof(pte_t), PAGE_SIZE);
  752. /*
  753. * RED-PEN putting page tables only on node 0 could
  754. * cause a hotspot and fill up ZONE_DMA. The page tables
  755. * need roughly 0.5KB per GB.
  756. */
  757. start = 0x7000;
  758. table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
  759. tables, PAGE_SIZE);
  760. if (table_start == -1UL)
  761. panic("Cannot find space for the kernel page tables");
  762. table_start >>= PAGE_SHIFT;
  763. table_end = table_start;
  764. table_top = table_start + (tables>>PAGE_SHIFT);
  765. printk(KERN_DEBUG "kernel direct mapping tables up to %lx @ %lx-%lx\n",
  766. end, table_start << PAGE_SHIFT,
  767. (table_start << PAGE_SHIFT) + tables);
  768. }
  769. unsigned long __init_refok init_memory_mapping(unsigned long start,
  770. unsigned long end)
  771. {
  772. pgd_t *pgd_base = swapper_pg_dir;
  773. unsigned long start_pfn, end_pfn;
  774. unsigned long big_page_start;
  775. #ifdef CONFIG_DEBUG_PAGEALLOC
  776. /*
  777. * For CONFIG_DEBUG_PAGEALLOC, identity mapping will use small pages.
  778. * This will simplify cpa(), which otherwise needs to support splitting
  779. * large pages into small in interrupt context, etc.
  780. */
  781. int use_pse = 0;
  782. #else
  783. int use_pse = cpu_has_pse;
  784. #endif
  785. /*
  786. * Find space for the kernel direct mapping tables.
  787. */
  788. if (!after_init_bootmem)
  789. find_early_table_space(end, use_pse);
  790. #ifdef CONFIG_X86_PAE
  791. set_nx();
  792. if (nx_enabled)
  793. printk(KERN_INFO "NX (Execute Disable) protection: active\n");
  794. #endif
  795. /* Enable PSE if available */
  796. if (cpu_has_pse)
  797. set_in_cr4(X86_CR4_PSE);
  798. /* Enable PGE if available */
  799. if (cpu_has_pge) {
  800. set_in_cr4(X86_CR4_PGE);
  801. __supported_pte_mask |= _PAGE_GLOBAL;
  802. }
  803. /*
  804. * Don't use a large page for the first 2/4MB of memory
  805. * because there are often fixed size MTRRs in there
  806. * and overlapping MTRRs into large pages can cause
  807. * slowdowns.
  808. */
  809. big_page_start = PMD_SIZE;
  810. if (start < big_page_start) {
  811. start_pfn = start >> PAGE_SHIFT;
  812. end_pfn = min(big_page_start>>PAGE_SHIFT, end>>PAGE_SHIFT);
  813. } else {
  814. /* head is not big page alignment ? */
  815. start_pfn = start >> PAGE_SHIFT;
  816. end_pfn = ((start + (PMD_SIZE - 1))>>PMD_SHIFT)
  817. << (PMD_SHIFT - PAGE_SHIFT);
  818. }
  819. if (start_pfn < end_pfn)
  820. kernel_physical_mapping_init(pgd_base, start_pfn, end_pfn, 0);
  821. /* big page range */
  822. start_pfn = ((start + (PMD_SIZE - 1))>>PMD_SHIFT)
  823. << (PMD_SHIFT - PAGE_SHIFT);
  824. if (start_pfn < (big_page_start >> PAGE_SHIFT))
  825. start_pfn = big_page_start >> PAGE_SHIFT;
  826. end_pfn = (end>>PMD_SHIFT) << (PMD_SHIFT - PAGE_SHIFT);
  827. if (start_pfn < end_pfn)
  828. kernel_physical_mapping_init(pgd_base, start_pfn, end_pfn,
  829. use_pse);
  830. /* tail is not big page alignment ? */
  831. start_pfn = end_pfn;
  832. if (start_pfn > (big_page_start>>PAGE_SHIFT)) {
  833. end_pfn = end >> PAGE_SHIFT;
  834. if (start_pfn < end_pfn)
  835. kernel_physical_mapping_init(pgd_base, start_pfn,
  836. end_pfn, 0);
  837. }
  838. early_ioremap_page_table_range_init(pgd_base);
  839. load_cr3(swapper_pg_dir);
  840. __flush_tlb_all();
  841. if (!after_init_bootmem)
  842. reserve_early(table_start << PAGE_SHIFT,
  843. table_end << PAGE_SHIFT, "PGTABLE");
  844. if (!after_init_bootmem)
  845. early_memtest(start, end);
  846. return end >> PAGE_SHIFT;
  847. }
  848. /*
  849. * paging_init() sets up the page tables - note that the first 8MB are
  850. * already mapped by head.S.
  851. *
  852. * This routines also unmaps the page at virtual kernel address 0, so
  853. * that we can trap those pesky NULL-reference errors in the kernel.
  854. */
  855. void __init paging_init(void)
  856. {
  857. pagetable_init();
  858. __flush_tlb_all();
  859. kmap_init();
  860. /*
  861. * NOTE: at this point the bootmem allocator is fully available.
  862. */
  863. sparse_init();
  864. zone_sizes_init();
  865. }
  866. /*
  867. * Test if the WP bit works in supervisor mode. It isn't supported on 386's
  868. * and also on some strange 486's. All 586+'s are OK. This used to involve
  869. * black magic jumps to work around some nasty CPU bugs, but fortunately the
  870. * switch to using exceptions got rid of all that.
  871. */
  872. static void __init test_wp_bit(void)
  873. {
  874. printk(KERN_INFO
  875. "Checking if this processor honours the WP bit even in supervisor mode...");
  876. /* Any page-aligned address will do, the test is non-destructive */
  877. __set_fixmap(FIX_WP_TEST, __pa(&swapper_pg_dir), PAGE_READONLY);
  878. boot_cpu_data.wp_works_ok = do_test_wp_bit();
  879. clear_fixmap(FIX_WP_TEST);
  880. if (!boot_cpu_data.wp_works_ok) {
  881. printk(KERN_CONT "No.\n");
  882. #ifdef CONFIG_X86_WP_WORKS_OK
  883. panic(
  884. "This kernel doesn't support CPU's with broken WP. Recompile it for a 386!");
  885. #endif
  886. } else {
  887. printk(KERN_CONT "Ok.\n");
  888. }
  889. }
  890. static struct kcore_list kcore_mem, kcore_vmalloc;
  891. void __init mem_init(void)
  892. {
  893. int codesize, reservedpages, datasize, initsize;
  894. int tmp;
  895. pci_iommu_alloc();
  896. #ifdef CONFIG_FLATMEM
  897. BUG_ON(!mem_map);
  898. #endif
  899. /* this will put all low memory onto the freelists */
  900. totalram_pages += free_all_bootmem();
  901. reservedpages = 0;
  902. for (tmp = 0; tmp < max_low_pfn; tmp++)
  903. /*
  904. * Only count reserved RAM pages:
  905. */
  906. if (page_is_ram(tmp) && PageReserved(pfn_to_page(tmp)))
  907. reservedpages++;
  908. set_highmem_pages_init();
  909. codesize = (unsigned long) &_etext - (unsigned long) &_text;
  910. datasize = (unsigned long) &_edata - (unsigned long) &_etext;
  911. initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
  912. kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
  913. kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
  914. VMALLOC_END-VMALLOC_START);
  915. printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
  916. "%dk reserved, %dk data, %dk init, %ldk highmem)\n",
  917. (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
  918. num_physpages << (PAGE_SHIFT-10),
  919. codesize >> 10,
  920. reservedpages << (PAGE_SHIFT-10),
  921. datasize >> 10,
  922. initsize >> 10,
  923. (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10))
  924. );
  925. printk(KERN_INFO "virtual kernel memory layout:\n"
  926. " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
  927. #ifdef CONFIG_HIGHMEM
  928. " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
  929. #endif
  930. " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
  931. " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
  932. " .init : 0x%08lx - 0x%08lx (%4ld kB)\n"
  933. " .data : 0x%08lx - 0x%08lx (%4ld kB)\n"
  934. " .text : 0x%08lx - 0x%08lx (%4ld kB)\n",
  935. FIXADDR_START, FIXADDR_TOP,
  936. (FIXADDR_TOP - FIXADDR_START) >> 10,
  937. #ifdef CONFIG_HIGHMEM
  938. PKMAP_BASE, PKMAP_BASE+LAST_PKMAP*PAGE_SIZE,
  939. (LAST_PKMAP*PAGE_SIZE) >> 10,
  940. #endif
  941. VMALLOC_START, VMALLOC_END,
  942. (VMALLOC_END - VMALLOC_START) >> 20,
  943. (unsigned long)__va(0), (unsigned long)high_memory,
  944. ((unsigned long)high_memory - (unsigned long)__va(0)) >> 20,
  945. (unsigned long)&__init_begin, (unsigned long)&__init_end,
  946. ((unsigned long)&__init_end -
  947. (unsigned long)&__init_begin) >> 10,
  948. (unsigned long)&_etext, (unsigned long)&_edata,
  949. ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
  950. (unsigned long)&_text, (unsigned long)&_etext,
  951. ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
  952. /*
  953. * Check boundaries twice: Some fundamental inconsistencies can
  954. * be detected at build time already.
  955. */
  956. #define __FIXADDR_TOP (-PAGE_SIZE)
  957. #ifdef CONFIG_HIGHMEM
  958. BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START);
  959. BUILD_BUG_ON(VMALLOC_END > PKMAP_BASE);
  960. #endif
  961. #define high_memory (-128UL << 20)
  962. BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END);
  963. #undef high_memory
  964. #undef __FIXADDR_TOP
  965. #ifdef CONFIG_HIGHMEM
  966. BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START);
  967. BUG_ON(VMALLOC_END > PKMAP_BASE);
  968. #endif
  969. BUG_ON(VMALLOC_START >= VMALLOC_END);
  970. BUG_ON((unsigned long)high_memory > VMALLOC_START);
  971. if (boot_cpu_data.wp_works_ok < 0)
  972. test_wp_bit();
  973. save_pg_dir();
  974. zap_low_mappings();
  975. }
  976. #ifdef CONFIG_MEMORY_HOTPLUG
  977. int arch_add_memory(int nid, u64 start, u64 size)
  978. {
  979. struct pglist_data *pgdata = NODE_DATA(nid);
  980. struct zone *zone = pgdata->node_zones + ZONE_HIGHMEM;
  981. unsigned long start_pfn = start >> PAGE_SHIFT;
  982. unsigned long nr_pages = size >> PAGE_SHIFT;
  983. return __add_pages(nid, zone, start_pfn, nr_pages);
  984. }
  985. #endif
  986. /*
  987. * This function cannot be __init, since exceptions don't work in that
  988. * section. Put this after the callers, so that it cannot be inlined.
  989. */
  990. static noinline int do_test_wp_bit(void)
  991. {
  992. char tmp_reg;
  993. int flag;
  994. __asm__ __volatile__(
  995. " movb %0, %1 \n"
  996. "1: movb %1, %0 \n"
  997. " xorl %2, %2 \n"
  998. "2: \n"
  999. _ASM_EXTABLE(1b,2b)
  1000. :"=m" (*(char *)fix_to_virt(FIX_WP_TEST)),
  1001. "=q" (tmp_reg),
  1002. "=r" (flag)
  1003. :"2" (1)
  1004. :"memory");
  1005. return flag;
  1006. }
  1007. #ifdef CONFIG_DEBUG_RODATA
  1008. const int rodata_test_data = 0xC3;
  1009. EXPORT_SYMBOL_GPL(rodata_test_data);
  1010. void mark_rodata_ro(void)
  1011. {
  1012. unsigned long start = PFN_ALIGN(_text);
  1013. unsigned long size = PFN_ALIGN(_etext) - start;
  1014. #ifndef CONFIG_DYNAMIC_FTRACE
  1015. /* Dynamic tracing modifies the kernel text section */
  1016. set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
  1017. printk(KERN_INFO "Write protecting the kernel text: %luk\n",
  1018. size >> 10);
  1019. #ifdef CONFIG_CPA_DEBUG
  1020. printk(KERN_INFO "Testing CPA: Reverting %lx-%lx\n",
  1021. start, start+size);
  1022. set_pages_rw(virt_to_page(start), size>>PAGE_SHIFT);
  1023. printk(KERN_INFO "Testing CPA: write protecting again\n");
  1024. set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
  1025. #endif
  1026. #endif /* CONFIG_DYNAMIC_FTRACE */
  1027. start += size;
  1028. size = (unsigned long)__end_rodata - start;
  1029. set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
  1030. printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
  1031. size >> 10);
  1032. rodata_test();
  1033. #ifdef CONFIG_CPA_DEBUG
  1034. printk(KERN_INFO "Testing CPA: undo %lx-%lx\n", start, start + size);
  1035. set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);
  1036. printk(KERN_INFO "Testing CPA: write protecting again\n");
  1037. set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
  1038. #endif
  1039. }
  1040. #endif
  1041. #ifdef CONFIG_BLK_DEV_INITRD
  1042. void free_initrd_mem(unsigned long start, unsigned long end)
  1043. {
  1044. free_init_pages("initrd memory", start, end);
  1045. }
  1046. #endif
  1047. int __init reserve_bootmem_generic(unsigned long phys, unsigned long len,
  1048. int flags)
  1049. {
  1050. return reserve_bootmem(phys, len, flags);
  1051. }