[PATCH v2] arm64/mm: Delete __init region from memblock.reserved

Rong Qianfeng posted 1 patch 1 year, 3 months ago
arch/arm64/mm/init.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH v2] arm64/mm: Delete __init region from memblock.reserved
Posted by Rong Qianfeng 1 year, 3 months ago
If CONFIG_ARCH_KEEP_MEMBLOCK is enabled, the memory information in
memblock will be retained.  We release the __init memory here, and
we should also delete the corresponding region in memblock.reserved,
which allows debugfs/memblock/reserved to display correct memory
information.

Signed-off-by: Rong Qianfeng <rongqianfeng@vivo.com>
---
-v2:
* Removed the conditional check for whether CONFIG_ARCH_KEEP_MEMBLOCK
  is enabled, since it is always enabled on arm64.Thanks to
  Ard Biesheuvel for the correction.

-v1:
https://lore.kernel.org/lkml/20240830080020.33666-1-rongqianfeng@vivo.com/

 arch/arm64/mm/init.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index bfb10969cbf0..b275ead50415 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -402,6 +402,12 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
+	unsigned long aligned_begin = ALIGN_DOWN((u64)__init_begin, PAGE_SIZE);
+	unsigned long aligned_end = ALIGN((u64)__init_end, PAGE_SIZE);
+
+	/* Delete __init region from memblock.reserved. */
+	memblock_free((void *)aligned_begin, aligned_end - aligned_begin);
+
 	free_reserved_area(lm_alias(__init_begin),
 			   lm_alias(__init_end),
 			   POISON_FREE_INITMEM, "unused kernel");
-- 
2.39.0
Re: [PATCH v2] arm64/mm: Delete __init region from memblock.reserved
Posted by Will Deacon 1 year, 3 months ago
On Mon, 02 Sep 2024 10:39:35 +0800, Rong Qianfeng wrote:
> If CONFIG_ARCH_KEEP_MEMBLOCK is enabled, the memory information in
> memblock will be retained.  We release the __init memory here, and
> we should also delete the corresponding region in memblock.reserved,
> which allows debugfs/memblock/reserved to display correct memory
> information.
> 
> 
> [...]

Applied to arm64 (for-next/mm), thanks!

[1/1] arm64/mm: Delete __init region from memblock.reserved
      https://git.kernel.org/arm64/c/1db9716d4487

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev