kexec.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. /*
  2. * kexec.c - kexec system call
  3. * Copyright (C) 2002-2004 Eric Biederman <ebiederm@xmission.com>
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <linux/capability.h>
  9. #include <linux/mm.h>
  10. #include <linux/file.h>
  11. #include <linux/slab.h>
  12. #include <linux/fs.h>
  13. #include <linux/kexec.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/list.h>
  16. #include <linux/highmem.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/reboot.h>
  19. #include <linux/ioport.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/elf.h>
  22. #include <linux/elfcore.h>
  23. #include <linux/utsrelease.h>
  24. #include <linux/utsname.h>
  25. #include <linux/numa.h>
  26. #include <asm/page.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/io.h>
  29. #include <asm/system.h>
  30. #include <asm/sections.h>
  31. /* Per cpu memory for storing cpu states in case of system crash. */
  32. note_buf_t* crash_notes;
  33. /* vmcoreinfo stuff */
  34. unsigned char vmcoreinfo_data[VMCOREINFO_BYTES];
  35. u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
  36. size_t vmcoreinfo_size;
  37. size_t vmcoreinfo_max_size = sizeof(vmcoreinfo_data);
  38. /* Location of the reserved area for the crash kernel */
  39. struct resource crashk_res = {
  40. .name = "Crash kernel",
  41. .start = 0,
  42. .end = 0,
  43. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  44. };
  45. int kexec_should_crash(struct task_struct *p)
  46. {
  47. if (in_interrupt() || !p->pid || is_global_init(p) || panic_on_oops)
  48. return 1;
  49. return 0;
  50. }
  51. /*
  52. * When kexec transitions to the new kernel there is a one-to-one
  53. * mapping between physical and virtual addresses. On processors
  54. * where you can disable the MMU this is trivial, and easy. For
  55. * others it is still a simple predictable page table to setup.
  56. *
  57. * In that environment kexec copies the new kernel to its final
  58. * resting place. This means I can only support memory whose
  59. * physical address can fit in an unsigned long. In particular
  60. * addresses where (pfn << PAGE_SHIFT) > ULONG_MAX cannot be handled.
  61. * If the assembly stub has more restrictive requirements
  62. * KEXEC_SOURCE_MEMORY_LIMIT and KEXEC_DEST_MEMORY_LIMIT can be
  63. * defined more restrictively in <asm/kexec.h>.
  64. *
  65. * The code for the transition from the current kernel to the
  66. * the new kernel is placed in the control_code_buffer, whose size
  67. * is given by KEXEC_CONTROL_CODE_SIZE. In the best case only a single
  68. * page of memory is necessary, but some architectures require more.
  69. * Because this memory must be identity mapped in the transition from
  70. * virtual to physical addresses it must live in the range
  71. * 0 - TASK_SIZE, as only the user space mappings are arbitrarily
  72. * modifiable.
  73. *
  74. * The assembly stub in the control code buffer is passed a linked list
  75. * of descriptor pages detailing the source pages of the new kernel,
  76. * and the destination addresses of those source pages. As this data
  77. * structure is not used in the context of the current OS, it must
  78. * be self-contained.
  79. *
  80. * The code has been made to work with highmem pages and will use a
  81. * destination page in its final resting place (if it happens
  82. * to allocate it). The end product of this is that most of the
  83. * physical address space, and most of RAM can be used.
  84. *
  85. * Future directions include:
  86. * - allocating a page table with the control code buffer identity
  87. * mapped, to simplify machine_kexec and make kexec_on_panic more
  88. * reliable.
  89. */
  90. /*
  91. * KIMAGE_NO_DEST is an impossible destination address..., for
  92. * allocating pages whose destination address we do not care about.
  93. */
  94. #define KIMAGE_NO_DEST (-1UL)
  95. static int kimage_is_destination_range(struct kimage *image,
  96. unsigned long start, unsigned long end);
  97. static struct page *kimage_alloc_page(struct kimage *image,
  98. gfp_t gfp_mask,
  99. unsigned long dest);
  100. static int do_kimage_alloc(struct kimage **rimage, unsigned long entry,
  101. unsigned long nr_segments,
  102. struct kexec_segment __user *segments)
  103. {
  104. size_t segment_bytes;
  105. struct kimage *image;
  106. unsigned long i;
  107. int result;
  108. /* Allocate a controlling structure */
  109. result = -ENOMEM;
  110. image = kzalloc(sizeof(*image), GFP_KERNEL);
  111. if (!image)
  112. goto out;
  113. image->head = 0;
  114. image->entry = &image->head;
  115. image->last_entry = &image->head;
  116. image->control_page = ~0; /* By default this does not apply */
  117. image->start = entry;
  118. image->type = KEXEC_TYPE_DEFAULT;
  119. /* Initialize the list of control pages */
  120. INIT_LIST_HEAD(&image->control_pages);
  121. /* Initialize the list of destination pages */
  122. INIT_LIST_HEAD(&image->dest_pages);
  123. /* Initialize the list of unuseable pages */
  124. INIT_LIST_HEAD(&image->unuseable_pages);
  125. /* Read in the segments */
  126. image->nr_segments = nr_segments;
  127. segment_bytes = nr_segments * sizeof(*segments);
  128. result = copy_from_user(image->segment, segments, segment_bytes);
  129. if (result)
  130. goto out;
  131. /*
  132. * Verify we have good destination addresses. The caller is
  133. * responsible for making certain we don't attempt to load
  134. * the new image into invalid or reserved areas of RAM. This
  135. * just verifies it is an address we can use.
  136. *
  137. * Since the kernel does everything in page size chunks ensure
  138. * the destination addreses are page aligned. Too many
  139. * special cases crop of when we don't do this. The most
  140. * insidious is getting overlapping destination addresses
  141. * simply because addresses are changed to page size
  142. * granularity.
  143. */
  144. result = -EADDRNOTAVAIL;
  145. for (i = 0; i < nr_segments; i++) {
  146. unsigned long mstart, mend;
  147. mstart = image->segment[i].mem;
  148. mend = mstart + image->segment[i].memsz;
  149. if ((mstart & ~PAGE_MASK) || (mend & ~PAGE_MASK))
  150. goto out;
  151. if (mend >= KEXEC_DESTINATION_MEMORY_LIMIT)
  152. goto out;
  153. }
  154. /* Verify our destination addresses do not overlap.
  155. * If we alloed overlapping destination addresses
  156. * through very weird things can happen with no
  157. * easy explanation as one segment stops on another.
  158. */
  159. result = -EINVAL;
  160. for (i = 0; i < nr_segments; i++) {
  161. unsigned long mstart, mend;
  162. unsigned long j;
  163. mstart = image->segment[i].mem;
  164. mend = mstart + image->segment[i].memsz;
  165. for (j = 0; j < i; j++) {
  166. unsigned long pstart, pend;
  167. pstart = image->segment[j].mem;
  168. pend = pstart + image->segment[j].memsz;
  169. /* Do the segments overlap ? */
  170. if ((mend > pstart) && (mstart < pend))
  171. goto out;
  172. }
  173. }
  174. /* Ensure our buffer sizes are strictly less than
  175. * our memory sizes. This should always be the case,
  176. * and it is easier to check up front than to be surprised
  177. * later on.
  178. */
  179. result = -EINVAL;
  180. for (i = 0; i < nr_segments; i++) {
  181. if (image->segment[i].bufsz > image->segment[i].memsz)
  182. goto out;
  183. }
  184. result = 0;
  185. out:
  186. if (result == 0)
  187. *rimage = image;
  188. else
  189. kfree(image);
  190. return result;
  191. }
  192. static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry,
  193. unsigned long nr_segments,
  194. struct kexec_segment __user *segments)
  195. {
  196. int result;
  197. struct kimage *image;
  198. /* Allocate and initialize a controlling structure */
  199. image = NULL;
  200. result = do_kimage_alloc(&image, entry, nr_segments, segments);
  201. if (result)
  202. goto out;
  203. *rimage = image;
  204. /*
  205. * Find a location for the control code buffer, and add it
  206. * the vector of segments so that it's pages will also be
  207. * counted as destination pages.
  208. */
  209. result = -ENOMEM;
  210. image->control_code_page = kimage_alloc_control_pages(image,
  211. get_order(KEXEC_CONTROL_CODE_SIZE));
  212. if (!image->control_code_page) {
  213. printk(KERN_ERR "Could not allocate control_code_buffer\n");
  214. goto out;
  215. }
  216. result = 0;
  217. out:
  218. if (result == 0)
  219. *rimage = image;
  220. else
  221. kfree(image);
  222. return result;
  223. }
  224. static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
  225. unsigned long nr_segments,
  226. struct kexec_segment __user *segments)
  227. {
  228. int result;
  229. struct kimage *image;
  230. unsigned long i;
  231. image = NULL;
  232. /* Verify we have a valid entry point */
  233. if ((entry < crashk_res.start) || (entry > crashk_res.end)) {
  234. result = -EADDRNOTAVAIL;
  235. goto out;
  236. }
  237. /* Allocate and initialize a controlling structure */
  238. result = do_kimage_alloc(&image, entry, nr_segments, segments);
  239. if (result)
  240. goto out;
  241. /* Enable the special crash kernel control page
  242. * allocation policy.
  243. */
  244. image->control_page = crashk_res.start;
  245. image->type = KEXEC_TYPE_CRASH;
  246. /*
  247. * Verify we have good destination addresses. Normally
  248. * the caller is responsible for making certain we don't
  249. * attempt to load the new image into invalid or reserved
  250. * areas of RAM. But crash kernels are preloaded into a
  251. * reserved area of ram. We must ensure the addresses
  252. * are in the reserved area otherwise preloading the
  253. * kernel could corrupt things.
  254. */
  255. result = -EADDRNOTAVAIL;
  256. for (i = 0; i < nr_segments; i++) {
  257. unsigned long mstart, mend;
  258. mstart = image->segment[i].mem;
  259. mend = mstart + image->segment[i].memsz - 1;
  260. /* Ensure we are within the crash kernel limits */
  261. if ((mstart < crashk_res.start) || (mend > crashk_res.end))
  262. goto out;
  263. }
  264. /*
  265. * Find a location for the control code buffer, and add
  266. * the vector of segments so that it's pages will also be
  267. * counted as destination pages.
  268. */
  269. result = -ENOMEM;
  270. image->control_code_page = kimage_alloc_control_pages(image,
  271. get_order(KEXEC_CONTROL_CODE_SIZE));
  272. if (!image->control_code_page) {
  273. printk(KERN_ERR "Could not allocate control_code_buffer\n");
  274. goto out;
  275. }
  276. result = 0;
  277. out:
  278. if (result == 0)
  279. *rimage = image;
  280. else
  281. kfree(image);
  282. return result;
  283. }
  284. static int kimage_is_destination_range(struct kimage *image,
  285. unsigned long start,
  286. unsigned long end)
  287. {
  288. unsigned long i;
  289. for (i = 0; i < image->nr_segments; i++) {
  290. unsigned long mstart, mend;
  291. mstart = image->segment[i].mem;
  292. mend = mstart + image->segment[i].memsz;
  293. if ((end > mstart) && (start < mend))
  294. return 1;
  295. }
  296. return 0;
  297. }
  298. static struct page *kimage_alloc_pages(gfp_t gfp_mask, unsigned int order)
  299. {
  300. struct page *pages;
  301. pages = alloc_pages(gfp_mask, order);
  302. if (pages) {
  303. unsigned int count, i;
  304. pages->mapping = NULL;
  305. set_page_private(pages, order);
  306. count = 1 << order;
  307. for (i = 0; i < count; i++)
  308. SetPageReserved(pages + i);
  309. }
  310. return pages;
  311. }
  312. static void kimage_free_pages(struct page *page)
  313. {
  314. unsigned int order, count, i;
  315. order = page_private(page);
  316. count = 1 << order;
  317. for (i = 0; i < count; i++)
  318. ClearPageReserved(page + i);
  319. __free_pages(page, order);
  320. }
  321. static void kimage_free_page_list(struct list_head *list)
  322. {
  323. struct list_head *pos, *next;
  324. list_for_each_safe(pos, next, list) {
  325. struct page *page;
  326. page = list_entry(pos, struct page, lru);
  327. list_del(&page->lru);
  328. kimage_free_pages(page);
  329. }
  330. }
  331. static struct page *kimage_alloc_normal_control_pages(struct kimage *image,
  332. unsigned int order)
  333. {
  334. /* Control pages are special, they are the intermediaries
  335. * that are needed while we copy the rest of the pages
  336. * to their final resting place. As such they must
  337. * not conflict with either the destination addresses
  338. * or memory the kernel is already using.
  339. *
  340. * The only case where we really need more than one of
  341. * these are for architectures where we cannot disable
  342. * the MMU and must instead generate an identity mapped
  343. * page table for all of the memory.
  344. *
  345. * At worst this runs in O(N) of the image size.
  346. */
  347. struct list_head extra_pages;
  348. struct page *pages;
  349. unsigned int count;
  350. count = 1 << order;
  351. INIT_LIST_HEAD(&extra_pages);
  352. /* Loop while I can allocate a page and the page allocated
  353. * is a destination page.
  354. */
  355. do {
  356. unsigned long pfn, epfn, addr, eaddr;
  357. pages = kimage_alloc_pages(GFP_KERNEL, order);
  358. if (!pages)
  359. break;
  360. pfn = page_to_pfn(pages);
  361. epfn = pfn + count;
  362. addr = pfn << PAGE_SHIFT;
  363. eaddr = epfn << PAGE_SHIFT;
  364. if ((epfn >= (KEXEC_CONTROL_MEMORY_LIMIT >> PAGE_SHIFT)) ||
  365. kimage_is_destination_range(image, addr, eaddr)) {
  366. list_add(&pages->lru, &extra_pages);
  367. pages = NULL;
  368. }
  369. } while (!pages);
  370. if (pages) {
  371. /* Remember the allocated page... */
  372. list_add(&pages->lru, &image->control_pages);
  373. /* Because the page is already in it's destination
  374. * location we will never allocate another page at
  375. * that address. Therefore kimage_alloc_pages
  376. * will not return it (again) and we don't need
  377. * to give it an entry in image->segment[].
  378. */
  379. }
  380. /* Deal with the destination pages I have inadvertently allocated.
  381. *
  382. * Ideally I would convert multi-page allocations into single
  383. * page allocations, and add everyting to image->dest_pages.
  384. *
  385. * For now it is simpler to just free the pages.
  386. */
  387. kimage_free_page_list(&extra_pages);
  388. return pages;
  389. }
  390. static struct page *kimage_alloc_crash_control_pages(struct kimage *image,
  391. unsigned int order)
  392. {
  393. /* Control pages are special, they are the intermediaries
  394. * that are needed while we copy the rest of the pages
  395. * to their final resting place. As such they must
  396. * not conflict with either the destination addresses
  397. * or memory the kernel is already using.
  398. *
  399. * Control pages are also the only pags we must allocate
  400. * when loading a crash kernel. All of the other pages
  401. * are specified by the segments and we just memcpy
  402. * into them directly.
  403. *
  404. * The only case where we really need more than one of
  405. * these are for architectures where we cannot disable
  406. * the MMU and must instead generate an identity mapped
  407. * page table for all of the memory.
  408. *
  409. * Given the low demand this implements a very simple
  410. * allocator that finds the first hole of the appropriate
  411. * size in the reserved memory region, and allocates all
  412. * of the memory up to and including the hole.
  413. */
  414. unsigned long hole_start, hole_end, size;
  415. struct page *pages;
  416. pages = NULL;
  417. size = (1 << order) << PAGE_SHIFT;
  418. hole_start = (image->control_page + (size - 1)) & ~(size - 1);
  419. hole_end = hole_start + size - 1;
  420. while (hole_end <= crashk_res.end) {
  421. unsigned long i;
  422. if (hole_end > KEXEC_CONTROL_MEMORY_LIMIT)
  423. break;
  424. if (hole_end > crashk_res.end)
  425. break;
  426. /* See if I overlap any of the segments */
  427. for (i = 0; i < image->nr_segments; i++) {
  428. unsigned long mstart, mend;
  429. mstart = image->segment[i].mem;
  430. mend = mstart + image->segment[i].memsz - 1;
  431. if ((hole_end >= mstart) && (hole_start <= mend)) {
  432. /* Advance the hole to the end of the segment */
  433. hole_start = (mend + (size - 1)) & ~(size - 1);
  434. hole_end = hole_start + size - 1;
  435. break;
  436. }
  437. }
  438. /* If I don't overlap any segments I have found my hole! */
  439. if (i == image->nr_segments) {
  440. pages = pfn_to_page(hole_start >> PAGE_SHIFT);
  441. break;
  442. }
  443. }
  444. if (pages)
  445. image->control_page = hole_end;
  446. return pages;
  447. }
  448. struct page *kimage_alloc_control_pages(struct kimage *image,
  449. unsigned int order)
  450. {
  451. struct page *pages = NULL;
  452. switch (image->type) {
  453. case KEXEC_TYPE_DEFAULT:
  454. pages = kimage_alloc_normal_control_pages(image, order);
  455. break;
  456. case KEXEC_TYPE_CRASH:
  457. pages = kimage_alloc_crash_control_pages(image, order);
  458. break;
  459. }
  460. return pages;
  461. }
  462. static int kimage_add_entry(struct kimage *image, kimage_entry_t entry)
  463. {
  464. if (*image->entry != 0)
  465. image->entry++;
  466. if (image->entry == image->last_entry) {
  467. kimage_entry_t *ind_page;
  468. struct page *page;
  469. page = kimage_alloc_page(image, GFP_KERNEL, KIMAGE_NO_DEST);
  470. if (!page)
  471. return -ENOMEM;
  472. ind_page = page_address(page);
  473. *image->entry = virt_to_phys(ind_page) | IND_INDIRECTION;
  474. image->entry = ind_page;
  475. image->last_entry = ind_page +
  476. ((PAGE_SIZE/sizeof(kimage_entry_t)) - 1);
  477. }
  478. *image->entry = entry;
  479. image->entry++;
  480. *image->entry = 0;
  481. return 0;
  482. }
  483. static int kimage_set_destination(struct kimage *image,
  484. unsigned long destination)
  485. {
  486. int result;
  487. destination &= PAGE_MASK;
  488. result = kimage_add_entry(image, destination | IND_DESTINATION);
  489. if (result == 0)
  490. image->destination = destination;
  491. return result;
  492. }
  493. static int kimage_add_page(struct kimage *image, unsigned long page)
  494. {
  495. int result;
  496. page &= PAGE_MASK;
  497. result = kimage_add_entry(image, page | IND_SOURCE);
  498. if (result == 0)
  499. image->destination += PAGE_SIZE;
  500. return result;
  501. }
  502. static void kimage_free_extra_pages(struct kimage *image)
  503. {
  504. /* Walk through and free any extra destination pages I may have */
  505. kimage_free_page_list(&image->dest_pages);
  506. /* Walk through and free any unuseable pages I have cached */
  507. kimage_free_page_list(&image->unuseable_pages);
  508. }
  509. static int kimage_terminate(struct kimage *image)
  510. {
  511. if (*image->entry != 0)
  512. image->entry++;
  513. *image->entry = IND_DONE;
  514. return 0;
  515. }
  516. #define for_each_kimage_entry(image, ptr, entry) \
  517. for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); \
  518. ptr = (entry & IND_INDIRECTION)? \
  519. phys_to_virt((entry & PAGE_MASK)): ptr +1)
  520. static void kimage_free_entry(kimage_entry_t entry)
  521. {
  522. struct page *page;
  523. page = pfn_to_page(entry >> PAGE_SHIFT);
  524. kimage_free_pages(page);
  525. }
  526. static void kimage_free(struct kimage *image)
  527. {
  528. kimage_entry_t *ptr, entry;
  529. kimage_entry_t ind = 0;
  530. if (!image)
  531. return;
  532. kimage_free_extra_pages(image);
  533. for_each_kimage_entry(image, ptr, entry) {
  534. if (entry & IND_INDIRECTION) {
  535. /* Free the previous indirection page */
  536. if (ind & IND_INDIRECTION)
  537. kimage_free_entry(ind);
  538. /* Save this indirection page until we are
  539. * done with it.
  540. */
  541. ind = entry;
  542. }
  543. else if (entry & IND_SOURCE)
  544. kimage_free_entry(entry);
  545. }
  546. /* Free the final indirection page */
  547. if (ind & IND_INDIRECTION)
  548. kimage_free_entry(ind);
  549. /* Handle any machine specific cleanup */
  550. machine_kexec_cleanup(image);
  551. /* Free the kexec control pages... */
  552. kimage_free_page_list(&image->control_pages);
  553. kfree(image);
  554. }
  555. static kimage_entry_t *kimage_dst_used(struct kimage *image,
  556. unsigned long page)
  557. {
  558. kimage_entry_t *ptr, entry;
  559. unsigned long destination = 0;
  560. for_each_kimage_entry(image, ptr, entry) {
  561. if (entry & IND_DESTINATION)
  562. destination = entry & PAGE_MASK;
  563. else if (entry & IND_SOURCE) {
  564. if (page == destination)
  565. return ptr;
  566. destination += PAGE_SIZE;
  567. }
  568. }
  569. return NULL;
  570. }
  571. static struct page *kimage_alloc_page(struct kimage *image,
  572. gfp_t gfp_mask,
  573. unsigned long destination)
  574. {
  575. /*
  576. * Here we implement safeguards to ensure that a source page
  577. * is not copied to its destination page before the data on
  578. * the destination page is no longer useful.
  579. *
  580. * To do this we maintain the invariant that a source page is
  581. * either its own destination page, or it is not a
  582. * destination page at all.
  583. *
  584. * That is slightly stronger than required, but the proof
  585. * that no problems will not occur is trivial, and the
  586. * implementation is simply to verify.
  587. *
  588. * When allocating all pages normally this algorithm will run
  589. * in O(N) time, but in the worst case it will run in O(N^2)
  590. * time. If the runtime is a problem the data structures can
  591. * be fixed.
  592. */
  593. struct page *page;
  594. unsigned long addr;
  595. /*
  596. * Walk through the list of destination pages, and see if I
  597. * have a match.
  598. */
  599. list_for_each_entry(page, &image->dest_pages, lru) {
  600. addr = page_to_pfn(page) << PAGE_SHIFT;
  601. if (addr == destination) {
  602. list_del(&page->lru);
  603. return page;
  604. }
  605. }
  606. page = NULL;
  607. while (1) {
  608. kimage_entry_t *old;
  609. /* Allocate a page, if we run out of memory give up */
  610. page = kimage_alloc_pages(gfp_mask, 0);
  611. if (!page)
  612. return NULL;
  613. /* If the page cannot be used file it away */
  614. if (page_to_pfn(page) >
  615. (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) {
  616. list_add(&page->lru, &image->unuseable_pages);
  617. continue;
  618. }
  619. addr = page_to_pfn(page) << PAGE_SHIFT;
  620. /* If it is the destination page we want use it */
  621. if (addr == destination)
  622. break;
  623. /* If the page is not a destination page use it */
  624. if (!kimage_is_destination_range(image, addr,
  625. addr + PAGE_SIZE))
  626. break;
  627. /*
  628. * I know that the page is someones destination page.
  629. * See if there is already a source page for this
  630. * destination page. And if so swap the source pages.
  631. */
  632. old = kimage_dst_used(image, addr);
  633. if (old) {
  634. /* If so move it */
  635. unsigned long old_addr;
  636. struct page *old_page;
  637. old_addr = *old & PAGE_MASK;
  638. old_page = pfn_to_page(old_addr >> PAGE_SHIFT);
  639. copy_highpage(page, old_page);
  640. *old = addr | (*old & ~PAGE_MASK);
  641. /* The old page I have found cannot be a
  642. * destination page, so return it.
  643. */
  644. addr = old_addr;
  645. page = old_page;
  646. break;
  647. }
  648. else {
  649. /* Place the page on the destination list I
  650. * will use it later.
  651. */
  652. list_add(&page->lru, &image->dest_pages);
  653. }
  654. }
  655. return page;
  656. }
  657. static int kimage_load_normal_segment(struct kimage *image,
  658. struct kexec_segment *segment)
  659. {
  660. unsigned long maddr;
  661. unsigned long ubytes, mbytes;
  662. int result;
  663. unsigned char __user *buf;
  664. result = 0;
  665. buf = segment->buf;
  666. ubytes = segment->bufsz;
  667. mbytes = segment->memsz;
  668. maddr = segment->mem;
  669. result = kimage_set_destination(image, maddr);
  670. if (result < 0)
  671. goto out;
  672. while (mbytes) {
  673. struct page *page;
  674. char *ptr;
  675. size_t uchunk, mchunk;
  676. page = kimage_alloc_page(image, GFP_HIGHUSER, maddr);
  677. if (!page) {
  678. result = -ENOMEM;
  679. goto out;
  680. }
  681. result = kimage_add_page(image, page_to_pfn(page)
  682. << PAGE_SHIFT);
  683. if (result < 0)
  684. goto out;
  685. ptr = kmap(page);
  686. /* Start with a clear page */
  687. memset(ptr, 0, PAGE_SIZE);
  688. ptr += maddr & ~PAGE_MASK;
  689. mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
  690. if (mchunk > mbytes)
  691. mchunk = mbytes;
  692. uchunk = mchunk;
  693. if (uchunk > ubytes)
  694. uchunk = ubytes;
  695. result = copy_from_user(ptr, buf, uchunk);
  696. kunmap(page);
  697. if (result) {
  698. result = (result < 0) ? result : -EIO;
  699. goto out;
  700. }
  701. ubytes -= uchunk;
  702. maddr += mchunk;
  703. buf += mchunk;
  704. mbytes -= mchunk;
  705. }
  706. out:
  707. return result;
  708. }
  709. static int kimage_load_crash_segment(struct kimage *image,
  710. struct kexec_segment *segment)
  711. {
  712. /* For crash dumps kernels we simply copy the data from
  713. * user space to it's destination.
  714. * We do things a page at a time for the sake of kmap.
  715. */
  716. unsigned long maddr;
  717. unsigned long ubytes, mbytes;
  718. int result;
  719. unsigned char __user *buf;
  720. result = 0;
  721. buf = segment->buf;
  722. ubytes = segment->bufsz;
  723. mbytes = segment->memsz;
  724. maddr = segment->mem;
  725. while (mbytes) {
  726. struct page *page;
  727. char *ptr;
  728. size_t uchunk, mchunk;
  729. page = pfn_to_page(maddr >> PAGE_SHIFT);
  730. if (!page) {
  731. result = -ENOMEM;
  732. goto out;
  733. }
  734. ptr = kmap(page);
  735. ptr += maddr & ~PAGE_MASK;
  736. mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
  737. if (mchunk > mbytes)
  738. mchunk = mbytes;
  739. uchunk = mchunk;
  740. if (uchunk > ubytes) {
  741. uchunk = ubytes;
  742. /* Zero the trailing part of the page */
  743. memset(ptr + uchunk, 0, mchunk - uchunk);
  744. }
  745. result = copy_from_user(ptr, buf, uchunk);
  746. kexec_flush_icache_page(page);
  747. kunmap(page);
  748. if (result) {
  749. result = (result < 0) ? result : -EIO;
  750. goto out;
  751. }
  752. ubytes -= uchunk;
  753. maddr += mchunk;
  754. buf += mchunk;
  755. mbytes -= mchunk;
  756. }
  757. out:
  758. return result;
  759. }
  760. static int kimage_load_segment(struct kimage *image,
  761. struct kexec_segment *segment)
  762. {
  763. int result = -ENOMEM;
  764. switch (image->type) {
  765. case KEXEC_TYPE_DEFAULT:
  766. result = kimage_load_normal_segment(image, segment);
  767. break;
  768. case KEXEC_TYPE_CRASH:
  769. result = kimage_load_crash_segment(image, segment);
  770. break;
  771. }
  772. return result;
  773. }
  774. /*
  775. * Exec Kernel system call: for obvious reasons only root may call it.
  776. *
  777. * This call breaks up into three pieces.
  778. * - A generic part which loads the new kernel from the current
  779. * address space, and very carefully places the data in the
  780. * allocated pages.
  781. *
  782. * - A generic part that interacts with the kernel and tells all of
  783. * the devices to shut down. Preventing on-going dmas, and placing
  784. * the devices in a consistent state so a later kernel can
  785. * reinitialize them.
  786. *
  787. * - A machine specific part that includes the syscall number
  788. * and the copies the image to it's final destination. And
  789. * jumps into the image at entry.
  790. *
  791. * kexec does not sync, or unmount filesystems so if you need
  792. * that to happen you need to do that yourself.
  793. */
  794. struct kimage *kexec_image;
  795. struct kimage *kexec_crash_image;
  796. /*
  797. * A home grown binary mutex.
  798. * Nothing can wait so this mutex is safe to use
  799. * in interrupt context :)
  800. */
  801. static int kexec_lock;
  802. asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
  803. struct kexec_segment __user *segments,
  804. unsigned long flags)
  805. {
  806. struct kimage **dest_image, *image;
  807. int locked;
  808. int result;
  809. /* We only trust the superuser with rebooting the system. */
  810. if (!capable(CAP_SYS_BOOT))
  811. return -EPERM;
  812. /*
  813. * Verify we have a legal set of flags
  814. * This leaves us room for future extensions.
  815. */
  816. if ((flags & KEXEC_FLAGS) != (flags & ~KEXEC_ARCH_MASK))
  817. return -EINVAL;
  818. /* Verify we are on the appropriate architecture */
  819. if (((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH) &&
  820. ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT))
  821. return -EINVAL;
  822. /* Put an artificial cap on the number
  823. * of segments passed to kexec_load.
  824. */
  825. if (nr_segments > KEXEC_SEGMENT_MAX)
  826. return -EINVAL;
  827. image = NULL;
  828. result = 0;
  829. /* Because we write directly to the reserved memory
  830. * region when loading crash kernels we need a mutex here to
  831. * prevent multiple crash kernels from attempting to load
  832. * simultaneously, and to prevent a crash kernel from loading
  833. * over the top of a in use crash kernel.
  834. *
  835. * KISS: always take the mutex.
  836. */
  837. locked = xchg(&kexec_lock, 1);
  838. if (locked)
  839. return -EBUSY;
  840. dest_image = &kexec_image;
  841. if (flags & KEXEC_ON_CRASH)
  842. dest_image = &kexec_crash_image;
  843. if (nr_segments > 0) {
  844. unsigned long i;
  845. /* Loading another kernel to reboot into */
  846. if ((flags & KEXEC_ON_CRASH) == 0)
  847. result = kimage_normal_alloc(&image, entry,
  848. nr_segments, segments);
  849. /* Loading another kernel to switch to if this one crashes */
  850. else if (flags & KEXEC_ON_CRASH) {
  851. /* Free any current crash dump kernel before
  852. * we corrupt it.
  853. */
  854. kimage_free(xchg(&kexec_crash_image, NULL));
  855. result = kimage_crash_alloc(&image, entry,
  856. nr_segments, segments);
  857. }
  858. if (result)
  859. goto out;
  860. result = machine_kexec_prepare(image);
  861. if (result)
  862. goto out;
  863. for (i = 0; i < nr_segments; i++) {
  864. result = kimage_load_segment(image, &image->segment[i]);
  865. if (result)
  866. goto out;
  867. }
  868. result = kimage_terminate(image);
  869. if (result)
  870. goto out;
  871. }
  872. /* Install the new kernel, and Uninstall the old */
  873. image = xchg(dest_image, image);
  874. out:
  875. locked = xchg(&kexec_lock, 0); /* Release the mutex */
  876. BUG_ON(!locked);
  877. kimage_free(image);
  878. return result;
  879. }
  880. #ifdef CONFIG_COMPAT
  881. asmlinkage long compat_sys_kexec_load(unsigned long entry,
  882. unsigned long nr_segments,
  883. struct compat_kexec_segment __user *segments,
  884. unsigned long flags)
  885. {
  886. struct compat_kexec_segment in;
  887. struct kexec_segment out, __user *ksegments;
  888. unsigned long i, result;
  889. /* Don't allow clients that don't understand the native
  890. * architecture to do anything.
  891. */
  892. if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT)
  893. return -EINVAL;
  894. if (nr_segments > KEXEC_SEGMENT_MAX)
  895. return -EINVAL;
  896. ksegments = compat_alloc_user_space(nr_segments * sizeof(out));
  897. for (i=0; i < nr_segments; i++) {
  898. result = copy_from_user(&in, &segments[i], sizeof(in));
  899. if (result)
  900. return -EFAULT;
  901. out.buf = compat_ptr(in.buf);
  902. out.bufsz = in.bufsz;
  903. out.mem = in.mem;
  904. out.memsz = in.memsz;
  905. result = copy_to_user(&ksegments[i], &out, sizeof(out));
  906. if (result)
  907. return -EFAULT;
  908. }
  909. return sys_kexec_load(entry, nr_segments, ksegments, flags);
  910. }
  911. #endif
  912. void crash_kexec(struct pt_regs *regs)
  913. {
  914. int locked;
  915. /* Take the kexec_lock here to prevent sys_kexec_load
  916. * running on one cpu from replacing the crash kernel
  917. * we are using after a panic on a different cpu.
  918. *
  919. * If the crash kernel was not located in a fixed area
  920. * of memory the xchg(&kexec_crash_image) would be
  921. * sufficient. But since I reuse the memory...
  922. */
  923. locked = xchg(&kexec_lock, 1);
  924. if (!locked) {
  925. if (kexec_crash_image) {
  926. struct pt_regs fixed_regs;
  927. crash_setup_regs(&fixed_regs, regs);
  928. crash_save_vmcoreinfo();
  929. machine_crash_shutdown(&fixed_regs);
  930. machine_kexec(kexec_crash_image);
  931. }
  932. locked = xchg(&kexec_lock, 0);
  933. BUG_ON(!locked);
  934. }
  935. }
  936. static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
  937. size_t data_len)
  938. {
  939. struct elf_note note;
  940. note.n_namesz = strlen(name) + 1;
  941. note.n_descsz = data_len;
  942. note.n_type = type;
  943. memcpy(buf, &note, sizeof(note));
  944. buf += (sizeof(note) + 3)/4;
  945. memcpy(buf, name, note.n_namesz);
  946. buf += (note.n_namesz + 3)/4;
  947. memcpy(buf, data, note.n_descsz);
  948. buf += (note.n_descsz + 3)/4;
  949. return buf;
  950. }
  951. static void final_note(u32 *buf)
  952. {
  953. struct elf_note note;
  954. note.n_namesz = 0;
  955. note.n_descsz = 0;
  956. note.n_type = 0;
  957. memcpy(buf, &note, sizeof(note));
  958. }
  959. void crash_save_cpu(struct pt_regs *regs, int cpu)
  960. {
  961. struct elf_prstatus prstatus;
  962. u32 *buf;
  963. if ((cpu < 0) || (cpu >= NR_CPUS))
  964. return;
  965. /* Using ELF notes here is opportunistic.
  966. * I need a well defined structure format
  967. * for the data I pass, and I need tags
  968. * on the data to indicate what information I have
  969. * squirrelled away. ELF notes happen to provide
  970. * all of that, so there is no need to invent something new.
  971. */
  972. buf = (u32*)per_cpu_ptr(crash_notes, cpu);
  973. if (!buf)
  974. return;
  975. memset(&prstatus, 0, sizeof(prstatus));
  976. prstatus.pr_pid = current->pid;
  977. elf_core_copy_regs(&prstatus.pr_reg, regs);
  978. buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS,
  979. &prstatus, sizeof(prstatus));
  980. final_note(buf);
  981. }
  982. static int __init crash_notes_memory_init(void)
  983. {
  984. /* Allocate memory for saving cpu registers. */
  985. crash_notes = alloc_percpu(note_buf_t);
  986. if (!crash_notes) {
  987. printk("Kexec: Memory allocation for saving cpu register"
  988. " states failed\n");
  989. return -ENOMEM;
  990. }
  991. return 0;
  992. }
  993. module_init(crash_notes_memory_init)
  994. /*
  995. * parsing the "crashkernel" commandline
  996. *
  997. * this code is intended to be called from architecture specific code
  998. */
  999. /*
  1000. * This function parses command lines in the format
  1001. *
  1002. * crashkernel=ramsize-range:size[,...][@offset]
  1003. *
  1004. * The function returns 0 on success and -EINVAL on failure.
  1005. */
  1006. static int __init parse_crashkernel_mem(char *cmdline,
  1007. unsigned long long system_ram,
  1008. unsigned long long *crash_size,
  1009. unsigned long long *crash_base)
  1010. {
  1011. char *cur = cmdline, *tmp;
  1012. /* for each entry of the comma-separated list */
  1013. do {
  1014. unsigned long long start, end = ULLONG_MAX, size;
  1015. /* get the start of the range */
  1016. start = memparse(cur, &tmp);
  1017. if (cur == tmp) {
  1018. pr_warning("crashkernel: Memory value expected\n");
  1019. return -EINVAL;
  1020. }
  1021. cur = tmp;
  1022. if (*cur != '-') {
  1023. pr_warning("crashkernel: '-' expected\n");
  1024. return -EINVAL;
  1025. }
  1026. cur++;
  1027. /* if no ':' is here, than we read the end */
  1028. if (*cur != ':') {
  1029. end = memparse(cur, &tmp);
  1030. if (cur == tmp) {
  1031. pr_warning("crashkernel: Memory "
  1032. "value expected\n");
  1033. return -EINVAL;
  1034. }
  1035. cur = tmp;
  1036. if (end <= start) {
  1037. pr_warning("crashkernel: end <= start\n");
  1038. return -EINVAL;
  1039. }
  1040. }
  1041. if (*cur != ':') {
  1042. pr_warning("crashkernel: ':' expected\n");
  1043. return -EINVAL;
  1044. }
  1045. cur++;
  1046. size = memparse(cur, &tmp);
  1047. if (cur == tmp) {
  1048. pr_warning("Memory value expected\n");
  1049. return -EINVAL;
  1050. }
  1051. cur = tmp;
  1052. if (size >= system_ram) {
  1053. pr_warning("crashkernel: invalid size\n");
  1054. return -EINVAL;
  1055. }
  1056. /* match ? */
  1057. if (system_ram >= start && system_ram < end) {
  1058. *crash_size = size;
  1059. break;
  1060. }
  1061. } while (*cur++ == ',');
  1062. if (*crash_size > 0) {
  1063. while (*cur != ' ' && *cur != '@')
  1064. cur++;
  1065. if (*cur == '@') {
  1066. cur++;
  1067. *crash_base = memparse(cur, &tmp);
  1068. if (cur == tmp) {
  1069. pr_warning("Memory value expected "
  1070. "after '@'\n");
  1071. return -EINVAL;
  1072. }
  1073. }
  1074. }
  1075. return 0;
  1076. }
  1077. /*
  1078. * That function parses "simple" (old) crashkernel command lines like
  1079. *
  1080. * crashkernel=size[@offset]
  1081. *
  1082. * It returns 0 on success and -EINVAL on failure.
  1083. */
  1084. static int __init parse_crashkernel_simple(char *cmdline,
  1085. unsigned long long *crash_size,
  1086. unsigned long long *crash_base)
  1087. {
  1088. char *cur = cmdline;
  1089. *crash_size = memparse(cmdline, &cur);
  1090. if (cmdline == cur) {
  1091. pr_warning("crashkernel: memory value expected\n");
  1092. return -EINVAL;
  1093. }
  1094. if (*cur == '@')
  1095. *crash_base = memparse(cur+1, &cur);
  1096. return 0;
  1097. }
  1098. /*
  1099. * That function is the entry point for command line parsing and should be
  1100. * called from the arch-specific code.
  1101. */
  1102. int __init parse_crashkernel(char *cmdline,
  1103. unsigned long long system_ram,
  1104. unsigned long long *crash_size,
  1105. unsigned long long *crash_base)
  1106. {
  1107. char *p = cmdline, *ck_cmdline = NULL;
  1108. char *first_colon, *first_space;
  1109. BUG_ON(!crash_size || !crash_base);
  1110. *crash_size = 0;
  1111. *crash_base = 0;
  1112. /* find crashkernel and use the last one if there are more */
  1113. p = strstr(p, "crashkernel=");
  1114. while (p) {
  1115. ck_cmdline = p;
  1116. p = strstr(p+1, "crashkernel=");
  1117. }
  1118. if (!ck_cmdline)
  1119. return -EINVAL;
  1120. ck_cmdline += 12; /* strlen("crashkernel=") */
  1121. /*
  1122. * if the commandline contains a ':', then that's the extended
  1123. * syntax -- if not, it must be the classic syntax
  1124. */
  1125. first_colon = strchr(ck_cmdline, ':');
  1126. first_space = strchr(ck_cmdline, ' ');
  1127. if (first_colon && (!first_space || first_colon < first_space))
  1128. return parse_crashkernel_mem(ck_cmdline, system_ram,
  1129. crash_size, crash_base);
  1130. else
  1131. return parse_crashkernel_simple(ck_cmdline, crash_size,
  1132. crash_base);
  1133. return 0;
  1134. }
  1135. void crash_save_vmcoreinfo(void)
  1136. {
  1137. u32 *buf;
  1138. if (!vmcoreinfo_size)
  1139. return;
  1140. vmcoreinfo_append_str("CRASHTIME=%ld", get_seconds());
  1141. buf = (u32 *)vmcoreinfo_note;
  1142. buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data,
  1143. vmcoreinfo_size);
  1144. final_note(buf);
  1145. }
  1146. void vmcoreinfo_append_str(const char *fmt, ...)
  1147. {
  1148. va_list args;
  1149. char buf[0x50];
  1150. int r;
  1151. va_start(args, fmt);
  1152. r = vsnprintf(buf, sizeof(buf), fmt, args);
  1153. va_end(args);
  1154. if (r + vmcoreinfo_size > vmcoreinfo_max_size)
  1155. r = vmcoreinfo_max_size - vmcoreinfo_size;
  1156. memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r);
  1157. vmcoreinfo_size += r;
  1158. }
  1159. /*
  1160. * provide an empty default implementation here -- architecture
  1161. * code may override this
  1162. */
  1163. void __attribute__ ((weak)) arch_crash_save_vmcoreinfo(void)
  1164. {}
  1165. unsigned long __attribute__ ((weak)) paddr_vmcoreinfo_note(void)
  1166. {
  1167. return __pa((unsigned long)(char *)&vmcoreinfo_note);
  1168. }
  1169. static int __init crash_save_vmcoreinfo_init(void)
  1170. {
  1171. VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
  1172. VMCOREINFO_PAGESIZE(PAGE_SIZE);
  1173. VMCOREINFO_SYMBOL(init_uts_ns);
  1174. VMCOREINFO_SYMBOL(node_online_map);
  1175. VMCOREINFO_SYMBOL(swapper_pg_dir);
  1176. VMCOREINFO_SYMBOL(_stext);
  1177. #ifndef CONFIG_NEED_MULTIPLE_NODES
  1178. VMCOREINFO_SYMBOL(mem_map);
  1179. VMCOREINFO_SYMBOL(contig_page_data);
  1180. #endif
  1181. #ifdef CONFIG_SPARSEMEM
  1182. VMCOREINFO_SYMBOL(mem_section);
  1183. VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS);
  1184. VMCOREINFO_STRUCT_SIZE(mem_section);
  1185. VMCOREINFO_OFFSET(mem_section, section_mem_map);
  1186. #endif
  1187. VMCOREINFO_STRUCT_SIZE(page);
  1188. VMCOREINFO_STRUCT_SIZE(pglist_data);
  1189. VMCOREINFO_STRUCT_SIZE(zone);
  1190. VMCOREINFO_STRUCT_SIZE(free_area);
  1191. VMCOREINFO_STRUCT_SIZE(list_head);
  1192. VMCOREINFO_SIZE(nodemask_t);
  1193. VMCOREINFO_OFFSET(page, flags);
  1194. VMCOREINFO_OFFSET(page, _count);
  1195. VMCOREINFO_OFFSET(page, mapping);
  1196. VMCOREINFO_OFFSET(page, lru);
  1197. VMCOREINFO_OFFSET(pglist_data, node_zones);
  1198. VMCOREINFO_OFFSET(pglist_data, nr_zones);
  1199. #ifdef CONFIG_FLAT_NODE_MEM_MAP
  1200. VMCOREINFO_OFFSET(pglist_data, node_mem_map);
  1201. #endif
  1202. VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
  1203. VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
  1204. VMCOREINFO_OFFSET(pglist_data, node_id);
  1205. VMCOREINFO_OFFSET(zone, free_area);
  1206. VMCOREINFO_OFFSET(zone, vm_stat);
  1207. VMCOREINFO_OFFSET(zone, spanned_pages);
  1208. VMCOREINFO_OFFSET(free_area, free_list);
  1209. VMCOREINFO_OFFSET(list_head, next);
  1210. VMCOREINFO_OFFSET(list_head, prev);
  1211. VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER);
  1212. VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES);
  1213. VMCOREINFO_NUMBER(NR_FREE_PAGES);
  1214. VMCOREINFO_NUMBER(PG_lru);
  1215. VMCOREINFO_NUMBER(PG_private);
  1216. VMCOREINFO_NUMBER(PG_swapcache);
  1217. arch_crash_save_vmcoreinfo();
  1218. return 0;
  1219. }
  1220. module_init(crash_save_vmcoreinfo_init)