[PATCH] Avoid unsafe use of struct pages in move_freepages when CONFIG_HOLES_IN_ZONE is set

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Mel Gorman
Date: Wednesday, March 14, 2007 - 12:10 pm

In the majority of situations, mem_map is guaranteed to be valid within
a MAX_ORDER_NR_PAGES block of pages. However, when CONFIG_HOLES_IN_ZONE
is set, there is no guarantee that mem_map exists for the entire block.
This means that when checking struct pages around a known valid page, there
is no guarantee they are valid. 

move_freepages() operates on a MAX_ORDER_NR_PAGES range of pages based on
a known valid page retrieved from the free lists. However, a bug check is
unsafe when CONFIG_HOLES_IN_ZONE is set and pfn_valid() is called too late.

This patch disables the bug check when CONFIG_HOLES_IN_ZONE and checks
pfn_valid() earlier before calling PageBuddy(). It applies on top of
move-free-pages-between-lists-on-steal-fix-2.patch from Yasunori Goto in -mm.

Credit to Bjorn Helgaas for reporting this bug and testing.

Signed-off-by: Mel Gorman <mel@csn.ul.ie>

 page_alloc.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff -rup -X /usr/src/patchset-0.6/bin//dontdiff linux-2.6.21-rc3-mm2-goto/mm/page_alloc.c linux-2.6.21-rc3-mm2-zone_holes_ia64_fix/mm/page_alloc.c
--- linux-2.6.21-rc3-mm2-goto/mm/page_alloc.c	2007-03-14 16:07:23.000000000 +0000
+++ linux-2.6.21-rc3-mm2-zone_holes_ia64_fix/mm/page_alloc.c	2007-03-14 18:51:41.000000000 +0000
@@ -707,13 +707,18 @@ int move_freepages(struct zone *zone,
 	unsigned long order;
 	int blocks_moved = 0;
 
+#ifndef CONFIG_HOLES_IN_ZONE
+	/*
+	 * page_zone is not safe to call in this context when
+	 * CONFIG_HOLES_IN_ZONE is set. This bug check is probably redundant
+	 * anyway as we check zone boundaries in move_freepages_block().
+	 * Remove at a later date when no bug reports exist related to
+	 * CONFIG_PAGE_GROUP_BY_MOBILITY
+	 */
 	BUG_ON(page_zone(start_page) != page_zone(end_page - 1));
+#endif
 
 	for (page = start_page; page < end_page;) {
-		if (!PageBuddy(page)) {
-			page++;
-			continue;
-		}
 #ifdef CONFIG_HOLES_IN_ZONE
 		if (!pfn_valid(page_to_pfn(page))) {
 			page++;
@@ -721,6 +726,11 @@ int move_freepages(struct zone *zone,
 		}
 #endif
 
+		if (!PageBuddy(page)) {
+			page++;
+			continue;
+		}
+
 		order = page_order(page);
 		list_del(&page->lru);
 		list_add(&page->lru,
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.21-rc3-mm2, Andrew Morton, (Wed Mar 7, 9:19 pm)
Re: 2.6.21-rc3-mm2, Con Kolivas, (Thu Mar 8, 7:52 am)
Re: 2.6.21-rc3-mm2, Con Kolivas, (Thu Mar 8, 2:04 pm)
2.6.21-rc3: /proc broken, Con Kolivas, (Thu Mar 8, 2:56 pm)
Re: 2.6.21-rc3: /proc broken, Russell King, (Fri Mar 9, 1:53 am)
Re: 2.6.21-rc3: /proc broken, Con Kolivas, (Fri Mar 9, 2:59 am)
Re: 2.6.21-rc3-mm2 hangs my opteron during bootup, ACPI?, Helge Hafting, (Mon Mar 12, 5:56 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Bjorn Helgaas, (Tue Mar 13, 8:52 pm)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Mel Gorman, (Wed Mar 14, 2:44 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Bjorn Helgaas, (Wed Mar 14, 8:11 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Mel Gorman, (Wed Mar 14, 9:13 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Bjorn Helgaas, (Wed Mar 14, 9:52 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Mel Gorman, (Wed Mar 14, 10:21 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Bjorn Helgaas, (Wed Mar 14, 11:36 am)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Mel Gorman, (Wed Mar 14, 11:59 am)
[PATCH] Avoid unsafe use of struct pages in move_freepages ..., Mel Gorman, (Wed Mar 14, 12:10 pm)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Bjorn Helgaas, (Wed Mar 14, 1:46 pm)
Re: 2.6.21-rc3-mm2 (oops in move_freepages), Mel Gorman, (Wed Mar 14, 1:55 pm)
Re: 2.6.21-rc3-mm2 hangs my opteron during bootup, ACPI?, Helge Hafting, (Fri Mar 16, 5:10 pm)
Re: 2.6.21-rc3-mm2, Randy Dunlap, (Mon Mar 19, 12:17 pm)
Re: 2.6.21-rc3-mm2, Randy Dunlap, (Mon Mar 19, 12:40 pm)
Re: 2.6.21-rc3-mm2, Andrew Morton, (Mon Mar 19, 12:55 pm)
[PATCH] ptrace needs PROC_FS, Randy Dunlap, (Mon Mar 19, 3:26 pm)
Re: [PATCH] ptrace needs PROC_FS, Roland McGrath, (Mon Mar 19, 3:48 pm)
Re: 2.6.21-rc3-mm2, Kay Sievers, (Mon Mar 19, 4:01 pm)
Re: 2.6.21-rc3-mm2, Randy Dunlap, (Mon Mar 19, 5:27 pm)
Re: 2.6.21-rc3-mm2, Andrew Morton, (Mon Mar 19, 5:39 pm)
Re: 2.6.21-rc3-mm2, Randy Dunlap, (Mon Mar 19, 5:51 pm)
Re: [PATCH] ptrace needs PROC_FS, Pavel Machek, (Tue Mar 20, 4:18 am)
Re: 2.6.21-rc3-mm2, Sam Ravnborg, (Tue Mar 20, 5:14 am)
Re: 2.6.21-rc3-mm2, Randy Dunlap, (Tue Mar 20, 8:43 am)
Re: 2.6.21-rc3-mm2, Roland McGrath, (Tue Mar 20, 11:51 am)