linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: kexec: Add crashkernel=YM handling
@ 2020-09-19  1:55 Youling Tang
  2020-09-19  7:02 ` Jiaxun Yang
  2020-09-21 20:41 ` Thomas Bogendoerfer
  0 siblings, 2 replies; 5+ messages in thread
From: Youling Tang @ 2020-09-19  1:55 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel

When the kernel crashkernel parameter is specified with just a size,
we are supposed to allocate a region from RAM to store the crashkernel.
However, MIPS merely reserves physical address zero with no checking
that there is even RAM there.

Fix this by lifting similar code from x86, importing it to MIPS with the
MIPS specific parameters added. In the absence of any platform specific
information, we allocate the crashkernel region from the first 512MB of
physical memory (limited to CKSEG0 or KSEG0 address range).

When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM).

E.g. without this patch:

The environment as follows:
[    0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a
...
[    0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ...

The warning as follows:
[    0.000000] Invalid memory region reserved for crash kernel

And the iomem as follows:
00200000-0effffff : System RAM
  00200000-00b47f87 : Kernel code
  00b47f88-00dfffff : Kernel data
  00e60000-01f73c7f : Kernel bss
1a000000-1bffffff : pci@1a000000
...

With this patch:

After increasing crash_base <= 0 handling.

And the iomem as follows:
00200000-0effffff : System RAM
  00200000-00b47f87 : Kernel code
  00b47f88-00dfffff : Kernel data
  00e60000-01f73c7f : Kernel bss
  04000000-09ffffff : Crash kernel
1a000000-1bffffff : pci@1a000000
...

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 arch/mips/kernel/setup.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index bf5f5ac..59a88ea 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr);
 #endif
 
 #ifdef CONFIG_KEXEC
+
+/* 64M alignment for crash kernel regions */
+#define CRASH_ALIGN	SZ_64M
+#define CRASH_ADDR_MAX	SZ_512M
+
 static void __init mips_parse_crashkernel(void)
 {
 	unsigned long long total_mem;
@@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void)
 	if (ret != 0 || crash_size <= 0)
 		return;
 
-	if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) {
-		pr_warn("Invalid memory region reserved for crash kernel\n");
-		return;
+	if (crash_base <= 0) {
+		crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX,
+							crash_size, CRASH_ALIGN);
+		if (!crash_base) {
+			pr_warn("crashkernel reservation failed - No suitable area found.\n");
+			return;
+		}
+	} else {
+		unsigned long long start;
+
+		start = memblock_find_in_range(crash_base, crash_base + crash_size,
+						crash_size, 1);
+		if (start != crash_base) {
+			pr_warn("Invalid memory region reserved for crash kernel\n");
+			return;
+		}
 	}
 
 	crashk_res.start = crash_base;
-- 
2.1.0


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

* Re: [PATCH] MIPS: kexec: Add crashkernel=YM handling
  2020-09-19  1:55 [PATCH] MIPS: kexec: Add crashkernel=YM handling Youling Tang
