1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 29a163ed8SThomas Gleixner /* 3835c34a1SDave Jones * Memory preserving reboot related code. 49a163ed8SThomas Gleixner * 59a163ed8SThomas Gleixner * Created by: Hariprasad Nellitheertha (hari@in.ibm.com) 69a163ed8SThomas Gleixner * Copyright (C) IBM Corporation, 2004. All rights reserved 79a163ed8SThomas Gleixner */ 89a163ed8SThomas Gleixner 95a0e3ad6STejun Heo #include <linux/slab.h> 109a163ed8SThomas Gleixner #include <linux/errno.h> 119a163ed8SThomas Gleixner #include <linux/highmem.h> 129a163ed8SThomas Gleixner #include <linux/crash_dump.h> 13*5d8de293SMatthew Wilcox (Oracle) #include <linux/uio.h> 149a163ed8SThomas Gleixner 1572ed7de7SJiri Slaby static inline bool is_crashed_pfn_valid(unsigned long pfn) 1672ed7de7SJiri Slaby { 1772ed7de7SJiri Slaby #ifndef CONFIG_X86_PAE 1872ed7de7SJiri Slaby /* 1972ed7de7SJiri Slaby * non-PAE kdump kernel executed from a PAE one will crop high pte 2072ed7de7SJiri Slaby * bits and poke unwanted space counting again from address 0, we 2172ed7de7SJiri Slaby * don't want that. pte must fit into unsigned long. In fact the 2272ed7de7SJiri Slaby * test checks high 12 bits for being zero (pfn will be shifted left 2372ed7de7SJiri Slaby * by PAGE_SHIFT). 2472ed7de7SJiri Slaby */ 2572ed7de7SJiri Slaby return pte_pfn(pfn_pte(pfn, __pgprot(0))) == pfn; 2672ed7de7SJiri Slaby #else 2772ed7de7SJiri Slaby return true; 2872ed7de7SJiri Slaby #endif 2972ed7de7SJiri Slaby } 3072ed7de7SJiri Slaby 31*5d8de293SMatthew Wilcox (Oracle) ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn, size_t csize, 32*5d8de293SMatthew Wilcox (Oracle) unsigned long offset) 339a163ed8SThomas Gleixner { 349a163ed8SThomas Gleixner void *vaddr; 359a163ed8SThomas Gleixner 369a163ed8SThomas Gleixner if (!csize) 379a163ed8SThomas Gleixner return 0; 389a163ed8SThomas Gleixner 3972ed7de7SJiri Slaby if (!is_crashed_pfn_valid(pfn)) 4072ed7de7SJiri Slaby return -EFAULT; 4172ed7de7SJiri Slaby 427e015a27SThomas Gleixner vaddr = kmap_local_pfn(pfn); 43*5d8de293SMatthew Wilcox (Oracle) csize = copy_to_iter(vaddr + offset, csize, iter); 447e015a27SThomas Gleixner kunmap_local(vaddr); 459a163ed8SThomas Gleixner 469a163ed8SThomas Gleixner return csize; 479a163ed8SThomas Gleixner } 48