linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
@ 2011-11-23 10:11 Michael Holzheu
  2011-11-23 10:22 ` Simon Horman
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Holzheu @ 2011-11-23 10:11 UTC (permalink / raw)
  To: akpm
  Cc: Eric W. Biederman, Vivek Goyal, schwidefsky, heiko.carstens,
	kexec, linux-kernel

From: Michael Holzheu <holzheu@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@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;
 		goto unlock;
 	}



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 10:11 [PATCH] kdump: crashk_res init check for /sys/kernel/kexec_crash_size Michael Holzheu
@ 2011-11-23 10:22 ` Simon Horman
  2011-11-23 13:18   ` [PATCH v2] " Michael Holzheu
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Horman @ 2011-11-23 10:22 UTC (permalink / raw)
  To: Michael Holzheu
  Cc: akpm, heiko.carstens, kexec, linux-kernel, Eric W. Biederman,
	schwidefsky, Vivek Goyal

On Wed, Nov 23, 2011 at 11:11:08AM +0100, Michael Holzheu wrote:
> From: Michael Holzheu <holzheu@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@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@verge.net.au>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 10:22 ` Simon Horman
@ 2011-11-23 13:18   ` Michael Holzheu
  2011-11-23 13:34     ` Dave Young
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Michael Holzheu @ 2011-11-23 13:18 UTC (permalink / raw)
  To: akpm
  Cc: Simon Horman, heiko.carstens, kexec, linux-kernel,
	Eric W. Biederman, schwidefsky, akpm, Vivek Goyal

From: Michael Holzheu <holzheu@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".

In addition to that this patch also simplifies the "ret = -EINVAL"
vs. "ret = 0" logic as suggested by Simon Horman.

Cc: Simon Horman <horms@verge.net.au>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
 kernel/kexec.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 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,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;
 	}
 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 13:18   ` [PATCH v2] " Michael Holzheu
@ 2011-11-23 13:34     ` Dave Young
  2011-11-23 13:46       ` Michael Holzheu
  2011-11-23 15:01     ` Cong Wang
  2011-11-24  0:10     ` Simon Horman
  2 siblings, 1 reply; 8+ messages in thread
From: Dave Young @ 2011-11-23 13:34 UTC (permalink / raw)
  To: holzheu
  Cc: akpm, heiko.carstens, kexec, linux-kernel, Simon Horman,
	Eric W. Biederman, schwidefsky, Vivek Goyal

On 11/23/2011 09:18 PM, Michael Holzheu wrote:

> From: Michael Holzheu <holzheu@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".
> 
> In addition to that this patch also simplifies the "ret = -EINVAL"
> vs. "ret = 0" logic as suggested by Simon Horman.
> 
> Cc: Simon Horman <horms@verge.net.au>
> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
> ---
>  kernel/kexec.c |   10 ++++------
>  1 file changed, 4 insertions(+), 6 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;


Sorry for jump in a little late, instead of introduce a new variable,
why not add something like:

if (!end)
	return -EINVAL;

>  
>  	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;
>  	}
>  
> 
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec



-- 
Thanks
Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 13:34     ` Dave Young
@ 2011-11-23 13:46       ` Michael Holzheu
  2011-11-23 14:03         ` Dave Young
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Holzheu @ 2011-11-23 13:46 UTC (permalink / raw)
  To: Dave Young
  Cc: heiko.carstens, kexec, linux-kernel, Simon Horman,
	Eric W. Biederman, schwidefsky, akpm, Vivek Goyal

Hi Dave,

On Wed, 2011-11-23 at 21:34 +0800, Dave Young wrote:
> On 11/23/2011 09:18 PM, Michael Holzheu wrote:
> 
> > From: Michael Holzheu <holzheu@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".
> > 
> > In addition to that this patch also simplifies the "ret = -EINVAL"
> > vs. "ret = 0" logic as suggested by Simon Horman.
> > 
> > Cc: Simon Horman <horms@verge.net.au>
> > Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
> > ---
> >  kernel/kexec.c |   10 ++++------
> >  1 file changed, 4 insertions(+), 6 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;
> 
> 
> Sorry for jump in a little late, instead of introduce a new variable,
> why not add something like:
> 
> 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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 13:46       ` Michael Holzheu
@ 2011-11-23 14:03         ` Dave Young
  0 siblings, 0 replies; 8+ messages in thread
