2009-03-31 18:23:17 -04:00
|
|
|
#include <linux/kernel.h>
|
2011-10-31 20:08:10 -04:00
|
|
|
#include <linux/string.h>
|
2009-03-31 18:23:17 -04:00
|
|
|
#include <linux/mm.h>
|
2011-10-31 20:08:38 -04:00
|
|
|
#include <linux/highmem.h>
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
#include <linux/page_ext.h>
|
2009-03-31 18:23:17 -04:00
|
|
|
#include <linux/poison.h>
|
2011-10-31 20:08:05 -04:00
|
|
|
#include <linux/ratelimit.h>
|
2009-03-31 18:23:17 -04:00
|
|
|
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
static bool page_poisoning_enabled __read_mostly;
|
|
|
|
|
|
|
|
static bool need_page_poisoning(void)
|
|
|
|
{
|
2014-12-12 19:55:52 -05:00
|
|
|
if (!debug_pagealloc_enabled())
|
|
|
|
return false;
|
|
|
|
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_page_poisoning(void)
|
|
|
|
{
|
2014-12-12 19:55:52 -05:00
|
|
|
if (!debug_pagealloc_enabled())
|
|
|
|
return;
|
|
|
|
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
page_poisoning_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct page_ext_operations page_poisoning_ops = {
|
|
|
|
.need = need_page_poisoning,
|
|
|
|
.init = init_page_poisoning,
|
|
|
|
};
|
|
|
|
|
2009-03-31 18:23:17 -04:00
|
|
|
static inline void set_page_poison(struct page *page)
|
|
|
|
{
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
struct page_ext *page_ext;
|
|
|
|
|
|
|
|
page_ext = lookup_page_ext(page);
|
|
|
|
__set_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
|
2009-03-31 18:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_page_poison(struct page *page)
|
|
|
|
{
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
struct page_ext *page_ext;
|
|
|
|
|
|
|
|
page_ext = lookup_page_ext(page);
|
|
|
|
__clear_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
|
2009-03-31 18:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool page_poison(struct page *page)
|
|
|
|
{
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
struct page_ext *page_ext;
|
|
|
|
|
|
|
|
page_ext = lookup_page_ext(page);
|
|
|
|
return test_bit(PAGE_EXT_DEBUG_POISON, &page_ext->flags);
|
2009-03-31 18:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void poison_page(struct page *page)
|
|
|
|
{
|
2011-10-31 20:08:38 -04:00
|
|
|
void *addr = kmap_atomic(page);
|
2009-03-31 18:23:17 -04:00
|
|
|
|
|
|
|
set_page_poison(page);
|
|
|
|
memset(addr, PAGE_POISON, PAGE_SIZE);
|
2011-10-31 20:08:38 -04:00
|
|
|
kunmap_atomic(addr);
|
2009-03-31 18:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void poison_pages(struct page *page, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
poison_page(page + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool single_bit_flip(unsigned char a, unsigned char b)
|
|
|
|
{
|
|
|
|
unsigned char error = a ^ b;
|
|
|
|
|
|
|
|
return error && !(error & (error - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_poison_mem(unsigned char *mem, size_t bytes)
|
|
|
|
{
|
2011-10-31 20:08:05 -04:00
|
|
|
static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);
|
2009-03-31 18:23:17 -04:00
|
|
|
unsigned char *start;
|
|
|
|
unsigned char *end;
|
|
|
|
|
2011-10-31 20:08:10 -04:00
|
|
|
start = memchr_inv(mem, PAGE_POISON, bytes);
|
|
|
|
if (!start)
|
2009-03-31 18:23:17 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (end = mem + bytes - 1; end > start; end--) {
|
|
|
|
if (*end != PAGE_POISON)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-31 20:08:05 -04:00
|
|
|
if (!__ratelimit(&ratelimit))
|
2009-03-31 18:23:17 -04:00
|
|
|
return;
|
|
|
|
else if (start == end && single_bit_flip(*start, PAGE_POISON))
|
|
|
|
printk(KERN_ERR "pagealloc: single bit error\n");
|
|
|
|
else
|
|
|
|
printk(KERN_ERR "pagealloc: memory corruption\n");
|
|
|
|
|
|
|
|
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1, start,
|
|
|
|
end - start + 1, 1);
|
|
|
|
dump_stack();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unpoison_page(struct page *page)
|
|
|
|
{
|
2011-10-31 20:08:38 -04:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
if (!page_poison(page))
|
2009-03-31 18:23:17 -04:00
|
|
|
return;
|
|
|
|
|
2011-10-31 20:08:38 -04:00
|
|
|
addr = kmap_atomic(page);
|
|
|
|
check_poison_mem(addr, PAGE_SIZE);
|
|
|
|
clear_page_poison(page);
|
|
|
|
kunmap_atomic(addr);
|
2009-03-31 18:23:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unpoison_pages(struct page *page, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
unpoison_page(page + i);
|
|
|
|
}
|
|
|
|
|
2014-12-12 19:55:52 -05:00
|
|
|
void __kernel_map_pages(struct page *page, int numpages, int enable)
|
2009-03-31 18:23:17 -04:00
|
|
|
{
|
mm/debug-pagealloc: prepare boottime configurable on/off
Until now, debug-pagealloc needs extra flags in struct page, so we need to
recompile whole source code when we decide to use it. This is really
painful, because it takes some time to recompile and sometimes rebuild is
not possible due to third party module depending on struct page. So, we
can't use this good feature in many cases.
Now, we have the page extension feature that allows us to insert extra
flags to outside of struct page. This gets rid of third party module
issue mentioned above. And, this allows us to determine if we need extra
memory for this page extension in boottime. With these property, we can
avoid using debug-pagealloc in boottime with low computational overhead in
the kernel built with CONFIG_DEBUG_PAGEALLOC. This will help our
development process greatly.
This patch is the preparation step to achive above goal. debug-pagealloc
originally uses extra field of struct page, but, after this patch, it will
use field of struct page_ext. Because memory for page_ext is allocated
later than initialization of page allocator in CONFIG_SPARSEMEM, we should
disable debug-pagealloc feature temporarily until initialization of
page_ext. This patch implements this.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-12-12 19:55:49 -05:00
|
|
|
if (!page_poisoning_enabled)
|
|
|
|
return;
|
|
|
|
|
2009-03-31 18:23:17 -04:00
|
|
|
if (enable)
|
|
|
|
unpoison_pages(page, numpages);
|
|
|
|
else
|
|
|
|
poison_pages(page, numpages);
|
|
|
|
}
|