[PATCH] kdump: crashk_res init check for /sys/kernel/kexec_crash_size

Simon Horman horms at verge.net.au
Wed Nov 23 05:22:15 EST 2011


On Wed, Nov 23, 2011 at 11:11:08AM +0100, Michael Holzheu wrote:
> From: Michael Holzheu <holzheu at linux.vnet.ibm.com>
> 
> 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".
> 
> Signed-off-by: Michael Holzheu <holzheu at linux.vnet.ibm.com>
> ---
>  kernel/kexec.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> --- a/kernel/kexec.c
> +++ b/kernel/kexec.c
> @@ -1131,7 +1131,7 @@ void __weak crash_free_reserved_phys_ran
>  int 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;

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.

>  		goto unlock;
>  	}

But I am happy with the patch without my above suggestion.

Reviewed-by-by: Simon Horman <horms at verge.net.au>




More information about the kexec mailing list