All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mips: kernel: setup: fix crash kernel resource allocation
@ 2021-02-06 12:59 Ivan Khoronzhuk
  2021-02-07  3:19 ` Jinyang He
  2021-02-07  9:18 ` Mike Rapoport
  0 siblings, 2 replies; 5+ messages in thread
From: Ivan Khoronzhuk @ 2021-02-06 12:59 UTC (permalink / raw)
  To: linux-mips, tsbogend, linux-kernel
  Cc: yangtiezhu, rppt, ivan.khoronzhuk, Ivan Khoronzhuk

In order to avoid crash kernel corruption, its memory is reserved
early in memblock and as result, in time when resources are inited
it's not present in memblock.memory, so crash kernel memory is out
of ranges listed with for_each_mem_range(). To avoid it and still
keep memory reserved lets reseve it out of loop by inserting it in
iomem_resource.

Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map")
Signed-off-by: Ivan Khoronzhuk <ikhoronz@cisco.com>
---
Based on linux-next/master

 arch/mips/kernel/setup.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 3785c72bc3bc..25e376ef2f2a 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -473,14 +473,15 @@ static void __init mips_parse_crashkernel(void)
 	crashk_res.end	 = crash_base + crash_size - 1;
 }
 
-static void __init request_crashkernel(struct resource *res)
+static void __init request_crashkernel(void)
 {
 	int ret;
 
 	if (crashk_res.start == crashk_res.end)
 		return;
 
-	ret = request_resource(res, &crashk_res);
+	/* The crashk resource shoud be located in normal mem */
+	ret = insert_resource(&iomem_resource, &crashk_res);
 	if (!ret)
 		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
 			(unsigned long)(resource_size(&crashk_res) >> 20),
@@ -734,8 +735,9 @@ static void __init resource_init(void)
 		request_resource(res, &code_resource);
 		request_resource(res, &data_resource);
 		request_resource(res, &bss_resource);
-		request_crashkernel(res);
 	}
+
+	request_crashkernel();
 }
 
 #ifdef CONFIG_SMP
-- 
2.23.1


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

* Re: [PATCH] mips: kernel: setup: fix crash kernel resource allocation
  2021-02-06 12:59 [PATCH] mips: kernel: setup: fix crash kernel resource allocation Ivan Khoronzhuk
@ 2021-02-07  3:19 ` Jinyang He
  2021-02-08 13:17   ` Ivan Khoronzhuk
  2021-02-07  9:18 ` Mike Rapoport
  1 sibling, 1 reply; 5+ messages in thread
From: Jinyang He @ 2021-02-07  3:19 UTC (permalink / raw)
  To: Ivan Khoronzhuk, linux-mips, tsbogend, linux-kernel
  Cc: yangtiezhu, rppt, ivan.khoronzhuk

On 02/06/2021 08:59 PM, Ivan Khoronzhuk wrote:

> In order to avoid crash kernel corruption, its memory is reserved
> early in memblock and as result, in time when resources are inited
> it's not present in memblock.memory, so crash kernel memory is out
> of ranges listed with for_each_mem_range(). To avoid it and still
> keep memory reserved lets reseve it out of loop by inserting it in
> iomem_resource.

Hi, Ivan,

I'm not familiar with memblock. If the following my ideas show my
ignorance, please forgive me.

First, not only the crash kernel is reserved early in memblock, but also
code, data, and bss are also reserved in bootmem_init():

     /* Reserve memory occupied by kernel. */
     memblock_reserve(__pa_symbol(&_text),
             __pa_symbol(&_end) - __pa_symbol(&_text));

(CONFIG_NUMA is not enabled. NUMA platform reserved them is earlier.)

If there is something unsuitable with the crash kernel, is there something
unsuitable with the kernel memory?


Then, for_each_mem_range() is normal memory. Although memblock_reserve()
has used before that, it just adds memory to memblock.reserved. That means
it will still appear in memblock.memory. Thus, here I have a question,
do we need to use replace for_each_mem_range with for_each_mem_range_rev?

Finally, thank you for the patch, it makes me think a lot.

Thanks,
Jinyang

> Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map")
> Signed-off-by: Ivan Khoronzhuk <ikhoronz@cisco.com>
> ---
> Based on linux-next/master
>
>   arch/mips/kernel/setup.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 3785c72bc3bc..25e376ef2f2a 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -473,14 +473,15 @@ static void __init mips_parse_crashkernel(void)
>   	crashk_res.end	 = crash_base + crash_size - 1;
>   }
>   
> -static void __init request_crashkernel(struct resource *res)
> +static void __init request_crashkernel(void)
>   {
>   	int ret;
>   
>   	if (crashk_res.start == crashk_res.end)
>   		return;
>   
> -	ret = request_resource(res, &crashk_res);
> +	/* The crashk resource shoud be located in normal mem */
> +	ret = insert_resource(&iomem_resource, &crashk_res);
>   	if (!ret)
>   		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
>   			(unsigned long)(resource_size(&crashk_res) >> 20),
> @@ -734,8 +735,9 @@ static void __init resource_init(void)
>   		request_resource(res, &code_resource);
>   		request_resource(res, &data_resource);
>   		request_resource(res, &bss_resource);
> -		request_crashkernel(res);
>   	}
> +
> +	request_crashkernel();
>   }
>   
>   #ifdef CONFIG_SMP


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

* Re: [PATCH] mips: kernel: setup: fix crash kernel resource allocation
  2021-02-06 12:59 [PATCH] mips: kernel: setup: fix crash kernel resource allocation Ivan Khoronzhuk
  2021-02-07  3:19 ` Jinyang He
@ 2021-02-07  9:18 ` Mike Rapoport
  2021-02-08 13:29   ` Ivan Khoronzhuk
  1 sibling, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2021-02-07  9:18 UTC (permalink / raw)
  To: Ivan Khoronzhuk
  Cc: linux-mips, tsbogend, linux-kernel, yangtiezhu, ivan.khoronzhuk

On Sat, Feb 06, 2021 at 12:59:40PM +0000, Ivan Khoronzhuk wrote:
> In order to avoid crash kernel corruption, its memory is reserved
> early in memblock and as result, in time when resources are inited
> it's not present in memblock.memory, so crash kernel memory is out
> of ranges listed with for_each_mem_range(). To avoid it and still
> keep memory reserved lets reseve it out of loop by inserting it in
> iomem_resource.

Unless I misread the code, the crash kernel memory is actually allocated
from memblock (memblock_find_in_range + memblock_reserve), but for some
reason memblock_reserve(<crash kernel>) is called outside
mips_parse_crashkernel(). So the crash kernel memory is surely in both
memblock.memory and memblock.reserved and it will be covered by
for_each_mem_range().

The mips_parse_crashkernel() function and the following reservation of
crash kernel memory should be merged, IMO, and this can be further
simplified with memblock_alloc() helpers.

Is there a particular issue you are trying to fix?
 
> Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map")
> Signed-off-by: Ivan Khoronzhuk <ikhoronz@cisco.com>
> ---
> Based on linux-next/master
> 
>  arch/mips/kernel/setup.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 3785c72bc3bc..25e376ef2f2a 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -473,14 +473,15 @@ static void __init mips_parse_crashkernel(void)
>  	crashk_res.end	 = crash_base + crash_size - 1;
>  }
>  
> -static void __init request_crashkernel(struct resource *res)
> +static void __init request_crashkernel(void)
>  {
>  	int ret;
>  
>  	if (crashk_res.start == crashk_res.end)
>  		return;
>  
> -	ret = request_resource(res, &crashk_res);
> +	/* The crashk resource shoud be located in normal mem */
> +	ret = insert_resource(&iomem_resource, &crashk_res);
>  	if (!ret)
>  		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
>  			(unsigned long)(resource_size(&crashk_res) >> 20),
> @@ -734,8 +735,9 @@ static void __init resource_init(void)
>  		request_resource(res, &code_resource);
>  		request_resource(res, &data_resource);
>  		request_resource(res, &bss_resource);
> -		request_crashkernel(res);
>  	}
> +
> +	request_crashkernel();
>  }
>  
>  #ifdef CONFIG_SMP
> -- 
> 2.23.1
> 

