Skip to contentSkip to conversation

provide a generic free_initmem implementation

PATCH In review Mike Rapoport 1 participant 6 messages Feb 18, 2019 – Mar 25, 2019

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

v2 cover provide a generic free_initmem implementation

Hi,

Many architectures implement free_initmem() in exactly the same or very similar way: they wrap the call to free_initmem_default() with sometimes different 'poison' parameter.

These patches switch those architectures to use a generic implementation that does free_initmem_default(POISON_FREE_INITMEM).

This was inspired by Christoph's patches for free_initrd_mem [1] and I shamelessly copied changelog entries from his patches :)

v2: rebased on top of v5.0-rc7 + Christoph's patches for free_initrd_mem

[1] https://lore.kernel.org/lkml/[email protected]/

Mike Rapoport (4):
init: provide a generic free_initmem implementation
hexagon: switch over to generic free_initmem()
init: free_initmem: poison freed init memory
riscv: switch over to generic free_initmem()

 arch/alpha/mm/init.c      |  6 ------
 arch/arc/mm/init.c        |  8 --------
 arch/c6x/mm/init.c        |  5 -----
 arch/h8300/mm/init.c      |  6 ------
 arch/hexagon/mm/init.c    | 10 ----------
 arch/microblaze/mm/init.c |  5 -----
 arch/nds32/mm/init.c      |  5 -----
 arch/nios2/mm/init.c      |  5 -----
 arch/openrisc/mm/init.c   |  5 -----
 arch/riscv/mm/init.c      |  5 -----
 arch/sh/mm/init.c         |  5 -----
 arch/sparc/mm/init_32.c   |  5 -----
 arch/unicore32/mm/init.c  |  5 -----
 arch/xtensa/mm/init.c     |  5 -----
 init/main.c               |  5 +++++
 15 files changed, 5 insertions(+), 80 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/4 init: provide a generic free_initmem implementation

For most architectures free_initmem just a wrapper for the same free_initmem_default(-1) call.
Provide that as a generic implementation marked __weak.

---
 arch/alpha/mm/init.c      | 6 ------
 arch/arc/mm/init.c        | 8 --------
 arch/c6x/mm/init.c        | 5 -----
 arch/h8300/mm/init.c      | 6 ------
 arch/microblaze/mm/init.c | 5 -----
 arch/nds32/mm/init.c      | 5 -----
 arch/nios2/mm/init.c      | 5 -----
 arch/openrisc/mm/init.c   | 5 -----
 arch/sh/mm/init.c         | 5 -----
 arch/unicore32/mm/init.c  | 5 -----
 arch/xtensa/mm/init.c     | 5 -----
 init/main.c               | 5 +++++
 12 files changed, 5 insertions(+), 60 deletions(-)
arch/alpha/mm/init.c +0 -6
index 97f4940..e2cbec3 100644
@@ -285,9 +285,3 @@ mem_init(void)
 	memblock_free_all();
 	mem_init_print_info(NULL);
 }
-
-void
-free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/arc/mm/init.c +0 -8
index c357a3b..02b7a3b 100644
@@ -206,11 +206,3 @@ void __init mem_init(void)
 	memblock_free_all();
 	mem_init_print_info(NULL);
 }
-
-/*
- * free_initmem: Free all the __init memory.
- */
-void __ref free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/c6x/mm/init.c +0 -5
index 5504b71..3257c53 100644
@@ -66,8 +66,3 @@ void __init mem_init(void)
 
 	mem_init_print_info(NULL);
 }
-
-void __init free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/h8300/mm/init.c +0 -6
index 2eff00d..73671d0 100644
@@ -100,9 +100,3 @@ void __init mem_init(void)
 
 	mem_init_print_info(NULL);
 }
-
-void
-free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/microblaze/mm/init.c +0 -5
index 3bd32de..cf29692 100644
@@ -186,11 +186,6 @@ void __init setup_memory(void)
 	paging_init();
 }
 
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
-
 void __init mem_init(void)
 {
 	high_memory = (void *)__va(memory_start + lowmem_size - 1);
arch/nds32/mm/init.c +0 -5
index c02e10a..0003187 100644
@@ -244,11 +244,6 @@ void __init mem_init(void)
 	return;
 }
 
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
-
 void __set_fixmap(enum fixed_addresses idx,
 			       phys_addr_t phys, pgprot_t flags)
 {
arch/nios2/mm/init.c +0 -5
index 60736a7..2c609c2 100644
@@ -82,11 +82,6 @@ void __init mmu_init(void)
 	flush_tlb_all();
 }
 
-void __ref free_initmem(void)
-{
-	free_initmem_default(-1);
-}
-
 #define __page_aligned(order) __aligned(PAGE_SIZE << (order))
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PGD_ORDER);
 pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);
arch/openrisc/mm/init.c +0 -5
index d0d94a4..aa83f7d 100644
@@ -220,8 +220,3 @@ void __init mem_init(void)
 	mem_init_done = 1;
 	return;
 }
-
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/sh/mm/init.c +0 -5
index 2fa824336..ca9761b 100644
@@ -405,11 +405,6 @@ void __init mem_init(void)
 	mem_init_done = 1;
 }
 
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
-
 #ifdef CONFIG_MEMORY_HOTPLUG
 int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
 		bool want_memblock)
