xref: /openbmc/linux/arch/x86/kernel/crash_dump_64.c (revision 9a29f5fc)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *	Memory preserving reboot related code.
4  *
5  *	Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
6  *	Copyright (C) IBM Corporation, 2004. All rights reserved
7  */
8 
9 #include <linux/errno.h>
10 #include <linux/crash_dump.h>
11 #include <linux/uio.h>
12 #include <linux/io.h>
13 #include <linux/cc_platform.h>
14 
15 static ssize_t __copy_oldmem_page(struct iov_iter *iter, unsigned long pfn,
16 				  size_t csize, unsigned long offset,
17 				  bool encrypted)
18 {
19 	void  *vaddr;
20 
21 	if (!csize)
22 		return 0;
23 
24 	if (encrypted)
25 		vaddr = (__force void *)ioremap_encrypted(pfn << PAGE_SHIFT, PAGE_SIZE);
26 	else
27 		vaddr = (__force void *)ioremap_cache(pfn << PAGE_SHIFT, PAGE_SIZE);
28 
29 	if (!vaddr)
30 		return -ENOMEM;
31 
32 	csize = copy_to_iter(vaddr + offset, csize, iter);
33 
34 	iounmap((void __iomem *)vaddr);
35 	return csize;
36 }
37 
38 ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn, size_t csize,
39 			 unsigned long offset)
40 {
41 	return __copy_oldmem_page(iter, pfn, csize, offset, false);
42 }
43 
44 /*
45  * copy_oldmem_page_encrypted - same as copy_oldmem_page() above but ioremap the
46  * memory with the encryption mask set to accommodate kdump on SME-enabled
47  * machines.
48  */
49 ssize_t copy_oldmem_page_encrypted(struct iov_iter *iter, unsigned long pfn,
50 				   size_t csize, unsigned long offset)
51 {
52 	return __copy_oldmem_page(iter, pfn, csize, offset, true);
53 }
54 
55 ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
56 {
57 	struct kvec kvec = { .iov_base = buf, .iov_len = count };
58 	struct iov_iter iter;
59 
60 	iov_iter_kvec(&iter, READ, &kvec, 1, count);
61 
62 	return read_from_oldmem(&iter, count, ppos,
63 				cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT));
64 }
65