Skip to contentSkip to conversation

fix x86 page table init

PATCH In review Brian Gerst 2 participants 3 messages Jul 31, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix x86 page table init

The recent changes to the x86 page table init reintroduced a bug with the 4k pagetables. The page table must be filled with entries before it is inserted into the pmd or else you risk a tlb miss on a kernel code page causing an oops. This patch takes a different approach than before - it allows for reuse of the boot pagetable pages instead of allocating new ones.

--
Brian Gerst

arch/i386/mm/init.c +9 -7
diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c
@@ -70,10 +70,14 @@
  */
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
-	pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
-	set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
-	if (page_table != pte_offset_kernel(pmd, 0))
-		BUG();	
+	pte_t *page_table;
+	page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+	if (pmd_none(*pmd)) {
+		set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
+		if (page_table != pte_offset_kernel(pmd, 0))
+			BUG();	
+	} else
+		page_table = pte_offset_kernel(pmd, 0);
 
 	return page_table;
 }
@@ -107,9 +111,7 @@
 
 		pmd = pmd_offset(pgd, vaddr);
 		for (; (pmd_ofs < PTRS_PER_PMD) && (vaddr != end); pmd++, pmd_ofs++) {
-			if (pmd_none(*pmd)) 
-				one_page_table_init(pmd);
-
+			one_page_table_init(pmd);
 			vaddr += PMD_SIZE;
 		}
 		pmd_ofs = 0;
#1 lore raw
Quoted 6 lines · Brian Gerst

The recent changes to the x86 page table init reintroduced a bug with the 4k pagetables. The page table must be filled with entries before it is inserted into the pmd or else you risk a tlb miss on a kernel code page causing an oops. This patch takes a different approach than before
- it allows for reuse of the boot pagetable pages instead of allocating new ones.

In the patch below, isn't there a bootmem page leak in case !pmd_none(*pmd)?

Quoted 33 lines

diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c

arch/i386/mm/init.c +9 -7
@@ -70,10 +70,14 @@
  */
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
-	pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
-	set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
-	if (page_table != pte_offset_kernel(pmd, 0))
-		BUG();	
+	pte_t *page_table;
+	page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+	if (pmd_none(*pmd)) {
+		set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
+		if (page_table != pte_offset_kernel(pmd, 0))
+			BUG();	
+	} else
+		page_table = pte_offset_kernel(pmd, 0);
 
 	return page_table;
 }
@@ -107,9 +111,7 @@
 
 		pmd = pmd_offset(pgd, vaddr);
 		for (; (pmd_ofs < PTRS_PER_PMD) && (vaddr != end); pmd++, pmd_ofs++) {
-			if (pmd_none(*pmd)) 
-				one_page_table_init(pmd);
-
+			one_page_table_init(pmd);
 			vaddr += PMD_SIZE;
 		}
 		pmd_ofs = 0;
Signature · 2 lines
Dan Aloni
[email protected]
#2 lore raw
Quoted 8 lines · Dan Aloni
Quoted 3 lines · Brian Gerst

The recent changes to the x86 page table init reintroduced a bug with the 4k pagetables. The page table must be filled with entries before it is inserted into the pmd or else you risk a tlb miss on a kernel code page causing an oops. This patch takes a different approach than before
- it allows for reuse of the boot pagetable pages instead of allocating
new ones.

In the patch below, isn't there a bootmem page leak in case !pmd_none(*pmd)?

Whoops. That's what happens when one needs to recreate a patch from memory. Revised patch attached.

--
Brian Gerst

arch/i386/mm/init.c +9 -7
diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c
@@ -70,10 +70,14 @@
  */
 static pte_t * __init one_page_table_init(pmd_t *pmd)
 {
-	pte_t *page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
-	set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
-	if (page_table != pte_offset_kernel(pmd, 0))
-		BUG();	
+	pte_t *page_table;
+	if (pmd_none(*pmd)) {
+		page_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+		set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
+		if (page_table != pte_offset_kernel(pmd, 0))
+			BUG();	
+	} else
+		page_table = pte_offset_kernel(pmd, 0);
 
 	return page_table;
 }
@@ -107,9 +111,7 @@
 
 		pmd = pmd_offset(pgd, vaddr);
 		for (; (pmd_ofs < PTRS_PER_PMD) && (vaddr != end); pmd++, pmd_ofs++) {
-			if (pmd_none(*pmd)) 
-				one_page_table_init(pmd);
-
+			one_page_table_init(pmd);
 			vaddr += PMD_SIZE;
 		}
 		pmd_ofs = 0;