mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fix x86 page table init
@ 2002-07-31  1:45 Brian Gerst
  2002-07-31  3:05 ` Dan Aloni
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Gerst @ 2002-07-31  1:45 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Linux-Kernel, da-x

[-- Attachment #1: Type: text/plain, Size: 393 bytes --]

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

[-- Attachment #2: pte_init-1 --]
[-- Type: text/plain, Size: 1007 bytes --]

diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c
--- linux-bk/arch/i386/mm/init.c	Tue Jul 30 20:59:27 2002
+++ linux/arch/i386/mm/init.c	Tue Jul 30 21:02:41 2002
@@ -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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix x86 page table init
  2002-07-31  1:45 [PATCH] fix x86 page table init Brian Gerst
@ 2002-07-31  3:05 ` Dan Aloni
  2002-07-31  4:35   ` Brian Gerst
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Aloni @ 2002-07-31  3:05 UTC (permalink / raw)
  To: Brian Gerst; +Cc: Linus Torvalds, Linux-Kernel

On Tue, Jul 30, 2002 at 09:45:17PM -0400, Brian Gerst wrote:
> 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)?

> diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c
> --- linux-bk/arch/i386/mm/init.c	Tue Jul 30 20:59:27 2002
> +++ linux/arch/i386/mm/init.c	Tue Jul 30 21:02:41 2002
> @@ -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;


-- 
Dan Aloni
da-x@gmx.net

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix x86 page table init
  2002-07-31  3:05 ` Dan Aloni
@ 2002-07-31  4:35   ` Brian Gerst
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Gerst @ 2002-07-31  4:35 UTC (permalink / raw)
  To: Dan Aloni; +Cc: Brian Gerst, Linus Torvalds, Linux-Kernel

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

Dan Aloni wrote:
> On Tue, Jul 30, 2002 at 09:45:17PM -0400, Brian Gerst wrote:
> 
>>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

[-- Attachment #2: pte_init-2 --]
[-- Type: text/plain, Size: 1008 bytes --]

diff -urN linux-bk/arch/i386/mm/init.c linux/arch/i386/mm/init.c
--- linux-bk/arch/i386/mm/init.c	Tue Jul 30 20:59:27 2002
+++ linux/arch/i386/mm/init.c	Wed Jul 31 00:32:37 2002
@@ -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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] fix x86 page table init
@ 2002-08-04 16:36 Brian Gerst
  0 siblings, 0 replies; 4+ messages in thread
From: Brian Gerst @ 2002-08-04 16:36 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Linux-Kernel

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

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 is the third iteration of the patch and it 
goes back to the 2.4 method, which is compatabile with the boot 
pagetable changes I just sent in.

--
				Brian Gerst


[-- Attachment #2: pte_init-3 --]
[-- Type: text/plain, Size: 1031 bytes --]

diff -urN linux-bg1/arch/i386/mm/init.c linux/arch/i386/mm/init.c
--- linux-bg1/arch/i386/mm/init.c	Fri Aug  2 10:15:28 2002
+++ linux/arch/i386/mm/init.c	Sun Aug  4 12:14:42 2002
@@ -126,7 +126,7 @@
 	unsigned long pfn;
 	pgd_t *pgd;
 	pmd_t *pmd;
-	pte_t *pte;
+	pte_t *pte, *pte_base;
 	int pgd_ofs, pmd_ofs, pte_ofs;
 
 	pgd_ofs = __pgd_offset(PAGE_OFFSET);
@@ -141,10 +141,19 @@
 				set_pmd(pmd, pfn_pmd(pfn, PAGE_KERNEL_LARGE));
 				pfn += PTRS_PER_PTE;
 			} else {
-				pte = one_page_table_init(pmd);
+				/*
+				 * We cannot set the pmd until the page is full, since we are
+				 * changing the pte under running code and a tlb miss will
+				 * cause an oops.
+				 */
+				pte_base = pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
 
 				for (pte_ofs = 0; pte_ofs < PTRS_PER_PTE && pfn < max_low_pfn; pte++, pfn++, pte_ofs++)
 					set_pte(pte, pfn_pte(pfn, PAGE_KERNEL));
+
+				set_pmd(pmd, __pmd(__pa(pte_base) | _KERNPG_TABLE));
+				if (pte_base != pte_offset_kernel(pmd, 0))
+					BUG();	
 			}
 		}
 	}	

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-04 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-31  1:45 [PATCH] fix x86 page table init Brian Gerst
2002-07-31  3:05 ` Dan Aloni
2002-07-31  4:35   ` Brian Gerst
2002-08-04 16:36 Brian Gerst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®