login
Header Space

 
 

[PATCH] x86: fix PAE pmd_bad bootup warning

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Ingo Molnar <mingo@...>, Jeff Chua <jeff.chua.linux@...>, Thomas Gleixner <tglx@...>, H. Peter Anvin <hpa@...>, Gabriel C <nix.or.die@...>, Hans Rosenfeld <hans.rosenfeld@...>, Arjan van de Ven <arjan@...>, Nishanth Aravamudan <nacc@...>, <linux-kernel@...>, <linux-mm@...>
Date: Tuesday, May 6, 2008 - 3:49 pm

Fix warning from pmd_bad() at bootup on a HIGHMEM64G HIGHPTE x86_32.

That came from 9fc34113f6880b215cbea4e7017fc818700384c2 x86: debug pmd_bad();
but we understand now that the typecasting was wrong for PAE in the previous
version: pagetable pages above 4GB looked bad and stopped Arjan from booting.

And revert that cded932b75ab0a5f9181ee3da34a0a488d1a14fd x86: fix pmd_bad
and pud_bad to support huge pages.  It was the wrong way round: we shouldn't
weaken every pmd_bad and pud_bad check to let huge pages slip through - in
part they check that we _don't_ have a huge page where it's not expected.

Put the x86 pmd_bad() and pud_bad() definitions back to what they have long
been: they can be improved (x86_32 should use PTE_MASK, to stop PAE thinking
junk in the upper word is good; and x86_64 should follow x86_32's stricter
comparison, to stop thinking any subset of required bits is good); but that
should be a later patch.

Fix Hans' good observation that follow_page() will never find pmd_huge()
because that would have already failed the pmd_bad test: test pmd_huge in
between the pmd_none and pmd_bad tests.  Tighten x86's pmd_huge() check?
No, once it's a hugepage entry, it can get quite far from a good pmd: for
example, PROT_NONE leaves it with only ACCESSED of the KERN_PGTABLE bits.

However... though follow_page() contains this and another test for huge
pages, so it's nice to keep it working on them, where does it actually get
called on a huge page?  get_user_pages() checks is_vm_hugetlb_page(vma) to
to call alternative hugetlb processing, as does unmap_vmas() and others.

Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
So Hans' original hugepage leak remains unexplained and unfixed.
Hans, did you find that hugepage leak with a standard kernel, or were
you perhaps trying out some hugepage-using patch of your own, without
marking the vma VM_HUGETLB?  Or were you expecting the hugetlbfs file
to truncate itself once all mmappers had gone?  If the standard kernel
leaks hugepages, I'm surprised the hugetlb guys don't know about it.

 arch/x86/mm/pgtable_32.c     |    7 -------
 include/asm-x86/pgtable_32.h |    9 +--------
 include/asm-x86/pgtable_64.h |    6 ++----
 mm/memory.c                  |    5 ++++-
 4 files changed, 7 insertions(+), 20 deletions(-)

--- 2.6.26-rc1/arch/x86/mm/pgtable_32.c	2008-05-03 21:54:41.000000000 +0100
+++ linux/arch/x86/mm/pgtable_32.c	2008-05-06 14:13:24.000000000 +0100
@@ -172,10 +172,3 @@ void reserve_top_address(unsigned long r
 	__FIXADDR_TOP = -reserve - PAGE_SIZE;
 	__VMALLOC_RESERVE += reserve;
 }
-
-int pmd_bad(pmd_t pmd)
-{
-	WARN_ON_ONCE(pmd_bad_v1(pmd) != pmd_bad_v2(pmd));
-
-	return pmd_bad_v1(pmd);
-}
--- 2.6.26-rc1/include/asm-x86/pgtable_32.h	2008-05-03 21:55:10.000000000 +0100
+++ linux/include/asm-x86/pgtable_32.h	2008-05-06 14:13:24.000000000 +0100
@@ -88,14 +88,7 @@ extern unsigned long pg0[];
 /* To avoid harmful races, pmd_none(x) should check only the lower when PAE */
 #define pmd_none(x)	(!(unsigned long)pmd_val((x)))
 #define pmd_present(x)	(pmd_val((x)) & _PAGE_PRESENT)
