kexec.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  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 void kimage_terminate(struct kimage *image)
  510. {
  511. if (*image->entry != 0)
  512. image->entry++;
  513. *image->entry = IND_DONE;
  514. }
  515. #define for_each_kimage_entry(image, ptr, entry) \
  516. for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); \
  517. ptr = (entry & IND_INDIRECTION)? \
  518. phys_to_virt((entry & PAGE_MASK)): ptr +1)
  519. static void kimage_free_entry(kimage_entry_t entry)
  520. {
  521. struct page *page;
  522. page = pfn_to_page(entry >> PAGE_SHIFT);
  523. kimage_free_pages(page);
  524. }
  525. static void kimage_free(struct kimage *image)
  526. {
  527. kimage_entry_t *ptr, entry;
  528. kimage_entry_t ind = 0;
  529. if (!image)
  530. return;
  531. kimage_free_extra_pages(image);
  532. for_each_kimage_entry(image, ptr, entry) {
  533. if (entry & IND_INDIRECTION) {
  534. /* Free the previous indirection page */
  535. if (ind & IND_INDIRECTION)
  536. kimage_free_entry(ind);
  537. /* Save this indirection page until we are
  538. * done with it.
  539. */
  540. ind = entry;
  541. }
  542. else if (entry & IND_SOURCE)
  543. kimage_free_entry(entry);
  544. }
  545. /* Free the final indirection page */
  546. if (ind & IND_INDIRECTION)
  547. kimage_free_entry(ind);
  548. /* Handle any machine specific cleanup */
  549. machine_kexec_cleanup(image);
  550. /* Free the kexec control pages... */
  551. kimage_free_page_list(&image->control_pages);
  552. kfree(image);
  553. }
  554. static kimage_entry_t *kimage_dst_used(struct kimage *image,
  555. unsigned long page)
  556. {
  557. kimage_entry_t *ptr, entry;
  558. unsigned long destination = 0;
  559. for_each_kimage_entry(image, ptr, entry) {
  560. if (entry & IND_DESTINATION)
  561. destination = entry & PAGE_MASK;
  562. else if (entry & IND_SOURCE) {
  563. if (page == destination)
  564. return ptr;
  565. destination += PAGE_SIZE;
  566. }
  567. }
  568. return NULL;
  569. }
  570. static struct page *kimage_alloc_page(struct kimage *image,
  571. gfp_t gfp_mask,
  572. unsigned long destination)
  573. {
  574. /*
  575. * Here we implement safeguards to ensure that a source page
  576. * is not copied to its destination page before the data on
  577. * the destination page is no longer useful.
  578. *
  579. * To do this we maintain the invariant that a source page is
  580. * either its own destination page, or it is not a
  581. * destination page at all.
  582. *
  583. * That is slightly stronger than required, but the proof
  584. * that no problems will not occur is trivial, and the
  585. * implementation is simply to verify.
  586. *
  587. * When allocating all pages normally this algorithm will run
  588. * in O(N) time, but in the worst case it will run in O(N^2)
  589. * time. If the runtime is a problem the data structures can
  590. * be fixed.
  591. */
  592. struct page *page;
  593. unsigned long addr;
  594. /*
  595. * Walk through the list of destination pages, and see if I
  596. * have a match.
  597. */
  598. list_for_each_entry(page, &image->dest_pages, lru) {
  599. addr = page_to_pfn(page) << PAGE_SHIFT;
  600. if (addr == destination) {
  601. list_del(&page->lru);
  602. return page;
  603. }
  604. }
  605. page = NULL;
  606. while (1) {
  607. kimage_entry_t *old;
  608. /* Allocate a page, if we run out of memory give up */
  609. page = kimage_alloc_pages(gfp_mask, 0);
  610. if (!page)
  611. return NULL;
  612. /* If the page cannot be used file it away */
  613. if (page_to_pfn(page) >
  614. (KEXEC_SOURCE_MEMORY_LIMIT >> PAGE_SHIFT)) {
  615. list_add(&page->lru, &image->unuseable_pages);
  616. continue;
  617. }
  618. addr = page_to_pfn(page) << PAGE_SHIFT;
  619. /* If it is the destination page we want use it */
  620. if (addr == destination)
  621. break;
  622. /* If the page is not a destination page use it */
  623. if (!kimage_is_destination_range(image, addr,
  624. addr + PAGE_SIZE))
  625. break;
  626. /*
  627. * I know that the page is someones destination page.
  628. * See if there is already a source page for this
  629. * destination page. And if so swap the source pages.
  630. */
  631. old = kimage_dst_used(image, addr);
  632. if (old) {
  633. /* If so move it */
  634. unsigned long old_addr;
  635. struct page *old_page;
  636. old_addr = *old & PAGE_MASK;
  637. old_page = pfn_to_page(old_addr >> PAGE_SHIFT);
  638. copy_highpage(page, old_page);
  639. *old = addr | (*old & ~PAGE_MASK);
  640. /* The old page I have found cannot be a
  641. * destination page, so return it.
  642. */
  643. addr = old_addr;
  644. page = old_page;
  645. break;
  646. }
  647. else {
  648. /* Place the page on the destination list I
  649. * will use it later.
  650. */
  651. list_add(&page->lru, &image->dest_pages);
  652. }
  653. }
  654. return page;
  655. }
  656. static int kimage_load_normal_segment(struct kimage *image,
  657. struct kexec_segment *segment)
  658. {
  659. unsigned long maddr;
  660. unsigned long ubytes, mbytes;
  661. int result;
  662. unsigned char __user *buf;
  663. result = 0;
  664. buf = segment->buf;
  665. ubytes = segment->bufsz;
  666. mbytes = segment->memsz;
  667. maddr = segment->mem;
  668. result = kimage_set_destination(image, maddr);
  669. if (result < 0)
  670. goto out;
  671. while (mbytes) {
  672. struct page *page;
  673. char *ptr;
  674. size_t uchunk, mchunk;
  675. page = kimage_alloc_page(image, GFP_HIGHUSER, maddr);
  676. if (!page) {
  677. result = -ENOMEM;
  678. goto out;
  679. }
  680. result = kimage_add_page(image, page_to_pfn(page)
  681. << PAGE_SHIFT);
  682. if (result < 0)
  683. goto out;
  684. ptr = kmap(page);
  685. /* Start with a clear page */
  686. memset(ptr, 0, PAGE_SIZE);
  687. ptr += maddr & ~PAGE_MASK;
  688. mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
  689. if (mchunk > mbytes)
  690. mchunk = mbytes;
  691. uchunk = mchunk;
  692. if (uchunk > ubytes)
  693. uchunk = ubytes;
  694. result = copy_from_user(ptr, buf, uchunk);
  695. kunmap(page);
  696. if (result) {
  697. result = (result < 0) ? result : -EIO;
  698. goto out;
  699. }
  700. ubytes -= uchunk;
  701. maddr += mchunk;
  702. buf += mchunk;
  703. mbytes -= mchunk;
  704. }
  705. out:
  706. return result;
  707. }
  708. static int kimage_load_crash_segment(struct kimage *image,
  709. struct kexec_segment *segment)
  710. {
  711. /* For crash dumps kernels we simply copy the data from
  712. * user space to it's destination.
  713. * We do things a page at a time for the sake of kmap.
  714. */
  715. unsigned long maddr;
  716. unsigned long ubytes, mbytes;
  717. int result;
  718. unsigned char __user *buf;
  719. result = 0;
  720. buf = segment->buf;
  721. ubytes = segment->bufsz;
  722. mbytes = segment->memsz;
  723. maddr = segment->mem;
  724. while (mbytes) {
  725. struct page *page;
  726. char *ptr;
  727. size_t uchunk, mchunk;
  728. page = pfn_to_page(maddr >> PAGE_SHIFT);
  729. if (!page) {
  730. result = -ENOMEM;
  731. goto out;
  732. }
  733. ptr = kmap(page);
  734. ptr += maddr & ~PAGE_MASK;
  735. mchunk = PAGE_SIZE - (maddr & ~PAGE_MASK);
  736. if (mchunk > mbytes)
  737. mchunk = mbytes;
  738. uchunk = mchunk;
  739. if (uchunk > ubytes) {
  740. uchunk = ubytes;
  741. /* Zero the trailing part of the page */
  742. memset(ptr + uchunk, 0, mchunk - uchunk);
  743. }
  744. result = copy_from_user(ptr, buf, uchunk);
  745. kexec_flush_icache_page(page);
  746. kunmap(page);
  747. if (result) {
  748. result = (result < 0) ? result : -EIO;
  749. goto out;
  750. }
  751. ubytes -= uchunk;
  752. maddr += mchunk;
  753. buf += mchunk;
  754. mbytes -= mchunk;
  755. }
  756. out:
  757. return result;
  758. }
  759. static int kimage_load_segment(struct kimage *image,
  760. struct kexec_segment *segment)
  761. {
  762. int result = -ENOMEM;
  763. switch (image->type) {
  764. case KEXEC_TYPE_DEFAULT:
  765. result = kimage_load_normal_segment(image, segment);
  766. break;
  767. case KEXEC_TYPE_CRASH:
  768. result = kimage_load_crash_segment(image, segment);
  769. break;
  770. }
  771. return result;
  772. }
  773. /*
  774. * Exec Kernel system call: for obvious reasons only root may call it.
  775. *
  776. * This call breaks up into three pieces.
  777. * - A generic part which loads the new kernel from the current
  778. * address space, and very carefully places the data in the
  779. * allocated pages.
  780. *
  781. * - A generic part that interacts with the kernel and tells all of
  782. * the devices to shut down. Preventing on-going dmas, and placing
  783. * the devices in a consistent state so a later kernel can
  784. * reinitialize them.
  785. *
  786. * - A machine specific part that includes the syscall number
  787. * and the copies the image to it's final destination. And
  788. * jumps into the image at entry.
  789. *
  790. * kexec does not sync, or unmount filesystems so if you need
  791. * that to happen you need to do that yourself.
  792. */
  793. struct kimage *kexec_image;
  794. struct kimage *kexec_crash_image;
  795. /*
  796. * A home grown binary mutex.
  797. * Nothing can wait so this mutex is safe to use
  798. * in interrupt context :)
  799. */
  800. static int kexec_lock;
  801. asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,
  802. struct kexec_segment __user *segments,
  803. unsigned long flags)
  804. {
  805. struct kimage **dest_image, *image;
  806. int locked;
  807. int result;
  808. /* We only trust the superuser with rebooting the system. */
  809. if (!capable(CAP_SYS_BOOT))
  810. return -EPERM;
  811. /*
  812. * Verify we have a legal set of flags
  813. * This leaves us room for future extensions.
  814. */
  815. if ((flags & KEXEC_FLAGS) != (flags & ~KEXEC_ARCH_MASK))
  816. return -EINVAL;
  817. /* Verify we are on the appropriate architecture */
  818. if (((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH) &&
  819. ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT))
  820. return -EINVAL;
  821. /* Put an artificial cap on the number
  822. * of segments passed to kexec_load.
  823. */
  824. if (nr_segments > KEXEC_SEGMENT_MAX)
  825. return -EINVAL;
  826. image = NULL;
  827. result = 0;
  828. /* Because we write directly to the reserved memory
  829. * region when loading crash kernels we need a mutex here to
  830. * prevent multiple crash kernels from attempting to load
  831. * simultaneously, and to prevent a crash kernel from loading
  832. * over the top of a in use crash kernel.
  833. *
  834. * KISS: always take the mutex.
  835. */
  836. locked = xchg(&kexec_lock, 1);
  837. if (locked)
  838. return -EBUSY;
  839. dest_image = &kexec_image;
  840. if (flags & KEXEC_ON_CRASH)
  841. dest_image = &kexec_crash_image;
  842. if (nr_segments > 0) {
  843. unsigned long i;
  844. /* Loading another kernel to reboot into */
  845. if ((flags & KEXEC_ON_CRASH) == 0)
  846. result = kimage_normal_alloc(&image, entry,
  847. nr_segments, segments);
  848. /* Loading another kernel to switch to if this one crashes */
  849. else if (flags & KEXEC_ON_CRASH) {
  850. /* Free any current crash dump kernel before
  851. * we corrupt it.
  852. */
  853. kimage_free(xchg(&kexec_crash_image, NULL));
  854. result = kimage_crash_alloc(&image, entry,
  855. nr_segments, segments);
  856. }
  857. if (result)
  858. goto out;
  859. result = machine_kexec_prepare(image);
  860. if (result)
  861. goto out;
  862. for (i = 0; i < nr_segments; i++) {
  863. result = kimage_load_segment(image, &image->segment[i]);
  864. if (result)
  865. goto out;
  866. }
  867. kimage_terminate(image);
  868. }
  869. /* Install the new kernel, and Uninstall the old */
  870. image = xchg(dest_image, image);
  871. out:
  872. locked = xchg(&kexec_lock, 0); /* Release the mutex */
  873. BUG_ON(!locked);
  874. kimage_free(image);
  875. return result;
  876. }
  877. #ifdef CONFIG_COMPAT
  878. asmlinkage long compat_sys_kexec_load(unsigned long entry,
  879. unsigned long nr_segments,
  880. struct compat_kexec_segment __user *segments,
  881. unsigned long flags)
  882. {
  883. struct compat_kexec_segment in;
  884. struct kexec_segment out, __user *ksegments;
  885. unsigned long i, result;
  886. /* Don't allow clients that don't understand the native
  887. * architecture to do anything.
  888. */
  889. if ((flags & KEXEC_ARCH_MASK) == KEXEC_ARCH_DEFAULT)
  890. return -EINVAL;
  891. if (nr_segments > KEXEC_SEGMENT_MAX)
  892. return -EINVAL;
  893. ksegments = compat_alloc_user_space(nr_segments * sizeof(out));
  894. for (i=0; i < nr_segments; i++) {
  895. result = copy_from_user(&in, &segments[i], sizeof(in));
  896. if (result)
  897. return -EFAULT;
  898. out.buf = compat_ptr(in.buf);
  899. out.bufsz = in.bufsz;
  900. out.mem = in.mem;
  901. out.memsz = in.memsz;
  902. result = copy_to_user(&ksegments[i], &out, sizeof(out));
  903. if (result)
  904. return -EFAULT;
  905. }
  906. return sys_kexec_load(entry, nr_segments, ksegments, flags);
  907. }
  908. #endif
  909. void crash_kexec(struct pt_regs *regs)
  910. {
  911. int locked;
  912. /* Take the kexec_lock here to prevent sys_kexec_load
  913. * running on one cpu from replacing the crash kernel
  914. * we are using after a panic on a different cpu.
  915. *
  916. * If the crash kernel was not located in a fixed area
  917. * of memory the xchg(&kexec_crash_image) would be
  918. * sufficient. But since I reuse the memory...
  919. */
  920. locked = xchg(&kexec_lock, 1);
  921. if (!locked) {
  922. if (kexec_crash_image) {
  923. struct pt_regs fixed_regs;
  924. crash_setup_regs(&fixed_regs, regs);
  925. crash_save_vmcoreinfo();
  926. machine_crash_shutdown(&fixed_regs);
  927. machine_kexec(kexec_crash_image);
  928. }
  929. locked = xchg(&kexec_lock, 0);
  930. BUG_ON(!locked);
  931. }
  932. }
  933. static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
  934. size_t data_len)
  935. {
  936. struct elf_note note;
  937. note.n_namesz = strlen(name) + 1;
  938. note.n_descsz = data_len;
  939. note.n_type = type;
  940. memcpy(buf, &note, sizeof(note));
  941. buf += (sizeof(note) + 3)/4;
  942. memcpy(buf, name, note.n_namesz);
  943. buf += (note.n_namesz + 3)/4;
  944. memcpy(buf, data, note.n_descsz);
  945. buf += (note.n_descsz + 3)/4;
  946. return buf;
  947. }
  948. static void final_note(u32 *buf)
  949. {
  950. struct elf_note note;
  951. note.n_namesz = 0;
  952. note.n_descsz = 0;
  953. note.n_type = 0;
  954. memcpy(buf, &note, sizeof(note));
  955. }
  956. void crash_save_cpu(struct pt_regs *regs, int cpu)
  957. {
  958. struct elf_prstatus prstatus;
  959. u32 *buf;
  960. if ((cpu < 0) || (cpu >= NR_CPUS))
  961. return;
  962. /* Using ELF notes here is opportunistic.
  963. * I need a well defined structure format
  964. * for the data I pass, and I need tags
  965. * on the data to indicate what information I have
  966. * squirrelled away. ELF notes happen to provide
  967. * all of that, so there is no need to invent something new.
  968. */
  969. buf = (u32*)per_cpu_ptr(crash_notes, cpu);
  970. if (!buf)
  971. return;
  972. memset(&prstatus, 0, sizeof(prstatus));
  973. prstatus.pr_pid = current->pid;
  974. elf_core_copy_regs(&prstatus.pr_reg, regs);
  975. buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS,
  976. &prstatus, sizeof(prstatus));
  977. final_note(buf);
  978. }
  979. static int __init crash_notes_memory_init(void)
  980. {
  981. /* Allocate memory for saving cpu registers. */
  982. crash_notes = alloc_percpu(note_buf_t);
  983. if (!crash_notes) {
  984. printk("Kexec: Memory allocation for saving cpu register"
  985. " states failed\n");
  986. return -ENOMEM;
  987. }
  988. return 0;
  989. }
  990. module_init(crash_notes_memory_init)
  991. /*
  992. * parsing the "crashkernel" commandline
  993. *
  994. * this code is intended to be called from architecture specific code
  995. */
  996. /*
  997. * This function parses command lines in the format
  998. *
  999. * crashkernel=ramsize-range:size[,...][@offset]
  1000. *
  1001. * The function returns 0 on success and -EINVAL on failure.
  1002. */
  1003. static int __init parse_crashkernel_mem(char *cmdline,
  1004. unsigned long long system_ram,
  1005. unsigned long long *crash_size,
  1006. unsigned long long *crash_base)
  1007. {
  1008. char *cur = cmdline, *tmp;
  1009. /* for each entry of the comma-separated list */
  1010. do {
  1011. unsigned long long start, end = ULLONG_MAX, size;
  1012. /* get the start of the range */
  1013. start = memparse(cur, &tmp);
  1014. if (cur == tmp) {
  1015. pr_warning("crashkernel: Memory value expected\n");
  1016. return -EINVAL;
  1017. }
  1018. cur = tmp;
  1019. if (*cur != '-') {
  1020. pr_warning("crashkernel: '-' expected\n");
  1021. return -EINVAL;
  1022. }
  1023. cur++;
  1024. /* if no ':' is here, than we read the end */
  1025. if (*cur != ':') {
  1026. end = memparse(cur, &tmp);
  1027. if (cur == tmp) {
  1028. pr_warning("crashkernel: Memory "
  1029. "value expected\n");
  1030. return -EINVAL;
  1031. }
  1032. cur = tmp;
  1033. if (end <= start) {
  1034. pr_warning("crashkernel: end <= start\n");
  1035. return -EINVAL;
  1036. }
  1037. }
  1038. if (*cur != ':') {
  1039. pr_warning("crashkernel: ':' expected\n");
  1040. return -EINVAL;
  1041. }
  1042. cur++;
  1043. size = memparse(cur, &tmp);
  1044. if (cur == tmp) {
  1045. pr_warning("Memory value expected\n");
  1046. return -EINVAL;
  1047. }
  1048. cur = tmp;
  1049. if (size >= system_ram) {
  1050. pr_warning("crashkernel: invalid size\n");
  1051. return -EINVAL;
  1052. }
  1053. /* match ? */
  1054. if (system_ram >= start && system_ram < end) {
  1055. *crash_size = size;
  1056. break;
  1057. }
  1058. } while (*cur++ == ',');
  1059. if (*crash_size > 0) {
  1060. while (*cur != ' ' && *cur != '@')
  1061. cur++;
  1062. if (*cur == '@') {
  1063. cur++;
  1064. *crash_base = memparse(cur, &tmp);
  1065. if (cur == tmp) {
  1066. pr_warning("Memory value expected "
  1067. "after '@'\n");
  1068. return -EINVAL;
  1069. }
  1070. }
  1071. }
  1072. return 0;
  1073. }
  1074. /*
  1075. * That function parses "simple" (old) crashkernel command lines like
  1076. *
  1077. * crashkernel=size[@offset]
  1078. *
  1079. * It returns 0 on success and -EINVAL on failure.
  1080. */
  1081. static int __init parse_crashkernel_simple(char *cmdline,
  1082. unsigned long long *crash_size,
  1083. unsigned long long *crash_base)
  1084. {
  1085. char *cur = cmdline;
  1086. *crash_size = memparse(cmdline, &cur);
  1087. if (cmdline == cur) {
  1088. pr_warning("crashkernel: memory value expected\n");
  1089. return -EINVAL;
  1090. }
  1091. if (*cur == '@')
  1092. *crash_base = memparse(cur+1, &cur);
  1093. return 0;
  1094. }
  1095. /*
  1096. * That function is the entry point for command line parsing and should be
  1097. * called from the arch-specific code.
  1098. */
  1099. int __init parse_crashkernel(char *cmdline,
  1100. unsigned long long system_ram,
  1101. unsigned long long *crash_size,
  1102. unsigned long long *crash_base)
  1103. {
  1104. char *p = cmdline, *ck_cmdline = NULL;
  1105. char *first_colon, *first_space;
  1106. BUG_ON(!crash_size || !crash_base);
  1107. *crash_size = 0;
  1108. *crash_base = 0;
  1109. /* find crashkernel and use the last one if there are more */
  1110. p = strstr(p, "crashkernel=");
  1111. while (p) {
  1112. ck_cmdline = p;
  1113. p = strstr(p+1, "crashkernel=");
  1114. }
  1115. if (!ck_cmdline)
  1116. return -EINVAL;
  1117. ck_cmdline += 12; /* strlen("crashkernel=") */
  1118. /*
  1119. * if the commandline contains a ':', then that's the extended
  1120. * syntax -- if not, it must be the classic syntax
  1121. */
  1122. first_colon = strchr(ck_cmdline, ':');
  1123. first_space = strchr(ck_cmdline, ' ');
  1124. if (first_colon && (!first_space || first_colon < first_space))
  1125. return parse_crashkernel_mem(ck_cmdline, system_ram,
  1126. crash_size, crash_base);
  1127. else
  1128. return parse_crashkernel_simple(ck_cmdline, crash_size,
  1129. crash_base);
  1130. return 0;
  1131. }
  1132. void crash_save_vmcoreinfo(void)
  1133. {
  1134. u32 *buf;
  1135. if (!vmcoreinfo_size)
  1136. return;
  1137. vmcoreinfo_append_str("CRASHTIME=%ld", get_seconds());
  1138. buf = (u32 *)vmcoreinfo_note;
  1139. buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data,
  1140. vmcoreinfo_size);
  1141. final_note(buf);
  1142. }
  1143. void vmcoreinfo_append_str(const char *fmt, ...)
  1144. {
  1145. va_list args;
  1146. char buf[0x50];
  1147. int r;
  1148. va_start(args, fmt);
  1149. r = vsnprintf(buf, sizeof(buf), fmt, args);
  1150. va_end(args);
  1151. if (r + vmcoreinfo_size > vmcoreinfo_max_size)
  1152. r = vmcoreinfo_max_size - vmcoreinfo_size;
  1153. memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r);
  1154. vmcoreinfo_size += r;
  1155. }
  1156. /*
  1157. * provide an empty default implementation here -- architecture
  1158. * code may override this
  1159. */
  1160. void __attribute__ ((weak)) arch_crash_save_vmcoreinfo(void)
  1161. {}
  1162. unsigned long __attribute__ ((weak)) paddr_vmcoreinfo_note(void)
  1163. {
  1164. return __pa((unsigned long)(char *)&vmcoreinfo_note);
  1165. }
  1166. static int __init crash_save_vmcoreinfo_init(void)
  1167. {
  1168. VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
  1169. VMCOREINFO_PAGESIZE(PAGE_SIZE);
  1170. VMCOREINFO_SYMBOL(init_uts_ns);
  1171. VMCOREINFO_SYMBOL(node_online_map);
  1172. VMCOREINFO_SYMBOL(swapper_pg_dir);
  1173. VMCOREINFO_SYMBOL(_stext);
  1174. #ifndef CONFIG_NEED_MULTIPLE_NODES
  1175. VMCOREINFO_SYMBOL(mem_map);
  1176. VMCOREINFO_SYMBOL(contig_page_data);
  1177. #endif
  1178. #ifdef CONFIG_SPARSEMEM
  1179. VMCOREINFO_SYMBOL(mem_section);
  1180. VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS);
  1181. VMCOREINFO_STRUCT_SIZE(mem_section);
  1182. VMCOREINFO_OFFSET(mem_section, section_mem_map);
  1183. #endif
  1184. VMCOREINFO_STRUCT_SIZE(page);
  1185. VMCOREINFO_STRUCT_SIZE(pglist_data);
  1186. VMCOREINFO_STRUCT_SIZE(zone);
  1187. VMCOREINFO_STRUCT_SIZE(free_area);
  1188. VMCOREINFO_STRUCT_SIZE(list_head);
  1189. VMCOREINFO_SIZE(nodemask_t);
  1190. VMCOREINFO_OFFSET(page, flags);
  1191. VMCOREINFO_OFFSET(page, _count);
  1192. VMCOREINFO_OFFSET(page, mapping);
  1193. VMCOREINFO_OFFSET(page, lru);
  1194. VMCOREINFO_OFFSET(pglist_data, node_zones);
  1195. VMCOREINFO_OFFSET(pglist_data, nr_zones);
  1196. #ifdef CONFIG_FLAT_NODE_MEM_MAP
  1197. VMCOREINFO_OFFSET(pglist_data, node_mem_map);
  1198. #endif
  1199. VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
  1200. VMCOREINFO_OFFSET(pglist_data, node_spanned_pages);
  1201. VMCOREINFO_OFFSET(pglist_data, node_id);
  1202. VMCOREINFO_OFFSET(zone, free_area);
  1203. VMCOREINFO_OFFSET(zone, vm_stat);
  1204. VMCOREINFO_OFFSET(zone, spanned_pages);
  1205. VMCOREINFO_OFFSET(free_area, free_list);
  1206. VMCOREINFO_OFFSET(list_head, next);
  1207. VMCOREINFO_OFFSET(list_head, prev);
  1208. VMCOREINFO_LENGTH(zone.free_area, MAX_ORDER);
  1209. VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES);
  1210. VMCOREINFO_NUMBER(NR_FREE_PAGES);
  1211. VMCOREINFO_NUMBER(PG_lru);
  1212. VMCOREINFO_NUMBER(PG_private);
  1213. VMCOREINFO_NUMBER(PG_swapcache);
  1214. arch_crash_save_vmcoreinfo();
  1215. return 0;
  1216. }
  1217. module_init(crash_save_vmcoreinfo_init)