From: Dave Young @ 2011-11-23 14:03 UTC (permalink / raw)
  To: holzheu
  Cc: heiko.carstens, kexec, linux-kernel, Simon Horman,
	Eric W. Biederman, schwidefsky, akpm, Vivek Goyal

On 11/23/2011 09:46 PM, Michael Holzheu wrote:

> Hi Dave,
> 
> On Wed, 2011-11-23 at 21:34 +0800, Dave Young wrote:
>> On 11/23/2011 09:18 PM, Michael Holzheu wrote:
>>
>>> From: Michael Holzheu <holzheu@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".
>>>
>>> In addition to that this patch also simplifies the "ret = -EINVAL"
>>> vs. "ret = 0" logic as suggested by Simon Horman.
>>>
>>> Cc: Simon Horman <horms@verge.net.au>
>>> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
>>> ---
>>>  kernel/kexec.c |   10 ++++------
>>>  1 file changed, 4 insertions(+), 6 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;
>>
>>
>> Sorry for jump in a little late, instead of introduce a new variable,
>> why not add something like:
>>
>> 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:


Thanks, I missed this case. fair enough.

Reviewed-by: Dave Young <dyoung@redhat.com>

> 
> 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
> 
> 



-- 
Thanks
Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 13:18   ` [PATCH v2] " Michael Holzheu
  2011-11-23 13:34     ` Dave Young
@ 2011-11-23 15:01     ` Cong Wang
  2011-11-24  0:10     ` Simon Horman
  2 siblings, 0 replies; 8+ messages in thread
From: Cong Wang @ 2011-11-23 15:01 UTC (permalink / raw)
  To: holzheu
  Cc: akpm, Simon Horman, heiko.carstens, kexec, linux-kernel,
	Eric W. Biederman, schwidefsky, Vivek Goyal

On Wed, Nov 23, 2011 at 9:18 PM, Michael Holzheu
<holzheu@linux.vnet.ibm.com> wrote:
> From: Michael Holzheu <holzheu@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".
>
> In addition to that this patch also simplifies the "ret = -EINVAL"
> vs. "ret = 0" logic as suggested by Simon Horman.
>
> Cc: Simon Horman <horms@verge.net.au>
> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>

Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] kdump: crashk_res init check for /sys/kernel/kexec_crash_size
  2011-11-23 13:18   ` [PATCH v2] " Michael Holzheu
  2011-11-23 13:34     ` Dave Young
  2011-11-23 15:01     ` Cong Wang
@ 2011-11-24  0:10     ` Simon Horman
  2 siblings, 0 replies; 8+ messages in thread
From: Simon Horman @ 2011-11-24  0:10 UTC (permalink / raw)
  To: Michael Holzheu
  Cc: akpm, heiko.carstens, kexec, linux-kernel, Eric W. Biederman,
	schwidefsky, Vivek Goyal

On Wed, Nov 23, 2011 at 02:18:03PM +0100, Michael Holzheu wrote:
> From: Michael Holzheu <holzheu@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".
> 
> In addition to that this patch also simplifies the "ret = -EINVAL"
> vs. "ret = 0" logic as suggested by Simon Horman.
> 
> Cc: Simon Horman <horms@verge.net.au>
> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>

Thanks Michael,

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-24  0:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-23 10:11 [PATCH] kdump: crashk_res init check for /sys/kernel/kexec_crash_size Michael Holzheu
2011-11-23 10:22 ` Simon Horman
2011-11-23 13:18   ` [PATCH v2] " Michael Holzheu
2011-11-23 13:34     ` Dave Young
2011-11-23 13:46       ` Michael Holzheu
2011-11-23 14:03         ` Dave Young
2011-11-23 15:01     ` Cong Wang
2011-11-24  0:10     ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).