-
-extern int pmd_bad(pmd_t pmd);
-
-#define pmd_bad_v1(x)							\
-	(_KERNPG_TABLE != (pmd_val((x)) & ~(PAGE_MASK | _PAGE_USER)))
-#define	pmd_bad_v2(x)							\
-	(_KERNPG_TABLE != (pmd_val((x)) & ~(PAGE_MASK | _PAGE_USER |	\
-					    _PAGE_PSE | _PAGE_NX)))
+#define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
 
 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
 
--- 2.6.26-rc1/include/asm-x86/pgtable_64.h	2008-05-03 21:55:10.000000000 +0100
+++ linux/include/asm-x86/pgtable_64.h	2008-05-06 14:13:24.000000000 +0100
@@ -158,14 +158,12 @@ static inline unsigned long pgd_bad(pgd_
 
 static inline unsigned long pud_bad(pud_t pud)
 {
-	return pud_val(pud) &
-		~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER | _PAGE_PSE | _PAGE_NX);
+	return pud_val(pud) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
 }
 
 static inline unsigned long pmd_bad(pmd_t pmd)
 {
-	return pmd_val(pmd) &
-		~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER | _PAGE_PSE | _PAGE_NX);
+	return pmd_val(pmd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
 }
 
 #define pte_none(x)	(!pte_val((x)))
--- 2.6.26-rc1/mm/memory.c	2008-05-03 21:55:12.000000000 +0100
+++ linux/mm/memory.c	2008-05-06 14:13:24.000000000 +0100
@@ -969,7 +969,7 @@ struct page *follow_page(struct vm_area_
 		goto no_page_table;
 	
 	pmd = pmd_offset(pud, address);
-	if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
+	if (pmd_none(*pmd))
 		goto no_page_table;
 
 	if (pmd_huge(*pmd)) {
@@ -978,6 +978,9 @@ struct page *follow_page(struct vm_area_
 		goto out;
 	}
 
+	if (unlikely(pmd_bad(*pmd)))
+		goto no_page_table;
+
 	ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
 	if (!ptep)
 		goto out;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Jeff Chua, (Mon May 5, 9:06 pm)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Ingo Molnar, (Tue May 6, 8:49 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Hugh Dickins, (Tue May 6, 9:56 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Linus Torvalds, (Tue May 6, 2:39 pm)
[PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Tue May 6, 3:49 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Jeff Chua, (Wed May 7, 12:40 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Wed May 7, 1:30 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Tue May 6, 4:22 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Tue May 6, 4:42 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 10:34 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 10:52 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Nishanth Aravamudan, (Thu May 8, 11:44 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 11:11 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 11:51 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 12:19 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 12:42 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Nishanth Aravamudan, (Thu May 8, 12:33 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 12:51 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Nishanth Aravamudan, (Thu May 8, 1:16 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Thu May 8, 2:48 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 4:02 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Paul Mundt, (Fri May 9, 5:03 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 7:15 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Matt Mackall, (Wed May 14, 3:01 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 4:16 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Matt Mackall, (Thu May 8, 3:49 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 4:08 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 2:42 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Thu May 8, 2:58 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Dave Hansen, (Thu May 8, 3:06 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hans Rosenfeld, (Thu May 8, 10:39 am)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Tue May 6, 4:36 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Nishanth Aravamudan, (Wed May 7, 7:39 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Linus Torvalds, (Tue May 6, 4:06 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Hugh Dickins, (Tue May 6, 4:30 pm)
Re: [PATCH] x86: fix PAE pmd_bad bootup warning, Nishanth Aravamudan, (Thu May 8, 12:07 pm)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Hugh Dickins, (Tue May 6, 3:43 pm)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Ingo Molnar, (Tue May 6, 11:04 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Linus Torvalds, (Tue May 6, 11:09 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Jeremy Fitzhardinge, (Tue May 6, 11:32 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Hugh Dickins, (Tue May 6, 12:12 pm)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Ingo Molnar, (Tue May 6, 11:15 am)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Linus Torvalds, (Tue May 6, 12:16 pm)
Re: Linux 2.6.26-rc1 - pgtable_32.c:178 pmd_bad, Ingo Molnar, (Tue May 6, 12:30 pm)
speck-geostationary