Commit 4e042af4 authored by Heiko Carstens's avatar Heiko Carstens Committed by Martin Schwidefsky

s390/kexec: fix crash on resize of reserved memory

Reducing the size of reserved memory for the crash kernel will result
in an immediate crash on s390. Reason for that is that we do not
create struct pages for memory that is reserved. If that memory is
freed any access to struct pages which correspond to this memory will
result in invalid memory accesses and a kernel panic.

Fix this by properly creating struct pages when the system gets
initialized. Change the code also to make use of set_memory_ro() and
set_memory_rw() so page tables will be split if required.
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 2d0af224
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <asm/diag.h> #include <asm/diag.h>
#include <asm/elf.h> #include <asm/elf.h>
#include <asm/asm-offsets.h> #include <asm/asm-offsets.h>
#include <asm/cacheflush.h>
#include <asm/os_info.h> #include <asm/os_info.h>
#include <asm/switch_to.h> #include <asm/switch_to.h>
...@@ -60,8 +61,6 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action, ...@@ -60,8 +61,6 @@ static int machine_kdump_pm_cb(struct notifier_block *nb, unsigned long action,
static int __init machine_kdump_pm_init(void) static int __init machine_kdump_pm_init(void)
{ {
pm_notifier(machine_kdump_pm_cb, 0); pm_notifier(machine_kdump_pm_cb, 0);
/* Create initial mapping for crashkernel memory */
arch_kexec_unprotect_crashkres();
return 0; return 0;
} }
arch_initcall(machine_kdump_pm_init); arch_initcall(machine_kdump_pm_init);
...@@ -163,37 +162,27 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end) ...@@ -163,37 +162,27 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
os_info_crashkernel_add(0, 0); os_info_crashkernel_add(0, 0);
} }
/* static void crash_protect_pages(int protect)
* Map or unmap crashkernel memory
*/
static void crash_map_pages(int enable)
{ {
unsigned long size = resource_size(&crashk_res); unsigned long size;
BUG_ON(crashk_res.start % KEXEC_CRASH_MEM_ALIGN || if (!crashk_res.end)
size % KEXEC_CRASH_MEM_ALIGN); return;
if (enable) size = resource_size(&crashk_res);
vmem_add_mapping(crashk_res.start, size); if (protect)
set_memory_ro(crashk_res.start, size >> PAGE_SHIFT);
else else
vmem_remove_mapping(crashk_res.start, size); set_memory_rw(crashk_res.start, size >> PAGE_SHIFT);
} }
/*
* Unmap crashkernel memory
*/
void arch_kexec_protect_crashkres(void) void arch_kexec_protect_crashkres(void)
{ {
if (crashk_res.end) crash_protect_pages(1);
crash_map_pages(0);
} }
/*
* Map crashkernel memory
*/
void arch_kexec_unprotect_crashkres(void) void arch_kexec_unprotect_crashkres(void)
{ {
if (crashk_res.end) crash_protect_pages(0);
crash_map_pages(1);
} }
#endif #endif
......
...@@ -432,6 +432,20 @@ static void __init setup_resources(void) ...@@ -432,6 +432,20 @@ static void __init setup_resources(void)
} }
} }
} }
#ifdef CONFIG_CRASH_DUMP
/*
* Re-add removed crash kernel memory as reserved memory. This makes
* sure it will be mapped with the identity mapping and struct pages
* will be created, so it can be resized later on.
* However add it later since the crash kernel resource should not be
* part of the System RAM resource.
*/
if (crashk_res.end) {
memblock_add(crashk_res.start, resource_size(&crashk_res));
memblock_reserve(crashk_res.start, resource_size(&crashk_res));
insert_resource(&iomem_resource, &crashk_res);
}
#endif
} }
static void __init setup_memory_end(void) static void __init setup_memory_end(void)
...@@ -602,7 +616,6 @@ static void __init reserve_crashkernel(void) ...@@ -602,7 +616,6 @@ static void __init reserve_crashkernel(void)
diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size)); diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
crashk_res.start = crash_base; crashk_res.start = crash_base;
crashk_res.end = crash_base + crash_size - 1; crashk_res.end = crash_base + crash_size - 1;
insert_resource(&iomem_resource, &crashk_res);
memblock_remove(crash_base, crash_size); memblock_remove(crash_base, crash_size);
pr_info("Reserving %lluMB of memory at %lluMB " pr_info("Reserving %lluMB of memory at %lluMB "
"for crashkernel (System RAM: %luMB)\n", "for crashkernel (System RAM: %luMB)\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment