kdump: crashk_res init check for /sys/kernel/kexec_crash_size
Subsystems (3)
PATCH 1/1 kdump: crashk_res init check for /sys/kernel/kexec_crash_size
From: Michael Holzheu <[email protected]>
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".
--- kernel/kexec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/kexec.c +4 -4
@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;mutex_lock (&kexec_mutex);
@@ -1141,10 +1141,10 @@ int crash_shrink_memory(unsigned long ne } start = crashk_res.start; end = crashk_res.end; - -if (new_size >= end - start +1 ) { + old_size = (end ==0 ) ?0 : end - start +1 ; +if (new_size >= old_size) { ret = -EINVAL ; -if (new_size == end - start +1 ) +if (new_size == old_size) ret =0 ; goto unlock; }
Quoted 34 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "echo [not zero] >/sys/kernel/kexec_crash_size".Signed-off-by Michael Holzheu <[email protected]>--- kernel/kexec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/kexec.c +1
-1@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;mutex_lock (&kexec_mutex);@@ -1141,10 +1141,10 @@ int crash_shrink_memory(unsigned long ne }
kernel/kexec.c int crash_shrink_memory(unsigned long ne · line 1148
Quoted 10 lines
kernel/kexec.c +3
-3start = crashk_res.start; end = crashk_res.end; - -if (new_size >= end - start +1 ) { + old_size = (end ==0 ) ?0 : end - start +1 ; +if (new_size >= old_size) { ret = -EINVAL ; -if (new_size == end - start +1 ) +if (new_size == old_size) ret =0 ;
I wonder if while we are here we could clean up the logic above a little.
To my mind both
ret = new_size == old_size ? 0 : -EINVAL;
and
if (new_size == old_size) ret = 0; else ret = -EINVAL;
are easier on the eyes than the current logic.
kernel/kexec.c int crash_shrink_memory(unsigned long ne · line 1150
Quoted 2 lines
kernel/kexec.c +0
-0goto unlock; }
But I am happy with the patch without my above suggestion.
PATCH v2 1/1 kdump: crashk_res init check for /sys/kernel/kexec_crash_size
From: Michael Holzheu <[email protected]>
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.
--- kernel/kexec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
kernel/kexec.c +4 -6
@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;mutex_lock (&kexec_mutex);
@@ -1141,11 +1141,9 @@ int crash_shrink_memory(unsigned long ne } start = crashk_res.start; end = crashk_res.end; - -if (new_size >= end - start +1 ) { - ret = -EINVAL ; -if (new_size == end - start +1 ) - ret =0 ; + old_size = (end ==0 ) ?0 : end - start +1 ; +if (new_size >= old_size) { + ret = (new_size == old_size) ?0 : -EINVAL ; goto unlock; }
Quoted 28 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "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.Cc Simon Horman <[email protected]>Signed-off-by Michael Holzheu <[email protected]>--- kernel/kexec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
kernel/kexec.c void __weak crash_free_reserved_phys_ran · line 1134
Quoted 5 lines
kernel/kexec.c +1
-1@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;
Sorry for jump in a little late, instead of introduce a new variable, why not add something like:
if (!end)
return -EINVAL;
Quoted 25 lines
kernel/kexec.c +3
-5mutex_lock (&kexec_mutex);@@ -1141,11 +1141,9 @@ int crash_shrink_memory(unsigned long ne } start = crashk_res.start; end = crashk_res.end; - -if (new_size >= end - start +1 ) { - ret = -EINVAL ; -if (new_size == end - start +1 ) - ret =0 ; + old_size = (end ==0 ) ?0 : end - start +1 ; +if (new_size >= old_size) { + ret = (new_size == old_size) ?0 : -EINVAL ; goto unlock; }_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Signature · 7 lines
Thanks Dave _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Dave,
Quoted 40 lines · Dave Young
Quoted 28 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "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.Cc Simon Horman <[email protected]>Signed-off-by Michael Holzheu <[email protected]>--- kernel/kexec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)kernel/kexec.c void __weak crash_free_reserved_phys_ran · line 1134
Quoted 5 lines
kernel/kexec.c +1
-1@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;Sorry for jump in a little late, instead of introduce a new variable, why not add something like:
Quoted 2 lines
if (!end)
return -EINVAL;
If the crashkernel parameter is not set, "/sys/kernel/kexec_crash_size" returns zero:
cat /sys/kernel/kexec_crash_size
0
So I think if we set it again to zero we should *not* return -EINVAL:
echo 0 > /sys/kernel/kexec_crash_size
--> Exit code should be zero in this case
Otherwise we would change the current behavior.
And besides of that, I think introducing the "old_size" variable makes the code more readable.
Michael
Dave Young
Reviewed-byQuoted 46 lines · Michael Holzheu
Hi Dave,
Quoted 40 lines · Dave Young
Quoted 28 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "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.Cc Simon Horman <[email protected]>Signed-off-by Michael Holzheu <[email protected]>--- kernel/kexec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)kernel/kexec.c void __weak crash_free_reserved_phys_ran · line 1134
Quoted 5 lines
kernel/kexec.c +1
-1@@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ranint crash_shrink_memory (unsigned long new_size) {int ret =0 ; -unsigned long start, end; +unsigned long start, end, old_size;Sorry for jump in a little late, instead of introduce a new variable, why not add something like:
Quoted 2 lines
if (!end)
return -EINVAL;
Quoted 7 lines
If the crashkernel parameter is not set, "
/sys/kernel/kexec_crash_size" returns zero:cat
/sys/kernel/kexec_crash_size
0So I think if we set it again to zero we should *not* return
-EINVAL:
Thanks, I missed this case. fair enough.
Quoted 12 lines
echo 0 >
/sys/kernel/kexec_crash_size
--> Exit code should be zero in this caseOtherwise we would change the current behavior.
And besides of that, I think introducing the "
old_size" variable makes the code more readable.Michael
Signature · 7 lines
Thanks Dave _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 16 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "echo [not zero] >/sys/kernel/kexec_crash_size".
Quoted 5 lines
In addition to that this patch also simplifies the "ret =
-EINVAL" vs. "ret = 0" logic as suggested by Simon Horman.Cc Simon Horman <[email protected]>Signed-off-by Michael Holzheu <[email protected]>
Thanks.
Quoted 16 lines · Michael Holzheu
From: Michael Holzheu <[email protected]>
Currently it is possible to set the
crash_sizevia the sysfs/sys/kernel/kexec_crash_sizeeven 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. Unfortunatelyresource_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 incrash_shrink_memory(). "old_sizeis set to "0" ifcrashk_resis not initialized. With this changecrash_shrink_memory()will do nothing, when "crashk_res" is not initialized. It will return "0" for "echo 0 >/sys/kernel/kexec_crash_size" and-EINVALfor "echo [not zero] >/sys/kernel/kexec_crash_size".
Quoted 5 lines
In addition to that this patch also simplifies the "ret =
-EINVAL" vs. "ret = 0" logic as suggested by Simon Horman.Cc Simon Horman <[email protected]>Signed-off-by Michael Holzheu <[email protected]>
Thanks Michael,