mm: enhance free_reserved_area() to support poisoning memory with zero
authorJiang Liu <liuj97@gmail.com>
Wed, 3 Jul 2013 22:02:51 +0000 (15:02 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Jul 2013 23:07:32 +0000 (16:07 -0700)
Address more review comments from last round of code review.
1) Enhance free_reserved_area() to support poisoning freed memory with
   pattern '0'. This could be used to get rid of poison_init_mem()
   on ARM64.
2) A previous patch has disabled memory poison for initmem on s390
   by mistake, so restore to the original behavior.
3) Remove redundant PAGE_ALIGN() when calling free_reserved_area().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: <sworddragon2@aol.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Jianguo Wu <wujianguo@huawei.com>
Cc: Joonsoo Kim <js1304@gmail.com>
Cc: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Michel Lespinasse <walken@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Tang Chen <tangchen@cn.fujitsu.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wen Congyang <wency@cn.fujitsu.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
26 files changed:
arch/alpha/kernel/sys_nautilus.c
arch/alpha/mm/init.c
arch/arc/mm/init.c
arch/arm/mm/init.c
arch/arm64/mm/init.c
arch/avr32/mm/init.c
arch/blackfin/mm/init.c
arch/c6x/mm/init.c
arch/cris/mm/init.c
arch/frv/mm/init.c
arch/h8300/mm/init.c
arch/ia64/mm/init.c
arch/m32r/mm/init.c
arch/m68k/mm/init.c
arch/microblaze/mm/init.c
arch/openrisc/mm/init.c
arch/parisc/mm/init.c
arch/powerpc/kernel/kvm.c
arch/powerpc/mm/mem.c
arch/s390/mm/init.c
arch/sh/mm/init.c
arch/um/kernel/mem.c
arch/unicore32/mm/init.c
arch/xtensa/mm/init.c
include/linux/mm.h
mm/page_alloc.c

index 891bd274ccb5bfdb4af9be61eadcdc8af96b9d93..837c0fa58317a2ff308c494aa69b7ad477b62e5e 100644 (file)
@@ -239,7 +239,7 @@ nautilus_init_pci(void)
                memtop = pci_mem;
        if (memtop > alpha_mv.min_mem_address) {
                free_reserved_area(__va(alpha_mv.min_mem_address),
-                                  __va(memtop), 0, NULL);
+                                  __va(memtop), -1, NULL);
                printk("nautilus_init_pci: %ldk freed\n",
                        (memtop - alpha_mv.min_mem_address) >> 10);
        }
index d54848d4e464c864a3e94c77a1a6c1eb8e175aa2..218c29c14bb3eefbc9680c15bcc1172792a11365 100644 (file)
@@ -319,13 +319,13 @@ mem_init(void)
 void
 free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
 void
 free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
index dce02e4716a1bdb87b6a66f2b295c82834db9567..f9c707712096dcae406dbff8fc5d32ecf25f245c 100644 (file)
@@ -146,13 +146,13 @@ void __init mem_init(void)
  */
 void __init_refok free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #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");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
index 7fae391caf8651f1b72ea30a6864f159deb5dc07..2070651c1bb4adeed368598456392d8a6c625546 100644 (file)
@@ -601,7 +601,7 @@ void __init mem_init(void)
 
 #ifdef CONFIG_SA1111
        /* now that our DMA memory is actually so designated, we can free it */
-       free_reserved_area(__va(PHYS_PFN_OFFSET), swapper_pg_dir, 0, NULL);
+       free_reserved_area(__va(PHYS_PFN_OFFSET), swapper_pg_dir, -1, NULL);
 #endif
 
        free_highpages();
@@ -729,12 +729,12 @@ void free_initmem(void)
        extern char __tcm_start, __tcm_end;
 
        poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
-       free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
+       free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
 #endif
 
        poison_init_mem(__init_begin, __init_end - __init_begin);
        if (!machine_is_integrator() && !machine_is_cintegrator())
-               free_initmem_default(0);
+               free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -745,7 +745,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 {
        if (!keep_initrd) {
                poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
-               free_reserved_area((void *)start, (void *)end, 0, "initrd");
+               free_reserved_area((void *)start, (void *)end, -1, "initrd");
        }
 }
 
