Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/kexec: consolidate crash_map/unmap_reserved_pages() and arch_kexec_protect(unprotect)_crashkres()

Commit 3f625002581b ("kexec: introduce a protection mechanism for the
crashkernel reserved memory") is a similar mechanism for protecting the
crash kernel reserved memory to previous crash_map/unmap_reserved_pages()
implementation, the new one is more generic in name and cleaner in code
(besides, some arch may not be allowed to unmap the pgtable).

Therefore, this patch consolidates them, and uses the new
arch_kexec_protect(unprotect)_crashkres() to replace former
crash_map/unmap_reserved_pages() which by now has been only used by
S390.

The consolidation work needs the crash memory to be mapped initially,
this is done in machine_kdump_pm_init() which is after
reserve_crashkernel(). Once kdump kernel is loaded, the new
arch_kexec_protect_crashkres() implemented for S390 will actually
unmap the pgtable like before.

Signed-off-by: Xunlei Pang <xlpang@redhat.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Acked-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Minfei Huang <mhuang@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Baoquan He <bhe@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Xunlei Pang and committed by
Linus Torvalds
7a0058ec 0eea0867

+20 -33
+18 -10
arch/s390/kernel/machine_kexec.c
··· 43 43 switch (action) { 44 44 case PM_SUSPEND_PREPARE: 45 45 case PM_HIBERNATION_PREPARE: 46 - if (crashk_res.start) 47 - crash_map_reserved_pages(); 46 + if (kexec_crash_image) 47 + arch_kexec_unprotect_crashkres(); 48 48 break; 49 49 case PM_POST_SUSPEND: 50 50 case PM_POST_HIBERNATION: 51 - if (crashk_res.start) 52 - crash_unmap_reserved_pages(); 51 + if (kexec_crash_image) 52 + arch_kexec_protect_crashkres(); 53 53 break; 54 54 default: 55 55 return NOTIFY_DONE; ··· 60 60 static int __init machine_kdump_pm_init(void) 61 61 { 62 62 pm_notifier(machine_kdump_pm_cb, 0); 63 + /* Create initial mapping for crashkernel memory */ 64 + arch_kexec_unprotect_crashkres(); 63 65 return 0; 64 66 } 65 67 arch_initcall(machine_kdump_pm_init); ··· 148 146 #endif 149 147 } 150 148 149 + #ifdef CONFIG_CRASH_DUMP 150 + 151 151 /* 152 152 * Map or unmap crashkernel memory 153 153 */ ··· 171 167 } 172 168 173 169 /* 174 - * Map crashkernel memory 170 + * Unmap crashkernel memory 175 171 */ 176 - void crash_map_reserved_pages(void) 172 + void arch_kexec_protect_crashkres(void) 177 173 { 178 - crash_map_pages(1); 174 + if (crashk_res.end) 175 + crash_map_pages(0); 179 176 } 180 177 181 178 /* 182 - * Unmap crashkernel memory 179 + * Map crashkernel memory 183 180 */ 184 - void crash_unmap_reserved_pages(void) 181 + void arch_kexec_unprotect_crashkres(void) 185 182 { 186 - crash_map_pages(0); 183 + if (crashk_res.end) 184 + crash_map_pages(1); 187 185 } 186 + 187 + #endif 188 188 189 189 /* 190 190 * Give back memory to hypervisor before new kdump is loaded
-2
include/linux/kexec.h
··· 230 230 int kexec_should_crash(struct task_struct *); 231 231 void crash_save_cpu(struct pt_regs *regs, int cpu); 232 232 void crash_save_vmcoreinfo(void); 233 - void crash_map_reserved_pages(void); 234 - void crash_unmap_reserved_pages(void); 235 233 void arch_crash_save_vmcoreinfo(void); 236 234 __printf(1, 2) 237 235 void vmcoreinfo_append_str(const char *fmt, ...);
-12
kernel/kexec.c
··· 136 136 if (ret) 137 137 return ret; 138 138 139 - if (flags & KEXEC_ON_CRASH) 140 - crash_map_reserved_pages(); 141 - 142 139 if (flags & KEXEC_PRESERVE_CONTEXT) 143 140 image->preserve_context = 1; 144 141 ··· 158 161 if ((flags & KEXEC_ON_CRASH) && kexec_crash_image) 159 162 arch_kexec_protect_crashkres(); 160 163 161 - /* 162 - * Once the reserved memory is mapped, we should unmap this memory 163 - * before returning 164 - */ 165 - if (flags & KEXEC_ON_CRASH) 166 - crash_unmap_reserved_pages(); 167 164 kimage_free(image); 168 165 return ret; 169 166 } ··· 222 231 return -EBUSY; 223 232 224 233 result = do_kexec_load(entry, nr_segments, segments, flags); 225 - 226 - if ((flags & KEXEC_ON_CRASH) && kexec_crash_image) 227 - arch_kexec_protect_crashkres(); 228 234 229 235 mutex_unlock(&kexec_mutex); 230 236
+2 -9
kernel/kexec_core.c
··· 954 954 start = roundup(start, KEXEC_CRASH_MEM_ALIGN); 955 955 end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN); 956 956 957 - crash_map_reserved_pages(); 958 957 crash_free_reserved_phys_range(end, crashk_res.end); 959 958 960 959 if ((start == end) && (crashk_res.parent != NULL)) ··· 967 968 crashk_res.end = end - 1; 968 969 969 970 insert_resource(&iomem_resource, ram_res); 970 - crash_unmap_reserved_pages(); 971 971 972 972 unlock: 973 973 mutex_unlock(&kexec_mutex); ··· 1551 1553 } 1552 1554 1553 1555 /* 1554 - * Add and remove page tables for crashkernel memory 1556 + * Protection mechanism for crashkernel reserved memory after 1557 + * the kdump kernel is loaded. 1555 1558 * 1556 1559 * Provide an empty default implementation here -- architecture 1557 1560 * code may override this 1558 1561 */ 1559 - void __weak crash_map_reserved_pages(void) 1560 - {} 1561 - 1562 - void __weak crash_unmap_reserved_pages(void) 1563 - {} 1564 - 1565 1562 void __weak arch_kexec_protect_crashkres(void) 1566 1563 {} 1567 1564