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