-- 
Sincerely yours,
Mike.

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

* Re: [PATCH] mips: kernel: setup: fix crash kernel resource allocation
  2021-02-07  3:19 ` Jinyang He
@ 2021-02-08 13:17   ` Ivan Khoronzhuk
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Khoronzhuk @ 2021-02-08 13:17 UTC (permalink / raw)
  To: Jinyang He
  Cc: Ivan Khoronzhuk, linux-mips, tsbogend, linux-kernel, yangtiezhu, rppt

On Sun, Feb 07, 2021 at 11:19:03AM +0800, Jinyang He wrote:
>On 02/06/2021 08:59 PM, Ivan Khoronzhuk wrote:
>
>>In order to avoid crash kernel corruption, its memory is reserved
>>early in memblock and as result, in time when resources are inited
>>it's not present in memblock.memory, so crash kernel memory is out
>>of ranges listed with for_each_mem_range(). To avoid it and still
>>keep memory reserved lets reseve it out of loop by inserting it in
>>iomem_resource.
>
>Hi, Ivan,
>
>I'm not familiar with memblock. If the following my ideas show my
>ignorance, please forgive me.
>
>First, not only the crash kernel is reserved early in memblock, but also
>code, data, and bss are also reserved in bootmem_init():
>
>    /* Reserve memory occupied by kernel. */
>    memblock_reserve(__pa_symbol(&_text),
>            __pa_symbol(&_end) - __pa_symbol(&_text));
>
>(CONFIG_NUMA is not enabled. NUMA platform reserved them is earlier.)
>
>If there is something unsuitable with the crash kernel, is there something
>unsuitable with the kernel memory?
>
>
>Then, for_each_mem_range() is normal memory. Although memblock_reserve()
>has used before that, it just adds memory to memblock.reserved. That means
>it will still appear in memblock.memory. Thus, here I have a question,
>do we need to use replace for_each_mem_range with for_each_mem_range_rev?

Reserve doesn't mean it's present in memblock.memory, if it memory was not
added before, like it's supposed. In my canse, seems like to local issue it
wasn't, that's why it was not present. So, traverse direction won't solve
this obviously.

>
>Finally, thank you for the patch, it makes me think a lot.
>
>Thanks,
>Jinyang
>
>>Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map")
>>Signed-off-by: Ivan Khoronzhuk <ikhoronz@cisco.com>
>>---
>>Based on linux-next/master
>>
>>  arch/mips/kernel/setup.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>>diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
>>index 3785c72bc3bc..25e376ef2f2a 100644
>>--- a/arch/mips/kernel/setup.c
>>+++ b/arch/mips/kernel/setup.c
>>@@ -473,14 +473,15 @@ static void __init mips_parse_crashkernel(void)
>>  	crashk_res.end	 = crash_base + crash_size - 1;
>>  }
>>-static void __init request_crashkernel(struct resource *res)
>>+static void __init request_crashkernel(void)
>>  {
>>  	int ret;
>>  	if (crashk_res.start == crashk_res.end)
>>  		return;
>>-	ret = request_resource(res, &crashk_res);
>>+	/* The crashk resource shoud be located in normal mem */
>>+	ret = insert_resource(&iomem_resource, &crashk_res);
>>  	if (!ret)
>>  		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
>>  			(unsigned long)(resource_size(&crashk_res) >> 20),
>>@@ -734,8 +735,9 @@ static void __init resource_init(void)
>>  		request_resource(res, &code_resource);
>>  		request_resource(res, &data_resource);
>>  		request_resource(res, &bss_resource);
>>-		request_crashkernel(res);
>>  	}
>>+
>>+	request_crashkernel();
>>  }
>>  #ifdef CONFIG_SMP
>

