Commit c9cf5528 authored by Randy Dunlap's avatar Randy Dunlap Committed by Linus Torvalds

[PATCH] add poison.h and patch primary users

Localize poison values into one header file for better documentation and
easier/quicker debugging and so that the same values won't be used for
multiple purposes.

Use these constants in core arch., mm, driver, and fs code.
Signed-off-by: default avatarRandy Dunlap <rdunlap@xenotime.net>
Acked-by: default avatarMatt Mackall <mpm@selenic.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e6e5494c
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/poison.h>
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
...@@ -753,7 +754,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end) ...@@ -753,7 +754,7 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
for (addr = begin; addr < end; addr += PAGE_SIZE) { for (addr = begin; addr < end; addr += PAGE_SIZE) {
ClearPageReserved(virt_to_page(addr)); ClearPageReserved(virt_to_page(addr));
init_page_count(virt_to_page(addr)); init_page_count(virt_to_page(addr));
memset((void *)addr, 0xcc, PAGE_SIZE); memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
free_page(addr); free_page(addr);
totalram_pages++; totalram_pages++;
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/nodemask.h> #include <linux/nodemask.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/poison.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/page.h> #include <asm/page.h>
...@@ -90,7 +91,7 @@ void free_initmem(void) ...@@ -90,7 +91,7 @@ void free_initmem(void)
addr = (unsigned long)__init_begin; addr = (unsigned long)__init_begin;
for (; addr < (unsigned long)__init_end; addr += PAGE_SIZE) { for (; addr < (unsigned long)__init_end; addr += PAGE_SIZE) {
memset((void *)addr, 0xcc, PAGE_SIZE); memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
ClearPageReserved(virt_to_page(addr)); ClearPageReserved(virt_to_page(addr));
init_page_count(virt_to_page(addr)); init_page_count(virt_to_page(addr));
free_page(addr); free_page(addr);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/initrd.h> #include <linux/initrd.h>
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/poison.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
...@@ -1520,7 +1521,7 @@ void free_initmem(void) ...@@ -1520,7 +1521,7 @@ void free_initmem(void)
page = (addr + page = (addr +
((unsigned long) __va(kern_base)) - ((unsigned long) __va(kern_base)) -
((unsigned long) KERNBASE)); ((unsigned long) KERNBASE));
memset((void *)addr, 0xcc, PAGE_SIZE); memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
p = virt_to_page(page); p = virt_to_page(page);
ClearPageReserved(p); ClearPageReserved(p);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/poison.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/memory_hotplug.h> #include <linux/memory_hotplug.h>
...@@ -660,7 +661,8 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end) ...@@ -660,7 +661,8 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
for (addr = begin; addr < end; addr += PAGE_SIZE) { for (addr = begin; addr < end; addr += PAGE_SIZE) {
ClearPageReserved(virt_to_page(addr)); ClearPageReserved(virt_to_page(addr));
init_page_count(virt_to_page(addr)); init_page_count(virt_to_page(addr));
memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE); memset((void *)(addr & ~(PAGE_SIZE-1)),
POISON_FREE_INITMEM, PAGE_SIZE);
free_page(addr); free_page(addr);
totalram_pages++; totalram_pages++;
} }
...@@ -668,7 +670,8 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end) ...@@ -668,7 +670,8 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
void free_initmem(void) void free_initmem(void)
{ {
memset(__initdata_begin, 0xba, __initdata_end - __initdata_begin); memset(__initdata_begin, POISON_FREE_INITDATA,
__initdata_end - __initdata_begin);
free_init_pages("unused kernel memory", free_init_pages("unused kernel memory",
(unsigned long)(&__init_begin), (unsigned long)(&__init_begin),
(unsigned long)(&__init_end)); (unsigned long)(&__init_end));
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/dmapool.h> #include <linux/dmapool.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/poison.h>
/* /*
* Pool allocator ... wraps the dma_alloc_coherent page allocator, so * Pool allocator ... wraps the dma_alloc_coherent page allocator, so
...@@ -35,8 +36,6 @@ struct dma_page { /* cacheable header for 'allocation' bytes */ ...@@ -35,8 +36,6 @@ struct dma_page { /* cacheable header for 'allocation' bytes */
}; };
#define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000) #define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000)
#define POOL_POISON_FREED 0xa7 /* !inuse */
#define POOL_POISON_ALLOCATED 0xa9 /* !initted */
static DECLARE_MUTEX (pools_lock); static DECLARE_MUTEX (pools_lock);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/kthread.h> #include <linux/kthread.h>
#include <linux/poison.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -1675,7 +1676,7 @@ static void journal_free_journal_head(struct journal_head *jh) ...@@ -1675,7 +1676,7 @@ static void journal_free_journal_head(struct journal_head *jh)
{ {
#ifdef CONFIG_JBD_DEBUG #ifdef CONFIG_JBD_DEBUG
atomic_dec(&nr_journal_heads); atomic_dec(&nr_journal_heads);
memset(jh, 0x5b, sizeof(*jh)); memset(jh, JBD_POISON_FREE, sizeof(*jh));
#endif #endif
kmem_cache_free(journal_head_cache, jh); kmem_cache_free(journal_head_cache, jh);
} }
......
...@@ -4,17 +4,10 @@ ...@@ -4,17 +4,10 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/poison.h>
#include <linux/prefetch.h> #include <linux/prefetch.h>
#include <asm/system.h> #include <asm/system.h>
/*
* These are non-NULL pointers that will result in page faults
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries.
*/
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)
/* /*
* Simple doubly linked list implementation. * Simple doubly linked list implementation.
* *
......
#ifndef _LINUX_POISON_H
#define _LINUX_POISON_H
/********** include/linux/list.h **********/
/*
* These are non-NULL pointers that will result in page faults
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries.
*/
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)
/********** mm/slab.c **********/
/*
* Magic nums for obj red zoning.
* Placed in the first word before and the first word after an obj.
*/
#define RED_INACTIVE 0x5A2CF071UL /* when obj is inactive */
#define RED_ACTIVE 0x170FC2A5UL /* when obj is active */
/* ...and for poisoning */
#define POISON_INUSE 0x5a /* for use-uninitialised poisoning */
#define POISON_FREE 0x6b /* for use-after-free poisoning */
#define POISON_END 0xa5 /* end-byte of poisoning */
/********** arch/$ARCH/mm/init.c **********/
#define POISON_FREE_INITMEM 0xcc
/********** arch/x86_64/mm/init.c **********/
#define POISON_FREE_INITDATA 0xba
/********** arch/ia64/hp/common/sba_iommu.c **********/
/*
* arch/ia64/hp/common/sba_iommu.c uses a 16-byte poison string with a
* value of "SBAIOMMU POISON\0" for spill-over poisoning.
*/
/********** fs/jbd/journal.c **********/
#define JBD_POISON_FREE 0x5b
/********** drivers/base/dmapool.c **********/
#define POOL_POISON_FREED 0xa7 /* !inuse */
#define POOL_POISON_ALLOCATED 0xa9 /* !initted */
#endif
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
#include <linux/config.h> #include <linux/config.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/poison.h>
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -492,17 +493,6 @@ struct kmem_cache { ...@@ -492,17 +493,6 @@ struct kmem_cache {
#endif #endif
#if DEBUG #if DEBUG
/*
* Magic nums for obj red zoning.
* Placed in the first word before and the first word after an obj.
*/
#define RED_INACTIVE 0x5A2CF071UL /* when obj is inactive */
#define RED_ACTIVE 0x170FC2A5UL /* when obj is active */
/* ...and for poisoning */
#define POISON_INUSE 0x5a /* for use-uninitialised poisoning */
#define POISON_FREE 0x6b /* for use-after-free poisoning */
#define POISON_END 0xa5 /* end-byte of poisoning */
/* /*
* memory layout of objects: * memory layout of objects:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment