Commit bec013c4 authored by Michael Holzheu's avatar Michael Holzheu Committed by Linus Torvalds

kdump: crashk_res init check for /sys/kernel/kexec_crash_size

Currently it is possible to set the crash_size via the sysfs
/sys/kernel/kexec_crash_size even if no crash kernel memory has been
defined with the "crashkernel" parameter.  In this case "crashk_res" is
not initialized and crashk_res.start = crashk_res.end = 0.  Unfortunately
resource_size(&crashk_res) returns 1 in this case.  This breaks the s390
implementation of crash_(un)map_reserved_pages().

To fix the problem the correct "old_size" is now calculated in
crash_shrink_memory().  "old_size is set to "0" if crashk_res is not
initialized.  With this change crash_shrink_memory() will do nothing, when
"crashk_res" is not initialized.  It will return "0" for "echo 0 >
/sys/kernel/kexec_crash_size" and -EINVAL for "echo [not zero] >
/sys/kernel/kexec_crash_size".

In addition to that this patch also simplifies the "ret = -EINVAL" vs.
"ret = 0" logic as suggested by Simon Horman.
Signed-off-by: default avatarMichael Holzheu <holzheu@linux.vnet.ibm.com>
Reviewed-by: default avatarDave Young <dyoung@redhat.com>
Reviewed-by: default avatarWANG Cong <xiyou.wangcong@gmail.com>
Reviewed-by: default avatarSimon Horman <horms@verge.net.au>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6480e5a0
...@@ -1129,6 +1129,7 @@ int crash_shrink_memory(unsigned long new_size) ...@@ -1129,6 +1129,7 @@ int crash_shrink_memory(unsigned long new_size)
{ {
int ret = 0; int ret = 0;
unsigned long start, end; unsigned long start, end;
unsigned long old_size;
struct resource *ram_res; struct resource *ram_res;
mutex_lock(&kexec_mutex); mutex_lock(&kexec_mutex);
...@@ -1139,11 +1140,9 @@ int crash_shrink_memory(unsigned long new_size) ...@@ -1139,11 +1140,9 @@ int crash_shrink_memory(unsigned long new_size)
} }
start = crashk_res.start; start = crashk_res.start;
end = crashk_res.end; end = crashk_res.end;
old_size = (end == 0) ? 0 : end - start + 1;
if (new_size >= end - start + 1) { if (new_size >= old_size) {
ret = -EINVAL; ret = (new_size == old_size) ? 0 : -EINVAL;
if (new_size == end - start + 1)
ret = 0;
goto unlock; goto unlock;
} }
......
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