Skip to contentSkip to conversation

x86: add sanity checks to init_32.c

PATCH In review Pekka Enberg 1 participant 2 messages Mar 3, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 x86: add sanity checks to init_32.c

From: Pekka Enberg <[email protected]>

Impact: unification

This patch adds sanity checks that are already in init_64.c to init_32.c.

---
 arch/x86/mm/init_32.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
arch/x86/mm/init_32.c +11 -6
index a0c32d5..ee4b032 100644
@@ -1193,18 +1193,21 @@ void mark_rodata_ro(void)
 
 void free_init_pages(char *what, unsigned long begin, unsigned long end)
 {
-#ifdef CONFIG_DEBUG_PAGEALLOC
+	unsigned long addr = begin;
+
+	if (addr >= end)
+		return;
+
 	/*
 	 * If debugging page accesses then do not free this memory but
 	 * mark them not present - any buggy init-section access will
 	 * create a kernel page fault:
 	 */
+#ifdef CONFIG_DEBUG_PAGEALLOC
 	printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
 		begin, PAGE_ALIGN(end));
 	set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
 #else
-	unsigned long addr;
-
 	/*
 	 * We just marked the kernel text read only above, now that
 	 * we are going to free part of that, we need to make that
@@ -1212,14 +1215,16 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 	 */
 	set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
 
-	for (addr = begin; addr < end; addr += PAGE_SIZE) {
+	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
+
+	for (; addr < end; addr += PAGE_SIZE) {
 		ClearPageReserved(virt_to_page(addr));
 		init_page_count(virt_to_page(addr));
-		memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
+		memset((void *)(addr & ~(PAGE_SIZE-1)),
+			POISON_FREE_INITMEM, PAGE_SIZE);
 		free_page(addr);
 		totalram_pages++;
 	}
-	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
 #endif
 }
 
Signature · 1 line
1.5.4.3
#1 lore raw
Commit-ID:  05f209e7b936a48e341d36831079116a06658ccc
Gitweb:     http://git.kernel.org/tip/05f209e7b936a48e341d36831079116a06658ccc
Author:     "Pekka Enberg" <[email protected]>
AuthorDate: Tue, 3 Mar 2009 13:15:02 +0200
Commit:     Ingo Molnar <[email protected]>
CommitDate: Tue, 3 Mar 2009 12:21:17 +0100

x86: add sanity checks to init_32.c

Impact: unification

This patch adds sanity checks that are already in init_64.c to init_32.c.

LKML-Reference: <1236078902.2675.16.camel@penberg-laptop>

---
 arch/x86/mm/init_32.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
arch/x86/mm/init_32.c +11 -6
index 1dd6b63..1570a82 100644
@@ -1214,18 +1214,21 @@ void mark_rodata_ro(void)
 
 void free_init_pages(char *what, unsigned long begin, unsigned long end)
 {
-#ifdef CONFIG_DEBUG_PAGEALLOC
+	unsigned long addr = begin;
+
+	if (addr >= end)
+		return;
+
 	/*
 	 * If debugging page accesses then do not free this memory but
 	 * mark them not present - any buggy init-section access will
 	 * create a kernel page fault:
 	 */
+#ifdef CONFIG_DEBUG_PAGEALLOC
 	printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
 		begin, PAGE_ALIGN(end));
 	set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
 #else
-	unsigned long addr;
-
 	/*
 	 * We just marked the kernel text read only above, now that
 	 * we are going to free part of that, we need to make that
@@ -1233,14 +1236,16 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
 	 */
 	set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
 
-	for (addr = begin; addr < end; addr += PAGE_SIZE) {
+	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
+
+	for (; addr < end; addr += PAGE_SIZE) {
 		ClearPageReserved(virt_to_page(addr));
 		init_page_count(virt_to_page(addr));
-		memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
+		memset((void *)(addr & ~(PAGE_SIZE-1)),
+			POISON_FREE_INITMEM, PAGE_SIZE);
 		free_page(addr);
 		totalram_pages++;
 	}
-	printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
 #endif
 }