Skip to contentSkip to conversation

arm64: use generic free_initrd_mem()

PATCH Applied Mike Rapoport 4 participants 6 messages Sep 28, 2019 – Oct 16, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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 the only purpose of the memblock_free() call is to keep track of initrd memory for debugging and accounting.

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the generic implementation of free_initrd_mem() on arm64.

---

v4:
* memblock_free() aligned area around the initrd

v3:
* fix powerpc build

v2:
* add memblock_free() to the generic free_initrd_mem()
* rebase on the current upstream

 arch/arm64/mm/init.c | 12 ------------
 init/initramfs.c     |  8 ++++++++
 2 files changed, 8 insertions(+), 12 deletions(-)
arch/arm64/mm/init.c +0 -12
index 45c00a5..87a0e3b 100644
@@ -580,18 +580,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)
-{
-	unsigned long aligned_start, aligned_end;
-
-	aligned_start = __virt_to_phys(start) & PAGE_MASK;
-	aligned_end = PAGE_ALIGN(__virt_to_phys(end));
-	memblock_free(aligned_start, aligned_end - aligned_start);
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-}
-#endif
-
 /*
  * Dump out memory limit information on panic.
  */
init/initramfs.c +8 -0
index c47dad0..8ec1be4 100644
@@ -10,6 +10,7 @@
 #include <linux/syscalls.h>
 #include <linux/utime.h>
 #include <linux/file.h>
+#include <linux/memblock.h>
 
 static ssize_t __init xwrite(int fd, const char *p, size_t count)
 {
@@ -529,6 +530,13 @@ extern unsigned long __initramfs_size;
 
 void __weak free_initrd_mem(unsigned long start, unsigned long end)
 {
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+	unsigned long aligned_start = ALIGN_DOWN(start, PAGE_SIZE);
+	unsigned long aligned_end = ALIGN(end, PAGE_SIZE);
+
+	memblock_free(__pa(aligned_start), aligned_end - aligned_start);
+#endif
+
 	free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
 			"initrd");
 }
Signature · 1 line
2.7.4
Tested-by Reviewed-by on v4 1/1
#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 the only purpose of the memblock_free() call is to keep track of initrd memory for debugging and accounting.

Thats correct. memblock_free_all() gets called before free_initrd_mem().

Quoted 7 lines

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the generic implementation of free_initrd_mem() on arm64.

This improves free_initrd_mem() generic implementation for others to use.

Quoted 2 lines
Quoted 57 lines

---

v4:
* memblock_free() aligned area around the initrd

v3:
* fix powerpc build

v2:
* add memblock_free() to the generic free_initrd_mem()
* rebase on the current upstream

 arch/arm64/mm/init.c | 12 ------------
 init/initramfs.c     |  8 ++++++++
 2 files changed, 8 insertions(+), 12 deletions(-)
arch/arm64/mm/init.c +0 -12
index 45c00a5..87a0e3b 100644
@@ -580,18 +580,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)
-{
-	unsigned long aligned_start, aligned_end;
-
-	aligned_start = __virt_to_phys(start) & PAGE_MASK;
-	aligned_end = PAGE_ALIGN(__virt_to_phys(end));
-	memblock_free(aligned_start, aligned_end - aligned_start);
-	free_reserved_area((void *)start, (void *)end, 0, "initrd");
-}
-#endif
-
 /*
  * Dump out memory limit information on panic.
  */
init/initramfs.c +1 -0
index c47dad0..8ec1be4 100644
@@ -10,6 +10,7 @@
 #include <linux/syscalls.h>
 #include <linux/utime.h>
 #include <linux/file.h>
+#include <linux/memblock.h>
 
 static ssize_t __init xwrite(int fd, const char *p, size_t count)
 {
@@ -529,6 +530,13 @@ extern unsigned long __initramfs_size;
 
 void __weak free_initrd_mem(unsigned long start, unsigned long end)
 {

init/initramfs.c extern unsigned long __initramfs_size; · line 542

Quoted 10 lines
init/initramfs.c +7 -0
+#ifdef CONFIG_ARCH_KEEP_MEMBLOCK
+	unsigned long aligned_start = ALIGN_DOWN(start, PAGE_SIZE);
+	unsigned long aligned_end = ALIGN(end, PAGE_SIZE);
+
+	memblock_free(__pa(aligned_start), aligned_end - aligned_start);
+#endif
+
 	free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
 			"initrd");
 }

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

maintainer Acked-by on v4 1/1
#2 lore raw
In reply to Mike Rapoport
Quoted 16 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 the only purpose of the memblock_free() call is to keep track of initrd memory for debugging and accounting.

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the generic implementation of free_initrd_mem() on arm64.

Quoted 5 lines

---

v4:
* memblock_free() aligned area around the initrd

Looks straightforward to me:

Will

#3 lore raw
Quoted 27 lines · Will Deacon
Quoted 3 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation

of

Quoted 1 line

free_initrd_mem(), but this call has no actual effect that late in

the boot

Quoted 1 line

process. By the time initrd is freed, all the reserved memory is

managed by

Quoted 1 line

the page allocator and the memblock.reserved is unused, so the only

purpose

Quoted 1 line

of the memblock_free() call is to keep track of initrd memory for

debugging

Quoted 3 lines

and accounting.

Without the memblock_free() call the only difference between arm64

and the

Quoted 4 lines

generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the

generic

Quoted 5 lines

implementation of free_initrd_mem() on arm64.

---

Quoted 6 lines
Quoted 2 lines

v4:
* memblock_free() aligned area around the initrd

Looks straightforward to me:

Can it go via arm64 tree?

Quoted 1 line

Will

Signature · 2 lines
Sincerely yours,
Mike
maintainer
#4 lore raw
Quoted 28 lines · Mike Rapoport
Quoted 27 lines · Will Deacon
Quoted 3 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

arm64 calls memblock_free() for the initrd area in its implementation

of

Quoted 1 line

free_initrd_mem(), but this call has no actual effect that late in

the boot

Quoted 1 line

process. By the time initrd is freed, all the reserved memory is

managed by

Quoted 1 line

the page allocator and the memblock.reserved is unused, so the only

purpose

Quoted 1 line

of the memblock_free() call is to keep track of initrd memory for

debugging

Quoted 3 lines

and accounting.

Without the memblock_free() call the only difference between arm64

and the

Quoted 4 lines

generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the

generic

Quoted 5 lines

implementation of free_initrd_mem() on arm64.

---

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

v4:
* memblock_free() aligned area around the initrd

Looks straightforward to me:

Can it go via arm64 tree?

Yes, I was hoping Catalin would pick it up for 5.5.

Will

maintainer Applied
#5 lore raw
In reply to Mike Rapoport
Quoted 9 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 the only purpose of the memblock_free() call is to keep track of initrd memory for debugging and accounting.

Quoted 8 lines

Without the memblock_free() call the only difference between arm64 and the generic versions of free_initrd_mem() is the memory poisoning.

Move memblock_free() call to the generic code, enable it there for the architectures that define ARCH_KEEP_MEMBLOCK and use the generic implementation of free_initrd_mem() on arm64.

Queued for 5.5. Thanks.

Signature · 1 line
Catalin