aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Holzheu <holzheu@linux.vnet.ibm.com>2012-01-12 20:20:15 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-12 23:13:11 -0500
commitbec013c40bc89671d8d457944fdf7d2b8e79d651 (patch)
treef48220571120805a319f0df876c1cc465586978e
parent6480e5a0923756b500634d9777ec4189492fbbfe (diff)
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: Michael Holzheu <holzheu@linux.vnet.ibm.com> Reviewed-by: Dave Young <dyoung@redhat.com> Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com> Reviewed-by: Simon Horman <horms@verge.net.au> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--kernel/kexec.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 60bf181b3eae..7b0886786701 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -1129,6 +1129,7 @@ int crash_shrink_memory(unsigned long new_size)
1129{ 1129{
1130 int ret = 0; 1130 int ret = 0;
1131 unsigned long start, end; 1131 unsigned long start, end;
1132 unsigned long old_size;
1132 struct resource *ram_res; 1133 struct resource *ram_res;
1133 1134
1134 mutex_lock(&kexec_mutex); 1135 mutex_lock(&kexec_mutex);
@@ -1139,11 +1140,9 @@ int crash_shrink_memory(unsigned long new_size)
1139 } 1140 }
1140 start = crashk_res.start; 1141 start = crashk_res.start;
1141 end = crashk_res.end; 1142 end = crashk_res.end;
1142 1143 old_size = (end == 0) ? 0 : end - start + 1;
1143 if (new_size >= end - start + 1) { 1144 if (new_size >= old_size) {
1144 ret = -EINVAL; 1145 ret = (new_size == old_size) ? 0 : -EINVAL;
1145 if (new_size == end - start + 1)
1146 ret = 0;
1147 goto unlock; 1146 goto unlock;
1148 } 1147 }
1149 1148