^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * S390 kdump implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/crash_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/lowcore.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/os_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/ipl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define PTR_ADD(x, y) (((char *) (x)) + ((unsigned long) (y)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define PTR_DIFF(x, y) ((unsigned long)(((char *) (x)) - ((unsigned long) (y))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static struct memblock_region oldmem_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct memblock_type oldmem_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .cnt = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .max = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .total_size = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .regions = &oldmem_region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .name = "oldmem",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct save_area {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u64 psw[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 ctrs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u64 gprs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u32 acrs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u64 fprs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u32 fpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u64 todpreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u64 todcmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u64 vxrs_low[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __vector128 vxrs_high[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static LIST_HEAD(dump_save_areas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Allocate a save area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct save_area * __init save_area_alloc(bool is_boot_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct save_area *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) sa = (void *) memblock_phys_alloc(sizeof(*sa), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (!sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) panic("Failed to allocate save area\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (is_boot_cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) list_add(&sa->list, &dump_save_areas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) list_add_tail(&sa->list, &dump_save_areas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Return the address of the save area for the boot CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct save_area * __init save_area_boot_cpu(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return list_first_entry_or_null(&dump_save_areas, struct save_area, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Copy CPU registers into the save area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void __init save_area_add_regs(struct save_area *sa, void *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct lowcore *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) lc = (struct lowcore *)(regs - __LC_FPREGS_SAVE_AREA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) memcpy(&sa->psw, &lc->psw_save_area, sizeof(sa->psw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) memcpy(&sa->ctrs, &lc->cregs_save_area, sizeof(sa->ctrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) memcpy(&sa->gprs, &lc->gpregs_save_area, sizeof(sa->gprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) memcpy(&sa->acrs, &lc->access_regs_save_area, sizeof(sa->acrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) memcpy(&sa->fprs, &lc->floating_pt_save_area, sizeof(sa->fprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) memcpy(&sa->fpc, &lc->fpt_creg_save_area, sizeof(sa->fpc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) memcpy(&sa->prefix, &lc->prefixreg_save_area, sizeof(sa->prefix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) memcpy(&sa->todpreg, &lc->tod_progreg_save_area, sizeof(sa->todpreg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) memcpy(&sa->timer, &lc->cpu_timer_save_area, sizeof(sa->timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) memcpy(&sa->todcmp, &lc->clock_comp_save_area, sizeof(sa->todcmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * Copy vector registers into the save area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void __init save_area_add_vxrs(struct save_area *sa, __vector128 *vxrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Copy lower halves of vector registers 0-15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) for (i = 0; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) memcpy(&sa->vxrs_low[i], &vxrs[i].u[2], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Copy vector registers 16-31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) memcpy(sa->vxrs_high, vxrs + 16, 16 * sizeof(__vector128));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Return physical address for virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static inline void *load_real_addr(void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned long real_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) " lra %0,0(%1)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) " jz 0f\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) " la %0,0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "0:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) : "=a" (real_addr) : "a" (addr) : "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return (void *)real_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Copy memory of the old, dumped system to a kernel space virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int copy_oldmem_kernel(void *dst, void *src, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) unsigned long from, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void *ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) from = __pa(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!OLDMEM_BASE && from < sclp.hsa_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Copy from zfcp/nvme dump HSA area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) len = min(count, sclp.hsa_size - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) rc = memcpy_hsa_kernel(dst, from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* Check for swapped kdump oldmem areas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (OLDMEM_BASE && from - OLDMEM_BASE < OLDMEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) from -= OLDMEM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) len = min(count, OLDMEM_SIZE - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) } else if (OLDMEM_BASE && from < OLDMEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) len = min(count, OLDMEM_SIZE - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) from += OLDMEM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (is_vmalloc_or_module_addr(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ra = load_real_addr(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) len = min(PAGE_SIZE - offset_in_page(ra), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ra = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (memcpy_real(ra, (void *) from, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dst += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) src += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Copy memory of the old, dumped system to a user space virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int copy_oldmem_user(void __user *dst, void *src, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) unsigned long from, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) from = __pa(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!OLDMEM_BASE && from < sclp.hsa_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Copy from zfcp/nvme dump HSA area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) len = min(count, sclp.hsa_size - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rc = memcpy_hsa_user(dst, from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Check for swapped kdump oldmem areas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (OLDMEM_BASE && from - OLDMEM_BASE < OLDMEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) from -= OLDMEM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) len = min(count, OLDMEM_SIZE - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else if (OLDMEM_BASE && from < OLDMEM_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) len = min(count, OLDMEM_SIZE - from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) from += OLDMEM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) len = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) rc = copy_to_user_real(dst, (void *) from, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) dst += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) src += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * Copy one page from "oldmem"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) unsigned long offset, int userbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!csize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) src = (void *) (pfn << PAGE_SHIFT) + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (userbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) rc = copy_oldmem_user((void __force __user *) buf, src, csize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) rc = copy_oldmem_kernel((void *) buf, src, csize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Remap "oldmem" for kdump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * For the kdump reserved memory this functions performs a swap operation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * [0 - OLDMEM_SIZE] is mapped to [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) unsigned long from, unsigned long pfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned long size, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned long size_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (pfn < OLDMEM_SIZE >> PAGE_SHIFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) size_old = min(size, OLDMEM_SIZE - (pfn << PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) rc = remap_pfn_range(vma, from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) pfn + (OLDMEM_BASE >> PAGE_SHIFT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) size_old, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (rc || size == size_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) size -= size_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) from += size_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) pfn += size_old >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return remap_pfn_range(vma, from, pfn, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * Remap "oldmem" for zfcp/nvme dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * We only map available memory above HSA size. Memory below HSA size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * is read on demand using the copy_oldmem_page() function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) unsigned long from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) unsigned long pfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unsigned long size, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) unsigned long hsa_end = sclp.hsa_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unsigned long size_hsa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (pfn < hsa_end >> PAGE_SHIFT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (size == size_hsa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) size -= size_hsa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) from += size_hsa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pfn += size_hsa >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return remap_pfn_range(vma, from, pfn, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Remap "oldmem" for kdump or zfcp/nvme dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unsigned long pfn, unsigned long size, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (OLDMEM_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return remap_oldmem_pfn_range_kdump(vma, from, pfn, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return remap_oldmem_pfn_range_zfcpdump(vma, from, pfn, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static const char *nt_name(Elf64_Word type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const char *name = "LINUX";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (type == NT_PRPSINFO || type == NT_PRSTATUS || type == NT_PRFPREG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) name = KEXEC_CORE_NOTE_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * Initialize ELF note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static void *nt_init_name(void *buf, Elf64_Word type, void *desc, int d_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) Elf64_Nhdr *note;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) u64 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) note = (Elf64_Nhdr *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) note->n_namesz = strlen(name) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) note->n_descsz = d_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) note->n_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) len = sizeof(Elf64_Nhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) memcpy(buf + len, name, note->n_namesz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) len = roundup(len + note->n_namesz, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) memcpy(buf + len, desc, note->n_descsz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) len = roundup(len + note->n_descsz, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return PTR_ADD(buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static inline void *nt_init(void *buf, Elf64_Word type, void *desc, int d_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return nt_init_name(buf, type, desc, d_len, nt_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Calculate the size of ELF note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static size_t nt_size_name(int d_len, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) size = sizeof(Elf64_Nhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) size += roundup(strlen(name) + 1, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) size += roundup(d_len, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static inline size_t nt_size(Elf64_Word type, int d_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return nt_size_name(d_len, nt_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * Fill ELF notes for one CPU with save area registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static void *fill_cpu_elf_notes(void *ptr, int cpu, struct save_area *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct elf_prstatus nt_prstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) elf_fpregset_t nt_fpregset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* Prepare prstatus note */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) memset(&nt_prstatus, 0, sizeof(nt_prstatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) memcpy(&nt_prstatus.pr_reg.gprs, sa->gprs, sizeof(sa->gprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) memcpy(&nt_prstatus.pr_reg.psw, sa->psw, sizeof(sa->psw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) memcpy(&nt_prstatus.pr_reg.acrs, sa->acrs, sizeof(sa->acrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) nt_prstatus.pr_pid = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* Prepare fpregset (floating point) note */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) memset(&nt_fpregset, 0, sizeof(nt_fpregset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) memcpy(&nt_fpregset.fpc, &sa->fpc, sizeof(sa->fpc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) memcpy(&nt_fpregset.fprs, &sa->fprs, sizeof(sa->fprs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Create ELF notes for the CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ptr = nt_init(ptr, NT_PRSTATUS, &nt_prstatus, sizeof(nt_prstatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ptr = nt_init(ptr, NT_PRFPREG, &nt_fpregset, sizeof(nt_fpregset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ptr = nt_init(ptr, NT_S390_TIMER, &sa->timer, sizeof(sa->timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ptr = nt_init(ptr, NT_S390_TODCMP, &sa->todcmp, sizeof(sa->todcmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ptr = nt_init(ptr, NT_S390_TODPREG, &sa->todpreg, sizeof(sa->todpreg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ptr = nt_init(ptr, NT_S390_CTRS, &sa->ctrs, sizeof(sa->ctrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ptr = nt_init(ptr, NT_S390_PREFIX, &sa->prefix, sizeof(sa->prefix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (MACHINE_HAS_VX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ptr = nt_init(ptr, NT_S390_VXRS_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) &sa->vxrs_high, sizeof(sa->vxrs_high));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ptr = nt_init(ptr, NT_S390_VXRS_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) &sa->vxrs_low, sizeof(sa->vxrs_low));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * Calculate size of ELF notes per cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static size_t get_cpu_elf_notes_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct save_area *sa = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) size = nt_size(NT_PRSTATUS, sizeof(struct elf_prstatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) size += nt_size(NT_PRFPREG, sizeof(elf_fpregset_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) size += nt_size(NT_S390_TIMER, sizeof(sa->timer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) size += nt_size(NT_S390_TODCMP, sizeof(sa->todcmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) size += nt_size(NT_S390_TODPREG, sizeof(sa->todpreg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) size += nt_size(NT_S390_CTRS, sizeof(sa->ctrs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) size += nt_size(NT_S390_PREFIX, sizeof(sa->prefix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (MACHINE_HAS_VX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) size += nt_size(NT_S390_VXRS_HIGH, sizeof(sa->vxrs_high));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) size += nt_size(NT_S390_VXRS_LOW, sizeof(sa->vxrs_low));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * Initialize prpsinfo note (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static void *nt_prpsinfo(void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct elf_prpsinfo prpsinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) memset(&prpsinfo, 0, sizeof(prpsinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) prpsinfo.pr_sname = 'R';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) strcpy(prpsinfo.pr_fname, "vmlinux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return nt_init(ptr, NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * Get vmcoreinfo using lowcore->vmcore_info (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static void *get_vmcoreinfo_old(unsigned long *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) char nt_name[11], *vmcoreinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) Elf64_Nhdr note;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (copy_oldmem_kernel(&addr, &S390_lowcore.vmcore_info, sizeof(addr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) memset(nt_name, 0, sizeof(nt_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (copy_oldmem_kernel(¬e, addr, sizeof(note)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (copy_oldmem_kernel(nt_name, addr + sizeof(note),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) sizeof(nt_name) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (strcmp(nt_name, VMCOREINFO_NOTE_NAME) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) vmcoreinfo = kzalloc(note.n_descsz, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (!vmcoreinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (copy_oldmem_kernel(vmcoreinfo, addr + 24, note.n_descsz)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) kfree(vmcoreinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) *size = note.n_descsz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return vmcoreinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * Initialize vmcoreinfo note (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static void *nt_vmcoreinfo(void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) const char *name = VMCOREINFO_NOTE_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) void *vmcoreinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) vmcoreinfo = os_info_old_entry(OS_INFO_VMCOREINFO, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (vmcoreinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return nt_init_name(ptr, 0, vmcoreinfo, size, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) vmcoreinfo = get_vmcoreinfo_old(&size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (!vmcoreinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ptr = nt_init_name(ptr, 0, vmcoreinfo, size, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) kfree(vmcoreinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static size_t nt_vmcoreinfo_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) const char *name = VMCOREINFO_NOTE_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void *vmcoreinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) vmcoreinfo = os_info_old_entry(OS_INFO_VMCOREINFO, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (vmcoreinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return nt_size_name(size, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) vmcoreinfo = get_vmcoreinfo_old(&size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (!vmcoreinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) kfree(vmcoreinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return nt_size_name(size, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * Initialize final note (needed for /proc/vmcore code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) static void *nt_final(void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) Elf64_Nhdr *note;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) note = (Elf64_Nhdr *) ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) note->n_namesz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) note->n_descsz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) note->n_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return PTR_ADD(ptr, sizeof(Elf64_Nhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * Initialize ELF header (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) memset(ehdr, 0, sizeof(*ehdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ehdr->e_ident[EI_CLASS] = ELFCLASS64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ehdr->e_ident[EI_VERSION] = EV_CURRENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ehdr->e_type = ET_CORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ehdr->e_machine = EM_S390;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) ehdr->e_version = EV_CURRENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ehdr->e_phoff = sizeof(Elf64_Ehdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ehdr->e_ehsize = sizeof(Elf64_Ehdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) ehdr->e_phentsize = sizeof(Elf64_Phdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ehdr->e_phnum = mem_chunk_cnt + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) return ehdr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * Return CPU count for ELF header (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static int get_cpu_cnt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct save_area *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int cpus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) list_for_each_entry(sa, &dump_save_areas, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (sa->prefix != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) cpus++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) return cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * Return memory chunk count for ELF header (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static int get_mem_chunk_cnt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u64 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) for_each_physmem_range(idx, &oldmem_type, NULL, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * Initialize ELF loads (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static void loads_init(Elf64_Phdr *phdr, u64 loads_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) phys_addr_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) u64 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) for_each_physmem_range(idx, &oldmem_type, &start, &end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) phdr->p_filesz = end - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) phdr->p_type = PT_LOAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) phdr->p_offset = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) phdr->p_vaddr = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) phdr->p_paddr = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) phdr->p_memsz = end - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) phdr->p_flags = PF_R | PF_W | PF_X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) phdr->p_align = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) phdr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * Initialize notes (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static void *notes_init(Elf64_Phdr *phdr, void *ptr, u64 notes_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct save_area *sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) void *ptr_start = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ptr = nt_prpsinfo(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) cpu = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) list_for_each_entry(sa, &dump_save_areas, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (sa->prefix != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) ptr = fill_cpu_elf_notes(ptr, cpu++, sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ptr = nt_vmcoreinfo(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) ptr = nt_final(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) memset(phdr, 0, sizeof(*phdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) phdr->p_type = PT_NOTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) phdr->p_offset = notes_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) phdr->p_filesz = (unsigned long) PTR_SUB(ptr, ptr_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) phdr->p_memsz = phdr->p_filesz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static size_t get_elfcorehdr_size(int mem_chunk_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) size = sizeof(Elf64_Ehdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* PT_NOTES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) size += sizeof(Elf64_Phdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* nt_prpsinfo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) size += nt_size(NT_PRPSINFO, sizeof(struct elf_prpsinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /* regsets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) size += get_cpu_cnt() * get_cpu_elf_notes_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /* nt_vmcoreinfo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) size += nt_vmcoreinfo_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /* nt_final */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) size += sizeof(Elf64_Nhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /* PT_LOADS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) size += mem_chunk_cnt * sizeof(Elf64_Phdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * Create ELF core header (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) Elf64_Phdr *phdr_notes, *phdr_loads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) int mem_chunk_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) void *ptr, *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) u32 alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) u64 hdr_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* If we are not in kdump or zfcp/nvme dump mode return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (!OLDMEM_BASE && !is_ipl_type_dump())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) /* If we cannot get HSA size for zfcp/nvme dump return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) if (is_ipl_type_dump() && !sclp.hsa_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) /* For kdump, exclude previous crashkernel memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (OLDMEM_BASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) oldmem_region.base = OLDMEM_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) oldmem_region.size = OLDMEM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) oldmem_type.total_size = OLDMEM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) mem_chunk_cnt = get_mem_chunk_cnt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) alloc_size = get_elfcorehdr_size(mem_chunk_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) hdr = kzalloc(alloc_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) /* Without elfcorehdr /proc/vmcore cannot be created. Thus creating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * a dump with this crash kernel will fail. Panic now to allow other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * dump mechanisms to take over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) panic("s390 kdump allocating elfcorehdr failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /* Init elf header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) ptr = ehdr_init(hdr, mem_chunk_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* Init program headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) phdr_notes = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) phdr_loads = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* Init notes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) hdr_off = PTR_DIFF(ptr, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* Init loads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) hdr_off = PTR_DIFF(ptr, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) loads_init(phdr_loads, hdr_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) *addr = (unsigned long long) hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) *size = (unsigned long long) hdr_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) BUG_ON(elfcorehdr_size > alloc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * Free ELF core header (new kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) void elfcorehdr_free(unsigned long long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) kfree((void *)(unsigned long)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * Read from ELF header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) void *src = (void *)(unsigned long)*ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) memcpy(buf, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) *ppos += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * Read from ELF notes data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) void *src = (void *)(unsigned long)*ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) memcpy(buf, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) *ppos += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }