Skip to contentSkip to conversation

x86: clean up pte functions in pgtable*.h

PATCH New Jeremy Fitzhardinge 3 participants 42 messages Feb 5, 2009 – Feb 6, 2009

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

PATCH 1/1 x86: clean up pte functions in pgtable*.h

Hi Ingo,

Here's a bunch of tiny patches to move as much as possible from pgtable_*.h to pgtable.h. This serves two purposes:

1. There was a lot of redundancy in there, so there's a fair amount of unification, and

2. Moves all the pte-manipulation into one place, to make further header restructuring easier.

Lightly built on 32 and 64-bit pvops, and 64-bit non-pvops configs. 64-bit test boot under kvm.

Thanks,
J

#1 lore raw

PATCH 1/1 x86: unify pte_none

Impact: cleanup

Unify and demacro pte_none.

---
 arch/x86/include/asm/pgtable-2level.h |    2 --
 arch/x86/include/asm/pgtable-3level.h |    5 -----
 arch/x86/include/asm/pgtable.h        |    5 +++++
 arch/x86/include/asm/pgtable_64.h     |    1 -
 4 files changed, 5 insertions(+), 8 deletions(-)
arch/x86/include/asm/pgtable-2level.h +0 -2
@@ -53,8 +53,6 @@
 #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)
 #endif
 
-#define pte_none(x)		(!(x).pte_low)
-
 /*
  * Bits _PAGE_BIT_PRESENT, _PAGE_BIT_FILE and _PAGE_BIT_PROTNONE are taken,
  * split up the 29 bits of offset into this range:
arch/x86/include/asm/pgtable-3level.h +0 -5
@@ -151,11 +151,6 @@
 	return a.pte_low == b.pte_low && a.pte_high == b.pte_high;
 }
 
-static inline int pte_none(pte_t pte)
-{
-	return !pte.pte_low && !pte.pte_high;
-}
-
 /*
  * Bits 0, 6 and 7 are taken in the low part of the pte,
  * put the 32 bits of offset into the high part.
arch/x86/include/asm/pgtable.h +5 -0
@@ -457,6 +457,11 @@
 }
 #endif	/* CONFIG_PARAVIRT */
 
+static inline int pte_none(pte_t pte)
+{
+	return !pte.pte;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -170,7 +170,6 @@
 	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
-#define pte_none(x)	(!pte_val((x)))
 #define pte_present(x)	(pte_val((x)) & (_PAGE_PRESENT | _PAGE_PROTNONE))
 
 #ifdef CONFIG_KMEMCHECK
#2 lore raw

PATCH 1/1 x86: unify pte_same

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pte_same.

---
 arch/x86/include/asm/pgtable-3level.h |    6 ------
 arch/x86/include/asm/pgtable.h        |    6 ++++++
 arch/x86/include/asm/pgtable_64.h     |    2 --
 3 files changed, 6 insertions(+), 8 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -6
@@ -145,12 +145,6 @@
 #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)
 #endif
 
-#define __HAVE_ARCH_PTE_SAME
-static inline int pte_same(pte_t a, pte_t b)
-{
-	return a.pte_low == b.pte_low && a.pte_high == b.pte_high;
-}
-
 /*
  * Bits 0, 6 and 7 are taken in the low part of the pte,
  * put the 32 bits of offset into the high part.
arch/x86/include/asm/pgtable.h +6 -0
@@ -462,6 +462,12 @@
 	return !pte.pte;
 }
 
+#define __HAVE_ARCH_PTE_SAME
+static inline int pte_same(pte_t a, pte_t b)
+{
+	return a.pte == b.pte;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -133,8 +133,6 @@
 	native_set_pgd(pgd, native_make_pgd(0));
 }
 
-#define pte_same(a, b)		((a).pte == (b).pte)
-
 #endif /* !__ASSEMBLY__ */
 
 #define PMD_SIZE	(_AC(1, UL) << PMD_SHIFT)
#3 lore raw

PATCH 1/1 x86: unify pte_present

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pte_present.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    2 --
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -468,6 +468,11 @@
 	return a.pte == b.pte;
 }
 
+static inline int pte_present(pte_t a)
+{
+	return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -85,8 +85,6 @@
 /* The boot page tables (all created as a single array) */
 extern unsigned long pg0[];
 
-#define pte_present(x)	((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
-
 #ifdef CONFIG_KMEMCHECK
 #define pte_hidden(x)	((x).pte_low & (_PAGE_HIDDEN))
 #else
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -168,8 +168,6 @@
 	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
-#define pte_present(x)	(pte_val((x)) & (_PAGE_PRESENT | _PAGE_PROTNONE))
-
 #ifdef CONFIG_KMEMCHECK
 #define pte_hidden(x)	(pte_val((x)) & (_PAGE_HIDDEN))
 #else
#4 lore raw

PATCH 1/1 x86: make _PAGE_HIDDEN conditional

In reply to Jeremy Fitzhardinge

Only _PAGE_HIDDEN when CONFIG_KMEMCHECK is defined, otherwise set it to 0. Allows later cleanups.

---
 arch/x86/include/asm/pgtable.h |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +6 -1
@@ -38,13 +38,18 @@
 #define _PAGE_GLOBAL	(_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
 #define _PAGE_UNUSED1	(_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
 #define _PAGE_IOMAP	(_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
-#define _PAGE_HIDDEN	(_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
 #define _PAGE_PAT	(_AT(pteval_t, 1) << _PAGE_BIT_PAT)
 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
 #define _PAGE_SPECIAL	(_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
 #define _PAGE_CPA_TEST	(_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
 #define __HAVE_ARCH_PTE_SPECIAL
 
+#ifdef CONFIG_KMEMCHECK
+#define _PAGE_HIDDEN	(_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
+#else
+#define _PAGE_HIDDEN	(_AT(pteval_t, 0))
+#endif
+
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
 #define _PAGE_NX	(_AT(pteval_t, 1) << _PAGE_BIT_NX)
 #else
#5 lore raw

PATCH 1/1 x86: unify pgd_present

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_present.

---
 arch/x86/include/asm/pgtable.h    |    7 +++++++
 arch/x86/include/asm/pgtable_64.h |    1 -
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +7 -0
@@ -490,6 +490,13 @@
 }
 #endif	/* PAGETABLE_LEVELS > 2 */
 
+#if PAGETABLE_LEVELS > 3
+static inline int pgd_present(pgd_t pgd)
+{
+	return pgd_val(pgd) & _PAGE_PRESENT;
+}
+#endif	/* PAGETABLE_LEVELS > 3 */
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -181,7 +181,6 @@
 #define pgd_page_vaddr(pgd)						\
 	((unsigned long)__va((unsigned long)pgd_val((pgd)) & PTE_PFN_MASK))
 #define pgd_page(pgd)		(pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