@ 2020-09-19  7:02 ` Jiaxun Yang
  2020-09-19  8:29   ` Youling Tang
  2020-09-21 20:41 ` Thomas Bogendoerfer
  1 sibling, 1 reply; 5+ messages in thread
From: Jiaxun Yang @ 2020-09-19  7:02 UTC (permalink / raw)
  To: Youling Tang, Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel



于 2020年9月19日 GMT+08:00 上午9:55:46, Youling Tang <tangyouling@loongson.cn> 写到:
>When the kernel crashkernel parameter is specified with just a size,
>we are supposed to allocate a region from RAM to store the crashkernel.
>However, MIPS merely reserves physical address zero with no checking
>that there is even RAM there.
>
>Fix this by lifting similar code from x86, importing it to MIPS with the
>MIPS specific parameters added. In the absence of any platform specific
>information, we allocate the crashkernel region from the first 512MB of
>physical memory (limited to CKSEG0 or KSEG0 address range).
>
>When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM).
>
>E.g. without this patch:
>
>The environment as follows:
>[    0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a
>...
>[    0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ...
>
>The warning as follows:
>[    0.000000] Invalid memory region reserved for crash kernel
>
>And the iomem as follows:
>00200000-0effffff : System RAM
>  00200000-00b47f87 : Kernel code
>  00b47f88-00dfffff : Kernel data
>  00e60000-01f73c7f : Kernel bss
>1a000000-1bffffff : pci@1a000000
>...
>
>With this patch:
>
>After increasing crash_base <= 0 handling.
>
>And the iomem as follows:
>00200000-0effffff : System RAM
>  00200000-00b47f87 : Kernel code
>  00b47f88-00dfffff : Kernel data
>  00e60000-01f73c7f : Kernel bss
>  04000000-09ffffff : Crash kernel
>1a000000-1bffffff : pci@1a000000
>...
>
>Signed-off-by: Youling Tang <tangyouling@loongson.cn>
>---
> arch/mips/kernel/setup.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
>diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
>index bf5f5ac..59a88ea 100644
>--- a/arch/mips/kernel/setup.c
>+++ b/arch/mips/kernel/setup.c
>@@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr);
> #endif
> 
> #ifdef CONFIG_KEXEC
>+
>+/* 64M alignment for crash kernel regions */
>+#define CRASH_ALIGN	SZ_64M
>+#define CRASH_ADDR_MAX	SZ_512M

Hi Youling

How do you determine the alignment requirement?

Can we relax it?

Thanks.

- Jiaxun

>+
> static void __init mips_parse_crashkernel(void)
> {
> 	unsigned long long total_mem;
>@@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void)
> 	if (ret != 0 || crash_size <= 0)
> 		return;
> 
>-	if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) {
>-		pr_warn("Invalid memory region reserved for crash kernel\n");
>-		return;
>+	if (crash_base <= 0) {
>+		crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX,
>+							crash_size, CRASH_ALIGN);
>+		if (!crash_base) {
>+			pr_warn("crashkernel reservation failed - No suitable area found.\n");
>+			return;
>+		}
>+	} else {
>+		unsigned long long start;
>+
>+		start = memblock_find_in_range(crash_base, crash_base + crash_size,
>+						crash_size, 1);
>+		if (start != crash_base) {
>+			pr_warn("Invalid memory region reserved for crash kernel\n");
>+			return;
>+		}
> 	}
> 
> 	crashk_res.start = crash_base;

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

* Re: [PATCH] MIPS: kexec: Add crashkernel=YM handling
  2020-09-19  7:02 ` Jiaxun Yang
@ 2020-09-19  8:29   ` Youling Tang
  2020-09-19 10:17     ` Jiaxun Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Youling Tang @ 2020-09-19  8:29 UTC (permalink / raw)
  To: Jiaxun Yang, Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel



On 09/19/2020 03:02 PM, Jiaxun Yang wrote:
>
> 于 2020年9月19日 GMT+08:00 上午9:55:46, Youling Tang <tangyouling@loongson.cn> 写到:
>> When the kernel crashkernel parameter is specified with just a size,
>> we are supposed to allocate a region from RAM to store the crashkernel.
>> However, MIPS merely reserves physical address zero with no checking
>> that there is even RAM there.
>>
>> Fix this by lifting similar code from x86, importing it to MIPS with the
>> MIPS specific parameters added. In the absence of any platform specific
>> information, we allocate the crashkernel region from the first 512MB of
>> physical memory (limited to CKSEG0 or KSEG0 address range).
>>
>> When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM).
>>
>> E.g. without this patch:
>>
>> The environment as follows:
>> [    0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a
>> ...
>> [    0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ...
>>
>> The warning as follows:
>> [    0.000000] Invalid memory region reserved for crash kernel
>>
>> And the iomem as follows:
>> 00200000-0effffff : System RAM
>>   00200000-00b47f87 : Kernel code
>>   00b47f88-00dfffff : Kernel data
>>   00e60000-01f73c7f : Kernel bss
>> 1a000000-1bffffff : pci@1a000000
>> ...
>>
>> With this patch:
>>
>> After increasing crash_base <= 0 handling.
>>
>> And the iomem as follows:
>> 00200000-0effffff : System RAM
>>   00200000-00b47f87 : Kernel code
>>   00b47f88-00dfffff : Kernel data
>>   00e60000-01f73c7f : Kernel bss
>>   04000000-09ffffff : Crash kernel
>> 1a000000-1bffffff : pci@1a000000
>> ...
>>
>> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
>> ---
>> arch/mips/kernel/setup.c | 24 +++++++++++++++++++++---
>> 1 file changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
>> index bf5f5ac..59a88ea 100644
>> --- a/arch/mips/kernel/setup.c
>> +++ b/arch/mips/kernel/setup.c
>> @@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr);
>> #endif
>>
>> #ifdef CONFIG_KEXEC
>> +
>> +/* 64M alignment for crash kernel regions */
>> +#define CRASH_ALIGN	SZ_64M
>> +#define CRASH_ADDR_MAX	SZ_512M
> Hi Youling
>
> How do you determine the alignment requirement?
>
> Can we relax it?
>
> Thanks.
>
> - Jiaxun
Hi Jiaxun

Only when XM is not specified, 64M alignment is specified.

After the capture kernel is configured with CRASH_DUMP, PHYSICAL_START
defaults to 0x0xffffffff84000000 (64M). The kexec -p operation will
succeed only when the reserved Crash kernel start address is consistent
with PHYSICAL_START.

The description of PHYSICAL_START in arch/mips/Kconfig:2996 is as follows:
This gives the CKSEG0 or KSEG0 address where the kernel is loaded.If you
plan to use kernel for capturing the crash dump change this value to start
of the reserved region (the "X" value as specified in the 
"crashkernel=YM@XM"
command line boot parameter passed to the panic-ed kernel).

Thanks,

- Youling
>> +
>> static void __init mips_parse_crashkernel(void)
>> {
>> 	unsigned long long total_mem;
>> @@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void)
>> 	if (ret != 0 || crash_size <= 0)
>> 		return;
>>
>> -	if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) {
>> -		pr_warn("Invalid memory region reserved for crash kernel\n");
>> -		return;
>> +	if (crash_base <= 0) {
>> +		crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX,
>> +							crash_size, CRASH_ALIGN);
>> +		if (!crash_base) {
>> +			pr_warn("crashkernel reservation failed - No suitable area found.\n");
>> +			return;
>> +		}
>> +	} else {
>> +		unsigned long long start;
>> +
>> +		start = memblock_find_in_range(crash_base, crash_base + crash_size,
>> +						crash_size, 1);
>> +		if (start != crash_base) {
>> +			pr_warn("Invalid memory region reserved for crash kernel\n");
>> +			return;
>> +		}
>> 	}
>>
>> 	crashk_res.start = crash_base;


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

* Re: [PATCH] MIPS: kexec: Add crashkernel=YM handling
  2020-09-19  8:29   ` Youling Tang
@ 2020-09-19 10:17     ` Jiaxun Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Jiaxun Yang @ 2020-09-19 10:17 UTC (permalink / raw)
  To: Youling Tang, Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel



