0001
0002 #ifndef LINUX_CRASH_DUMP_H
0003 #define LINUX_CRASH_DUMP_H
0004
0005 #include <linux/kexec.h>
0006 #include <linux/proc_fs.h>
0007 #include <linux/elf.h>
0008 #include <linux/pgtable.h>
0009 #include <uapi/linux/vmcore.h>
0010
0011
0012 #define ELFCORE_ADDR_MAX (-1ULL)
0013 #define ELFCORE_ADDR_ERR (-2ULL)
0014
0015 extern unsigned long long elfcorehdr_addr;
0016 extern unsigned long long elfcorehdr_size;
0017
0018 #ifdef CONFIG_CRASH_DUMP
0019 extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size);
0020 extern void elfcorehdr_free(unsigned long long addr);
0021 extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos);
0022 extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
0023 extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
0024 unsigned long from, unsigned long pfn,
0025 unsigned long size, pgprot_t prot);
0026
0027 ssize_t copy_oldmem_page(struct iov_iter *i, unsigned long pfn, size_t csize,
0028 unsigned long offset);
0029 ssize_t copy_oldmem_page_encrypted(struct iov_iter *iter, unsigned long pfn,
0030 size_t csize, unsigned long offset);
0031
0032 void vmcore_cleanup(void);
0033
0034
0035
0036 #ifndef vmcore_elf_check_arch_cross
0037 #define vmcore_elf_check_arch_cross(x) 0
0038 #endif
0039
0040
0041
0042
0043
0044
0045 #ifndef vmcore_elf32_check_arch
0046 #define vmcore_elf32_check_arch(x) elf_check_arch(x)
0047 #endif
0048
0049 #ifndef vmcore_elf64_check_arch
0050 #define vmcore_elf64_check_arch(x) (elf_check_arch(x) || vmcore_elf_check_arch_cross(x))
0051 #endif
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 static inline bool is_kdump_kernel(void)
0064 {
0065 return elfcorehdr_addr != ELFCORE_ADDR_MAX;
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 static inline int is_vmcore_usable(void)
0077 {
0078 return is_kdump_kernel() && elfcorehdr_addr != ELFCORE_ADDR_ERR ? 1 : 0;
0079 }
0080
0081
0082
0083
0084
0085 static inline void vmcore_unusable(void)
0086 {
0087 if (is_kdump_kernel())
0088 elfcorehdr_addr = ELFCORE_ADDR_ERR;
0089 }
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 struct vmcore_cb {
0109 bool (*pfn_is_ram)(struct vmcore_cb *cb, unsigned long pfn);
0110 struct list_head next;
0111 };
0112 extern void register_vmcore_cb(struct vmcore_cb *cb);
0113 extern void unregister_vmcore_cb(struct vmcore_cb *cb);
0114
0115 #else
0116 static inline bool is_kdump_kernel(void) { return false; }
0117 #endif
0118
0119
0120 struct vmcoredd_data {
0121 char dump_name[VMCOREDD_MAX_NAME_BYTES];
0122 unsigned int size;
0123
0124 int (*vmcoredd_callback)(struct vmcoredd_data *data, void *buf);
0125 };
0126
0127 #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP
0128 int vmcore_add_device_dump(struct vmcoredd_data *data);
0129 #else
0130 static inline int vmcore_add_device_dump(struct vmcoredd_data *data)
0131 {
0132 return -EOPNOTSUPP;
0133 }
0134 #endif
0135
0136 #ifdef CONFIG_PROC_VMCORE
0137 ssize_t read_from_oldmem(struct iov_iter *iter, size_t count,
0138 u64 *ppos, bool encrypted);
0139 #else
0140 static inline ssize_t read_from_oldmem(struct iov_iter *iter, size_t count,
0141 u64 *ppos, bool encrypted)
0142 {
0143 return -EOPNOTSUPP;
0144 }
0145 #endif
0146
0147 #endif