Skip to contentSkip to conversation

arm64: use generic free_initrd_mem()

PATCH Superseded Mike Rapoport 3 participants 4 messages Sep 16, 2019 – Sep 23, 2019

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: use generic free_initrd_mem()

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation of free_initrd_mem(), but this call has no actual effect that late in the boot process. By the time initrd is freed, all the reserved memory is managed by the page allocator and the memblock.reserved is unused, so there is no point to update it.

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning. Switching arm64 to the generic version will enable the poisoning.

---

I've boot tested it on qemu and I've checked that kexec works.

 arch/arm64/mm/init.c | 8 --------
 1 file changed, 8 deletions(-)
arch/arm64/mm/init.c +0 -8
index f3c7952..8ad2934 100644
@@ -567,14 +567,6 @@ void free_initmem(void)
 	unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
 }
 
-#ifdef CONFIG_BLK_DEV_INITRD
-void __init free_initrd_mem(unsigned long start, unsigned long end)
-{
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-	memblock_free(__virt_to_phys(start), end - start);
-}
-#endif
-
 /*
  * Dump out memory limit information on panic.
  */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation of free_initrd_mem(), but this call has no actual effect that late in the boot process. By the time initrd is freed, all the reserved memory is managed by the page allocator and the memblock.reserved is unused, so there is no point to update it.

People like to use memblock for keeping track of memory even if it has no actual effect. We made this change explicitly (see 05c58752f9dc ("arm64: To remove initrd reserved area entry from memblock") That said, moving to the generic APIs would be nice. Maybe we can find another place to update the accounting?

Quoted 22 lines

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning. Switching arm64 to the generic version will enable the poisoning.

---

I've boot tested it on qemu and I've checked that kexec works.

  arch/arm64/mm/init.c | 8 --------
  1 file changed, 8 deletions(-)
arch/arm64/mm/init.c +0 -1
index f3c7952..8ad2934 100644
@@ -567,14 +567,6 @@ void free_initmem(void)
  	unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
  }
 
-#ifdef CONFIG_BLK_DEV_INITRD

arch/arm64/mm/init.c void free_initmem(void) · line 572

Quoted 10 lines
arch/arm64/mm/init.c +0 -7
-void __init free_initrd_mem(unsigned long start, unsigned long end)
-{
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-	memblock_free(__virt_to_phys(start), end - start);
-}
-#endif
-
  /*
   * Dump out memory limit information on panic.
   */

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw

(added linux-arch)

Quoted 10 lines · Laura Abbott
Quoted 8 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation of free_initrd_mem(), but this call has no actual effect that late in the boot process. By the time initrd is freed, all the reserved memory is managed by the page allocator and the memblock.reserved is unused, so there is no point to update it.

Quoted 4 lines

People like to use memblock for keeping track of memory even if it has no actual effect. We made this change explicitly (see 05c58752f9dc ("arm64: To remove initrd reserved area entry from memblock") That said, moving to the generic APIs would be nice. Maybe we can find another place to update the accounting?

Any other place in arch/arm64 would make it messy because it would have to duplicate keepinitrd logic.

We could put the memblock_free() in the generic free_initrd_mem() with something like:

init/initramfs.c +0 -0
index c47dad0..403c6a0 100644
@@ -531,6 +531,10 @@ void __weak free_initrd_mem(unsigned long start,

unsigned long end)
{
free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
"initrd");
+
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+ memblock_free(__virt_to_phys(start), end - start);
+#endif
}

#ifdef CONFIG_KEXEC_CORE

Then powerpc and s390 folks will also be able to track the initrd memory :)

Quoted 32 lines
Quoted 31 lines

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning. Switching arm64 to the generic version will enable the poisoning.

---

I've boot tested it on qemu and I've checked that kexec works.

 arch/arm64/mm/init.c | 8 --------
 1 file changed, 8 deletions(-)
arch/arm64/mm/init.c +0 -8
index f3c7952..8ad2934 100644
@@ -567,14 +567,6 @@ void free_initmem(void)
 	unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
 }
-#ifdef CONFIG_BLK_DEV_INITRD
-void __init free_initrd_mem(unsigned long start, unsigned long end)
-{
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-	memblock_free(__virt_to_phys(start), end - start);
-}
-#endif
-
 /*
  * Dump out memory limit information on panic.
  */
 
Signature · 2 lines
Sincerely yours,
Mike.
#3 lore raw
Quoted 29 lines · Mike Rapoport

(added linux-arch)

Quoted 10 lines · Laura Abbott
Quoted 8 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation of free_initrd_mem(), but this call has no actual effect that late in the boot process. By the time initrd is freed, all the reserved memory is managed by the page allocator and the memblock.reserved is unused, so there is no point to update it.

Quoted 4 lines

People like to use memblock for keeping track of memory even if it has no actual effect. We made this change explicitly (see 05c58752f9dc ("arm64: To remove initrd reserved area entry from memblock") That said, moving to the generic APIs would be nice. Maybe we can find another place to update the accounting?

Any other place in arch/arm64 would make it messy because it would have to duplicate keepinitrd logic.

We could put the memblock_free() in the generic free_initrd_mem() with something like:

init/initramfs.c +0 -0
index c47dad0..403c6a0 100644

init/initramfs.c void __weak free_initrd_mem(unsigned long start, · line 539

Quoted 9 lines
init/initramfs.c +4 -0
@@ -531,6 +531,10 @@ void __weak free_initrd_mem(unsigned long start,
 unsigned long end)
 {
        free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
                        "initrd");
+
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+       memblock_free(__virt_to_phys(start), end - start);
+#endif
 }

This makes sense.

Quoted 5 lines
init/initramfs.c +0 -0
 #ifdef CONFIG_KEXEC_CORE

Then powerpc and s390 folks will also be able to track the initrd memory :)

Sure.

Quoted 34 lines
Quoted 33 lines
Quoted 32 lines

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning. Switching arm64 to the generic version will enable the poisoning.

---

I've boot tested it on qemu and I've checked that kexec works.

 arch/arm64/mm/init.c | 8 --------
 1 file changed, 8 deletions(-)
arch/arm64/mm/init.c +0 -8
index f3c7952..8ad2934 100644
@@ -567,14 +567,6 @@ void free_initmem(void)
 	unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
 }
-#ifdef CONFIG_BLK_DEV_INITRD
-void __init free_initrd_mem(unsigned long start, unsigned long end)
-{
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-	memblock_free(__virt_to_phys(start), end - start);
-}
-#endif
-
 /*
  * Dump out memory limit information on panic.
  */