crash_dump.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef LINUX_CRASH_DUMP_H
  3. #define LINUX_CRASH_DUMP_H
  4. #include <linux/kexec.h>
  5. #include <linux/proc_fs.h>
  6. #include <linux/elf.h>
  7. #include <uapi/linux/vmcore.h>
  8. #include <asm/pgtable.h> /* for pgprot_t */
  9. #ifdef CONFIG_CRASH_DUMP
  10. #define ELFCORE_ADDR_MAX (-1ULL)
  11. #define ELFCORE_ADDR_ERR (-2ULL)
  12. extern unsigned long long elfcorehdr_addr;
  13. extern unsigned long long elfcorehdr_size;
  14. extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size);
  15. extern void elfcorehdr_free(unsigned long long addr);
  16. extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos);
  17. extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
  18. extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
  19. unsigned long from, unsigned long pfn,
  20. unsigned long size, pgprot_t prot);
  21. extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
  22. unsigned long, int);
  23. extern ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf,
  24. size_t csize, unsigned long offset,
  25. int userbuf);
  26. void vmcore_cleanup(void);
  27. /* Architecture code defines this if there are other possible ELF
  28. * machine types, e.g. on bi-arch capable hardware. */
  29. #ifndef vmcore_elf_check_arch_cross
  30. #define vmcore_elf_check_arch_cross(x) 0
  31. #endif
  32. /*
  33. * Architecture code can redefine this if there are any special checks
  34. * needed for 32-bit ELF or 64-bit ELF vmcores. In case of 32-bit
  35. * only architecture, vmcore_elf64_check_arch can be set to zero.
  36. */
  37. #ifndef vmcore_elf32_check_arch
  38. #define vmcore_elf32_check_arch(x) elf_check_arch(x)
  39. #endif
  40. #ifndef vmcore_elf64_check_arch
  41. #define vmcore_elf64_check_arch(x) (elf_check_arch(x) || vmcore_elf_check_arch_cross(x))
  42. #endif
  43. /*
  44. * is_kdump_kernel() checks whether this kernel is booting after a panic of
  45. * previous kernel or not. This is determined by checking if previous kernel
  46. * has passed the elf core header address on command line.
  47. *
  48. * This is not just a test if CONFIG_CRASH_DUMP is enabled or not. It will
  49. * return true if CONFIG_CRASH_DUMP=y and if kernel is booting after a panic
  50. * of previous kernel.
  51. */
  52. static inline bool is_kdump_kernel(void)
  53. {
  54. return elfcorehdr_addr != ELFCORE_ADDR_MAX;
  55. }
  56. /* is_vmcore_usable() checks if the kernel is booting after a panic and
  57. * the vmcore region is usable.
  58. *
  59. * This makes use of the fact that due to alignment -2ULL is not
  60. * a valid pointer, much in the vain of IS_ERR(), except
  61. * dealing directly with an unsigned long long rather than a pointer.
  62. */
  63. static inline int is_vmcore_usable(void)
  64. {
  65. return is_kdump_kernel() && elfcorehdr_addr != ELFCORE_ADDR_ERR ? 1 : 0;
  66. }
  67. /* vmcore_unusable() marks the vmcore as unusable,
  68. * without disturbing the logic of is_kdump_kernel()
  69. */
  70. static inline void vmcore_unusable(void)
  71. {
  72. if (is_kdump_kernel())
  73. elfcorehdr_addr = ELFCORE_ADDR_ERR;
  74. }
  75. #define HAVE_OLDMEM_PFN_IS_RAM 1
  76. extern int register_oldmem_pfn_is_ram(int (*fn)(unsigned long pfn));
  77. extern void unregister_oldmem_pfn_is_ram(void);
  78. #else /* !CONFIG_CRASH_DUMP */
  79. static inline bool is_kdump_kernel(void) { return 0; }
  80. #endif /* CONFIG_CRASH_DUMP */
  81. extern unsigned long saved_max_pfn;
  82. /* Device Dump information to be filled by drivers */
  83. struct vmcoredd_data {
  84. char dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Unique name of the dump */
  85. unsigned int size; /* Size of the dump */
  86. /* Driver's registered callback to be invoked to collect dump */
  87. int (*vmcoredd_callback)(struct vmcoredd_data *data, void *buf);
  88. };
  89. #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP
  90. int vmcore_add_device_dump(struct vmcoredd_data *data);
  91. #else
  92. static inline int vmcore_add_device_dump(struct vmcoredd_data *data)
  93. {
  94. return -EOPNOTSUPP;
  95. }
  96. #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */
  97. #ifdef CONFIG_PROC_VMCORE
  98. ssize_t read_from_oldmem(char *buf, size_t count,
  99. u64 *ppos, int userbuf,
  100. bool encrypted);
  101. #else
  102. static inline ssize_t read_from_oldmem(char *buf, size_t count,
  103. u64 *ppos, int userbuf,
  104. bool encrypted)
  105. {
  106. return -EOPNOTSUPP;
  107. }
  108. #endif /* CONFIG_PROC_VMCORE */
  109. #endif /* LINUX_CRASHDUMP_H */