kexec.c 35 KB

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