-- 
Regards,
Ivan Khoronzhuk

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

* Re: [PATCH] mips: kernel: setup: fix crash kernel resource allocation
  2021-02-07  9:18 ` Mike Rapoport
@ 2021-02-08 13:29   ` Ivan Khoronzhuk
  0 siblings, 0 replies; 5+ messages in thread
From: Ivan Khoronzhuk @ 2021-02-08 13:29 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Ivan Khoronzhuk, linux-mips, tsbogend, linux-kernel, yangtiezhu

On Sun, Feb 07, 2021 at 11:18:42AM +0200, Mike Rapoport wrote:
>On Sat, Feb 06, 2021 at 12:59:40PM +0000, Ivan Khoronzhuk wrote:
>> In order to avoid crash kernel corruption, its memory is reserved
>> early in memblock and as result, in time when resources are inited
>> it's not present in memblock.memory, so crash kernel memory is out
>> of ranges listed with for_each_mem_range(). To avoid it and still
>> keep memory reserved lets reseve it out of loop by inserting it in
>> iomem_resource.
>
>Unless I misread the code, the crash kernel memory is actually allocated
>from memblock (memblock_find_in_range + memblock_reserve), but for some
>reason memblock_reserve(<crash kernel>) is called outside
>mips_parse_crashkernel(). So the crash kernel memory is surely in both
>memblock.memory and memblock.reserved and it will be covered by
>for_each_mem_range().
>
>The mips_parse_crashkernel() function and the following reservation of
>crash kernel memory should be merged, IMO, and this can be further
>simplified with memblock_alloc() helpers.
>
>Is there a particular issue you are trying to fix?

Yes, sorry, according to local code, seems like memory was not added
(was reverted memblock_find_in_range for some other reson while
porting), so I had only reserve. The issue is in another place,
so ignoe this patch, for now.

>
>> Fixes: a94e4f24ec83 ("MIPS: init: Drop boot_mem_map")
>> Signed-off-by: Ivan Khoronzhuk <ikhoronz@cisco.com>
>> ---
>> Based on linux-next/master
>>
>>  arch/mips/kernel/setup.c | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
>> index 3785c72bc3bc..25e376ef2f2a 100644
>> --- a/arch/mips/kernel/setup.c
>> +++ b/arch/mips/kernel/setup.c
>> @@ -473,14 +473,15 @@ static void __init mips_parse_crashkernel(void)
>>  	crashk_res.end	 = crash_base + crash_size - 1;
>>  }
>>
>> -static void __init request_crashkernel(struct resource *res)
>> +static void __init request_crashkernel(void)
>>  {
>>  	int ret;
>>
>>  	if (crashk_res.start == crashk_res.end)
>>  		return;
>>
>> -	ret = request_resource(res, &crashk_res);
>> +	/* The crashk resource shoud be located in normal mem */
>> +	ret = insert_resource(&iomem_resource, &crashk_res);
>>  	if (!ret)
>>  		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
>>  			(unsigned long)(resource_size(&crashk_res) >> 20),
>> @@ -734,8 +735,9 @@ static void __init resource_init(void)
>>  		request_resource(res, &code_resource);
>>  		request_resource(res, &data_resource);
>>  		request_resource(res, &bss_resource);
>> -		request_crashkernel(res);
>>  	}
>> +
>> +	request_crashkernel();
>>  }
>>
>>  #ifdef CONFIG_SMP
>> --
>> 2.23.1
>>
>
>-- 
>Sincerely yours,
>Mike.

-- 
Regards,
Ivan Khoronzhuk

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

end of thread, other threads:[~2021-02-08 13:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-06 12:59 [PATCH] mips: kernel: setup: fix crash kernel resource allocation Ivan Khoronzhuk
2021-02-07  3:19 ` Jinyang He
2021-02-08 13:17   ` Ivan Khoronzhuk
2021-02-07  9:18 ` Mike Rapoport
2021-02-08 13:29   ` Ivan Khoronzhuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.