Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
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 /* For IS_ENABLED(CONFIG_CRASH_DUMP) */
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 /* Architecture code defines this if there are other possible ELF
0035  * machine types, e.g. on bi-arch capable hardware. */
0036 #ifndef vmcore_elf_check_arch_cross
0037 #define vmcore_elf_check_arch_cross(x) 0
0038 #endif
0039 
0040 /*
0041  * Architecture code can redefine this if there are any special checks
0042  * needed for 32-bit ELF or 64-bit ELF vmcores.  In case of 32-bit
0043  * only architecture, vmcore_elf64_check_arch can be set to zero.
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  * is_kdump_kernel() checks whether this kernel is booting after a panic of
0055  * previous kernel or not. This is determined by checking if previous kernel
0056  * has passed the elf core header address on command line.
0057  *
0058  * This is not just a test if CONFIG_CRASH_DUMP is enabled or not. It will
0059  * return true if CONFIG_CRASH_DUMP=y and if kernel is booting after a panic
0060  * of previous kernel.
0061  */
0062 
0063 static inline bool is_kdump_kernel(void)
0064 {
0065     return elfcorehdr_addr != ELFCORE_ADDR_MAX;
0066 }
0067 
0068 /* is_vmcore_usable() checks if the kernel is booting after a panic and
0069  * the vmcore region is usable.
0070  *
0071  * This makes use of the fact that due to alignment -2ULL is not
0072  * a valid pointer, much in the vain of IS_ERR(), except
0073  * dealing directly with an unsigned long long rather than a pointer.
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 /* vmcore_unusable() marks the vmcore as unusable,
0082  * without disturbing the logic of is_kdump_kernel()
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  * struct vmcore_cb - driver callbacks for /proc/vmcore handling
0093  * @pfn_is_ram: check whether a PFN really is RAM and should be accessed when
0094  *              reading the vmcore. Will return "true" if it is RAM or if the
0095  *              callback cannot tell. If any callback returns "false", it's not
0096  *              RAM and the page must not be accessed; zeroes should be
0097  *              indicated in the vmcore instead. For example, a ballooned page
0098  *              contains no data and reading from such a page will cause high
0099  *              load in the hypervisor.
0100  * @next: List head to manage registered callbacks internally; initialized by
0101  *        register_vmcore_cb().
0102  *
0103  * vmcore callbacks allow drivers managing physical memory ranges to
0104  * coordinate with vmcore handling code, for example, to prevent accessing
0105  * physical memory ranges that should not be accessed when reading the vmcore,
0106  * although included in the vmcore header as memory ranges to dump.
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 /* !CONFIG_CRASH_DUMP */
0116 static inline bool is_kdump_kernel(void) { return false; }
0117 #endif /* CONFIG_CRASH_DUMP */
0118 
0119 /* Device Dump information to be filled by drivers */
0120 struct vmcoredd_data {
0121     char dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Unique name of the dump */
0122     unsigned int size;                       /* Size of the dump */
0123     /* Driver's registered callback to be invoked to collect dump */
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 /* CONFIG_PROC_VMCORE_DEVICE_DUMP */
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 /* CONFIG_PROC_VMCORE */
0146 
0147 #endif /* LINUX_CRASHDUMP_H */