linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memblock: Check memory add/cap ordering
@ 2021-08-11  8:55 Geert Uytterhoeven
  2021-08-11  9:35 ` David Hildenbrand
  2021-08-11 13:06 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2021-08-11  8:55 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton; +Cc: linux-mm, linux-kernel, Geert Uytterhoeven

For memblock_cap_memory_range() to work properly, it should be called
after memory is detected and added to memblock with memblock_add() or
memblock_add_node().  If memblock_cap_memory_range() would be called
before memory is registered, we may silently corrupt memory later
because the crash kernel will see all memory as available.

Print a warning and bail out if ordering is not satisfied.

Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 mm/memblock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/memblock.c b/mm/memblock.c
index 57a9849a5d820c34..e2ca8ddc8ebebf4e 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1685,6 +1685,11 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
 	if (!size)
 		return;
 
+	if (memblock.memory.cnt <= 1) {
+		pr_warn("%s: No memory registered yet\n", __func__);
+		return;
+	}
+
 	ret = memblock_isolate_range(&memblock.memory, base, size,
 						&start_rgn, &end_rgn);
 	if (ret)
-- 
2.25.1


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

* Re: [PATCH] memblock: Check memory add/cap ordering
  2021-08-11  8:55 [PATCH] memblock: Check memory add/cap ordering Geert Uytterhoeven
@ 2021-08-11  9:35 ` David Hildenbrand
  2021-08-11 13:06 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2021-08-11  9:35 UTC (permalink / raw)
  To: Geert Uytterhoeven, Mike Rapoport, Andrew Morton; +Cc: linux-mm, linux-kernel

On 11.08.21 10:55, Geert Uytterhoeven wrote:
> For memblock_cap_memory_range() to work properly, it should be called
> after memory is detected and added to memblock with memblock_add() or
> memblock_add_node().  If memblock_cap_memory_range() would be called
> before memory is registered, we may silently corrupt memory later
> because the crash kernel will see all memory as available.
> 
> Print a warning and bail out if ordering is not satisfied.
> 
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>   mm/memblock.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 57a9849a5d820c34..e2ca8ddc8ebebf4e 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1685,6 +1685,11 @@ void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size)
>   	if (!size)
>   		return;
>   
> +	if (memblock.memory.cnt <= 1) {
> +		pr_warn("%s: No memory registered yet\n", __func__);
> +		return;
> +	}
> +
>   	ret = memblock_isolate_range(&memblock.memory, base, size,
>   						&start_rgn, &end_rgn);
>   	if (ret)
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH] memblock: Check memory add/cap ordering
  2021-08-11  8:55 [PATCH] memblock: Check memory add/cap ordering Geert Uytterhoeven
  2021-08-11  9:35 ` David Hildenbrand
@ 2021-08-11 13:06 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2021-08-11 13:06 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Andrew Morton, David Hildenbrand, linux-mm, linux-kernel

On Wed, Aug 11, 2021 at 10:55:18AM +0200, Geert Uytterhoeven wrote:
> For memblock_cap_memory_range() to work properly, it should be called
> after memory is detected and added to memblock with memblock_add() or
> memblock_add_node().  If memblock_cap_memory_range() would be called
> before memory is registered, we may silently corrupt memory later
> because the crash kernel will see all memory as available.
> 
> Print a warning and bail out if ordering is not satisfied.
> 
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Applied for 5.15,
Thanks!

-- 
Sincerely yours,
Mike.

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  8:55 [PATCH] memblock: Check memory add/cap ordering Geert Uytterhoeven
2021-08-11  9:35 ` David Hildenbrand
2021-08-11 13:06 ` Mike Rapoport

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