index 6041e4008a83dead3e41bf22114b1bfcccd8134c..997c6345cdd653f1b0e01f895041a2451c131691 100644 (file)
@@ -387,7 +387,7 @@ void __init mem_init(void)
 void free_initmem(void)
 {
        poison_init_mem(__init_begin, __init_end - __init_begin);
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -398,7 +398,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 {
        if (!keep_initrd) {
                poison_init_mem((void *)start, PAGE_ALIGN(end) - start);
-               free_reserved_area((void *)start, (void *)end, 0, "initrd");
+               free_reserved_area((void *)start, (void *)end, -1, "initrd");
        }
 }
 
index 5a79fa08cb3c746a2a2b629b4667dd05ee51c823..b079e04f695446d1e9364d49d39d88f5620412f4 100644 (file)
@@ -148,12 +148,12 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
index 8e9eab272811fcde2f61ce0434de9822cbe2bd2f..fa241f5a7dcf1f50b99b468ba7f6d8231c1d745b 100644 (file)
@@ -133,7 +133,7 @@ void __init mem_init(void)
 void __init free_initrd_mem(unsigned long start, unsigned long end)
 {
 #ifndef CONFIG_MPU
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 #endif
 }
 #endif
@@ -141,7 +141,7 @@ void __init free_initrd_mem(unsigned long start, unsigned long end)
 void __init_refok free_initmem(void)
 {
 #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
-       free_initmem_default(0);
+       free_initmem_default(-1);
        if (memory_start == (unsigned long)(&__init_end))
                memory_start = (unsigned long)(&__init_begin);
 #endif
index 07bfcc98a3b79fa0507a4bdbaaa2f956f9dabb55..3987a20fdee6891a45d2360723c45cc646785e38 100644 (file)
@@ -78,11 +78,11 @@ void __init mem_init(void)
 #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");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
 void __init free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
index 9ac80946dada87401fb4a817fb5ed58313841ce8..8fec26392ae71f00381e209d5f58bc7ae2a8e234 100644 (file)
@@ -65,5 +65,5 @@ mem_init(void)
 void 
 free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
index a67f3a5897b8acca0f9812b8d889401fb6dd2994..8ba9d22d0d916c600b58a0abc116cf8f1c7fa2e3 100644 (file)
@@ -162,7 +162,7 @@ void __init mem_init(void)
 void free_initmem(void)
 {
 #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
-       free_initmem_default(0);
+       free_initmem_default(-1);
 #endif
 } /* end free_initmem() */
 
@@ -173,6 +173,6 @@ void free_initmem(void)
 #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");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 } /* end free_initrd_mem() */
 #endif
index 57e03c59861d68d95f822d180f54b53cb26d0f54..c831f1dba1324f77b38a005059cd58cb448d6619 100644 (file)
@@ -161,7 +161,7 @@ void __init mem_init(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
@@ -169,7 +169,7 @@ void
 free_initmem(void)
 {
 #ifdef CONFIG_RAMKERNEL
-       free_initmem_default(0);
+       free_initmem_default(-1);
 #endif
 }
 
index da568c2e839f60de6af3327a9ae920fe6e6ab6b7..f8a4f38b0ad580c035447d7cb87f27e2192fcf97 100644 (file)
@@ -155,7 +155,7 @@ void
 free_initmem (void)
 {
        free_reserved_area(ia64_imva(__init_begin), ia64_imva(__init_end),
-                          0, "unused kernel");
+                          -1, "unused kernel");
 }
 
 void __init
index d80412d0c14edb4494c3d08b8045422139e9c8e4..cca87d9184368490a7df81b9d564492f5edc9408 100644 (file)
@@ -181,7 +181,7 @@ void __init mem_init(void)
  *======================================================================*/
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -191,6 +191,6 @@ void free_initmem(void)
  *======================================================================*/
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
index 95de725534e99006bf3de2e0b304430b7bc492f5..ab0b54ca5d85b7fb3c12679c3d613fe6f11f10c7 100644 (file)
@@ -110,7 +110,7 @@ void __init paging_init(void)
 void free_initmem(void)
 {
 #ifndef CONFIG_MMU_SUN3
-       free_initmem_default(0);
+       free_initmem_default(-1);
 #endif /* CONFIG_MMU_SUN3 */
 }
 
@@ -202,6 +202,6 @@ void __init mem_init(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
index d7b8ada9345f491d56b5273ec904e2d6adab7870..d149e0ebb767706f01294f40d542352798ad7ee2 100644 (file)
@@ -235,13 +235,13 @@ void __init setup_memory(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 void __init mem_init(void)
index ab113325dc4c94dfab6fe2e0c86421dd89a8bb1d..c371e4a0fcac6e771466d0cfdbe2ae45b7f09007 100644 (file)
@@ -261,11 +261,11 @@ void __init mem_init(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
index 3223d5e4a3729baa473e965b6c1647506cf60294..ebac7bd76b560a65b1c07ffd8263fd0be750d864 100644 (file)
@@ -532,7 +532,7 @@ void free_initmem(void)
         * pages are no-longer executable */
        flush_icache_range(init_begin, init_end);
        
-       num_physpages += free_initmem_default(0);
+       num_physpages += free_initmem_default(-1);
 
        /* set up a new led state on systems shipped LED State panel */
        pdc_chassis_send_status(PDC_CHASSIS_DIRECT_BCOMPLETE);
@@ -1101,7 +1101,7 @@ void flush_tlb_all(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       num_physpages += free_reserved_area((void *)start, (void *)end, 0,
+       num_physpages += free_reserved_area((void *)start, (void *)end, -1,
                                            "initrd");
 }
 #endif
index 5e4830a33c083b113a9a74702ec7a60685a762bc..db28032e320e3e5332b6e60d77d1b56d29cea7d9 100644 (file)
@@ -750,13 +750,8 @@ EXPORT_SYMBOL_GPL(kvm_hypercall);
 
 static __init void kvm_free_tmp(void)
 {
-       unsigned long start, end;
-
-       start = (ulong)&kvm_tmp[kvm_tmp_index + (PAGE_SIZE - 1)] & PAGE_MASK;
-       end = (ulong)&kvm_tmp[ARRAY_SIZE(kvm_tmp)] & PAGE_MASK;
-
-       /* Free the tmp space we don't need */
-       free_reserved_area((void *)start, (void *)end, 0, NULL);
+       free_reserved_area(&kvm_tmp[kvm_tmp_index],
+                          &kvm_tmp[ARRAY_SIZE(kvm_tmp)], -1, NULL);
 }
 
 static int __init kvm_guest_init(void)
index 347c5b1bbd62b7e850c9e8f7bc4367b1ff8b0d92..7f47a05f55af0b8884d8c871fe740d6ae5ff6764 100644 (file)
@@ -407,7 +407,7 @@ void free_initmem(void)
 #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");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
index 0878c89fe7d22131a16fbed19c82f12e92bb4615..bf01d18422ec95ca7e1d0161fff90fb58c5f055e 100644 (file)
@@ -166,7 +166,7 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(POISON_FREE_INITMEM);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
index b892a9b7d7e365f94915e767aa24f72be4572989..d3af56b7a09815bcbf3c5b500cdb9bb512ce202c 100644 (file)
@@ -499,13 +499,13 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
index 2aa7a2448d5844237f7b0ae7bc51b367ee8650ff..8ff0b7ae8ec046df0885e2032d833491ed410bed 100644 (file)
@@ -244,7 +244,7 @@ void free_initmem(void)
 #ifdef CONFIG_BLK_DEV_INITRD
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
-       free_reserved_area((void *)start, (void *)end, 0, "initrd");
+       free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
index 220755cc970031610a5f4a1f9acd1dc7250ae5aa..df9b8abcb6a5d47ce2e229aa860ca4c5c34ad607 100644 (file)
@@ -476,7 +476,7 @@ void __init mem_init(void)
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
@@ -486,7 +486,7 @@ static int keep_initrd;
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
        if (!keep_initrd)
-               free_reserved_area((void *)start, (void *)end, 0, "initrd");
+               free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 
 static int __init keepinitrd_setup(char *__unused)
index 4d658efc3289caad3c3e1d8eb18300fcdf36fd41..026d29bee30b8190f89d9091d152c553bdb91185 100644 (file)
@@ -214,11 +214,11 @@ extern int initrd_is_mapped;
 void free_initrd_mem(unsigned long start, unsigned long end)
 {
        if (initrd_is_mapped)
-               free_reserved_area((void *)start, (void *)end, 0, "initrd");
+               free_reserved_area((void *)start, (void *)end, -1, "initrd");
 }
 #endif
 
 void free_initmem(void)
 {
-       free_initmem_default(0);
+       free_initmem_default(-1);
 }
index be1b96ce06501e81b58dbf31d04f41427c8c1a30..083cc0ba23848db7d5b35670dd3dffccd96e01fb 100644 (file)
@@ -1308,7 +1308,7 @@ extern void free_initmem(void);
 /*
  * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
  * into the buddy system. The freed pages will be poisoned with pattern
- * "poison" if it's non-zero.
+ * "poison" if it's within range [0, UCHAR_MAX].
  * Return pages freed into the buddy system.
  */
 extern unsigned long free_reserved_area(void *start, void *end,
@@ -1348,8 +1348,9 @@ static inline void mark_page_reserved(struct page *page)
 
 /*
  * Default method to free all the __init memory into the buddy system.
- * The freed pages will be poisoned with pattern "poison" if it is
- * non-zero. Return pages freed into the buddy system.
+ * The freed pages will be poisoned with pattern "poison" if it's within
+ * range [0, UCHAR_MAX].
+ * Return pages freed into the buddy system.
  */
 static inline unsigned long free_initmem_default(int poison)
 {
index be18ccd017bbf63d72c26129849423de742df0a8..6780b2e18aa1a6e3ebc4d9bdeadc990c5e39601c 100644 (file)
@@ -5214,7 +5214,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, char *s)
        start = (void *)PAGE_ALIGN((unsigned long)start);
        end = (void *)((unsigned long)end & PAGE_MASK);
        for (pos = start; pos < end; pos += PAGE_SIZE, pages++) {
-               if (poison)
+               if ((unsigned int)poison <= 0xFF)
                        memset(pos, poison, PAGE_SIZE);
                free_reserved_page(virt_to_page(pos));
        }