arch/unicore32/mm/init.c +0 -5
index 01271ce..2c52d9b 100644
@@ -311,8 +311,3 @@ void __init mem_init(void)
 		sysctl_overcommit_memory = OVERCOMMIT_ALWAYS;
 	}
 }
-
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
arch/xtensa/mm/init.c +0 -5
index d498610..b51746f 100644
@@ -216,11 +216,6 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 }
 #endif
 
-void free_initmem(void)
-{
-	free_initmem_default(-1);
-}
-
 static void __init parse_memmap_one(char *p)
 {
 	char *oldp;
init/main.c +5 -0
index c86a1c8..38d69e0 100644
@@ -1047,6 +1047,11 @@ static inline void mark_readonly(void)
 }
 #endif
 
+void __weak free_initmem(void)
+{
+	free_initmem_default(-1);
+}
+
 static int __ref kernel_init(void *unused)
 {
 	int ret;
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/4 hexagon: switch over to generic free_initmem()

In reply to Mike Rapoport

hexagon implementation of free_initmem() is currently empty and marked with comment

* Todo: free pages between __init_begin and __init_end; possibly
* some devtree related stuff as well.

Switch it to the generic implementation.

---
 arch/hexagon/mm/init.c | 10 ----------
 1 file changed, 10 deletions(-)
arch/hexagon/mm/init.c +0 -10
index 1719ede..41cf342 100644
@@ -85,16 +85,6 @@ void __init mem_init(void)
 }
 
 /*
- * free_initmem - frees memory used by stuff declared with __init
- *
- * Todo:  free pages between __init_begin and __init_end; possibly
- * some devtree related stuff as well.
- */
-void __ref free_initmem(void)
-{
-}
-
-/*
  * free_initrd_mem - frees...  initrd memory.
  * @start - start of init memory
  * @end - end of init memory
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/4 init: free_initmem: poison freed init memory

In reply to Mike Rapoport

Various architectures including x86 poison the freed init memory. Do the same in the generic free_initmem implementation and switch sparc32 architecture that is identical to the generic code over to it now.

---
 arch/sparc/mm/init_32.c | 5 -----
 init/main.c             | 2 +-
 2 files changed, 1 insertion(+), 6 deletions(-)
arch/sparc/mm/init_32.c +0 -5
index f0dbc0b..d02a9ae 100644
@@ -294,11 +294,6 @@ void __init mem_init(void)
 	mem_init_print_info(NULL);
 }
 
-void free_initmem (void)
-{
-	free_initmem_default(POISON_FREE_INITMEM);
-}
-
 void sparc_flush_page_to_ram(struct page *page)
 {
 	unsigned long vaddr = (unsigned long)page_address(page);
init/main.c +1 -1
index 38d69e0..9a61e9c 100644
@@ -1049,7 +1049,7 @@ static inline void mark_readonly(void)
 
 void __weak free_initmem(void)
 {
-	free_initmem_default(-1);
+	free_initmem_default(POISON_FREE_INITMEM);
 }
 
 static int __ref kernel_init(void *unused)
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 4/4 riscv: switch over to generic free_initmem()

In reply to Mike Rapoport

The riscv version of free_initmem() differs from the generic one only in that it sets the freed memory to zero.

Make ricsv use the generic version and poison the freed memory.

---
 arch/riscv/mm/init.c | 5 -----
 1 file changed, 5 deletions(-)
arch/riscv/mm/init.c +0 -5
index 658ebf6..2af0010 100644
@@ -60,11 +60,6 @@ void __init mem_init(void)
 	mem_init_print_info(NULL);
 }
 
-void free_initmem(void)
-{
-	free_initmem_default(0);
-}
-
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
Signature · 1 line
2.7.4
#5 lore raw
In reply to Mike Rapoport

Any comments on this?

Quoted 42 lines · Mike Rapoport

Hi,

Many architectures implement free_initmem() in exactly the same or very similar way: they wrap the call to free_initmem_default() with sometimes different 'poison' parameter.

These patches switch those architectures to use a generic implementation that does free_initmem_default(POISON_FREE_INITMEM).

This was inspired by Christoph's patches for free_initrd_mem [1] and I shamelessly copied changelog entries from his patches :)

v2: rebased on top of v5.0-rc7 + Christoph's patches for free_initrd_mem

[1] https://lore.kernel.org/lkml/[email protected]/

Mike Rapoport (4):
init: provide a generic free_initmem implementation
hexagon: switch over to generic free_initmem()
init: free_initmem: poison freed init memory
riscv: switch over to generic free_initmem()

 arch/alpha/mm/init.c      |  6 ------
 arch/arc/mm/init.c        |  8 --------
 arch/c6x/mm/init.c        |  5 -----
 arch/h8300/mm/init.c      |  6 ------
 arch/hexagon/mm/init.c    | 10 ----------
 arch/microblaze/mm/init.c |  5 -----
 arch/nds32/mm/init.c      |  5 -----
 arch/nios2/mm/init.c      |  5 -----
 arch/openrisc/mm/init.c   |  5 -----
 arch/riscv/mm/init.c      |  5 -----
 arch/sh/mm/init.c         |  5 -----
 arch/sparc/mm/init_32.c   |  5 -----
 arch/unicore32/mm/init.c  |  5 -----
 arch/xtensa/mm/init.c     |  5 -----
 init/main.c               |  5 +++++
 15 files changed, 5 insertions(+), 80 deletions(-)
Signature · 1 line
2.7.4
Signature · 2 lines
Sincerely yours,
Mike.