于 2020年9月19日 GMT+08:00 下午4:29:39, Youling Tang <tangyouling@loongson.cn> 写到:
>
>
>On 09/19/2020 03:02 PM, Jiaxun Yang wrote:
>>
>> 于 2020年9月19日 GMT+08:00 上午9:55:46, Youling Tang <tangyouling@loongson.cn> 写到:
>>> When the kernel crashkernel parameter is specified with just a size,
>>> we are supposed to allocate a region from RAM to store the crashkernel.
>>> However, MIPS merely reserves physical address zero with no checking
>>> that there is even RAM there.
>>>
>>> Fix this by lifting similar code from x86, importing it to MIPS with the
>>> MIPS specific parameters added. In the absence of any platform specific
>>> information, we allocate the crashkernel region from the first 512MB of
>>> physical memory (limited to CKSEG0 or KSEG0 address range).
>>>
>>> When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM).
>>>
>>> E.g. without this patch:
>>>
>>> The environment as follows:
>>> [    0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a
>>> ...
>>> [    0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ...
>>>
>>> The warning as follows:
>>> [    0.000000] Invalid memory region reserved for crash kernel
>>>
>>> And the iomem as follows:
>>> 00200000-0effffff : System RAM
>>>   00200000-00b47f87 : Kernel code
>>>   00b47f88-00dfffff : Kernel data
>>>   00e60000-01f73c7f : Kernel bss
>>> 1a000000-1bffffff : pci@1a000000
>>> ...
>>>
>>> With this patch:
>>>
>>> After increasing crash_base <= 0 handling.
>>>
>>> And the iomem as follows:
>>> 00200000-0effffff : System RAM
>>>   00200000-00b47f87 : Kernel code
>>>   00b47f88-00dfffff : Kernel data
>>>   00e60000-01f73c7f : Kernel bss
>>>   04000000-09ffffff : Crash kernel
>>> 1a000000-1bffffff : pci@1a000000
>>> ...
>>>
>>> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
>>> ---
>>> arch/mips/kernel/setup.c | 24 +++++++++++++++++++++---
>>> 1 file changed, 21 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
>>> index bf5f5ac..59a88ea 100644
>>> --- a/arch/mips/kernel/setup.c
>>> +++ b/arch/mips/kernel/setup.c
>>> @@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr);
>>> #endif
>>>
>>> #ifdef CONFIG_KEXEC
>>> +
>>> +/* 64M alignment for crash kernel regions */
>>> +#define CRASH_ALIGN	SZ_64M
>>> +#define CRASH_ADDR_MAX	SZ_512M
>> Hi Youling
>>
>> How do you determine the alignment requirement?
>>
>> Can we relax it?
>>
>> Thanks.
>>
>> - Jiaxun
>Hi Jiaxun
>
>Only when XM is not specified, 64M alignment is specified.
>
>After the capture kernel is configured with CRASH_DUMP, PHYSICAL_START
>defaults to 0x0xffffffff84000000 (64M). The kexec -p operation will
>succeed only when the reserved Crash kernel start address is consistent
>with PHYSICAL_START.
>
>The description of PHYSICAL_START in arch/mips/Kconfig:2996 is as follows:
>This gives the CKSEG0 or KSEG0 address where the kernel is loaded.If you
>plan to use kernel for capturing the crash dump change this value to start
>of the reserved region (the "X" value as specified in the 
>"crashkernel=YM@XM"
>command line boot parameter passed to the panic-ed kernel).

Thanks for your explanation~

That makes sense.

- Jiaxun


>
>Thanks,
>
>- Youling

[...]

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

* Re: [PATCH] MIPS: kexec: Add crashkernel=YM handling
  2020-09-19  1:55 [PATCH] MIPS: kexec: Add crashkernel=YM handling Youling Tang
  2020-09-19  7:02 ` Jiaxun Yang
@ 2020-09-21 20:41 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Bogendoerfer @ 2020-09-21 20:41 UTC (permalink / raw)
  To: Youling Tang; +Cc: linux-mips, linux-kernel

On Sat, Sep 19, 2020 at 09:55:46AM +0800, Youling Tang wrote:
> When the kernel crashkernel parameter is specified with just a size,
> we are supposed to allocate a region from RAM to store the crashkernel.
> However, MIPS merely reserves physical address zero with no checking
> that there is even RAM there.
> 
> Fix this by lifting similar code from x86, importing it to MIPS with the
> MIPS specific parameters added. In the absence of any platform specific
> information, we allocate the crashkernel region from the first 512MB of
> physical memory (limited to CKSEG0 or KSEG0 address range).
> 
> When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM).
> 
> E.g. without this patch:
> 
> The environment as follows:
> [    0.000000] MIPS: machine is loongson,loongson64c-4core-ls7a
> ...
> [    0.000000] Kernel command line: root=/dev/sda2 crashkernel=96M ...
> 
> The warning as follows:
> [    0.000000] Invalid memory region reserved for crash kernel
> 
> And the iomem as follows:
> 00200000-0effffff : System RAM
>   00200000-00b47f87 : Kernel code
>   00b47f88-00dfffff : Kernel data
>   00e60000-01f73c7f : Kernel bss
> 1a000000-1bffffff : pci@1a000000
> ...
> 
> With this patch:
> 
> After increasing crash_base <= 0 handling.
> 
> And the iomem as follows:
> 00200000-0effffff : System RAM
>   00200000-00b47f87 : Kernel code
>   00b47f88-00dfffff : Kernel data
>   00e60000-01f73c7f : Kernel bss
>   04000000-09ffffff : Crash kernel
> 1a000000-1bffffff : pci@1a000000
> ...
> 
> Signed-off-by: Youling Tang <tangyouling@loongson.cn>
> ---
>  arch/mips/kernel/setup.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

end of thread, other threads:[~2020-09-21 21:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-19  1:55 [PATCH] MIPS: kexec: Add crashkernel=YM handling Youling Tang
2020-09-19  7:02 ` Jiaxun Yang
2020-09-19  8:29   ` Youling Tang
2020-09-19 10:17     ` Jiaxun Yang
2020-09-21 20:41 ` Thomas Bogendoerfer

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