2009-04-01 00:23:17 +02:00
|
|
|
#include <linux/kernel.h>
|
2011-11-01 01:08:10 +01:00
|
|
|
#include <linux/string.h>
|
2009-04-01 00:23:17 +02:00
|
|
|
#include <linux/mm.h>
|
2011-11-01 01:08:38 +01: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-13 01:55:49 +01:00
|
|
|
#include <linux/page_ext.h>
|
2009-04-01 00:23:17 +02:00
|
|
|
#include <linux/poison.h>
|
2011-11-01 01:08:05 +01:00
|
|
|
#include <linux/ratelimit.h>
|
2009-04-01 00:23:17 +02:00
|
|
|
|
2016-03-15 22:56:27 +01:00
|
|
|
static bool want_page_poisoning __read_mostly;
|
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-13 01:55:49 +01:00
|
|
|
|
2016-03-15 22:56:27 +01:00
|
|
|
static int early_page_poison_param(char *buf)
|
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-13 01:55:49 +01:00
|
|
|
{
|
2016-03-15 22:56:27 +01:00
|
|
|
if (!buf)
|
|
|
|
return -EINVAL;
|
2016-05-21 01:58:13 +02:00
|
|
|
return strtobool(buf, &want_page_poisoning);
|
2016-03-15 22:56:27 +01:00
|
|
|
}
|
|
|
|
early_param("page_poison", early_page_poison_param);
|
|
|
|
|
|
|
|
bool page_poisoning_enabled(void)
|
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-13 01:55:49 +01:00
|
|
|
{
|
2016-03-15 22:56:27 +01:00
|
|
|
/*
|
2017-05-03 23:54:42 +02:00
|
|
|
* Assumes that debug_pagealloc_enabled is set before
|
|
|
|
* free_all_bootmem.
|
|
|
|
* Page poisoning is debug page alloc for some arches. If
|
|
|
|
* either of those options are enabled, enable poisoning.
|
2016-03-15 22:56:27 +01:00
|
|
|
*/
|
2017-05-03 23:54:42 +02:00
|
|
|
return (want_page_poisoning ||
|
|
|
|
(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
|
|
|
|
debug_pagealloc_enabled()));
|
2009-04-01 00:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void poison_page(struct page *page)
|
|
|
|
{
|
2011-11-01 01:08:38 +01:00
|
|
|
void *addr = kmap_atomic(page);
|
2009-04-01 00:23:17 +02:00
|
|
|
|
|
|
|
memset(addr, PAGE_POISON, PAGE_SIZE);
|
2011-11-01 01:08:38 +01:00
|
|
|
kunmap_atomic(addr);
|
2009-04-01 00:23:17 +02: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-11-01 01:08:05 +01:00
|
|
|
static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);
|
2009-04-01 00:23:17 +02:00
|
|
|
unsigned char *start;
|
|
|
|
unsigned char *end;
|
|
|
|
|
2016-03-15 22:56:27 +01:00
|
|
|
if (IS_ENABLED(CONFIG_PAGE_POISONING_NO_SANITY))
|
|
|
|
return;
|
|
|
|
|
2011-11-01 01:08:10 +01:00
|
|
|
start = memchr_inv(mem, PAGE_POISON, bytes);
|
|
|
|
if (!start)
|
2009-04-01 00:23:17 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (end = mem + bytes - 1; end > start; end--) {
|
|
|
|
if (*end != PAGE_POISON)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-01 01:08:05 +01:00
|
|
|
if (!__ratelimit(&ratelimit))
|
2009-04-01 00:23:17 +02:00
|
|
|
return;
|
|
|
|
else if (start == end && single_bit_flip(*start, PAGE_POISON))
|
2016-03-15 22:56:27 +01:00
|
|
|
pr_err("pagealloc: single bit error\n");
|
2009-04-01 00:23:17 +02:00
|
|
|
else
|
2016-03-15 22:56:27 +01:00
|
|
|
pr_err("pagealloc: memory corruption\n");
|
2009-04-01 00:23:17 +02:00
|
|
|
|
|
|
|
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-11-01 01:08:38 +01:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
addr = kmap_atomic(page);
|
2017-05-03 23:54:42 +02:00
|
|
|
/*
|
|
|
|
* Page poisoning when enabled poisons each and every page
|
|
|
|
* that is freed to buddy. Thus no extra check is done to
|
|
|
|
* see if a page was posioned.
|
|
|
|
*/
|
2011-11-01 01:08:38 +01:00
|
|
|
check_poison_mem(addr, PAGE_SIZE);
|
|
|
|
kunmap_atomic(addr);
|
2009-04-01 00:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void unpoison_pages(struct page *page, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
unpoison_page(page + i);
|
|
|
|
}
|
|
|
|
|
2016-03-15 22:56:27 +01:00
|
|
|
void kernel_poison_pages(struct page *page, int numpages, int enable)
|
2009-04-01 00:23:17 +02:00
|
|
|
{
|
2016-03-15 22:56:27 +01:00
|
|
|
if (!page_poisoning_enabled())
|
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-13 01:55:49 +01:00
|
|
|
return;
|
|
|
|
|
2009-04-01 00:23:17 +02:00
|
|
|
if (enable)
|
|
|
|
unpoison_pages(page, numpages);
|
|
|
|
else
|
|
|
|
poison_pages(page, numpages);
|
|
|
|
}
|
2016-03-15 22:56:27 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC
|
|
|
|
void __kernel_map_pages(struct page *page, int numpages, int enable)
|
|
|
|
{
|
|
|
|
/* This function does nothing, all work is done via poison pages */
|
|
|
|
}
|
|
|
|
#endif
|