Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] MIPS: Fix unable to reserve memory for Crash kernel
@ 2020-07-25  5:56 Jinyang He
  2020-07-25  7:01 ` Jiaxun Yang
  2020-07-26 11:57 ` Thomas Bogendoerfer
  0 siblings, 2 replies; 3+ messages in thread
From: Jinyang He @ 2020-07-25  5:56 UTC (permalink / raw)
  To: linux-mips; +Cc: Jinyang He

Use 0 as the align parameter in memblock_find_in_range() is
incorrect when we reserve memory for Crash kernel.

The environment as follows:
[    0.000000] MIPS: machine is loongson,loongson64c-4core-rs780e
...
[    1.951016]     crashkernel=64M@128M

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

And the iomem as follows:
00200000-0effffff : System RAM
  04000000-0484009f : Kernel code
  048400a0-04ad7fff : Kernel data
  04b40000-05c4c6bf : Kernel bss
1a000000-1bffffff : pci@1a000000
...

The align parameter may be finally used by round_down() or round_up().
Like the following call tree:

mips-next: mm/memblock.c

memblock_find_in_range
└── memblock_find_in_range_node
    ├── __memblock_find_range_bottom_up
    │   └── round_up
    └── __memblock_find_range_top_down
        └── round_down
\#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
\#define round_down(x, y) ((x) & ~__round_mask(x, y))
\#define __round_mask(x, y) ((__typeof__(x))((y)-1))

The round_down(or round_up)'s second parameter must be a power of 2.
If the second parameter is 0, it both will return 0.

Use 1 as the parameter to fix the bug and the iomem as follows:
00200000-0effffff : System RAM
  04000000-0484009f : Kernel code
  048400a0-04ad7fff : Kernel data
  04b40000-05c4c6bf : Kernel bss
  08000000-0bffffff : Crash kernel
1a000000-1bffffff : pci@1a000000
...

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 7b537fa..588b212 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -497,7 +497,7 @@ 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, 0)) {
+	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;
 	}
-- 
2.1.0


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

* Re: [PATCH] MIPS: Fix unable to reserve memory for Crash kernel
  2020-07-25  5:56 [PATCH] MIPS: Fix unable to reserve memory for Crash kernel Jinyang He
@ 2020-07-25  7:01 ` Jiaxun Yang
  2020-07-26 11:57 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Jiaxun Yang @ 2020-07-25  7:01 UTC (permalink / raw)
  To: Jinyang He, linux-mips



在 2020/7/25 13:56, Jinyang He 写道:
> Use 0 as the align parameter in memblock_find_in_range() is
> incorrect when we reserve memory for Crash kernel.
>
> The environment as follows:
> [    0.000000] MIPS: machine is loongson,loongson64c-4core-rs780e
> ...
> [    1.951016]     crashkernel=64M@128M
>
> The warning as follows:
> [    0.000000] Invalid memory region reserved for crash kernel
>
> And the iomem as follows:
> 00200000-0effffff : System RAM
>    04000000-0484009f : Kernel code
>    048400a0-04ad7fff : Kernel data
>    04b40000-05c4c6bf : Kernel bss
> 1a000000-1bffffff : pci@1a000000
> ...
>
> The align parameter may be finally used by round_down() or round_up().
> Like the following call tree:
>
> mips-next: mm/memblock.c
>
> memblock_find_in_range
> └── memblock_find_in_range_node
>      ├── __memblock_find_range_bottom_up
>      │   └── round_up
>      └── __memblock_find_range_top_down
>          └── round_down
> \#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
> \#define round_down(x, y) ((x) & ~__round_mask(x, y))
> \#define __round_mask(x, y) ((__typeof__(x))((y)-1))
>
> The round_down(or round_up)'s second parameter must be a power of 2.
> If the second parameter is 0, it both will return 0.
>
> Use 1 as the parameter to fix the bug and the iomem as follows:
> 00200000-0effffff : System RAM
>    04000000-0484009f : Kernel code
>    048400a0-04ad7fff : Kernel data
>    04b40000-05c4c6bf : Kernel bss
>    08000000-0bffffff : Crash kernel
> 1a000000-1bffffff : pci@1a000000
> ...
>
> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

Oops, looks like my fault during switch boot_mem_map to memblock.

Thanks.

- Jiaxun

> ---
>   arch/mips/kernel/setup.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 7b537fa..588b212 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -497,7 +497,7 @@ 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, 0)) {
> +	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;
>   	}

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

* Re: [PATCH] MIPS: Fix unable to reserve memory for Crash kernel
  2020-07-25  5:56 [PATCH] MIPS: Fix unable to reserve memory for Crash kernel Jinyang He
  2020-07-25  7:01 ` Jiaxun Yang
@ 2020-07-26 11:57 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Bogendoerfer @ 2020-07-26 11:57 UTC (permalink / raw)
  To: Jinyang He; +Cc: linux-mips

On Sat, Jul 25, 2020 at 01:56:38PM +0800, Jinyang He wrote:
> Use 0 as the align parameter in memblock_find_in_range() is
> incorrect when we reserve memory for Crash kernel.
> 
> The environment as follows:
> [    0.000000] MIPS: machine is loongson,loongson64c-4core-rs780e
> ...
> [    1.951016]     crashkernel=64M@128M
> 
> The warning as follows:
> [    0.000000] Invalid memory region reserved for crash kernel
> 
> And the iomem as follows:
> 00200000-0effffff : System RAM
>   04000000-0484009f : Kernel code
>   048400a0-04ad7fff : Kernel data
>   04b40000-05c4c6bf : Kernel bss
> 1a000000-1bffffff : pci@1a000000
> ...
> 
> The align parameter may be finally used by round_down() or round_up().
> Like the following call tree:
> 
> mips-next: mm/memblock.c
> 
> memblock_find_in_range
> └── memblock_find_in_range_node
>     ├── __memblock_find_range_bottom_up
>     │   └── round_up
>     └── __memblock_find_range_top_down
>         └── round_down
> \#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
> \#define round_down(x, y) ((x) & ~__round_mask(x, y))
> \#define __round_mask(x, y) ((__typeof__(x))((y)-1))
> 
> The round_down(or round_up)'s second parameter must be a power of 2.
> If the second parameter is 0, it both will return 0.
> 
> Use 1 as the parameter to fix the bug and the iomem as follows:
> 00200000-0effffff : System RAM
>   04000000-0484009f : Kernel code
>   048400a0-04ad7fff : Kernel data
>   04b40000-05c4c6bf : Kernel bss
>   08000000-0bffffff : Crash kernel
> 1a000000-1bffffff : pci@1a000000
> ...
> 
> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
> ---
>  arch/mips/kernel/setup.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-25  5:56 [PATCH] MIPS: Fix unable to reserve memory for Crash kernel Jinyang He
2020-07-25  7:01 ` Jiaxun Yang
2020-07-26 11:57 ` Thomas Bogendoerfer

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org
	public-inbox-index linux-mips

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mips


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git