[PATCH] [12/16] HWPOISON: check and isolate corrupted free pages

From: Andi Kleen
Date: Wed May 27 2009 - 16:16:26 EST



From: Wu Fengguang <fengguang.wu@xxxxxxxxx>

If memory corruption hits the free buddy pages, we can safely ignore them.
No one will access them until page allocation time, then prep_new_page()
will automatically check and isolate PG_hwpoison page for us (for 0-order
allocation).

This patch expands prep_new_page() to check every component page in a high
order page allocation, in order to completely stop PG_hwpoison pages from
being recirculated.

Note that the common case -- only allocating a single page, doesn't
do any more work than before. Allocating > order 0 does a bit more work,
but that's relatively uncommon.

This simple implementation may drop some innocent neighbor pages, hopefully
it is not a big problem because the event should be rare enough.

This patch adds some runtime costs to high order page users.

[AK: Improved description]
Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>

---
mm/page_alloc.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

Index: linux/mm/page_alloc.c
===================================================================
--- linux.orig/mm/page_alloc.c 2009-05-27 21:13:54.000000000 +0200
+++ linux/mm/page_alloc.c 2009-05-27 21:14:21.000000000 +0200
@@ -633,12 +633,22 @@
*/
static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
{
- if (unlikely(page_mapcount(page) |
- (page->mapping != NULL) |
- (page_count(page) != 0) |
- (page->flags & PAGE_FLAGS_CHECK_AT_PREP))) {
- bad_page(page);
- return 1;
+ int i;
+
+ for (i = 0; i < (1 << order); i++) {
+ struct page *p = page + i;
+
+ if (unlikely(page_mapcount(p) |
+ (p->mapping != NULL) |
+ (page_count(p) != 0) |
+ (p->flags & PAGE_FLAGS_CHECK_AT_PREP))) {
+ /*
+ * The whole array of pages will be dropped,
+ * hopefully this is a rare and abnormal event.
+ */
+ bad_page(p);
+ return 1;
+ }
}

set_page_private(page, 0);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/