-#define pgd_present(pgd) (pgd_val(pgd) & _PAGE_PRESENT)
 static inline int pgd_large(pgd_t pgd) { return 0; }
 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
 
#6 lore raw

PATCH 1/1 x86: unify pmd_none

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_none.

---
 arch/x86/include/asm/pgtable.h    |    7 +++++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    1 -
 3 files changed, 7 insertions(+), 3 deletions(-)
arch/x86/include/asm/pgtable.h +7 -0
@@ -488,6 +488,13 @@
 	return pmd_val(pmd) & _PAGE_PRESENT;
 }
 
+static inline int pmd_none(pmd_t pmd)
+{
+	/* Only check low word on 32-bit platforms, since it might be
+	   out of sync with upper half. */
+	return !(unsigned long)native_pmd_val(pmd);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -85,8 +85,6 @@
 /* The boot page tables (all created as a single array) */
 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_bad(x) ((pmd_val(x) & (PTE_FLAGS_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
 
 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -206,7 +206,6 @@
 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
 #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
 				  pmd_index(address))
-#define pmd_none(x)	(!pmd_val((x)))
 #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
 #define pmd_pfn(x)  ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
 
#7 lore raw

PATCH 1/1 x86: unify pmd_present

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_present.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    1 -
 arch/x86/include/asm/pgtable_64.h |    1 -
 3 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -483,6 +483,11 @@
 	return pte_flags(pte) & _PAGE_HIDDEN;
 }
 
+static inline int pmd_present(pmd_t pmd)
+{
+	return pmd_val(pmd) & _PAGE_PRESENT;
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -1
@@ -87,7 +87,6 @@
 
 /* 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)
 #define pmd_bad(x) ((pmd_val(x) & (PTE_FLAGS_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
 
 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -207,7 +207,6 @@
 #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
 				  pmd_index(address))
 #define pmd_none(x)	(!pmd_val((x)))
-#define pmd_present(x)	(pmd_val((x)) & _PAGE_PRESENT)
 #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
 #define pmd_pfn(x)  ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
 
#8 lore raw

PATCH 1/1 x86: unify pud_present

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_present.

---
 arch/x86/include/asm/pgtable-3level.h |    5 -----
 arch/x86/include/asm/pgtable.h        |    7 +++++++
 arch/x86/include/asm/pgtable_64.h     |    1 -
 3 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -5
@@ -28,11 +28,6 @@
 	return (pud_val(pud) & ~(PTE_PFN_MASK | _KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 
-static inline int pud_present(pud_t pud)
-{
-	return pud_val(pud) & _PAGE_PRESENT;
-}
-
 /* Rules for using set_pte: the pte being assigned *must* be
  * either not present or in a state where the hardware will
  * not attempt to update the pte.  In places where this is
arch/x86/include/asm/pgtable.h +7 -0
@@ -483,6 +483,13 @@
 	return pte_flags(pte) & _PAGE_HIDDEN;
 }
 
+#if PAGETABLE_LEVELS > 2
+static inline int pud_present(pud_t pud)
+{
+	return pud_val(pud) & _PAGE_PRESENT;
+}
+#endif	/* PAGETABLE_LEVELS > 2 */
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -193,7 +193,6 @@
 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
 #define pud_offset(pgd, address)					\
 	((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
-#define pud_present(pud) (pud_val((pud)) & _PAGE_PRESENT)
 
 static inline int pud_large(pud_t pte)
 {
#9 lore raw

PATCH 1/1 x86: unify pte_hidden

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pte_hidden.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    6 ------
 arch/x86/include/asm/pgtable_64.h |    6 ------
 3 files changed, 5 insertions(+), 12 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -478,6 +478,11 @@
 	return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);
 }
 
+static inline int pte_hidden(pte_t pte)
+{
+	return pte_flags(pte) & _PAGE_HIDDEN;
+}
+
 #endif	/* __ASSEMBLY__ */
 
 #ifdef CONFIG_X86_32
arch/x86/include/asm/pgtable_32.h +0 -6
@@ -85,12 +85,6 @@
 /* The boot page tables (all created as a single array) */
 extern unsigned long pg0[];
 
-#ifdef CONFIG_KMEMCHECK
-#define pte_hidden(x)	((x).pte_low & (_PAGE_HIDDEN))
-#else
-#define pte_hidden(x)	0
-#endif
-
 /* 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)
arch/x86/include/asm/pgtable_64.h +0 -6
@@ -168,12 +168,6 @@
 	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
-#ifdef CONFIG_KMEMCHECK
-#define pte_hidden(x)	(pte_val((x)) & (_PAGE_HIDDEN))
-#else
-#define pte_hidden(x)	0
-#endif
-
 #define pages_to_mb(x)	((x) >> (20 - PAGE_SHIFT))   /* FIXME: is this right? */
 
 /*
#10 lore raw

PATCH 1/1 x86: unify pgd_page_vaddr

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_page_vaddr.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    2 --
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -507,6 +507,11 @@
 {
 	return pgd_val(pgd) & _PAGE_PRESENT;
 }
+
+static inline unsigned long pgd_page_vaddr(pgd_t pgd)
+{
+	return (unsigned long)__va((unsigned long)pgd_val(pgd) & PTE_PFN_MASK);
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -178,8 +178,6 @@
 /*
  * Level 4 access.
  */
-#define pgd_page_vaddr(pgd)						\
-	((unsigned long)__va((unsigned long)pgd_val((pgd)) & PTE_PFN_MASK))
 #define pgd_page(pgd)		(pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
 static inline int pgd_large(pgd_t pgd) { return 0; }
 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
#11 lore raw

PATCH 1/1 x86: unify pud_page

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_page.

---
 arch/x86/include/asm/pgtable-3level.h |    2 --
 arch/x86/include/asm/pgtable.h        |    6 ++++++
 arch/x86/include/asm/pgtable_64.h     |    1 -
 3 files changed, 6 insertions(+), 3 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -2
@@ -115,8 +115,6 @@
 		write_cr3(pgd);
 }
 
-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
-
 /* Find an entry in the second-level page table.. */
 #define pmd_offset(pud, address) ((pmd_t *)pud_page_vaddr(*(pud)) +	\
 				  pmd_index(address))
arch/x86/include/asm/pgtable.h +6 -0
@@ -471,6 +471,7 @@
 #endif
 
 #ifndef __ASSEMBLY__
+#include <linux/mm_types.h>
 
 static inline int pte_none(pte_t pte)
 {
@@ -515,6 +516,11 @@
 {
 	return (unsigned long)__va((unsigned long)pud_val(pud) & PTE_PFN_MASK);
 }
+
+static inline struct page *pud_page(pud_t pud)
+{
+	return pfn_to_page(pud_val(pud) >> PAGE_SHIFT);
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -184,7 +184,6 @@
 
 /* PUD - Level3 access */
 /* to find an entry in a page-table-directory. */
-#define pud_page(pud)	(pfn_to_page(pud_val((pud)) >> PAGE_SHIFT))
 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
 #define pud_offset(pgd, address)					\
 	((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
#12 lore raw

PATCH 1/1 x86: unify pud_offset

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_offset.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    2 --
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -544,6 +544,11 @@
 {
 	return (address >> PUD_SHIFT) & (PTRS_PER_PUD - 1);
 }
+
+static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
+{
+	return (pud_t *)pgd_page_vaddr(*pgd) + pud_index(address);
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -182,8 +182,6 @@
 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
 
 /* PUD - Level3 access */
-#define pud_offset(pgd, address)					\
-	((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
 
 static inline int pud_large(pud_t pte)
 {
#13 lore raw

PATCH 1/1 x86: remove redundant pfn_pmd definition

In reply to Jeremy Fitzhardinge

Impact: cleanup

It's already defined in pgtable.h

---
 arch/x86/include/asm/pgtable_64.h |    1 -
 1 file changed, 1 deletion(-)
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -190,7 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
 #define pmd_pfn(x)  ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
 
 #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
#14 lore raw

PATCH 1/1 x86: unify pud_index

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_index.

---
 arch/x86/include/asm/pgtable.h    |    6 ++++++
 arch/x86/include/asm/pgtable_64.h |    2 --
 2 files changed, 6 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +6 -0
@@ -538,6 +538,12 @@
 {
 	return pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT);
 }
+
+/* to find an entry in a page-table-directory. */
+static inline unsigned pud_index(unsigned long address)
+{
+	return (address >> PUD_SHIFT) & (PTRS_PER_PUD - 1);
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -182,8 +182,6 @@
 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
 
 /* PUD - Level3 access */
-/* to find an entry in a page-table-directory. */
-#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
 #define pud_offset(pgd, address)					\
 	((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
 
#15 lore raw

PATCH 1/1 x86: unify pmd_pfn

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_pfn.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    2 --
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -548,6 +548,11 @@
 {
 	return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
 }
+
+static inline unsigned long pmd_pfn(pmd_t pmd)
+{
+	return (pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT;
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -190,8 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pmd_pfn(x)  ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
-
 #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
 #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) |	\
 					    _PAGE_FILE })
#16 lore raw

PATCH 1/1 x86: unify pte_offset_kernel

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pte_offset_kernel.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    3 ---
 arch/x86/include/asm/pgtable_64.h |    3 ---
 3 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -547,6 +547,11 @@
 	return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
 }
 
+static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
+{
+	return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -3
@@ -97,9 +97,6 @@
 
 static inline int pud_large(pud_t pud) { return 0; }
 
-#define pte_offset_kernel(dir, address)				\
-	((pte_t *)pmd_page_vaddr(*(dir)) +  pte_index((address)))
-
 #if defined(CONFIG_HIGHPTE)
 #define pte_offset_map(dir, address)					\
 	((pte_t *)kmap_atomic_pte(pmd_page(*(dir)), KM_PTE0) +		\
arch/x86/include/asm/pgtable_64.h +0 -3
@@ -197,9 +197,6 @@
 
 /* PTE - Level 1 access. */
 
-#define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
-					 pte_index((address)))
-
 /* x86-64 always has all page tables mapped. */
 #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
 #define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
#17 lore raw

PATCH 1/1 x86: unify pmd_bad

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_bad.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    5 -----
 3 files changed, 5 insertions(+), 7 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -552,6 +552,11 @@
 	return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
 }
 
+static inline int pmd_bad(pmd_t pmd)
+{
+	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -85,8 +85,6 @@
 /* The boot page tables (all created as a single array) */
 extern unsigned long pg0[];
 
-#define pmd_bad(x) ((pmd_val(x) & (PTE_FLAGS_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
-
 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
 
 #ifdef CONFIG_X86_PAE
arch/x86/include/asm/pgtable_64.h +0 -5
@@ -153,11 +153,6 @@
 
 #ifndef __ASSEMBLY__
 
-static inline int pmd_bad(pmd_t pmd)
-{
-	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
-}
-
 #define pages_to_mb(x)	((x) >> (20 - PAGE_SHIFT))   /* FIXME: is this right? */
 
 /*
#18 lore raw

PATCH 1/1 x86: unify pmd_pfn

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify pmd_pfn. Unfortunately it can't be demacroed because it has a cyclic dependency on linux/mm.h:page_to_nid().

---
 arch/x86/include/asm/pgtable.h    |    9 +++++++++
 arch/x86/include/asm/pgtable_32.h |    7 -------
 arch/x86/include/asm/pgtable_64.h |    3 ---
 3 files changed, 9 insertions(+), 10 deletions(-)
arch/x86/include/asm/pgtable.h +9 -0
@@ -527,6 +527,15 @@
 	return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
 }
 
+/*
+ * Conversion functions: convert a page and protection to a page entry,
+ * and a page entry and page directory to the page they refer to.
+ *
+ * (Currently stuck as a macro because of indirect forward reference
+ * to linux/mm.h:page_to_nid())
+ */
+#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -7
@@ -95,13 +95,6 @@
 # include <asm/pgtable-2level.h>
 #endif
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, pgprot)	pfn_pte(page_to_pfn(page), (pgprot))
-
-
 static inline int pud_large(pud_t pud) { return 0; }
 
 /*
arch/x86/include/asm/pgtable_64.h +0 -3
@@ -197,9 +197,6 @@
 
 /* PTE - Level 1 access. */
 
-/* page, protection -> pte */
-#define mk_pte(page, pgprot)	pfn_pte(page_to_pfn((page)), (pgprot))
-
 #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
 #define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
 					 pte_index((address)))
#19 lore raw

PATCH 1/1 x86: unify pud_large

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_large.

---
 arch/x86/include/asm/pgtable.h    |    6 ++++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    6 ------
 3 files changed, 6 insertions(+), 8 deletions(-)
arch/x86/include/asm/pgtable.h +6 -0
@@ -578,6 +578,12 @@
 {
 	return (pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT;
 }
+
+static inline int pud_large(pud_t pud)
+{
+	return (pud_val(pud) & (_PAGE_PSE | _PAGE_PRESENT)) ==
+		(_PAGE_PSE | _PAGE_PRESENT);
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -95,8 +95,6 @@
 # include <asm/pgtable-2level.h>
 #endif
 
-static inline int pud_large(pud_t pud) { return 0; }
-
 #if defined(CONFIG_HIGHPTE)
 #define pte_offset_map(dir, address)					\
 	((pte_t *)kmap_atomic_pte(pmd_page(*(dir)), KM_PTE0) +		\
arch/x86/include/asm/pgtable_64.h +0 -6
@@ -183,12 +183,6 @@
 
 /* PUD - Level3 access */
 
-static inline int pud_large(pud_t pte)
-{
-	return (pud_val(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
-		(_PAGE_PSE | _PAGE_PRESENT);
-}
-
 /* PMD  - Level 2 access */
 #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
 #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) |	\
#20 lore raw

PATCH 1/1 x86: make pgd/pud/pmd/pte_none consistent

In reply to Jeremy Fitzhardinge

The _none test is done differently for every level of the pagetable. Standardize them by:

1: Use the native_X_val to extract the raw entry, with no need to go

    via paravirt_ops, diff -r 1d0646d0d319 arch/x86/include/asm/pgtable.h, and

2: Compare with 0 rather than using a boolean !, since they are actually values
and not booleans.

---
 arch/x86/include/asm/pgtable.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/pgtable.h +3 -3
@@ -503,7 +503,7 @@
 {
 	/* Only check low word on 32-bit platforms, since it might be
 	   out of sync with upper half. */
-	return !(unsigned long)native_pmd_val(pmd);
+	return (unsigned long)native_pmd_val(pmd) == 0;
 }
 
 static inline unsigned long pmd_page_vaddr(pmd_t pmd)
@@ -568,7 +568,7 @@
 #if PAGETABLE_LEVELS > 2
 static inline int pud_none(pud_t pud)
 {
-	return pud_val(pud) == 0;
+	return native_pud_val(pud) == 0;
 }
 
 static inline int pud_present(pud_t pud)
@@ -643,7 +643,7 @@
 
 static inline int pgd_none(pgd_t pgd)
 {
-	return !pgd_val(pgd);
+	return !native_pgd_val(pgd);
 }
 #endif	/* PAGETABLE_LEVELS > 3 */
 
#24 lore raw

PATCH 1/1 x86: add and use pgd/pud/pmd_flags

In reply to Jeremy Fitzhardinge

Add pgd/pud/pmd_flags which are analogous to pte_flags, and use them where-ever we only care about testing the flags portions of the respective entries.

---
 arch/x86/include/asm/page.h    |   15 +++++++++++++++
 arch/x86/include/asm/pgtable.h |   16 ++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)
arch/x86/include/asm/page.h +15 -0
@@ -95,6 +95,11 @@
 	return pgd.pgd;
 }
 
+static inline pgdval_t pgd_flags(pgd_t pgd)
+{
+	return native_pgd_val(pgd) & PTE_FLAGS_MASK;
+}
+
 #if PAGETABLE_LEVELS >= 3
 #if PAGETABLE_LEVELS == 4
 typedef struct { pudval_t pud; } pud_t;
@@ -117,6 +122,11 @@
 }
 #endif	/* PAGETABLE_LEVELS == 4 */
 
+static inline pudval_t pud_flags(pud_t pud)
+{
+	return native_pud_val(pud) & PTE_FLAGS_MASK;
+}
+
 typedef struct { pmdval_t pmd; } pmd_t;
 
 static inline pmd_t native_make_pmd(pmdval_t val)
@@ -128,6 +138,11 @@
 {
 	return pmd.pmd;
 }
+
+static inline pmdval_t pmd_flags(pmd_t pmd)
+{
+	return native_pmd_val(pmd) & PTE_FLAGS_MASK;
+}
 #else  /* PAGETABLE_LEVELS == 2 */
 #include <asm-generic/pgtable-nopmd.h>
 
arch/x86/include/asm/pgtable.h +8 -8
@@ -241,7 +241,7 @@
 
 static inline int pmd_large(pmd_t pte)
 {
-	return (pmd_val(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
+	return (pmd_flags(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
 		(_PAGE_PSE | _PAGE_PRESENT);
 }
 
@@ -496,7 +496,7 @@
 
 static inline int pmd_present(pmd_t pmd)
 {
-	return pmd_val(pmd) & _PAGE_PRESENT;
+	return pmd_flags(pmd) & _PAGE_PRESENT;
 }
 
 static inline int pmd_none(pmd_t pmd)
@@ -554,7 +554,7 @@
 
 static inline int pmd_bad(pmd_t pmd)
 {
-	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
+	return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
 }
 
 static inline unsigned long pages_to_mb(unsigned long npg)
@@ -573,7 +573,7 @@
 
 static inline int pud_present(pud_t pud)
 {
-	return pud_val(pud) & _PAGE_PRESENT;
+	return pud_flags(pud) & _PAGE_PRESENT;
 }
 
 static inline unsigned long pud_page_vaddr(pud_t pud)
@@ -599,20 +599,20 @@
 
 static inline int pud_large(pud_t pud)
 {
-	return (pud_val(pud) & (_PAGE_PSE | _PAGE_PRESENT)) ==
+	return (pud_flags(pud) & (_PAGE_PSE | _PAGE_PRESENT)) ==
 		(_PAGE_PSE | _PAGE_PRESENT);
 }
 
 static inline int pud_bad(pud_t pud)
 {
-	return (pud_val(pud) & ~(PTE_PFN_MASK | _KERNPG_TABLE | _PAGE_USER)) != 0;
+	return (pud_flags(pud) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
 static inline int pgd_present(pgd_t pgd)
 {
-	return pgd_val(pgd) & _PAGE_PRESENT;
+	return pgd_flags(pgd) & _PAGE_PRESENT;
 }
 
 static inline unsigned long pgd_page_vaddr(pgd_t pgd)
@@ -638,7 +638,7 @@
 
 static inline int pgd_bad(pgd_t pgd)
 {
-	return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
+	return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
 }
 
 static inline int pgd_none(pgd_t pgd)
#25 lore raw

PATCH 1/1 x86: unify pgd_none

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_none.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    2 --
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -637,6 +637,11 @@
 {
 	return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
+
+static inline int pgd_none(pgd_t pgd)
+{
+	return !pgd_val(pgd);
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -66,8 +66,6 @@
 	printk("%s:%d: bad pgd %p(%016lx).\n",		\
 	       __FILE__, __LINE__, &(e), pgd_val(e))
 
-#define pgd_none(x)	(!pgd_val(x))
-
 struct mm_struct;
 
 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
#26 lore raw

PATCH 1/1 x86: make the X_bad functions consistent

In reply to Jeremy Fitzhardinge

Impact: cleanup

Use the same logic to implement all 3 _bad() functions.

---
 arch/x86/include/asm/pgtable.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +2 -2
@@ -554,7 +554,7 @@
 
 static inline int pmd_bad(pmd_t pmd)
 {
-	return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
+	return (pmd_flags(pmd) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 
 static inline unsigned long pages_to_mb(unsigned long npg)
@@ -638,7 +638,7 @@
 
 static inline int pgd_bad(pgd_t pgd)
 {
-	return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
+	return (pgd_flags(pgd) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 
 static inline int pgd_none(pgd_t pgd)
#29 lore raw

PATCH 1/1 x86: unify pages_to_mb

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pages_to_mb.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    2 --
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -557,6 +557,11 @@
 	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
 }
 
+static inline unsigned long pages_to_mb(unsigned long npg)
+{
+	return npg >> (20 - PAGE_SHIFT);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -85,8 +85,6 @@
 /* The boot page tables (all created as a single array) */
 extern unsigned long pg0[];
 
-#define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
-
 #ifdef CONFIG_X86_PAE
 # include <asm/pgtable-3level.h>
 #else
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -153,8 +153,6 @@
 
 #ifndef __ASSEMBLY__
 
-#define pages_to_mb(x)	((x) >> (20 - PAGE_SHIFT))   /* FIXME: is this right? */
-
 /*
  * Conversion functions: convert a page and protection to a page entry,
  * and a page entry and page directory to the page they refer to.
#30 lore raw

PATCH 1/1 x86: unify io_remap_pfn_range

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify io_remap_pfn_range. Don't demacro yet.

---
 arch/x86/include/asm/pgtable.h    |    3 +++
 arch/x86/include/asm/pgtable_32.h |    3 ---
 arch/x86/include/asm/pgtable_64.h |    3 ---
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable.h +3 -0
@@ -562,6 +562,9 @@
 	return npg >> (20 - PAGE_SHIFT);
 }
 
+#define io_remap_pfn_range(vma, vaddr, pfn, size, prot)	\
+	remap_pfn_range(vma, vaddr, pfn, size, prot)
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_none(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -3
@@ -133,7 +133,4 @@
 #define kern_addr_valid(kaddr)	(0)
 #endif
 
-#define io_remap_pfn_range(vma, vaddr, pfn, size, prot)	\
-	remap_pfn_range(vma, vaddr, pfn, size, prot)
-
 #endif /* _ASM_X86_PGTABLE_32_H */
arch/x86/include/asm/pgtable_64.h +0 -3
@@ -204,9 +204,6 @@
 extern int kern_addr_valid(unsigned long addr);
 extern void cleanup_highmap(void);
 
-#define io_remap_pfn_range(vma, vaddr, pfn, size, prot)	\
-	remap_pfn_range(vma, vaddr, pfn, size, prot)
-
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
 
#31 lore raw

PATCH 1/1 x86: unify pgd_bad

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_bad.

---
 arch/x86/include/asm/pgtable-3level.h |    5 -----
 arch/x86/include/asm/pgtable.h        |    5 +++++
 arch/x86/include/asm/pgtable_64.h     |    5 -----
 3 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -5
@@ -23,11 +23,6 @@
 	return pud_val(pud) == 0;
 }
 
-static inline int pud_bad(pud_t pud)
-{
-	return (pud_val(pud) & ~(PTE_PFN_MASK | _KERNPG_TABLE | _PAGE_USER)) != 0;
-}
-
 /* Rules for using set_pte: the pte being assigned *must* be
  * either not present or in a state where the hardware will
  * not attempt to update the pte.  In places where this is
arch/x86/include/asm/pgtable.h +5 -0
@@ -584,6 +584,11 @@
 	return (pud_val(pud) & (_PAGE_PSE | _PAGE_PRESENT)) ==
 		(_PAGE_PSE | _PAGE_PRESENT);
 }
+
+static inline int pud_bad(pud_t pud)
+{
+	return (pud_val(pud) & ~(PTE_PFN_MASK | _KERNPG_TABLE | _PAGE_USER)) != 0;
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_64.h +0 -5
@@ -153,11 +153,6 @@
 
 #ifndef __ASSEMBLY__
 
-static inline int pud_bad(pud_t pud)
-{
-	return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
-}
-
 static inline int pmd_bad(pmd_t pmd)
 {
 	return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
#32 lore raw

PATCH 1/1 x86: unify pud_none

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_none.

---
 arch/x86/include/asm/pgtable-3level.h |    5 -----
 arch/x86/include/asm/pgtable.h        |    5 +++++
 arch/x86/include/asm/pgtable_64.h     |    1 -
 3 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -5
@@ -18,11 +18,6 @@
 	printk("%s:%d: bad pgd %p(%016Lx).\n",				\
 	       __FILE__, __LINE__, &(e), pgd_val(e))
 
-static inline int pud_none(pud_t pud)
-{
-	return pud_val(pud) == 0;
-}
-
 /* Rules for using set_pte: the pte being assigned *must* be
  * either not present or in a state where the hardware will
  * not attempt to update the pte.  In places where this is
arch/x86/include/asm/pgtable.h +5 -0
@@ -563,6 +563,11 @@
 }
 
 #if PAGETABLE_LEVELS > 2
+static inline int pud_none(pud_t pud)
+{
+	return pud_val(pud) == 0;
+}
+
 static inline int pud_present(pud_t pud)
 {
 	return pud_val(pud) & _PAGE_PRESENT;
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -67,7 +67,6 @@
 	       __FILE__, __LINE__, &(e), pgd_val(e))
 
 #define pgd_none(x)	(!pgd_val(x))
-#define pud_none(x)	(!pud_val(x))
 
 struct mm_struct;
 
#33 lore raw

PATCH 1/1 x86: unify pte_index

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pte_index.

---
 arch/x86/include/asm/pgtable.h    |   11 +++++++++++
 arch/x86/include/asm/pgtable_32.h |    8 --------
 arch/x86/include/asm/pgtable_64.h |    1 -
 3 files changed, 11 insertions(+), 9 deletions(-)
arch/x86/include/asm/pgtable.h +11 -0
@@ -536,6 +536,17 @@
  */
 #define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
 
+/*
+ * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
+ *
+ * this function returns the index of the entry in the pte page which would
+ * control the given virtual address
+ */
+static inline unsigned pte_index(unsigned long address)
+{
+	return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -8
@@ -97,14 +97,6 @@
 
 static inline int pud_large(pud_t pud) { return 0; }
 
-/*
- * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
- *
- * this macro returns the index of the entry in the pte page which would
- * control the given virtual address
- */
-#define pte_index(address)					\
-	(((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
 #define pte_offset_kernel(dir, address)				\
 	((pte_t *)pmd_page_vaddr(*(dir)) +  pte_index((address)))
 
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -197,7 +197,6 @@
 
 /* PTE - Level 1 access. */
 
-#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
 #define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
 					 pte_index((address)))
 
#34 lore raw

PATCH 1/1 x86: unify pgd_bad

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_bad.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    5 -----
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -612,6 +612,11 @@
 {
 	return (pud_t *)pgd_page_vaddr(*pgd) + pud_index(address);
 }
+
+static inline int pgd_bad(pgd_t pgd)
+{
+	return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -5
@@ -153,11 +153,6 @@
 
 #ifndef __ASSEMBLY__
 
-static inline int pgd_bad(pgd_t pgd)
-{
-	return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
-}
-
 static inline int pud_bad(pud_t pud)
 {
 	return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
#35 lore raw

PATCH 1/1 x86: unify pmd_offset

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_offset.

---
 arch/x86/include/asm/pgtable-3level.h |    4 ----
 arch/x86/include/asm/pgtable.h        |    6 ++++++
 arch/x86/include/asm/pgtable_64.h     |    2 --
 3 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -4
@@ -115,10 +115,6 @@
 		write_cr3(pgd);
 }
 
-/* Find an entry in the second-level page table.. */
-#define pmd_offset(pud, address) ((pmd_t *)pud_page_vaddr(*(pud)) +	\
-				  pmd_index(address))
-
 #ifdef CONFIG_SMP
 static inline pte_t native_ptep_get_and_clear(pte_t *ptep)
 {
arch/x86/include/asm/pgtable.h +6 -0
@@ -542,6 +542,12 @@
 {
 	return pfn_to_page(pud_val(pud) >> PAGE_SHIFT);
 }
+
+/* Find an entry in the second-level page table.. */
+static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
+{
+	return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -190,8 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
-				  pmd_index(address))
 #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
 #define pmd_pfn(x)  ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
 
#36 lore raw

PATCH 1/1 x86: unify pmd_page_vaddr

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_page_vaddr.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    3 ---
 arch/x86/include/asm/pgtable_64.h |    1 -
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -506,6 +506,11 @@
 	return !(unsigned long)native_pmd_val(pmd);
 }
 
+static inline unsigned long pmd_page_vaddr(pmd_t pmd)
+{
+	return (unsigned long)__va(pmd_val(pmd) & PTE_PFN_MASK);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -3
@@ -126,9 +126,6 @@
 
 #define pmd_page(pmd) (pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
 
-#define pmd_page_vaddr(pmd)					\
-	((unsigned long)__va(pmd_val((pmd)) & PTE_PFN_MASK))
-
 #if defined(CONFIG_HIGHPTE)
 #define pte_offset_map(dir, address)					\
 	((pte_t *)kmap_atomic_pte(pmd_page(*(dir)), KM_PTE0) +		\
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -190,7 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val((pmd)) & PTE_PFN_MASK))
 #define pmd_page(pmd)		(pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
 
 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
#37 lore raw

PATCH 1/1 x86: include pgtable_SIZE.h earlier

In reply to Jeremy Fitzhardinge

We'll need the definitions sooner.

---
 arch/x86/include/asm/pgtable.h |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/pgtable.h +10 -6
@@ -462,6 +462,16 @@
 }
 #endif	/* CONFIG_PARAVIRT */
 
+#endif	/* __ASSEMBLY__ */
+
+#ifdef CONFIG_X86_32
+# include "pgtable_32.h"
+#else
+# include "pgtable_64.h"
+#endif
+
+#ifndef __ASSEMBLY__
+
 static inline int pte_none(pte_t pte)
 {
 	return !pte.pte;
@@ -521,12 +531,6 @@
 
 #endif	/* __ASSEMBLY__ */
 
-#ifdef CONFIG_X86_32
-# include "pgtable_32.h"
-#else
-# include "pgtable_64.h"
-#endif
-
 /*
  * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
  *
#38 lore raw

PATCH 1/1 x86: unify pgd_page

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pgd_page.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_64.h |    1 -
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -533,6 +533,11 @@
 {
 	return (unsigned long)__va((unsigned long)pgd_val(pgd) & PTE_PFN_MASK);
 }
+
+static inline struct page *pgd_page(pgd_t pgd)
+{
+	return pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT);
+}
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 #endif	/* __ASSEMBLY__ */
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -178,7 +178,6 @@
 /*
  * Level 4 access.
  */
-#define pgd_page(pgd)		(pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
 static inline int pgd_large(pgd_t pgd) { return 0; }
 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
 
#39 lore raw

PATCH 1/1 x86: unify pmd_index

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_index.

---
 arch/x86/include/asm/pgtable.h    |   11 +++++++++++
 arch/x86/include/asm/pgtable_32.h |    9 ---------
 arch/x86/include/asm/pgtable_64.h |    1 -
 3 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/include/asm/pgtable.h +11 -0
@@ -516,6 +516,17 @@
 	return pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT);
 }
 
+/*
+ * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
+ *
+ * this macro returns the index of the entry in the pmd page which would
+ * control the given virtual address
+ */
+static inline unsigned pmd_index(unsigned long address)
+{
+	return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -9
@@ -105,15 +105,6 @@
 static inline int pud_large(pud_t pud) { return 0; }
 
 /*
- * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
- *
- * this macro returns the index of the entry in the pmd page which would
- * control the given virtual address
- */
-#define pmd_index(address)				\
-	(((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
-
-/*
  * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
  *
  * this macro returns the index of the entry in the pte page which would
arch/x86/include/asm/pgtable_64.h +0 -1
@@ -190,7 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
 #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
 				  pmd_index(address))
 #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
#40 lore raw

PATCH 1/1 x86: unify pmd_page

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pmd_page.

---
 arch/x86/include/asm/pgtable.h    |    5 +++++
 arch/x86/include/asm/pgtable_32.h |    2 --
 arch/x86/include/asm/pgtable_64.h |    2 --
 3 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +5 -0
@@ -511,6 +511,11 @@
 	return (unsigned long)__va(pmd_val(pmd) & PTE_PFN_MASK);
 }
 
+static inline struct page *pmd_page(pmd_t pmd)
+{
+	return pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT);
+}
+
 #if PAGETABLE_LEVELS > 2
 static inline int pud_present(pud_t pud)
 {
arch/x86/include/asm/pgtable_32.h +0 -2
@@ -124,8 +124,6 @@
 #define pte_offset_kernel(dir, address)				\
 	((pte_t *)pmd_page_vaddr(*(dir)) +  pte_index((address)))
 
-#define pmd_page(pmd) (pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
-
 #if defined(CONFIG_HIGHPTE)
 #define pte_offset_map(dir, address)					\
 	((pte_t *)kmap_atomic_pte(pmd_page(*(dir)), KM_PTE0) +		\
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -190,8 +190,6 @@
 }
 
 /* PMD  - Level 2 access */
-#define pmd_page(pmd)		(pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
-
 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
 #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
 				  pmd_index(address))
#41 lore raw

PATCH 1/1 x86: unify pud_page_vaddr

In reply to Jeremy Fitzhardinge

Impact: cleanup

Unify and demacro pud_page_vaddr.

---
 arch/x86/include/asm/pgtable-3level.h |    3 ---
 arch/x86/include/asm/pgtable.h        |    5 +++++
 arch/x86/include/asm/pgtable_64.h     |    2 --
 3 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/include/asm/pgtable-3level.h +0 -3
@@ -117,9 +117,6 @@
 
 #define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
 
-#define pud_page_vaddr(pud) ((unsigned long) __va(pud_val(pud) & PTE_PFN_MASK))
-
-
 /* Find an entry in the second-level page table.. */
 #define pmd_offset(pud, address) ((pmd_t *)pud_page_vaddr(*(pud)) +	\
 				  pmd_index(address))
arch/x86/include/asm/pgtable.h +5 -0
@@ -500,6 +500,11 @@
 {
 	return pud_val(pud) & _PAGE_PRESENT;
 }
+
+static inline unsigned long pud_page_vaddr(pud_t pud)
+{
+	return (unsigned long)__va((unsigned long)pud_val(pud) & PTE_PFN_MASK);
+}
 #endif	/* PAGETABLE_LEVELS > 2 */
 
 #if PAGETABLE_LEVELS > 3
arch/x86/include/asm/pgtable_64.h +0 -2
@@ -184,8 +184,6 @@
 
 /* PUD - Level3 access */
 /* to find an entry in a page-table-directory. */
-#define pud_page_vaddr(pud)						\
-	((unsigned long)__va(pud_val((pud)) & PHYSICAL_PAGE_MASK))
 #define pud_page(pud)	(pfn_to_page(pud_val((pud)) >> PAGE_SHIFT))
 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
 #define pud_offset(pgd, address)					\
#27 lore raw

Re: [PATCH 36 of 36] x86: make the X_bad functions consistent

In reply to Jeremy Fitzhardinge
Quoted 5 lines · Jeremy Fitzhardinge

Impact: cleanup

Use the same logic to implement all 3 _bad() functions.

A backward step in my opinion.

Hugh

Quoted 25 lines
---
 arch/x86/include/asm/pgtable.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/pgtable.h +2 -2
@@ -554,7 +554,7 @@
 
 static inline int pmd_bad(pmd_t pmd)
 {
-	return (pmd_flags(pmd) & ~_PAGE_USER) != _KERNPG_TABLE;
+	return (pmd_flags(pmd) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 
 static inline unsigned long pages_to_mb(unsigned long npg)
@@ -638,7 +638,7 @@
 
 static inline int pgd_bad(pgd_t pgd)
 {
-	return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
+	return (pgd_flags(pgd) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
 }
 
 static inline int pgd_none(pgd_t pgd)
#28 lore raw

Re: [PATCH 36 of 36] x86: make the X_bad functions consistent

Quoted 12 lines · Hugh Dickins
Quoted 6 lines · Jeremy Fitzhardinge

Impact: cleanup

Use the same logic to implement all 3 _bad() functions.

A backward step in my opinion.

OK, I'm happy to go the other way. I'll give it a spin.

J

#21 lore raw

Re: [PATCH 35 of 36] x86: make pgd/pud/pmd/pte_none consistent

In reply to Jeremy Fitzhardinge
Quoted 7 lines · Jeremy Fitzhardinge

The _none test is done differently for every level of the pagetable. Standardize them by:

1: Use the native_X_val to extract the raw entry, with no need to go

    via paravirt_ops, diff -r 1d0646d0d319 arch/x86/include/asm/pgtable.h, and

2: Compare with 0 rather than using a boolean !, since they are actually values
and not booleans.

In a 32 bit Xen guest this one causes

        [    8.354898] 1 multicall(s) failed: cpu 1
        [    8.354921] Pid: 2213, comm: bootclean Not tainted 2.6.29-rc3-x86_32p-xenU-tip #135
        [    8.354937] Call Trace:
        [    8.354955]  [<c01036e3>] xen_mc_flush+0x133/0x1b0
        [    8.354971]  [<c0105d2a>] ? xen_force_evtchn_callback+0x1a/0x30
        [    8.354988]  [<c0105a60>] xen_flush_tlb_others+0xb0/0xd0
        [    8.355003]  [<c0126643>] flush_tlb_page+0x53/0xa0
        [    8.355018]  [<c0176a80>] do_wp_page+0x2a0/0x7c0
        [    8.355034]  [<c0238f0a>] ? notify_remote_via_irq+0x3a/0x70
        [    8.355049]  [<c0178950>] handle_mm_fault+0x7b0/0xa50
        [    8.355065]  [<c0131a3e>] ? wake_up_new_task+0x8e/0xb0
        [    8.355079]  [<c01337b5>] ? do_fork+0xe5/0x320
        [    8.355095]  [<c0121919>] do_page_fault+0xe9/0x240
        [    8.355109]  [<c0121830>] ? do_page_fault+0x0/0x240
        [    8.355125]  [<c032457a>] error_code+0x72/0x78
        [    8.355139]   call  1/1: op=2863311530 arg=[aaaaaaaa] result=-38	xen_flush_tlb_others+0x41/0xd0
        [    8.355161] ------------[ cut here ]------------
        [    8.355172] kernel BUG at /local/scratch/ianc/devel/kernels/paravirt/arch/x86/xen/multicalls.c:182!
        [    8.355189] invalid opcode: 0000 [#1] SMP 
        [    8.355207] last sysfs file: /sys/class/net/lo/operstate
        [    8.355218] Modules linked in:
        [    8.355230] 
        [    8.355239] Pid: 2213, comm: bootclean Not tainted (2.6.29-rc3-x86_32p-xenU-tip #135) 
        [    8.355254] EIP: 0061:[<c010374b>] EFLAGS: 00010002 CPU: 1
        [    8.355267] EIP is at xen_mc_flush+0x19b/0x1b0
        [    8.355278] EAX: 00000000 EBX: 00000000 ECX: c10cc060 EDX: 00000000
        [    8.355290] ESI: 00000000 EDI: 00000001 EBP: c4c61e70 ESP: c4c61e40
        [    8.355302]  DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0069
        [    8.355314] Process bootclean (pid: 2213, ti=c4c60000 task=c5ad3460 task.ti=c4c60000)
        [    8.355328] Stack:
        [    8.355336]  c0367d84 00000001 00000001 aaaaaaaa aaaaaaaa ffffffda c01059f1 c10cc060
        [    8.355372]  c10c0060 c4c7a6d4 bfabf790 bfabf790 c4c61e80 c0105a60 c4c7a6d4 c4c7a580
        [    8.355413]  c4c61ea0 c0126643 00000000 80000000 00000025 08428067 80000000 c4c

Didn't figure out why yet.

Quoted 45 lines
---
 arch/x86/include/asm/pgtable.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/pgtable.h +3 -4
@@ -503,7 +503,7 @@
 {
 	/* Only check low word on 32-bit platforms, since it might be
 	   out of sync with upper half. */
-	return !(unsigned long)native_pmd_val(pmd);
+	return (unsigned long)native_pmd_val(pmd) == 0;
 }
 
 static inline unsigned long pmd_page_vaddr(pmd_t pmd)
@@ -568,7 +568,7 @@
 #if PAGETABLE_LEVELS > 2
 static inline int pud_none(pud_t pud)
 {
-	return pud_val(pud) == 0;
+	return native_pud_val(pud) == 0;
 }
 
 static inline int pud_present(pud_t pud)
@@ -643,7 +643,7 @@
 
 static inline int pgd_none(pgd_t pgd)
 {
-	return !pgd_val(pgd);
+	return !native_pgd_val(pgd);
 }
 #endif	/* PAGETABLE_LEVELS > 3 */
 
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 3 lines
Ian Campbell

I can resist anything but temptation.
#22 lore raw

Re: [PATCH 35 of 36] x86: make pgd/pud/pmd/pte_none consistent

Quoted 4 lines · Ian Campbell
Quoted 3 lines · Jeremy Fitzhardinge

The _none test is done differently for every level of the pagetable. Standardize them by:

Quoted 8 lines
Quoted 4 lines

1: Use the native_X_val to extract the raw entry, with no need to go

    via paravirt_ops, diff -r 1d0646d0d319 arch/x86/include/asm/pgtable.h, and

2: Compare with 0 rather than using a boolean !, since they are actually values
and not booleans.

In a 32 bit Xen guest this one causes

        [    8.354898] 1 multicall(s) failed: cpu 1

Spoke too soon, it's not as 100% reliably reproducing as I thought which confused my bisection attempt. Will try and locate the real culprit...

Ian.

Signature · 3 lines
Ian Campbell

For a man to truly understand rejection, he must first be ignored by a cat.
#23 lore raw

Re: [PATCH 35 of 36] x86: make pgd/pud/pmd/pte_none consistent

Quoted 10 lines · Ian Campbell
Quoted 9 lines · Ian Campbell
Quoted 7 lines · Jeremy Fitzhardinge

The _none test is done differently for every level of the pagetable. Standardize them by:

1: Use the native_X_val to extract the raw entry, with no need to go

    via paravirt_ops, diff -r 1d0646d0d319 arch/x86/include/asm/pgtable.h, and

2: Compare with 0 rather than using a boolean !, since they are actually values
and not booleans.

Quoted 6 lines
Quoted 3 lines

In a 32 bit Xen guest this one causes

        [    8.354898] 1 multicall(s) failed: cpu 1

Spoke too soon, it's not as 100% reliably reproducing as I thought which confused my bisection attempt. Will try and locate the real culprit...

Real culprit was somewhere else entirely:

Subject: Fix xen_flush_tlb_others after const cpumask changes

The commit
commit 4595f9620cda8a1e973588e743cf5f8436dd20c6
Author: Rusty Russell <[email protected]>
Date: Sat Jan 10 21:58:09 2009 -0800

x86: change flush_tlb_others to take a const struct cpumask

causes xen_flush_tlb_others to allocate a multicall and then issue it without initializing it in the case where the cpumask is empty, leading to:

        [    8.354898] 1 multicall(s) failed: cpu 1
        [    8.354921] Pid: 2213, comm: bootclean Not tainted 2.6.29-rc3-x86_32p-xenU-tip #135
        [    8.354937] Call Trace:
        [    8.354955]  [<c01036e3>] xen_mc_flush+0x133/0x1b0
        [    8.354971]  [<c0105d2a>] ? xen_force_evtchn_callback+0x1a/0x30
        [    8.354988]  [<c0105a60>] xen_flush_tlb_others+0xb0/0xd0
        [    8.355003]  [<c0126643>] flush_tlb_page+0x53/0xa0
        [    8.355018]  [<c0176a80>] do_wp_page+0x2a0/0x7c0
        [    8.355034]  [<c0238f0a>] ? notify_remote_via_irq+0x3a/0x70
        [    8.355049]  [<c0178950>] handle_mm_fault+0x7b0/0xa50
        [    8.355065]  [<c0131a3e>] ? wake_up_new_task+0x8e/0xb0
        [    8.355079]  [<c01337b5>] ? do_fork+0xe5/0x320
        [    8.355095]  [<c0121919>] do_page_fault+0xe9/0x240
        [    8.355109]  [<c0121830>] ? do_page_fault+0x0/0x240
        [    8.355125]  [<c032457a>] error_code+0x72/0x78
        [    8.355139]   call  1/1: op=2863311530 arg=[aaaaaaaa] result=-38     xen_flush_tlb_others+0x41/0xd0

Since empty cpumasks are rare and undoing an xen_mc_entry() is tricky just issue such requests normally.

Cc Jeremy Fitzhardinge <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Mike Travis <[email protected]>
---
 arch/x86/xen/mmu.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
arch/x86/xen/mmu.c +0 -3
index d2e8ed1..319bd40 100644
@@ -1273,8 +1273,6 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 	/* Remove us, and any offline CPUS. */
 	cpumask_and(to_cpumask(args->mask), cpus, cpu_online_mask);
 	cpumask_clear_cpu(smp_processor_id(), to_cpumask(args->mask));
-	if (unlikely(cpumask_empty(to_cpumask(args->mask))))
-		goto issue;
 
 	if (va == TLB_FLUSH_ALL) {
 		args->op.cmd = MMUEXT_TLB_FLUSH_MULTI;
@@ -1285,7 +1283,6 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
 
 	MULTI_mmuext_op(mcs.mc, &args->op, 1, NULL, DOMID_SELF);
 
-issue:
 	xen_mc_issue(PARAVIRT_LAZY_MMU);
 }
 
Signature · 7 lines
1.5.6.5


-- 
Ian Campbell

We are now enjoying total mutual interaction in an imaginary hot tub ...