Skip to contentSkip to conversation

ARM: Add support for the Large Physical Address Extensions

PATCH Superseded Catalin Marinas 5 participants 77 messages Nov 12, 2010 – Nov 23, 2010 Arm (32-bit)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover ARM: Add support for the Large Physical Address Extensions

Hi,

This set of patches adds support for the Large Physical Extensions on the ARM architecture (available with the Cortex-A15 processor). LPAE comes with a 3-level page table format (compared to 2-level for the classic one), allowing up to 40-bit physical address space.

The ARM LPAE documentation is available from (free registration needed):

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0406b_virtualization_extns/index.html

The full set of patches (kernel fixes, LPAE and support for an emulated Versatile Express with Cortex-A15 tile) is available on this branch:

git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/linux-2.6-cm.git arm-lpae

Changelog:

- Upgraded to latest mainline kernel (2.6.37-rc1) solving several conflicts.
- Enable CONFIG_ARCH_DMA_ADDR_T_64BIT for future compatibility with the unified dma_addr_t patch.
- PHYS_ADDR_FMT printk format changed to be ANSI C compliant.
- Alignment fault now uses SIGBUS instead of SIGILL.
- arch/arm/kernel/head.S modified to use SECTION_SHIFT and reduce the amount of #ifdef's.
- setup_mm_for_reboot() modified for LPAE.
- identity_mapping_add/del() modified for LPAE.
- Removed FIRST_USER_PGD_NR definition as the place where it was used have been modified.

Any comments are welcome. Thanks.

Catalin Marinas (13):
ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*
ARM: LPAE: Factor out 2-level page table definitions into separate
files
ARM: LPAE: Do not assume Linux PTEs are always at PTRS_PER_PTE offset
ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE
ARM: LPAE: Introduce the 3-level page table format definitions
ARM: LPAE: Page table maintenance for the 3-level format
ARM: LPAE: MMU setup for the 3-level page table format
ARM: LPAE: Change setup_mm_for_reboot() to work with LPAE
ARM: LPAE: Remove the FIRST_USER_PGD_NR and USER_PTRS_PER_PGD
definitions
ARM: LPAE: Add fault handling support
ARM: LPAE: Add context switching support
ARM: LPAE: Add SMP support for the 3-level page table format
ARM: LPAE: Add the Kconfig entries

Will Deacon (7):
ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes
ARM: LPAE: use phys_addr_t instead of unsigned long for physical
addresses
ARM: LPAE: Use generic dma_addr_t type definition
ARM: LPAE: mark memory banks with start > ULONG_MAX as highmem
ARM: LPAE: use phys_addr_t for physical start address in early_mem
ARM: LPAE: add support for ATAG_MEM64
ARM: LPAE: define printk format for physical addresses and page table
entries

 arch/arm/Kconfig                            |    2 +-
 arch/arm/include/asm/cpu-multi32.h          |    8 +
 arch/arm/include/asm/cpu-single.h           |    4 +
 arch/arm/include/asm/memory.h               |   17 +-
 arch/arm/include/asm/outercache.h           |   14 +-
 arch/arm/include/asm/page-nommu.h           |    8 +-
 arch/arm/include/asm/page.h                 |   42 +----
 arch/arm/include/asm/pgalloc.h              |   34 +++-
 arch/arm/include/asm/pgtable-2level-hwdef.h |   91 +++++++++
 arch/arm/include/asm/pgtable-2level-types.h |   64 +++++++
 arch/arm/include/asm/pgtable-2level.h       |  147 +++++++++++++++
 arch/arm/include/asm/pgtable-3level-hwdef.h |   78 ++++++++
 arch/arm/include/asm/pgtable-3level-types.h |   55 ++++++
 arch/arm/include/asm/pgtable-3level.h       |  110 +++++++++++
 arch/arm/include/asm/pgtable-hwdef.h        |   81 +--------
 arch/arm/include/asm/pgtable.h              |  267 +++++++++++----------------
 arch/arm/include/asm/proc-fns.h             |   13 ++
 arch/arm/include/asm/setup.h                |   12 +-
 arch/arm/include/asm/types.h                |   24 +--
 arch/arm/kernel/compat.c                    |    4 +-
 arch/arm/kernel/head.S                      |  106 ++++++++----
 arch/arm/kernel/module.c                    |    2 +-
 arch/arm/kernel/setup.c                     |   19 ++-
 arch/arm/kernel/smp.c                       |   43 ++++-
 arch/arm/mm/Kconfig                         |   13 ++
 arch/arm/mm/alignment.c                     |    8 +-
 arch/arm/mm/context.c                       |   18 ++-
 arch/arm/mm/dma-mapping.c                   |    6 +-
 arch/arm/mm/fault.c                         |   88 +++++++++-
 arch/arm/mm/init.c                          |    6 +-
 arch/arm/mm/ioremap.c                       |    8 +-
 arch/arm/mm/mm.h                            |    8 +-
 arch/arm/mm/mmu.c                           |   99 +++++++---
 arch/arm/mm/pgd.c                           |   20 ++-
 arch/arm/mm/proc-macros.S                   |    5 +-
 arch/arm/mm/proc-v7.S                       |  115 +++++++++++-
 36 files changed, 1213 insertions(+), 426 deletions(-)
 create mode 100644 arch/arm/include/asm/pgtable-2level-hwdef.h
 create mode 100644 arch/arm/include/asm/pgtable-2level-types.h
 create mode 100644 arch/arm/include/asm/pgtable-2level.h
 create mode 100644 arch/arm/include/asm/pgtable-3level-hwdef.h
 create mode 100644 arch/arm/include/asm/pgtable-3level-types.h
 create mode 100644 arch/arm/include/asm/pgtable-3level.h
#1 lore raw

PATCH v2 1/20 ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*

PGDIR_SHIFT and PMD_SHIFT for the classic 2-level page table format have the same value (21). This patch converts the PGDIR_* uses in the kernel to the PMD_* equivalent.

---
 arch/arm/kernel/module.c  |    2 +-
 arch/arm/kernel/smp.c     |    4 ++--
 arch/arm/mm/dma-mapping.c |    6 +++---
 arch/arm/mm/mmu.c         |   16 ++++++++--------
 4 files changed, 14 insertions(+), 14 deletions(-)
arch/arm/kernel/module.c +1 -1
index d9bd786..6b30f01 100644
@@ -32,7 +32,7 @@
  * recompiling the whole kernel when CONFIG_XIP_KERNEL is turned on/off.
  */
 #undef MODULES_VADDR
-#define MODULES_VADDR	(((unsigned long)_etext + ~PGDIR_MASK) & PGDIR_MASK)
+#define MODULES_VADDR	(((unsigned long)_etext + ~PMD_MASK) & PMD_MASK)
 #endif
 
 #ifdef CONFIG_MMU
arch/arm/kernel/smp.c +2 -2
index 8c19595..40b386c 100644
@@ -78,7 +78,7 @@ static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
 	if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
 		prot |= PMD_BIT4;
 
-	for (addr = start & PGDIR_MASK; addr < end;) {
+	for (addr = start & PMD_MASK; addr < end;) {
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(addr | prot);
 		addr += SECTION_SIZE;
@@ -95,7 +95,7 @@ static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
 	unsigned long addr;
 	pmd_t *pmd;
 
-	for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
+	for (addr = start & PMD_MASK; addr < end; addr += PMD_SIZE) {
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(0);
 		pmd[1] = __pmd(0);
arch/arm/mm/dma-mapping.c +3 -3
index e4dd064..2aab1b4 100644
@@ -120,8 +120,8 @@ static void __dma_free_buffer(struct page *page, size_t size)
 #endif
 
 #define CONSISTENT_OFFSET(x)	(((unsigned long)(x) - CONSISTENT_BASE) >> PAGE_SHIFT)
-#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PGDIR_SHIFT)
-#define NUM_CONSISTENT_PTES (CONSISTENT_DMA_SIZE >> PGDIR_SHIFT)
+#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PMD_SHIFT)
+#define NUM_CONSISTENT_PTES (CONSISTENT_DMA_SIZE >> PMD_SHIFT)
 
 /*
  * These are the page tables (2MB each) covering uncached, DMA consistent allocations
@@ -171,7 +171,7 @@ static int __init consistent_init(void)
 		}
 
 		consistent_pte[i++] = pte;
-		base += (1 << PGDIR_SHIFT);
+		base += (1 << PMD_SHIFT);
 	} while (base < CONSISTENT_END);
 
 	return ret;
arch/arm/mm/mmu.c +8 -8
index 79c01f5..5e3adca 100644
@@ -858,14 +858,14 @@ static inline void prepare_page_table(void)
 	/*
 	 * Clear out all the mappings below the kernel image.
 	 */
-	for (addr = 0; addr < MODULES_VADDR; addr += PGDIR_SIZE)
+	for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
 		pmd_clear(pmd_off_k(addr));
 
 #ifdef CONFIG_XIP_KERNEL
 	/* The XIP kernel is mapped in the module area -- skip over it */
-	addr = ((unsigned long)_etext + PGDIR_SIZE - 1) & PGDIR_MASK;
+	addr = ((unsigned long)_etext + PMD_SIZE - 1) & PMD_MASK;
 #endif
-	for ( ; addr < PAGE_OFFSET; addr += PGDIR_SIZE)
+	for ( ; addr < PAGE_OFFSET; addr += PMD_SIZE)
 		pmd_clear(pmd_off_k(addr));
 
 	/*
@@ -880,7 +880,7 @@ static inline void prepare_page_table(void)
 	 * memory bank, up to the end of the vmalloc region.
 	 */
 	for (addr = __phys_to_virt(end);
-	     addr < VMALLOC_END; addr += PGDIR_SIZE)
+	     addr < VMALLOC_END; addr += PMD_SIZE)
 		pmd_clear(pmd_off_k(addr));
 }
 
@@ -921,7 +921,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
 	 */
 	vectors_page = early_alloc(PAGE_SIZE);
 
-	for (addr = VMALLOC_END; addr; addr += PGDIR_SIZE)
+	for (addr = VMALLOC_END; addr; addr += PMD_SIZE)
 		pmd_clear(pmd_off_k(addr));
 
 	/*
@@ -1068,12 +1068,12 @@ void setup_mm_for_reboot(char mode)
 		base_pmdval |= PMD_BIT4;
 
 	for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
-		unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
+		unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;
 		pmd_t *pmd;
 
-		pmd = pmd_off(pgd, i << PGDIR_SHIFT);
+		pmd = pmd_off(pgd, i << PMD_SHIFT);
 		pmd[0] = __pmd(pmdval);
-		pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
+		pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
 		flush_pmd_entry(pmd);
 	}
 
#5 lore raw

PATCH v2 2/20 ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Catalin Marinas

This patch moves page table definitions from asm/page.h, asm/pgtable.h and asm/ptgable-hwdef.h into corresponding *-2level* files.

---
 arch/arm/include/asm/page.h                 |   40 +-------
 arch/arm/include/asm/pgtable-2level-hwdef.h |   91 +++++++++++++++++
 arch/arm/include/asm/pgtable-2level-types.h |   64 ++++++++++++
 arch/arm/include/asm/pgtable-2level.h       |  147 +++++++++++++++++++++++++++
 arch/arm/include/asm/pgtable-hwdef.h        |   77 +--------------
 arch/arm/include/asm/pgtable.h              |  139 +-------------------------
 6 files changed, 306 insertions(+), 252 deletions(-)
 create mode 100644 arch/arm/include/asm/pgtable-2level-hwdef.h
 create mode 100644 arch/arm/include/asm/pgtable-2level-types.h
 create mode 100644 arch/arm/include/asm/pgtable-2level.h
arch/arm/include/asm/page.h +1 -39
index a485ac3..3848105 100644
@@ -151,45 +151,7 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from,
 #define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
 extern void copy_page(void *to, const void *from);
 
-#undef STRICT_MM_TYPECHECKS
-
-#ifdef STRICT_MM_TYPECHECKS
-/*
- * These are used to make use of C type-checking..
- */
-typedef struct { unsigned long pte; } pte_t;
-typedef struct { unsigned long pmd; } pmd_t;
-typedef struct { unsigned long pgd[2]; } pgd_t;
-typedef struct { unsigned long pgprot; } pgprot_t;
-
-#define pte_val(x)      ((x).pte)
-#define pmd_val(x)      ((x).pmd)
-#define pgd_val(x)	((x).pgd[0])
-#define pgprot_val(x)   ((x).pgprot)
-
-#define __pte(x)        ((pte_t) { (x) } )
-#define __pmd(x)        ((pmd_t) { (x) } )
-#define __pgprot(x)     ((pgprot_t) { (x) } )
-
-#else
-/*
- * .. while these make it easier on the compiler
- */
-typedef unsigned long pte_t;
-typedef unsigned long pmd_t;
-typedef unsigned long pgd_t[2];
-typedef unsigned long pgprot_t;
-
-#define pte_val(x)      (x)
-#define pmd_val(x)      (x)
-#define pgd_val(x)	((x)[0])
-#define pgprot_val(x)   (x)
-
-#define __pte(x)        (x)
-#define __pmd(x)        (x)
-#define __pgprot(x)     (x)
-
-#endif /* STRICT_MM_TYPECHECKS */
+#include <asm/pgtable-2level-types.h>
 
 #endif /* CONFIG_MMU */
 
arch/arm/include/asm/pgtable-2level-hwdef.h new file +91 -0

91 lines not on this page · raw message

arch/arm/include/asm/pgtable-2level-types.h new file +64 -0

64 lines not on this page · raw message

arch/arm/include/asm/pgtable-2level.h new file +147 -0

147 lines not on this page · raw message

arch/arm/include/asm/pgtable-hwdef.h +1 -76

82 lines not on this page · raw message

arch/arm/include/asm/pgtable.h +2 -137

157 lines not on this page · raw message

#12 lore raw

PATCH v2 3/20 ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

---
 arch/arm/include/asm/page-nommu.h           |    8 ++++----
 arch/arm/include/asm/pgtable-2level-types.h |   18 +++++++++---------
 2 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/include/asm/page-nommu.h +4 -4
index d1b162a..a20641a 100644
@@ -29,10 +29,10 @@
 /*
  * These are used to make use of C type-checking..
  */
-typedef unsigned long pte_t;
-typedef unsigned long pmd_t;
-typedef unsigned long pgd_t[2];
-typedef unsigned long pgprot_t;
+typedef u32 pte_t;
+typedef u32 pmd_t;
+typedef u32 pgd_t[2];
+typedef u32 pgprot_t;
 
 #define pte_val(x)      (x)
 #define pmd_val(x)      (x)
arch/arm/include/asm/pgtable-2level-types.h +9 -9
index 30f6741..adc4928 100644
@@ -21,16 +21,16 @@
 
 #undef STRICT_MM_TYPECHECKS
 
-typedef unsigned long pteval_t;
+typedef u32 pteval_t;
 
 #ifdef STRICT_MM_TYPECHECKS
 /*
  * These are used to make use of C type-checking..
  */
-typedef struct { unsigned long pte; } pte_t;
-typedef struct { unsigned long pmd; } pmd_t;
-typedef struct { unsigned long pgd[2]; } pgd_t;
-typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct { u32 pte; } pte_t;
+typedef struct { u32 pmd; } pmd_t;
+typedef struct { u32 pgd[2]; } pgd_t;
+typedef struct { u32 pgprot; } pgprot_t;
 
 #define pte_val(x)      ((x).pte)
 #define pmd_val(x)      ((x).pmd)
@@ -45,10 +45,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 /*
  * .. while these make it easier on the compiler
  */
-typedef unsigned long pte_t;
-typedef unsigned long pmd_t;
-typedef unsigned long pgd_t[2];
-typedef unsigned long pgprot_t;
+typedef u32 pte_t;
+typedef u32 pmd_t;
+typedef u32 pgd_t[2];
+typedef u32 pgprot_t;
 
 #define pte_val(x)      (x)
 #define pmd_val(x)      (x)
#27 lore raw

PATCH v2 4/20 ARM: LPAE: Do not assume Linux PTEs are always at PTRS_PER_PTE offset

In reply to Catalin Marinas

Placing the Linux PTEs at a 2KB offset inside a page is a workaround for the 2-level page table format where not enough spare bits are available. With LPAE this is no longer required. This patch changes such assumption by using a different macro, LINUX_PTE_OFFSET, which is defined to PTRS_PER_PTE for the 2-level page tables.

---
 arch/arm/include/asm/pgalloc.h        |    6 +++---
 arch/arm/include/asm/pgtable-2level.h |    1 +
 arch/arm/include/asm/pgtable.h        |    6 +++---
 arch/arm/mm/fault.c                   |    2 +-
 arch/arm/mm/mmu.c                     |    3 ++-
 5 files changed, 10 insertions(+), 8 deletions(-)
arch/arm/include/asm/pgalloc.h +3 -3
index b12cc98..c2a1f64 100644
@@ -62,7 +62,7 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
 	pte = (pte_t *)__get_free_page(PGALLOC_GFP);
 	if (pte) {
 		clean_dcache_area(pte, sizeof(pte_t) * PTRS_PER_PTE);
-		pte += PTRS_PER_PTE;
+		pte += LINUX_PTE_OFFSET;
 	}
 
 	return pte;
@@ -95,7 +95,7 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
 	if (pte) {
-		pte -= PTRS_PER_PTE;
+		pte -= LINUX_PTE_OFFSET;
 		free_page((unsigned long)pte);
 	}
 }
@@ -128,7 +128,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
 	 * The pmd must be loaded with the physical
 	 * address of the PTE table
 	 */
-	pte_ptr -= PTRS_PER_PTE * sizeof(void *);
+	pte_ptr -= LINUX_PTE_OFFSET * sizeof(void *);
 	__pmd_populate(pmdp, __pa(pte_ptr) | _PAGE_KERNEL_TABLE);
 }
 
arch/arm/include/asm/pgtable-2level.h +1 -0
index d60bda9..36bdef7 100644
@@ -71,6 +71,7 @@
 #define PTRS_PER_PTE		512
 #define PTRS_PER_PMD		1
 #define PTRS_PER_PGD		2048
+#define LINUX_PTE_OFFSET	PTRS_PER_PTE
 
 /*
  * PMD_SHIFT determines the size of the area a second-level page table can map
arch/arm/include/asm/pgtable.h +3 -3
index 17e7ba6..ea08ab7 100644
@@ -135,8 +135,8 @@ extern struct page *empty_zero_page;
 #define __pte_map(dir)		pmd_page_vaddr(*(dir))
 #define __pte_unmap(pte)	do { } while (0)
 #else
-#define __pte_map(dir)		((pte_t *)kmap_atomic(pmd_page(*(dir))) + PTRS_PER_PTE)
-#define __pte_unmap(pte)	kunmap_atomic((pte - PTRS_PER_PTE))
+#define __pte_map(dir)		((pte_t *)kmap_atomic(pmd_page(*(dir))) + LINUX_PTE_OFFSET)
+#define __pte_unmap(pte)	kunmap_atomic((pte - LINUX_PTE_OFFSET))
 #endif
 
 #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext)
@@ -232,7 +232,7 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 	unsigned long ptr;
 
 	ptr = pmd_val(pmd) & ~(PTRS_PER_PTE * sizeof(void *) - 1);
-	ptr += PTRS_PER_PTE * sizeof(void *);
+	ptr += LINUX_PTE_OFFSET * sizeof(void *);
 
 	return __va(ptr);
 }
arch/arm/mm/fault.c +1 -1
index 1e21e12..5da7b0c 100644
@@ -108,7 +108,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
 		pte = pte_offset_map(pmd, addr);
 		printk(", *pte=%08lx", pte_val(*pte));
-		printk(", *ppte=%08lx", pte_val(pte[-PTRS_PER_PTE]));
+		printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
 		pte_unmap(pte);
 	} while(0);
 
arch/arm/mm/mmu.c +2 -1
index 5e3adca..7324fbc 100644
@@ -535,7 +535,8 @@ static void __init *early_alloc(unsigned long sz)
 static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot)
 {
 	if (pmd_none(*pmd)) {
-		pte_t *pte = early_alloc(2 * PTRS_PER_PTE * sizeof(pte_t));
+		pte_t *pte = early_alloc((LINUX_PTE_OFFSET +
+					  PTRS_PER_PTE) * sizeof(pte_t));
 		__pmd_populate(pmd, __pa(pte) | prot);
 	}
 	BUG_ON(pmd_bad(*pmd));
#30 lore raw

PATCH v2 5/20 ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Catalin Marinas

The LPAE page table format needs to explicitly disable execution or write permissions on a page by setting the corresponding bits (similar to the classic page table format with Access Flag enabled). This patch introduces null definitions for the 2-level format and the actual noexec and nowrite bits for the LPAE format. It also changes several PTE maintenance macros and masks.

---
 arch/arm/include/asm/pgtable-2level.h |    2 +
 arch/arm/include/asm/pgtable.h        |   44 +++++++++++++++++++++------------
 arch/arm/mm/mmu.c                     |    6 ++--
 3 files changed, 33 insertions(+), 19 deletions(-)
arch/arm/include/asm/pgtable-2level.h +2 -0
index 36bdef7..4e21166 100644
@@ -128,6 +128,8 @@
 #define L_PTE_USER		(1 << 8)
 #define L_PTE_EXEC		(1 << 9)
 #define L_PTE_SHARED		(1 << 10)	/* shared(v6), coherent(xsc3) */
+#define L_PTE_NOEXEC		(0)
+#define L_PTE_NOWRITE		(0)
 
 /*
  * These are the memory types, defined to be compatible with
arch/arm/include/asm/pgtable.h +28 -16

78 lines not on this page · raw message

arch/arm/mm/mmu.c +3 -3
index 7324fbc..0ca33dd 100644
@@ -191,7 +191,7 @@ void adjust_cr(unsigned long mask, unsigned long set)
 }
 #endif
 
-#define PROT_PTE_DEVICE		L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_WRITE
+#define PROT_PTE_DEVICE		L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_WRITE|L_PTE_NOEXEC
 #define PROT_SECT_DEVICE	PMD_TYPE_SECT|PMD_SECT_AP_WRITE
 
 static struct mem_type mem_types[] = {
@@ -236,13 +236,13 @@ static struct mem_type mem_types[] = {
 	},
 	[MT_LOW_VECTORS] = {
 		.prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
-				L_PTE_EXEC,
+				L_PTE_EXEC | L_PTE_NOWRITE,
 		.prot_l1   = PMD_TYPE_TABLE,
 		.domain    = DOMAIN_USER,
 	},
 	[MT_HIGH_VECTORS] = {
 		.prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
-				L_PTE_USER | L_PTE_EXEC,
+				L_PTE_USER | L_PTE_EXEC | L_PTE_NOWRITE,
 		.prot_l1   = PMD_TYPE_TABLE,
 		.domain    = DOMAIN_USER,
 	},
#43 lore raw

PATCH v2 6/20 ARM: LPAE: Introduce the 3-level page table format definitions

In reply to Catalin Marinas

This patch introduces the pgtable-3level*.h files with definitions specific to the LPAE page table format (3 levels of page tables).

Each table is 4KB and has 512 64-bit entries. An entry can point to a 40-bit physical address. The young, write and exec software bits share the corresponding hardware bits (negated). Other software bits use spare bits in the PTE.

The patch also changes some variable types from unsigned long or int to pteval_t or pgprot_t.

---
 arch/arm/include/asm/page.h                 |    4 +
 arch/arm/include/asm/pgtable-3level-hwdef.h |   78 ++++++++++++++++++
 arch/arm/include/asm/pgtable-3level-types.h |   55 +++++++++++++
 arch/arm/include/asm/pgtable-3level.h       |  113 +++++++++++++++++++++++++++
 arch/arm/include/asm/pgtable-hwdef.h        |    4 +
 arch/arm/include/asm/pgtable.h              |    6 +-
 arch/arm/mm/mm.h                            |    8 +-
 arch/arm/mm/mmu.c                           |    2 +-
 8 files changed, 264 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/include/asm/pgtable-3level-hwdef.h
 create mode 100644 arch/arm/include/asm/pgtable-3level-types.h
 create mode 100644 arch/arm/include/asm/pgtable-3level.h
arch/arm/include/asm/page.h +4 -0
index 3848105..e5124db 100644
@@ -151,7 +151,11 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from,
 #define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
 extern void copy_page(void *to, const void *from);
 
+#ifdef CONFIG_ARM_LPAE
+#include <asm/pgtable-3level-types.h>
+#else
 #include <asm/pgtable-2level-types.h>
+#endif
 
 #endif /* CONFIG_MMU */
 
arch/arm/include/asm/pgtable-3level-hwdef.h new file +78 -0

78 lines not on this page · raw message

arch/arm/include/asm/pgtable-3level-types.h new file +55 -0

55 lines not on this page · raw message

arch/arm/include/asm/pgtable-3level.h new file +113 -0

113 lines not on this page · raw message

arch/arm/include/asm/pgtable-hwdef.h +4 -0
index 1831111..8426229 100644
@@ -10,6 +10,10 @@
 #ifndef _ASMARM_PGTABLE_HWDEF_H
 #define _ASMARM_PGTABLE_HWDEF_H
 
+#ifdef CONFIG_ARM_LPAE
+#include <asm/pgtable-3level-hwdef.h>
+#else
 #include <asm/pgtable-2level-hwdef.h>
+#endif
 
 #endif
arch/arm/include/asm/pgtable.h +5 -1
index 5bd0e64..97a5de3 100644
@@ -23,7 +23,11 @@
 #include <mach/vmalloc.h>
 #include <asm/pgtable-hwdef.h>
 
+#ifdef CONFIG_ARM_LPAE
+#include <asm/pgtable-3level.h>
+#else
 #include <asm/pgtable-2level.h>
+#endif
 
 /*
  * Just any arbitrary offset to the start of the vmalloc VM area: the
@@ -283,7 +287,7 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
-	const unsigned long mask = L_PTE_EXEC | L_PTE_WRITE | L_PTE_USER |
+	const pteval_t mask = L_PTE_EXEC | L_PTE_WRITE | L_PTE_USER |
 		L_PTE_NOEXEC | L_PTE_NOWRITE;
 	pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
 	return pte;
arch/arm/mm/mm.h +4 -4
index 6630620..a62f093 100644
@@ -16,10 +16,10 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
 }
 
 struct mem_type {
-	unsigned int prot_pte;
-	unsigned int prot_l1;
-	unsigned int prot_sect;
-	unsigned int domain;
+	pgprot_t prot_pte;
+	pgprot_t prot_l1;
+	pgprot_t prot_sect;
+	pgprot_t domain;
 };
 
 const struct mem_type *get_mem_type(unsigned int type);
arch/arm/mm/mmu.c +1 -1
index 0ca33dd..7c803c4 100644
@@ -292,7 +292,7 @@ static void __init build_mem_type_table(void)
 {
 	struct cachepolicy *cp;
 	unsigned int cr = get_cr();
-	unsigned int user_pgprot, kern_pgprot, vecs_pgprot;
+	pgprot_t user_pgprot, kern_pgprot, vecs_pgprot;
 	int cpu_arch = cpu_architecture();
 	int i;
 
#46 lore raw

PATCH v2 7/20 ARM: LPAE: Page table maintenance for the 3-level format

In reply to Catalin Marinas

This patch modifies the pgd/pmd/pte manipulation functions to support the 3-level page table format. Since there is no need for an 'ext' argument to cpu_set_pte_ext(), this patch conditionally defines a different prototype for this function when CONFIG_ARM_LPAE.

---
 arch/arm/include/asm/cpu-multi32.h |    8 ++++
 arch/arm/include/asm/cpu-single.h  |    4 ++
 arch/arm/include/asm/pgalloc.h     |   26 ++++++++++++-
 arch/arm/include/asm/pgtable.h     |   72 ++++++++++++++++++++++++++++++++++++
 arch/arm/include/asm/proc-fns.h    |   13 ++++++
 arch/arm/mm/ioremap.c              |    8 ++-
 arch/arm/mm/pgd.c                  |   18 +++++++--
 arch/arm/mm/proc-v7.S              |    8 ++++
 8 files changed, 149 insertions(+), 8 deletions(-)
arch/arm/include/asm/cpu-multi32.h +8 -0
index e2b5b0b..985fcf5 100644
@@ -57,7 +57,11 @@ extern struct processor {
 	 * Set a possibly extended PTE.  Non-extended PTEs should
 	 * ignore 'ext'.
 	 */
+#ifdef CONFIG_ARM_LPAE
+	void (*set_pte_ext)(pte_t *ptep, pte_t pte);
+#else
 	void (*set_pte_ext)(pte_t *ptep, pte_t pte, unsigned int ext);
+#endif
 } processor;
 
 #define cpu_proc_init()			processor._proc_init()
@@ -65,5 +69,9 @@ extern struct processor {
 #define cpu_reset(addr)			processor.reset(addr)
 #define cpu_do_idle()			processor._do_idle()
 #define cpu_dcache_clean_area(addr,sz)	processor.dcache_clean_area(addr,sz)
+#ifdef CONFIG_ARM_LPAE
+#define cpu_set_pte_ext(ptep,pte)	processor.set_pte_ext(ptep,pte)
+#else
 #define cpu_set_pte_ext(ptep,pte,ext)	processor.set_pte_ext(ptep,pte,ext)
+#endif
 #define cpu_do_switch_mm(pgd,mm)	processor.switch_mm(pgd,mm)
arch/arm/include/asm/cpu-single.h +4 -0
index f073a6d..f436df2 100644
@@ -40,5 +40,9 @@ extern void cpu_proc_fin(void);
 extern int cpu_do_idle(void);
 extern void cpu_dcache_clean_area(void *, int);
 extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm);
+#ifdef CONFIG_ARM_LPAE
+extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte);
+#else
 extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext);
+#endif
 extern void cpu_reset(unsigned long addr) __attribute__((noreturn));
arch/arm/include/asm/pgalloc.h +25 -1
index c2a1f64..64a303d 100644
@@ -23,6 +23,26 @@
 #define _PAGE_USER_TABLE	(PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
 #define _PAGE_KERNEL_TABLE	(PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
 
+#ifdef CONFIG_ARM_LPAE
+
+static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
+{
+	return (pmd_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
+}
+
+static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
+{
+	BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
+	free_page((unsigned long)pmd);
+}
+
+static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
+{
+	set_pgd(pgd, __pgd(__pa(pmd) | PMD_TYPE_TABLE));
+}
+
+#else	/* !CONFIG_ARM_LPAE */
+
 /*
  * Since we have only two-level page tables, these are trivial
  */
@@ -30,6 +50,8 @@
 #define pmd_free(mm, pmd)		do { } while (0)
 #define pgd_populate(mm,pmd,pte)	BUG()
 
+#endif	/* CONFIG_ARM_LPAE */
+
 extern pgd_t *get_pgd_slow(struct mm_struct *mm);
 extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd);
 
@@ -106,10 +128,12 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 	__free_page(pte);
 }
 
-static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval)
+static inline void __pmd_populate(pmd_t *pmdp, pmd_t pmdval)
 {
 	pmdp[0] = __pmd(pmdval);
+#ifndef CONFIG_ARM_LPAE
 	pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
+#endif
 	flush_pmd_entry(pmdp);
 }
 
arch/arm/include/asm/pgtable.h +72 -0

118 lines not on this page · raw message

arch/arm/include/asm/proc-fns.h +13 -0
index 8fdae9b..f00ae99 100644
@@ -263,6 +263,18 @@
 
 #define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)
 
+#ifdef CONFIG_ARM_LPAE
+#define cpu_get_pgd()	\
+	({						\
+		unsigned long pg, pg2;			\
+		__asm__("mrrc	p15, 0, %0, %1, c2"	\
+			: "=r" (pg), "=r" (pg2)		\
+			:				\
+			: "cc");			\
+		pg &= ~(PTRS_PER_PGD*sizeof(pgd_t)-1);	\
+		(pgd_t *)phys_to_virt(pg);		\
+	})
+#else
 #define cpu_get_pgd()	\
 	({						\
 		unsigned long pg;			\
@@ -271,6 +283,7 @@
 		pg &= ~0x3fff;				\
 		(pgd_t *)phys_to_virt(pg);		\
 	})
+#endif
 
 #endif
 
arch/arm/mm/ioremap.c +5 -3
index 17e7b0b..ccfb2ab 100644
@@ -64,7 +64,7 @@ void __check_kvm_seq(struct mm_struct *mm)
 	} while (seq != init_mm.context.kvm_seq);
 }
 
-#ifndef CONFIG_SMP
+#if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
 /*
  * Section support is unsafe on SMP - If you iounmap and ioremap a region,
  * the other CPUs will not see this change until their next context switch.
@@ -195,11 +195,13 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,
 	unsigned long addr;
  	struct vm_struct * area;
 
+#ifndef CONFIG_ARM_LPAE
 	/*
 	 * High mappings must be supersection aligned
 	 */
 	if (pfn >= 0x100000 && (__pfn_to_phys(pfn) & ~SUPERSECTION_MASK))
 		return NULL;
+#endif
 
 	/*
 	 * Don't allow RAM to be mapped - this causes problems with ARMv6+
@@ -225,7 +227,7 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,
  		return NULL;
  	addr = (unsigned long)area->addr;
 
-#ifndef CONFIG_SMP
+#if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
 	if (DOMAIN_IO == 0 &&
 	    (((cpu_architecture() >= CPU_ARCH_ARMv6) && (get_cr() & CR_XP)) ||
 	       cpu_is_xsc3()) && pfn >= 0x100000 &&
@@ -296,7 +298,7 @@ EXPORT_SYMBOL(__arm_ioremap);
 void __iounmap(volatile void __iomem *io_addr)
 {
 	void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);
-#ifndef CONFIG_SMP
+#if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
 	struct vm_struct **p, *tmp;
 
 	/*
arch/arm/mm/pgd.c +14 -4
index 69bbfc6..e7c149b 100644
@@ -10,6 +10,7 @@
 #include <linux/mm.h>
 #include <linux/gfp.h>
 #include <linux/highmem.h>
+#include <linux/slab.h>
 
 #include <asm/pgalloc.h>
 #include <asm/page.h>
@@ -17,7 +18,15 @@
 
 #include "mm.h"
 
+#ifdef CONFIG_ARM_LPAE
+#define alloc_pgd()	kmalloc(PTRS_PER_PGD * sizeof(pgd_t), GFP_KERNEL)
+#define free_pgd(pgd)	kfree(pgd)
+#define FIRST_KERNEL_PGD_NR	(PAGE_OFFSET >> PGDIR_SHIFT)
+#else
+#define alloc_pgd()	(pgd_t *)__get_free_pages(GFP_KERNEL, 2)
+#define free_pgd(pgd)	free_pages((unsigned long)pgd, 2)
 #define FIRST_KERNEL_PGD_NR	(FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
+#endif
 
 /*
  * need to get a 16k page for level 1
@@ -28,7 +37,7 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
 	pmd_t *new_pmd, *init_pmd;
 	pte_t *new_pte, *init_pte;
 
-	new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, 2);
+	new_pgd = alloc_pgd();
 	if (!new_pgd)
 		goto no_pgd;
 
@@ -68,7 +77,7 @@ pgd_t *get_pgd_slow(struct mm_struct *mm)
 no_pte:
 	pmd_free(mm, new_pmd);
 no_pmd:
-	free_pages((unsigned long)new_pgd, 2);
+	free_pgd(new_pgd);
 no_pgd:
 	return NULL;
 }
@@ -81,7 +90,8 @@ void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd)
 	if (!pgd)
 		return;
 
-	/* pgd is always present and good */
+	if (pgd_none(*pgd))
+		goto free;
 	pmd = pmd_off(pgd, 0);
 	if (pmd_none(*pmd))
 		goto free;
@@ -96,5 +106,5 @@ void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd)
 	pte_free(mm, pte);
 	pmd_free(mm, pmd);
 free:
-	free_pages((unsigned long) pgd, 2);
+	free_pgd(pgd);
 }
arch/arm/mm/proc-v7.S +8 -0
index 2b5b20b..1098a49 100644
@@ -130,6 +130,13 @@ ENDPROC(cpu_v7_switch_mm)
  */
 ENTRY(cpu_v7_set_pte_ext)
 #ifdef CONFIG_MMU
+#ifdef CONFIG_ARM_LPAE
+	tst	r2, #L_PTE_PRESENT
+	beq	1f
+	tst	r3, #1 << (55 - 32)		@ L_PTE_DIRTY
+	orreq	r2, #L_PTE_NOWRITE
+1:	strd	r2, r3, [r0]
+#else	/* !CONFIG_ARM_LPAE */
  ARM(	str	r1, [r0], #-2048	)	@ linux version
  THUMB(	str	r1, [r0]		)	@ linux version
  THUMB(	sub	r0, r0, #2048		)
@@ -162,6 +169,7 @@ ENTRY(cpu_v7_set_pte_ext)
 	moveq	r3, #0
 
 	str	r3, [r0]
+#endif	/* CONFIG_ARM_LPAE */
 	mcr	p15, 0, r0, c7, c10, 1		@ flush_pte
 #endif
 	mov	pc, lr
#48 lore raw

PATCH v2 8/20 ARM: LPAE: MMU setup for the 3-level page table format

In reply to Catalin Marinas

This patch adds the MMU initialisation for the LPAE page table format. The swapper_pg_dir size with LPAE is 5 rather than 4 pages. The __v7_setup function configures the TTBRx split based on the PAGE_OFFSET and sets the corresponding TTB control and MAIRx bits (similar to PRRR/NMRR for TEX remapping). The 36-bit mappings (supersections) and a few other memory types in mmu.c are conditionally compiled.

---
 arch/arm/kernel/head.S    |   96 +++++++++++++++++++++++++++++++------------
 arch/arm/mm/mmu.c         |   32 ++++++++++++++-
 arch/arm/mm/proc-macros.S |    5 +-
 arch/arm/mm/proc-v7.S     |   99 ++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 193 insertions(+), 39 deletions(-)
arch/arm/kernel/head.S +69 -27
index dd6b369..fd8a29e 100644
@@ -21,6 +21,7 @@
 #include <asm/memory.h>
 #include <asm/thread_info.h>
 #include <asm/system.h>
+#include <asm/pgtable.h>
 
 #ifdef CONFIG_DEBUG_LL
 #include <mach/debug-macro.S>
@@ -45,11 +46,20 @@
 #error KERNEL_RAM_VADDR must start at 0xXXXX8000
 #endif
 
+#ifdef CONFIG_ARM_LPAE
+	/* LPAE requires an additional page for the PGD */
+#define PG_DIR_SIZE	0x5000
+#define PTE_WORDS	3
+#else
+#define PG_DIR_SIZE	0x4000
+#define PTE_WORDS	2
+#endif
+
 	.globl	swapper_pg_dir
-	.equ	swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
+	.equ	swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
 
 	.macro	pgtbl, rd
-	ldr	\rd, =(KERNEL_RAM_PADDR - 0x4000)
+	ldr	\rd, =(KERNEL_RAM_PADDR - PG_DIR_SIZE)
 	.endm
 
 #ifdef CONFIG_XIP_KERNEL
@@ -129,11 +139,11 @@ __create_page_tables:
 	pgtbl	r4				@ page table address
 
 	/*
-	 * Clear the 16K level 1 swapper page table
+	 * Clear the swapper page table
 	 */
 	mov	r0, r4
 	mov	r3, #0
-	add	r6, r0, #0x4000
+	add	r6, r0, #PG_DIR_SIZE
 1:	str	r3, [r0], #4
 	str	r3, [r0], #4
 	str	r3, [r0], #4
@@ -141,6 +151,23 @@ __create_page_tables:
 	teq	r0, r6
 	bne	1b
 
+#ifdef CONFIG_ARM_LPAE
+	/*
+	 * Build the PGD table (first level) to point to the PMD table. A PGD
+	 * entry is 64-bit wide and the top 32 bits are 0.
+	 */
+	mov	r0, r4
+	add	r3, r4, #0x1000			@ first PMD table address
+	orr	r3, r3, #3			@ PGD block type
+	mov	r6, #4				@ PTRS_PER_PGD
+1:	str	r3, [r0], #8			@ set PGD entry
+	add	r3, r3, #0x1000			@ next PMD table
+	subs	r6, r6, #1
+	bne	1b
+
+	add	r4, r4, #0x1000			@ point to the PMD tables
+#endif
+
 	ldr	r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
 
 	/*
@@ -152,30 +179,30 @@ __create_page_tables:
 	sub	r0, r0, r3			@ virt->phys offset
 	add	r5, r5, r0			@ phys __enable_mmu
 	add	r6, r6, r0			@ phys __enable_mmu_end
-	mov	r5, r5, lsr #20
-	mov	r6, r6, lsr #20
+	mov	r5, r5, lsr #SECTION_SHIFT
+	mov	r6, r6, lsr #SECTION_SHIFT
 
-1:	orr	r3, r7, r5, lsl #20		@ flags + kernel base
-	str	r3, [r4, r5, lsl #2]		@ identity mapping
-	teq	r5, r6
-	addne	r5, r5, #1			@ next section
-	bne	1b
+1:	orr	r3, r7, r5, lsl #SECTION_SHIFT	@ flags + kernel base
+	str	r3, [r4, r5, lsl #PTE_WORDS]	@ identity mapping
+	cmp	r5, r6
+	addlo	r5, r5, #SECTION_SHIFT >> 20	@ next section
+	blo	1b
 
 	/*
 	 * Now setup the pagetables for our kernel direct
 	 * mapped region.
 	 */
 	mov	r3, pc
-	mov	r3, r3, lsr #20
-	orr	r3, r7, r3, lsl #20
+	mov	r3, r3, lsr #SECTION_SHIFT
+	orr	r3, r7, r3, lsl #SECTION_SHIFT
 	add	r0, r4,  #(KERNEL_START & 0xff000000) >> 18
-	str	r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!
+	str	r3, [r0, #(KERNEL_START & 0x00e00000) >> 18]!
 	ldr	r6, =(KERNEL_END - 1)
-	add	r0, r0, #4
+	add	r0, r0, #1 << PTE_WORDS
 	add	r6, r4, r6, lsr #18
 1:	cmp	r0, r6
-	add	r3, r3, #1 << 20
-	strls	r3, [r0], #4
+	add	r3, r3, #1 << SECTION_SHIFT
+	strls	r3, [r0], #1 << PTE_WORDS
 	bls	1b
 
 #ifdef CONFIG_XIP_KERNEL
@@ -198,12 +225,13 @@ __create_page_tables:
 #endif
 
 	/*
-	 * Then map first 1MB of ram in case it contains our boot params.
+	 * Then map first section of RAM in case it contains our boot params.
+	 * It assumes that PAGE_OFFSET is 2MB-aligned.
 	 */
 	add	r0, r4, #PAGE_OFFSET >> 18
 	orr	r6, r7, #(PHYS_OFFSET & 0xff000000)
-	.if	(PHYS_OFFSET & 0x00f00000)
-	orr	r6, r6, #(PHYS_OFFSET & 0x00f00000)
+	.if	(PHYS_OFFSET & 0x00e00000)
+	orr	r6, r6, #(PHYS_OFFSET & 0x00e00000)
 	.endif
 	str	r6, [r0]
 
@@ -216,21 +244,27 @@ __create_page_tables:
 	 */
 	addruart r7, r3
 
-	mov	r3, r3, lsr #20
-	mov	r3, r3, lsl #2
+	mov	r3, r3, lsr #SECTION_SHIFT
+	mov	r3, r3, lsl #PTE_WORDS
 
 	add	r0, r4, r3
 	rsb	r3, r3, #0x4000			@ PTRS_PER_PGD*sizeof(long)
 	cmp	r3, #0x0800			@ limit to 512MB
 	movhi	r3, #0x0800
 	add	r6, r0, r3
-	mov	r3, r7, lsr #20
+	mov	r3, r7, lsr #SECTION_SHIFT
 	ldr	r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
-	orr	r3, r7, r3, lsl #20
+	orr	r3, r7, r3, lsl #SECTION_SHIFT
+#ifdef CONFIG_ARM_LPAE
+	mov	r7, #1 << (54 - 32)		@ XN
+#endif
 1:	str	r3, [r0], #4
-	add	r3, r3, #1 << 20
-	teq	r0, r6
-	bne	1b
+#ifdef CONFIG_ARM_LPAE
+	str	r7, [r0], #4
+#endif
+	add	r3, r3, #1 << SECTION_SHIFT
+	cmp	r0, r6
+	blo	1b
 
 #else /* CONFIG_DEBUG_ICEDCC */
 	/* we don't need any serial debugging mappings for ICEDCC */
@@ -259,6 +293,9 @@ __create_page_tables:
 	str	r3, [r0]
 #endif
 #endif
+#ifdef CONFIG_ARM_LPAE
+	sub	r4, r4, #0x1000		@ point to the PGD table
+#endif
 	mov	pc, lr
 ENDPROC(__create_page_tables)
 	.ltorg
@@ -344,12 +381,17 @@ __enable_mmu:
 #ifdef CONFIG_CPU_ICACHE_DISABLE
 	bic	r0, r0, #CR_I
 #endif
+#ifdef CONFIG_ARM_LPAE
+	mov	r5, #0
+	mcrr	p15, 0, r4, r5, c2		@ load TTBR0
+#else
 	mov	r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
 		      domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
 		      domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
 		      domain_val(DOMAIN_IO, DOMAIN_CLIENT))
 	mcr	p15, 0, r5, c3, c0, 0		@ load domain access register
 	mcr	p15, 0, r4, c2, c0, 0		@ load page table pointer
+#endif
 	b	__turn_mmu_on
 ENDPROC(__enable_mmu)
 
arch/arm/mm/mmu.c +31 -1
index 7c803c4..4147cc6 100644
@@ -152,6 +152,7 @@ static int __init early_nowrite(char *__unused)
 }
 early_param("nowb", early_nowrite);
 
+#ifndef CONFIG_ARM_LPAE
 static int __init early_ecc(char *p)
 {
 	if (memcmp(p, "on", 2) == 0)
@@ -161,6 +162,7 @@ static int __init early_ecc(char *p)
 	return 0;
 }
 early_param("ecc", early_ecc);
+#endif
 
 static int __init noalign_setup(char *__unused)
 {
@@ -230,10 +232,12 @@ static struct mem_type mem_types[] = {
 		.prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
 		.domain    = DOMAIN_KERNEL,
 	},
+#ifndef CONFIG_ARM_LPAE
 	[MT_MINICLEAN] = {
 		.prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
 		.domain    = DOMAIN_KERNEL,
 	},
+#endif
 	[MT_LOW_VECTORS] = {
 		.prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
 				L_PTE_EXEC | L_PTE_NOWRITE,
@@ -425,6 +429,7 @@ static void __init build_mem_type_table(void)
 	 * ARMv6 and above have extended page tables.
 	 */
 	if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
+#ifndef CONFIG_ARM_LPAE
 		/*
 		 * Mark cache clean areas and XIP ROM read only
 		 * from SVC mode and no access from userspace.
@@ -432,6 +437,7 @@ static void __init build_mem_type_table(void)
 		mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
 		mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
 		mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
+#endif
 
 		if (is_smp()) {
 			/*
@@ -470,6 +476,18 @@ static void __init build_mem_type_table(void)
 		mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
 	}
 
+#ifdef CONFIG_ARM_LPAE
+	/*
+	 * Do not generate access flag faults for the kernel mappings.
+	 */
+	for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
+		mem_types[i].prot_pte |= PTE_EXT_AF;
+		mem_types[i].prot_sect |= PMD_SECT_AF;
+	}
+	kern_pgprot |= PTE_EXT_AF;
+	vecs_pgprot |= PTE_EXT_AF;
+#endif
+
 	for (i = 0; i < 16; i++) {
 		unsigned long v = pgprot_val(protection_map[i]);
 		protection_map[i] = __pgprot(v | user_pgprot);
@@ -587,6 +605,7 @@ static void __init alloc_init_section(pgd_t *pgd, unsigned long addr,
 	}
 }
 
+#ifndef CONFIG_ARM_LPAE
 static void __init create_36bit_mapping(struct map_desc *md,
 					const struct mem_type *type)
 {
@@ -644,6 +663,7 @@ static void __init create_36bit_mapping(struct map_desc *md,
 		pgd += SUPERSECTION_SIZE >> PGDIR_SHIFT;
 	} while (addr != end);
 }
+#endif	/* !CONFIG_ARM_LPAE */
 
 /*
  * Create the page directory entries and any necessary
@@ -674,6 +694,7 @@ static void __init create_mapping(struct map_desc *md)
 
 	type = &mem_types[md->type];
 
+#ifndef CONFIG_ARM_LPAE
 	/*
 	 * Catch 36-bit addresses
 	 */
@@ -681,6 +702,7 @@ static void __init create_mapping(struct map_desc *md)
 		create_36bit_mapping(md, type);
 		return;
 	}
+#endif
 
 	addr = md->virtual & PAGE_MASK;
 	phys = (unsigned long)__pfn_to_phys(md->pfn);
@@ -885,6 +907,14 @@ static inline void prepare_page_table(void)
 		pmd_clear(pmd_off_k(addr));
 }
 
+#ifdef CONFIG_ARM_LPAE
+/* the first page is reserved for pgd */
+#define SWAPPER_PG_DIR_SIZE	(PAGE_SIZE + \
+				 PTRS_PER_PGD * PTRS_PER_PMD * sizeof(pmd_t))
+#else
+#define SWAPPER_PG_DIR_SIZE	(PTRS_PER_PGD * sizeof(pgd_t))
+#endif
+
 /*
  * Reserve the special regions of memory
  */
@@ -894,7 +924,7 @@ void __init arm_mm_memblock_reserve(void)
 	 * Reserve the page tables.  These are already in use,
 	 * and can only be in node 0.
 	 */
-	memblock_reserve(__pa(swapper_pg_dir), PTRS_PER_PGD * sizeof(pgd_t));
+	memblock_reserve(__pa(swapper_pg_dir), SWAPPER_PG_DIR_SIZE);
 
 #ifdef CONFIG_SA1111
 	/*
arch/arm/mm/proc-macros.S +3 -2
index 337f102..fed053c 100644
@@ -81,8 +81,9 @@
 #if L_PTE_SHARED != PTE_EXT_SHARED
 #error PTE shared bit mismatch
 #endif
-#if (L_PTE_EXEC+L_PTE_USER+L_PTE_WRITE+L_PTE_DIRTY+L_PTE_YOUNG+\
-     L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
+#if !defined(CONFIG_ARM_LPAE) && \
+		(L_PTE_EXEC+L_PTE_USER+L_PTE_WRITE+L_PTE_DIRTY+L_PTE_YOUNG+ \
+		 L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED
 #error Invalid Linux PTE bit settings
 #endif
 #endif	/* CONFIG_MMU */
arch/arm/mm/proc-v7.S +90 -9

161 lines not on this page · raw message

#54 lore raw

PATCH v2 9/20 ARM: LPAE: Change setup_mm_for_reboot() to work with LPAE

In reply to Catalin Marinas

This function was assuming that there are only two levels of page tables. The patch changes looping over the PMD entries to make it compatible with LPAE.

---
 arch/arm/mm/mmu.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
arch/arm/mm/mmu.c +5 -2
index 4147cc6..3784acc 100644
@@ -1098,13 +1098,16 @@ void setup_mm_for_reboot(char mode)
 	if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
 		base_pmdval |= PMD_BIT4;
 
-	for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
+	for (i = 0; i < TASK_SIZE >> PMD_SHIFT; i++) {
 		unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;
 		pmd_t *pmd;
+		unsigned long addr = i << PMD_SHIFT;
 
-		pmd = pmd_off(pgd, i << PMD_SHIFT);
+		pmd = pmd_off(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(pmdval);
+#ifndef CONFIG_ARM_LPAE
 		pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
+#endif
 		flush_pmd_entry(pmd);
 	}
 
#56 lore raw

PATCH v2 10/20 ARM: LPAE: Remove the FIRST_USER_PGD_NR and USER_PTRS_PER_PGD definitions

In reply to Catalin Marinas

These macros were only used in setup_mm_for_reboot and get_pgd_slow. Both have been modified to no longer use these definitions. One of the reasons is the different meaning that PGD has with the 2-level and 3-level page tables.

---
 arch/arm/include/asm/pgtable-2level.h |    3 ---
 arch/arm/include/asm/pgtable-3level.h |    3 ---
 arch/arm/mm/pgd.c                     |    2 +-
 3 files changed, 1 insertions(+), 7 deletions(-)
arch/arm/include/asm/pgtable-2level.h +0 -3
index 4e21166..a0548b6 100644
@@ -92,9 +92,6 @@
  */
 #define FIRST_USER_ADDRESS	PAGE_SIZE
 
-#define FIRST_USER_PGD_NR	1
-#define USER_PTRS_PER_PGD	((TASK_SIZE/PGDIR_SIZE) - FIRST_USER_PGD_NR)
-
 /*
  * section address mask and size definitions.
  */
arch/arm/include/asm/pgtable-3level.h +0 -3
index 5b1482d..381b04b 100644
@@ -58,9 +58,6 @@
  */
 #define FIRST_USER_ADDRESS	PAGE_SIZE
 
-#define FIRST_USER_PGD_NR	1
-#define USER_PTRS_PER_PGD	((TASK_SIZE/PGDIR_SIZE) - FIRST_USER_PGD_NR)
-
 /*
  * section address mask and size definitions.
  */
arch/arm/mm/pgd.c +1 -1
index e7c149b..09238fa 100644
@@ -25,7 +25,7 @@
 #else
 #define alloc_pgd()	(pgd_t *)__get_free_pages(GFP_KERNEL, 2)
 #define free_pgd(pgd)	free_pages((unsigned long)pgd, 2)
-#define FIRST_KERNEL_PGD_NR	(FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
+#define FIRST_KERNEL_PGD_NR	(TASK_SIZE >> PGDIR_SHIFT)
 #endif
 
 /*
#58 lore raw

PATCH v2 11/20 ARM: LPAE: Add fault handling support

In reply to Catalin Marinas

The DFSR and IFSR register format is different when LPAE is enabled. In addition, DFSR and IFSR have the similar definitions for the fault type. This modifies modifies the fault code to correctly handle the new format.

---
 arch/arm/mm/alignment.c |    8 ++++-
 arch/arm/mm/fault.c     |   80 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 1 deletions(-)
arch/arm/mm/alignment.c +7 -1
index 724ba3b..bc98a6e 100644
@@ -906,6 +906,12 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	return 0;
 }
 
+#ifdef CONFIG_ARM_LPAE
+#define ALIGNMENT_FAULT		33
+#else
+#define ALIGNMENT_FAULT		1
+#endif
+
 /*
  * This needs to be done after sysctl_init, otherwise sys/ will be
  * overwritten.  Actually, this shouldn't be in sys/ at all since
@@ -939,7 +945,7 @@ static int __init alignment_init(void)
 		ai_usermode = UM_FIXUP;
 	}
 
-	hook_fault_code(1, do_alignment, SIGBUS, BUS_ADRALN,
+	hook_fault_code(ALIGNMENT_FAULT, do_alignment, SIGBUS, BUS_ADRALN,
 			"alignment exception");
 
 	/*
arch/arm/mm/fault.c +80 -0

133 lines not on this page · raw message

#63 lore raw

PATCH v2 12/20 ARM: LPAE: Add context switching support

In reply to Catalin Marinas

With LPAE, TTBRx registers are 64-bit. The ASID is stored in TTBR0 rather than a separate Context ID register. This patch makes the necessary changes to handle context switching on LPAE.

---
 arch/arm/mm/context.c |   18 ++++++++++++++++--
 arch/arm/mm/proc-v7.S |    8 +++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)
arch/arm/mm/context.c +16 -2
index b0ee9ba..d40d3fa 100644
@@ -22,6 +22,20 @@ unsigned int cpu_last_asid = ASID_FIRST_VERSION;
 DEFINE_PER_CPU(struct mm_struct *, current_mm);
 #endif
 
+#ifdef CONFIG_ARM_LPAE
+#define cpu_set_asid(asid) {						\
+	unsigned long ttbl, ttbh;					\
+	asm("	mrrc	p15, 0, %0, %1, c2		@ read TTBR0\n"	\
+	    "	mov	%1, %1, lsl #(48 - 32)		@ set ASID\n"	\
+	    "	mcrr	p15, 0, %0, %1, c2		@ set TTBR0\n"	\
+	    : "=r" (ttbl), "=r" (ttbh)					\
+	    : "r" (asid & ~ASID_MASK));					\
+}
+#else
+#define cpu_set_asid(asid) \
+	asm("	mcr	p15, 0, %0, c13, c0, 1\n" : : "r" (asid))
+#endif
+
 /*
  * We fork()ed a process, and we need a new context for the child
  * to run in.  We reserve version 0 for initial tasks so we will
@@ -37,7 +51,7 @@ void __init_new_context(struct task_struct *tsk, struct mm_struct *mm)
 static void flush_context(void)
 {
 	/* set the reserved ASID before flushing the TLB */
-	asm("mcr	p15, 0, %0, c13, c0, 1\n" : : "r" (0));
+	cpu_set_asid(0);
 	isb();
 	local_flush_tlb_all();
 	if (icache_is_vivt_asid_tagged()) {
@@ -99,7 +113,7 @@ static void reset_context(void *info)
 	set_mm_context(mm, asid);
 
 	/* set the new ASID */
-	asm("mcr	p15, 0, %0, c13, c0, 1\n" : : "r" (mm->context.id));
+	cpu_set_asid(mm->context.id);
 	isb();
 }
 
arch/arm/mm/proc-v7.S +7 -1
index 33a8c82..b0932c1 100644
@@ -117,6 +117,11 @@ ENTRY(cpu_v7_switch_mm)
 #ifdef CONFIG_MMU
 	mov	r2, #0
 	ldr	r1, [r1, #MM_CONTEXT_ID]	@ get mm->context.id
+#ifdef CONFIG_ARM_LPAE
+	and	r3, r1, #0xff
+	mov	r3, r3, lsl #(48 - 32)		@ ASID
+	mcrr	p15, 0, r0, r3, c2		@ set TTB 0
+#else	/* !CONFIG_ARM_LPAE */
 	ALT_SMP(orr	r0, r0, #TTB_FLAGS_SMP)
 	ALT_UP(orr	r0, r0, #TTB_FLAGS_UP)
 #ifdef CONFIG_ARM_ERRATA_430973
@@ -124,9 +129,10 @@ ENTRY(cpu_v7_switch_mm)
 #endif
 	mcr	p15, 0, r2, c13, c0, 1		@ set reserved context ID
 	isb
-1:	mcr	p15, 0, r0, c2, c0, 0		@ set TTB 0
+	mcr	p15, 0, r0, c2, c0, 0		@ set TTB 0
 	isb
 	mcr	p15, 0, r1, c13, c0, 1		@ set context ID
+#endif	/* CONFIG_ARM_LPAE */
 	isb
 #endif
 	mov	pc, lr
#64 lore raw

PATCH v2 13/20 ARM: LPAE: Add SMP support for the 3-level page table format

In reply to Catalin Marinas

With 3-level page tables, starting secondary CPUs required allocating the pgd as well. Since LPAE Linux uses TTBR1 for the kernel page tables, this patch reorders the CPU setup call in the head.S file so that the swapper_pg_dir is used. TTBR0 is set to the value generated by the primary CPU.

---
 arch/arm/kernel/head.S |   10 +++++-----
 arch/arm/kernel/smp.c  |   39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 7 deletions(-)
arch/arm/kernel/head.S +5 -5
index fd8a29e..b54d00e 100644
@@ -321,6 +321,10 @@ ENTRY(secondary_startup)
 	moveq	r0, #'p'			@ yes, error 'p'
 	beq	__error_p
 
+	pgtbl	r4
+	add	r12, r10, #BSYM(PROCINFO_INITFUNC)
+	blx	r12				@ initialise processor
+						@ (return control reg)
 	/*
 	 * Use the page tables supplied from  __cpu_up.
 	 */
@@ -328,12 +332,8 @@ ENTRY(secondary_startup)
 	ldmia	r4, {r5, r7, r12}		@ address to jump to after
 	sub	r4, r4, r5			@ mmu has been enabled
 	ldr	r4, [r7, r4]			@ get secondary_data.pgdir
-	adr	lr, BSYM(__enable_mmu)		@ return address
 	mov	r13, r12			@ __secondary_switched address
- ARM(	add	pc, r10, #PROCINFO_INITFUNC	) @ initialise processor
-						  @ (return control reg)
- THUMB(	add	r12, r10, #PROCINFO_INITFUNC	)
- THUMB(	mov	pc, r12				)
+	b	__enable_mmu
 ENDPROC(secondary_startup)
 
 	/*
arch/arm/kernel/smp.c +37 -2
index 40b386c..089e2ae 100644
@@ -82,8 +82,10 @@ static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(addr | prot);
 		addr += SECTION_SIZE;
+#ifndef CONFIG_ARM_LPAE
 		pmd[1] = __pmd(addr | prot);
 		addr += SECTION_SIZE;
+#endif
 		flush_pmd_entry(pmd);
 		outer_clean_range(__pa(pmd), __pa(pmd + 1));
 	}
@@ -98,7 +100,9 @@ static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
 	for (addr = start & PMD_MASK; addr < end; addr += PMD_SIZE) {
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(0);
+#ifndef CONFIG_ARM_LPAE
 		pmd[1] = __pmd(0);
+#endif
 		clean_pmd_entry(pmd);
 		outer_clean_range(__pa(pmd), __pa(pmd + 1));
 	}
@@ -109,6 +113,10 @@ int __cpuinit __cpu_up(unsigned int cpu)
 	struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
 	struct task_struct *idle = ci->idle;
 	pgd_t *pgd;
+#ifdef CONFIG_ARM_LPAE
+	pgd_t *pgd_phys;
+	pmd_t *pmd;
+#endif
 	int ret;
 
 	/*
@@ -137,8 +145,30 @@ int __cpuinit __cpu_up(unsigned int cpu)
 	 * a 1:1 mapping for the physical address of the kernel.
 	 */
 	pgd = pgd_alloc(&init_mm);
-	if (!pgd)
-		return -ENOMEM;
+	if (!pgd) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+#ifdef CONFIG_ARM_LPAE
+	/*
+	 * Check for overlapping between PHYS_OFFSET and PAGE_OFFSET and
+	 * duplicate the pmd to avoid overriding valid kernel mappings in the
+	 * init_mm page tables. The code assumes that the kernel text and data
+	 * sections are within 1GB of PHYS_OFFSET (maximum range convered by
+	 * a PMD table with LPAE).
+	 */
+	pgd_phys = pgd + pgd_index(PHYS_OFFSET);
+	pmd = pmd_alloc_one(NULL, PHYS_OFFSET);
+	if (!pmd) {
+		ret = -ENOMEM;
+		goto nopmd;
+	}
+	if (pgd_present(*pgd_phys))
+		memcpy(pmd, pmd_offset(pgd_phys, 0),
+		       PTRS_PER_PMD * sizeof(pmd_t));
+	pgd_populate(NULL, pgd_phys, pmd);
+#endif
 
 	if (PHYS_OFFSET != PAGE_OFFSET) {
 #ifndef CONFIG_HOTPLUG_CPU
@@ -192,8 +222,13 @@ int __cpuinit __cpu_up(unsigned int cpu)
 		identity_mapping_del(pgd, __pa(_sdata), __pa(_edata));
 	}
 
+#ifdef CONFIG_ARM_LPAE
+	pmd_free(&init_mm, pmd_offset(pgd_phys, 0));
+nopmd:
+#endif
 	pgd_free(&init_mm, pgd);
 
+out:
 	if (ret) {
 		printk(KERN_CRIT "CPU%u: processor failed to boot\n", cpu);
 
#66 lore raw

PATCH v2 14/20 ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

The unsigned long datatype is not sufficient for mapping physical addresses

Quoted 1 line

= 4GB.

This patch ensures that the phys_addr_t datatype is used to represent physical addresses which may be beyond the range of an unsigned long. The virt <-> phys macros are updated accordingly to ensure that virtual addresses can remain as they are.

---
 arch/arm/include/asm/memory.h     |   17 +++++++++--------
 arch/arm/include/asm/outercache.h |   14 ++++++++------
 arch/arm/include/asm/pgalloc.h    |    2 +-
 arch/arm/include/asm/pgtable.h    |    2 +-
 arch/arm/include/asm/setup.h      |    2 +-
 arch/arm/mm/init.c                |    6 +++---
 arch/arm/mm/mmu.c                 |   12 +++++++-----
 7 files changed, 30 insertions(+), 25 deletions(-)
arch/arm/include/asm/memory.h +9 -8
index 23c2e8e..756252b 100644
@@ -15,6 +15,7 @@
 
 #include <linux/compiler.h>
 #include <linux/const.h>
+#include <linux/types.h>
 #include <mach/memory.h>
 #include <asm/sizes.h>
 
@@ -138,15 +139,15 @@
  * files.  Use virt_to_phys/phys_to_virt/__pa/__va instead.
  */
 #ifndef __virt_to_phys
-#define __virt_to_phys(x)	((x) - PAGE_OFFSET + PHYS_OFFSET)
-#define __phys_to_virt(x)	((x) - PHYS_OFFSET + PAGE_OFFSET)
+#define __virt_to_phys(x)	(((phys_addr_t)(x) - PAGE_OFFSET + PHYS_OFFSET))
+#define __phys_to_virt(x)	((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET))
 #endif
 
 /*
  * Convert a physical address to a Page Frame Number and back
  */
-#define	__phys_to_pfn(paddr)	((paddr) >> PAGE_SHIFT)
-#define	__pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
+#define	__phys_to_pfn(paddr)	((unsigned long)((paddr) >> PAGE_SHIFT))
+#define	__pfn_to_phys(pfn)	((phys_addr_t)(pfn) << PAGE_SHIFT)
 
 /*
  * Convert a page to/from a physical address
@@ -188,21 +189,21 @@
  * translation for translating DMA addresses.  Use the driver
  * DMA support - see dma-mapping.h.
  */
-static inline unsigned long virt_to_phys(void *x)
+static inline phys_addr_t virt_to_phys(void *x)
 {
 	return __virt_to_phys((unsigned long)(x));
 }
 
-static inline void *phys_to_virt(unsigned long x)
+static inline void *phys_to_virt(phys_addr_t x)
 {
-	return (void *)(__phys_to_virt((unsigned long)(x)));
+	return (void *)(__phys_to_virt(x));
 }
 
 /*
  * Drivers should NOT use these either.
  */
 #define __pa(x)			__virt_to_phys((unsigned long)(x))
-#define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
+#define __va(x)			((void *)__phys_to_virt((phys_addr_t)(x)))
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 
 /*
arch/arm/include/asm/outercache.h +8 -6
index fc19009..88ad892 100644
@@ -21,6 +21,8 @@
 #ifndef __ASM_OUTERCACHE_H
 #define __ASM_OUTERCACHE_H
 
+#include <linux/types.h>
+
 struct outer_cache_fns {
 	void (*inv_range)(unsigned long, unsigned long);
 	void (*clean_range)(unsigned long, unsigned long);
@@ -37,17 +39,17 @@ struct outer_cache_fns {
 
 extern struct outer_cache_fns outer_cache;
 
-static inline void outer_inv_range(unsigned long start, unsigned long end)
+static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
 {
 	if (outer_cache.inv_range)
 		outer_cache.inv_range(start, end);
 }
-static inline void outer_clean_range(unsigned long start, unsigned long end)
+static inline void outer_clean_range(phys_addr_t start, phys_addr_t end)
 {
 	if (outer_cache.clean_range)
 		outer_cache.clean_range(start, end);
 }
-static inline void outer_flush_range(unsigned long start, unsigned long end)
+static inline void outer_flush_range(phys_addr_t start, phys_addr_t end)
 {
 	if (outer_cache.flush_range)
 		outer_cache.flush_range(start, end);
@@ -73,11 +75,11 @@ static inline void outer_disable(void)
 
 #else
 
-static inline void outer_inv_range(unsigned long start, unsigned long end)
+static inline void outer_inv_range(phys_addr_t start, phys_addr_t end)
 { }
-static inline void outer_clean_range(unsigned long start, unsigned long end)
+static inline void outer_clean_range(phys_addr_t start, phys_addr_t end)
 { }
-static inline void outer_flush_range(unsigned long start, unsigned long end)
+static inline void outer_flush_range(phys_addr_t start, phys_addr_t end)
 { }
 static inline void outer_flush_all(void) { }
 static inline void outer_inv_all(void) { }
arch/arm/include/asm/pgalloc.h +1 -1
index 64a303d..33761b8 100644
@@ -159,7 +159,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
 static inline void
 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
 {
-	__pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE);
+	__pmd_populate(pmdp, page_to_phys(ptep) | _PAGE_USER_TABLE);
 }
 #define pmd_pgtable(pmd) pmd_page(pmd)
 
arch/arm/include/asm/pgtable.h +1 -1
index 41236f0..bfbfcbd 100644
@@ -130,7 +130,7 @@ extern struct page *empty_zero_page;
 #define pte_pfn(pte)		(pte_val(pte) >> PAGE_SHIFT)
 #endif
 
-#define pfn_pte(pfn,prot)	(__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot)))
+#define pfn_pte(pfn,prot)	(__pte(((phys_addr_t)(pfn) << PAGE_SHIFT) | pgprot_val(prot)))
 
 #define pte_none(pte)		(!pte_val(pte))
 #define pte_clear(mm,addr,ptep)	set_pte_ext(ptep, __pte(0), 0)
arch/arm/include/asm/setup.h +1 -1
index f1e5a9b..5092118 100644
@@ -199,7 +199,7 @@ static struct tagtable __tagtable_##fn __tag = { tag, fn }
 #endif
 
 struct membank {
-	unsigned long start;
+	phys_addr_t start;
 	unsigned long size;
 	unsigned int highmem;
 };
arch/arm/mm/init.c +3 -3
index 5164069..14a00a1 100644
@@ -344,7 +344,7 @@ void __init bootmem_init(void)
 	 */
 	arm_bootmem_free(min, max_low, max_high);
 
-	high_memory = __va((max_low << PAGE_SHIFT) - 1) + 1;
+	high_memory = __va(((phys_addr_t)max_low << PAGE_SHIFT) - 1) + 1;
 
 	/*
 	 * This doesn't seem to be used by the Linux memory manager any
@@ -392,8 +392,8 @@ free_memmap(unsigned long start_pfn, unsigned long end_pfn)
 	 * Convert to physical addresses, and
 	 * round start upwards and end downwards.
 	 */
-	pg = PAGE_ALIGN(__pa(start_pg));
-	pgend = __pa(end_pg) & PAGE_MASK;
+	pg = (unsigned long)PAGE_ALIGN(__pa(start_pg));
+	pgend = (unsigned long)__pa(end_pg) & PAGE_MASK;
 
 	/*
 	 * If there are free pages between these,
arch/arm/mm/mmu.c +7 -5
index 3784acc..b03e431 100644
@@ -573,7 +573,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
 }
 
 static void __init alloc_init_section(pgd_t *pgd, unsigned long addr,
-				      unsigned long end, unsigned long phys,
+				      unsigned long end, phys_addr_t phys,
 				      const struct mem_type *type)
 {
 	pmd_t *pmd = pmd_offset(pgd, addr);
@@ -609,11 +609,12 @@ static void __init alloc_init_section(pgd_t *pgd, unsigned long addr,
 static void __init create_36bit_mapping(struct map_desc *md,
 					const struct mem_type *type)
 {
-	unsigned long phys, addr, length, end;
+	unsigned long addr, length, end;
+	phys_addr_t phys;
 	pgd_t *pgd;
 
 	addr = md->virtual;
-	phys = (unsigned long)__pfn_to_phys(md->pfn);
+	phys = __pfn_to_phys(md->pfn);
 	length = PAGE_ALIGN(md->length);
 
 	if (!(cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())) {
@@ -674,7 +675,8 @@ static void __init create_36bit_mapping(struct map_desc *md,
  */
 static void __init create_mapping(struct map_desc *md)
 {
-	unsigned long phys, addr, length, end;
+	unsigned long addr, length, end;
+	phys_addr_t phys;
 	const struct mem_type *type;
 	pgd_t *pgd;
 
@@ -705,7 +707,7 @@ static void __init create_mapping(struct map_desc *md)
 #endif
 
 	addr = md->virtual & PAGE_MASK;
-	phys = (unsigned long)__pfn_to_phys(md->pfn);
+	phys = __pfn_to_phys(md->pfn);
 	length = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
 
 	if (type->prot_l1 == 0 && ((addr | phys | length) & ~SECTION_MASK)) {
#67 lore raw

PATCH v2 15/20 ARM: LPAE: Use generic dma_addr_t type definition

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

This patch uses the types.h implementation in asm-generic to define the dma_addr_t type as the same width as phys_addr_t.

NOTE: this is a temporary patch until the corresponding patches unifying the dma_addr_t and removing the dma64_addr_t are merged into mainline.

---
 arch/arm/include/asm/types.h |   20 +-------------------
 1 files changed, 1 insertions(+), 19 deletions(-)
arch/arm/include/asm/types.h +1 -19
index 345df01..dc1bdbb 100644
@@ -1,30 +1,12 @@
 #ifndef __ASM_ARM_TYPES_H
 #define __ASM_ARM_TYPES_H
 
-#include <asm-generic/int-ll64.h>
+#include <asm-generic/types.h>
 
-#ifndef __ASSEMBLY__
-
-typedef unsigned short umode_t;
-
-#endif /* __ASSEMBLY__ */
-
-/*
- * These aren't exported outside the kernel to avoid name space clashes
- */
 #ifdef __KERNEL__
 
 #define BITS_PER_LONG 32
 
-#ifndef __ASSEMBLY__
-
-/* Dma addresses are 32-bits wide.  */
-
-typedef u32 dma_addr_t;
-typedef u32 dma64_addr_t;
-
-#endif /* __ASSEMBLY__ */
-
 #endif /* __KERNEL__ */
 
 #endif
#68 lore raw

PATCH v2 16/20 ARM: LPAE: mark memory banks with start > ULONG_MAX as highmem

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

Memory banks living outside of the 32-bit physical address space do not have a 1:1 pa <-> va mapping and therefore the __va macro may wrap.

This patch ensures that such banks are marked as highmem so that the Kernel doesn't try to split them up when it sees that the wrapped virtual address overlaps the vmalloc space.

---
 arch/arm/mm/mmu.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/mm/mmu.c +3 -2
index b03e431..787a409 100644
@@ -785,7 +785,8 @@ static void __init sanity_check_meminfo(void)
 
 #ifdef CONFIG_HIGHMEM
 		if (__va(bank->start) > vmalloc_min ||
-		    __va(bank->start) < (void *)PAGE_OFFSET)
+		    __va(bank->start) < (void *)PAGE_OFFSET ||
+		    bank->start > ULONG_MAX)
 			highmem = 1;
 
 		bank->highmem = highmem;
@@ -794,7 +795,7 @@ static void __init sanity_check_meminfo(void)
 		 * Split those memory banks which are partially overlapping
 		 * the vmalloc area greatly simplifying things later.
 		 */
-		if (__va(bank->start) < vmalloc_min &&
+		if (!highmem && __va(bank->start) < vmalloc_min &&
 		    bank->size > vmalloc_min - __va(bank->start)) {
 			if (meminfo.nr_banks >= NR_BANKS) {
 				printk(KERN_CRIT "NR_BANKS too low, "
#69 lore raw

PATCH v2 17/20 ARM: LPAE: use phys_addr_t for physical start address in early_mem

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

The physical start address of memory may be > 4GB and therefore unrepresentable using an unsigned long.

This patch changes early_mem and arm_add_memory to use phys_addr_t instead of unsigned long for the start address.

---
 arch/arm/kernel/setup.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
arch/arm/kernel/setup.c +3 -2
index 3cadb46..751ac80 100644
@@ -442,7 +442,7 @@ static struct machine_desc * __init setup_machine(unsigned int nr)
 	return list;
 }
 
-static int __init arm_add_memory(unsigned long start, unsigned long size)
+static int __init arm_add_memory(phys_addr_t start, unsigned long size)
 {
 	struct membank *bank = &meminfo.bank[meminfo.nr_banks];
 
@@ -478,7 +478,8 @@ static int __init arm_add_memory(unsigned long start, unsigned long size)
 static int __init early_mem(char *p)
 {
 	static int usermem __initdata = 0;
-	unsigned long size, start;
+	unsigned long size;
+	phys_addr_t start;
 	char *endp;
 
 	/*
#70 lore raw

PATCH v2 18/20 ARM: LPAE: add support for ATAG_MEM64

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

LPAE provides support for memory banks with physical addresses of up to 40 bits.

This patch adds a new atag, ATAG_MEM64, so that the Kernel can be informed about memory that exists above the 4GB boundary.

---
 arch/arm/include/asm/setup.h |   10 +++++++++-
 arch/arm/kernel/compat.c     |    4 ++--
 arch/arm/kernel/setup.c      |   12 +++++++++++-
 3 files changed, 22 insertions(+), 4 deletions(-)
arch/arm/include/asm/setup.h +9 -1
index 5092118..fab849f 100644
@@ -43,6 +43,13 @@ struct tag_mem32 {
 	__u32	start;	/* physical start address */
 };
 
+#define ATAG_MEM64	0x54420002
+
+struct tag_mem64 {
+	__u64	size;
+	__u64	start;	/* physical start address */
+};
+
 /* VGA text type displays */
 #define ATAG_VIDEOTEXT	0x54410003
 
@@ -147,7 +154,8 @@ struct tag {
 	struct tag_header hdr;
 	union {
 		struct tag_core		core;
-		struct tag_mem32	mem;
+		struct tag_mem32	mem32;
+		struct tag_mem64	mem64;
 		struct tag_videotext	videotext;
 		struct tag_ramdisk	ramdisk;
 		struct tag_initrd	initrd;
arch/arm/kernel/compat.c +2 -2
index 9256523..f224d95 100644
@@ -86,8 +86,8 @@ static struct tag * __init memtag(struct tag *tag, unsigned long start, unsigned
 	tag = tag_next(tag);
 	tag->hdr.tag = ATAG_MEM;
 	tag->hdr.size = tag_size(tag_mem32);
-	tag->u.mem.size = size;
-	tag->u.mem.start = start;
+	tag->u.mem32.size = size;
+	tag->u.mem32.start = start;
 
 	return tag;
 }
arch/arm/kernel/setup.c +11 -1
index 751ac80..0128db2 100644
@@ -591,11 +591,21 @@ __tagtable(ATAG_CORE, parse_tag_core);
 
 static int __init parse_tag_mem32(const struct tag *tag)
 {
-	return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
+	return arm_add_memory(tag->u.mem32.start, tag->u.mem32.size);
 }
 
 __tagtable(ATAG_MEM, parse_tag_mem32);
 
+#ifdef CONFIG_PHYS_ADDR_T_64BIT
+static int __init parse_tag_mem64(const struct tag *tag)
+{
+	/* We only use 32-bits for the size. */
+	return arm_add_memory(tag->u.mem64.start, (unsigned long)tag->u.mem64.size);
+}
+
+__tagtable(ATAG_MEM64, parse_tag_mem64);
+#endif /* CONFIG_PHYS_ADDR_T_64BIT */
+
 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
 struct screen_info screen_info = {
  .orig_video_lines	= 30,
#71 lore raw

PATCH v2 19/20 ARM: LPAE: define printk format for physical addresses and page table entries

In reply to Catalin Marinas

From: Will Deacon <[email protected]>

Now that the Kernel supports 2 level and 3 level page tables, physical addresses (and also page table entries) may be 32 or 64-bits depending upon the configuration.

This patch adds a conversion specifier (PHYS_ADDR_FMT) which represents a u32 or u64 depending on the width of a physical address.

---
 arch/arm/include/asm/types.h |    6 ++++++
 arch/arm/kernel/setup.c      |    2 +-
 arch/arm/mm/fault.c          |    8 ++++----
 arch/arm/mm/mmu.c            |   18 +++++++++---------
 4 files changed, 20 insertions(+), 14 deletions(-)
arch/arm/include/asm/types.h +6 -0
index dc1bdbb..b740539 100644
@@ -7,6 +7,12 @@
 
 #define BITS_PER_LONG 32
 
+#ifdef CONFIG_PHYS_ADDR_T_64BIT
+#define PHYS_ADDR_FMT	"%016llx"
+#else
+#define PHYS_ADDR_FMT	"%08x"
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif
arch/arm/kernel/setup.c +1 -1
index 0128db2..d143241 100644
@@ -448,7 +448,7 @@ static int __init arm_add_memory(phys_addr_t start, unsigned long size)
 
 	if (meminfo.nr_banks >= NR_BANKS) {
 		printk(KERN_CRIT "NR_BANKS too low, "
-			"ignoring memory at %#lx\n", start);
+			"ignoring memory at " PHYS_ADDR_FMT "\n", start);
 		return -EINVAL;
 	}
 
arch/arm/mm/fault.c +4 -4
index 2dde9cd..8112f77 100644
@@ -81,7 +81,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
 	printk(KERN_ALERT "pgd = %p\n", mm->pgd);
 	pgd = pgd_offset(mm, addr);
-	printk(KERN_ALERT "[%08lx] *pgd=%08lx", addr, pgd_val(*pgd));
+	printk(KERN_ALERT "[%08lx] *pgd=" PHYS_ADDR_FMT, addr, pgd_val(*pgd));
 
 	do {
 		pmd_t *pmd;
@@ -97,7 +97,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
 		pmd = pmd_offset(pgd, addr);
 		if (PTRS_PER_PMD != 1)
-			printk(", *pmd=%08lx", pmd_val(*pmd));
+			printk(", *pmd=" PHYS_ADDR_FMT, pmd_val(*pmd));
 
 		if (pmd_none(*pmd))
 			break;
@@ -112,9 +112,9 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 			break;
 
 		pte = pte_offset_map(pmd, addr);
-		printk(", *pte=%08lx", pte_val(*pte));
+		printk(", *pte=" PHYS_ADDR_FMT, pte_val(*pte));
 #ifndef CONFIG_ARM_LPAE
-		printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
+		printk(", *ppte=" PHYS_ADDR_FMT, pte_val(pte[-LINUX_PTE_OFFSET]));
 #endif
 		pte_unmap(pte);
 	} while(0);
arch/arm/mm/mmu.c +9 -9
index 787a409..f05f8ed 100644
@@ -619,7 +619,7 @@ static void __init create_36bit_mapping(struct map_desc *md,
 
 	if (!(cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())) {
 		printk(KERN_ERR "MM: CPU does not support supersection "
-		       "mapping for 0x%08llx at 0x%08lx\n",
+		       "mapping for 0x" PHYS_ADDR_FMT " at 0x%08lx\n",
 		       __pfn_to_phys((u64)md->pfn), addr);
 		return;
 	}
@@ -632,14 +632,14 @@ static void __init create_36bit_mapping(struct map_desc *md,
 	 */
 	if (type->domain) {
 		printk(KERN_ERR "MM: invalid domain in supersection "
-		       "mapping for 0x%08llx at 0x%08lx\n",
+		       "mapping for 0x" PHYS_ADDR_FMT " at 0x%08lx\n",
 		       __pfn_to_phys((u64)md->pfn), addr);
 		return;
 	}
 
 	if ((addr | length | __pfn_to_phys(md->pfn)) & ~SUPERSECTION_MASK) {
-		printk(KERN_ERR "MM: cannot create mapping for "
-		       "0x%08llx at 0x%08lx invalid alignment\n",
+		printk(KERN_ERR "MM: cannot create mapping for 0x" PHYS_ADDR_FMT
+		       " at 0x%08lx invalid alignment\n",
 		       __pfn_to_phys((u64)md->pfn), addr);
 		return;
 	}
@@ -681,16 +681,16 @@ static void __init create_mapping(struct map_desc *md)
 	pgd_t *pgd;
 
 	if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
-		printk(KERN_WARNING "BUG: not creating mapping for "
-		       "0x%08llx at 0x%08lx in user region\n",
+		printk(KERN_WARNING "BUG: not creating mapping for 0x"
+		       PHYS_ADDR_FMT "@0x%08lx in user region\n",
 		       __pfn_to_phys((u64)md->pfn), md->virtual);
 		return;
 	}
 
 	if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
 	    md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
-		printk(KERN_WARNING "BUG: mapping for 0x%08llx at 0x%08lx "
-		       "overlaps vmalloc space\n",
+		printk(KERN_WARNING "BUG: mapping for 0x" PHYS_ADDR_FMT
+		       "@0x%08lx overlaps vmalloc space\n",
 		       __pfn_to_phys((u64)md->pfn), md->virtual);
 	}
 
@@ -711,7 +711,7 @@ static void __init create_mapping(struct map_desc *md)
 	length = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
 
 	if (type->prot_l1 == 0 && ((addr | phys | length) & ~SECTION_MASK)) {
-		printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
+		printk(KERN_WARNING "BUG: map for 0x" PHYS_ADDR_FMT " at 0x%08lx can not "
 		       "be mapped using pages, ignoring.\n",
 		       __pfn_to_phys(md->pfn), addr);
 		return;
#74 lore raw

PATCH v2 20/20 ARM: LPAE: Add the Kconfig entries

In reply to Catalin Marinas

This patch adds the ARM_LPAE and ARCH_PHYS_ADDR_T_64BIT Kconfig entries allowing LPAE support to be compiled into the kernel.

---
 arch/arm/Kconfig    |    2 +-
 arch/arm/mm/Kconfig |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)
arch/arm/Kconfig +1 -1
index f35fe82..e376b7b 100644
@@ -1599,7 +1599,7 @@ config CMDLINE_FORCE
 
 config XIP_KERNEL
 	bool "Kernel Execute-In-Place from ROM"
-	depends on !ZBOOT_ROM
+	depends on !ZBOOT_ROM && !ARM_LPAE
 	help
 	  Execute-In-Place allows the kernel to run from non-volatile storage
 	  directly addressable by the CPU, such as NOR flash. This saves RAM
arch/arm/mm/Kconfig +13 -0
index 8493ed0..3ca2d15 100644
@@ -615,6 +615,19 @@ config IO_36
 
 comment "Processor Features"
 
+config ARM_LPAE
+	bool "Support for the Large Physical Address Extension"
+	depends on MMU && CPU_V7
+	help
+	  Say Y if you have an ARMv7 processor supporting the LPAE page table
+	  format and you would like access memory beyond the 4GB limit.
+
+config ARCH_PHYS_ADDR_T_64BIT
+	def_bool ARM_LPAE
+
+config ARCH_DMA_ADDR_T_64BIT
+	def_bool ARM_LPAE
+
 config ARM_THUMB
 	bool "Support Thumb user binaries"
 	depends on CPU_ARM720T || CPU_ARM740T || CPU_ARM920T || CPU_ARM922T || CPU_ARM925T || CPU_ARM926T || CPU_ARM940T || CPU_ARM946E || CPU_ARM1020 || CPU_ARM1020E || CPU_ARM1022 || CPU_ARM1026 || CPU_XSCALE || CPU_XSC3 || CPU_MOHAWK || CPU_V6 || CPU_V7 || CPU_FEROCEON
#75 lore raw

Re: [PATCH v2 20/20] ARM: LPAE: Add the Kconfig entries

Hello.

Quoted 4 lines · Catalin Marinas

This patch adds the ARM_LPAE and ARCH_PHYS_ADDR_T_64BIT Kconfig entries allowing LPAE support to be compiled into the kernel.

[...]

Quoted 5 lines
arch/arm/mm/Kconfig +0 -0
index 8493ed0..3ca2d15 100644

arch/arm/mm/Kconfig config IO_36 · line 623

Quoted 9 lines
arch/arm/mm/Kconfig +6 -0
@@ -615,6 +615,19 @@ config IO_36
 
  comment "Processor Features"
 
+config ARM_LPAE
+	bool "Support for the Large Physical Address Extension"
+	depends on MMU&&  CPU_V7
+	help
+	  Say Y if you have an ARMv7 processor supporting the LPAE page table
+	  format and you would like access memory beyond the 4GB limit.

Maybe "like to access"?

WBR, Sergei

#76 lore raw

Re: [PATCH v2 20/20] ARM: LPAE: Add the Kconfig entries

Quoted 10 lines · Sergei Shtylyov
Quoted 7 lines · Catalin Marinas

+config ARM_LPAE
+ ? ? ? bool "Support for the Large Physical Address Extension"
+ ? ? ? depends on MMU&& ?CPU_V7
+ ? ? ? help
+ ? ? ? ? Say Y if you have an ARMv7 processor supporting the LPAE page table
+ ? ? ? ? format and you would like access memory beyond the 4GB limit.

? Maybe "like to access"?

Yes, thanks.

Signature · 1 line
Catalin
#49 lore raw

Re: [PATCH v2 08/20] ARM: LPAE: MMU setup for the 3-level page table format

In reply to Catalin Marinas
Quoted 6 lines · Catalin Marinas

This patch adds the MMU initialisation for the LPAE page table format. The swapper_pg_dir size with LPAE is 5 rather than 4 pages. The __v7_setup function configures the TTBRx split based on the PAGE_OFFSET and sets the corresponding TTB control and MAIRx bits (similar to PRRR/NMRR for TEX remapping). The 36-bit mappings (supersections) and a few other memory types in mmu.c are conditionally compiled.

[...]

Quoted 6 lines
arch/arm/kernel/head.S +0 -0
@@ -45,11 +46,20 @@

?#error KERNEL_RAM_VADDR must start at 0xXXXX8000
?#endif

arch/arm/kernel/head.S

Quoted 8 lines
arch/arm/kernel/head.S +8 -0
+#ifdef CONFIG_ARM_LPAE
+ ? ? ? /* LPAE requires an additional page for the PGD */
+#define PG_DIR_SIZE ? ?0x5000
+#define PTE_WORDS ? ? ?3
+#else
+#define PG_DIR_SIZE ? ?0x4000
+#define PTE_WORDS ? ? ?2
+#endif

This should have been called PTE_ORDER, the PTE_WORDS naming is misleading.

Signature · 1 line
Catalin
#13 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Catalin Marinas
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

If we're going to make this change, we need to change more places than this patch covers. grep for pte_val to help find those places.

#14 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 11 lines · Russell King - ARM Linux
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

Quoted 6 lines

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

If we're going to make this change, we need to change more places than this patch covers. ?grep for pte_val to help find those places.

Patch 19/20 introduces a common macro for formatting but we should probably order the patches a bit to avoid problems if anyone is bisecting in the middle of the series.

Signature · 1 line
Catalin
#15 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 17 lines · Catalin Marinas
Quoted 15 lines · Russell King - ARM Linux
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

Quoted 6 lines
Quoted 2 lines

If we're going to make this change, we need to change more places than this patch covers. ?grep for pte_val to help find those places.

Patch 19/20 introduces a common macro for formatting but we should probably order the patches a bit to avoid problems if anyone is bisecting ?in the middle of the series.

Actually not a problem since LPAE is only enabled by the last patch. There may be some compiler warnings without 19/20, I need to check.

Signature · 1 line
Catalin
#16 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 21 lines · Catalin Marinas
Quoted 20 lines · Catalin Marinas
Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

If we're going to make this change, we need to change more places than this patch covers. ?grep for pte_val to help find those places.

Quoted 6 lines
Quoted 3 lines

Patch 19/20 introduces a common macro for formatting but we should probably order the patches a bit to avoid problems if anyone is bisecting ?in the middle of the series.

Actually not a problem since LPAE is only enabled by the last patch. There may be some compiler warnings without 19/20, I need to check.

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. Generic code cases pte values to (long long) and prints them using %08llx. We should do the same.

In any case, this patch on its own introduces new compiler warnings. These need to be fixed in this patch, rather than relying on one later in the series.

#17 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 26 lines · Russell King - ARM Linux
Quoted 25 lines · Catalin Marinas
Quoted 23 lines · Catalin Marinas
Quoted 11 lines · Russell King - ARM Linux
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

Quoted 6 lines

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

If we're going to make this change, we need to change more places than this patch covers. ?grep for pte_val to help find those places.

Patch 19/20 introduces a common macro for formatting but we should probably order the patches a bit to avoid problems if anyone is bisecting ?in the middle of the series.

Quoted 6 lines
Quoted 2 lines

Actually not a problem since LPAE is only enabled by the last patch. There may be some compiler warnings without 19/20, I need to check.

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Quoted 3 lines

In any case, this patch on its own introduces new compiler warnings. These need to be fixed in this patch, rather than relying on one later in the series.

Yes, we'll look into this.

Signature · 1 line
Catalin
#18 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 9 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. Generic code cases pte values to (long long) and prints them using %08llx. We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Why not just %010llx? That would just be two extra characters.

Arnd

#19 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

Quoted 7 lines
Quoted 5 lines

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Why not just %010llx? That would just be two extra characters.

We still have attributes (like XN, bit 54) stored in the top part of the pte. This may be of interest when debugging.

Signature · 1 line
Catalin
#24 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas
Quoted 3 lines · Russell King - ARM Linux

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Eeh? %08llx prints 8 characters _minimum_. If it needs more to represent the number, it will use more characters. You surely don't think generic code is brain dead enough to cast something to a 64-bit long long and then only print 32 bits of it???

#25 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

Quoted 13 lines · Russell King - ARM Linux
Quoted 11 lines · Catalin Marinas
Quoted 3 lines · Russell King - ARM Linux

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. Generic code cases pte values to (long long) and prints them using %08llx. We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Quoted 4 lines

Eeh? %08llx prints 8 characters _minimum_. If it needs more to represent the number, it will use more characters. You surely don't think generic code is brain dead enough to cast something to a 64-bit long long and then only print 32 bits of it???

That's correct. I was just wondering whether the alignment would look weird with ptes being printed with different lengths.

Anyway, here comes another set of patches with this update (%08llx in printk).

Signature · 1 line
Catalin
#28 lore raw

Re: [PATCH v2 04/20] ARM: LPAE: Do not assume Linux PTEs are always at PTRS_PER_PTE offset

In reply to Catalin Marinas
Quoted 5 lines · Catalin Marinas

Placing the Linux PTEs at a 2KB offset inside a page is a workaround for the 2-level page table format where not enough spare bits are available. With LPAE this is no longer required. This patch changes such assumption by using a different macro, LINUX_PTE_OFFSET, which is defined to PTRS_PER_PTE for the 2-level page tables.

Hmm. I think we should be doing this a different way - in fact, I think we should switch the order of the linux vs hardware page tables. This actually simplifies the code a bit too - notice that we lose the arith. in __pte_map, __pte_unmap, pmd_page_vaddr, which is all page table walking stuff.

 arch/arm/include/asm/pgalloc.h |   34 +++++++++++++++-------------------
 arch/arm/include/asm/pgtable.h |   30 +++++++++++++++---------------
 arch/arm/mm/fault.c            |    2 +-
 arch/arm/mm/mmu.c              |    2 +-
 arch/arm/mm/proc-macros.S      |   10 +++++-----
 arch/arm/mm/proc-v7.S          |    8 +++-----
 6 files changed, 40 insertions(+), 46 deletions(-)
arch/arm/include/asm/pgalloc.h +15 -19
index b12cc98..e2a6613 100644
@@ -38,6 +38,11 @@ extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd);
 
 #define PGALLOC_GFP	(GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
 
+static inline void clean_pte_table(void *ptr)
+{
+	clean_dcache_area(ptr + PTE_HWTABLE_OFF, PTE_HWTABLE_SIZE);
+}
+
 /*
  * Allocate one PTE table.
  *
@@ -60,10 +65,8 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
 	pte_t *pte;
 
 	pte = (pte_t *)__get_free_page(PGALLOC_GFP);
-	if (pte) {
-		clean_dcache_area(pte, sizeof(pte_t) * PTRS_PER_PTE);
-		pte += PTRS_PER_PTE;
-	}
+	if (pte)
+		clean_pte_table(pte);
 
 	return pte;
 }
@@ -79,10 +82,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 	pte = alloc_pages(PGALLOC_GFP, 0);
 #endif
 	if (pte) {
-		if (!PageHighMem(pte)) {
-			void *page = page_address(pte);
-			clean_dcache_area(page, sizeof(pte_t) * PTRS_PER_PTE);
-		}
+		if (!PageHighMem(pte))
+			clean_pte_table(page_address(pte));
 		pgtable_page_ctor(pte);
 	}
 
@@ -94,10 +95,8 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  */
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
-	if (pte) {
-		pte -= PTRS_PER_PTE;
+	if (pte)
 		free_page((unsigned long)pte);
-	}
 }
 
 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
@@ -106,8 +105,9 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 	__free_page(pte);
 }
 
-static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval)
+static inline void __pmd_populate(pmd_t *pmdp, unsigned long pte, unsigned long prot)
 {
+	unsigned long pmdval = (pte + PTE_HWTABLE_OFF) | prot;
 	pmdp[0] = __pmd(pmdval);
 	pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
 	flush_pmd_entry(pmdp);
@@ -122,20 +122,16 @@ static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval)
 static inline void
 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
 {
-	unsigned long pte_ptr = (unsigned long)ptep;
-
 	/*
-	 * The pmd must be loaded with the physical
-	 * address of the PTE table
+	 * The pmd must be loaded with the physical address of the PTE table
 	 */
-	pte_ptr -= PTRS_PER_PTE * sizeof(void *);
-	__pmd_populate(pmdp, __pa(pte_ptr) | _PAGE_KERNEL_TABLE);
+	__pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
 }
 
 static inline void
 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
 {
-	__pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE);
+	__pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT, _PAGE_USER_TABLE);
 }
 #define pmd_pgtable(pmd) pmd_page(pmd)
 
arch/arm/include/asm/pgtable.h +15 -15
index b155414..d9f1bfa 100644
@@ -54,7 +54,7 @@
  * Therefore, we tweak the implementation slightly - we tell Linux that we
  * have 2048 entries in the first level, each of which is 8 bytes (iow, two
  * hardware pointers to the second level.)  The second level contains two
- * hardware PTE tables arranged contiguously, followed by Linux versions
+ * hardware PTE tables arranged contiguously, preceded by Linux versions
  * which contain the state information Linux needs.  We, therefore, end up
  * with 512 entries in the "PTE" level.
  *
@@ -62,15 +62,15 @@
  *
  *    pgd             pte
  * |        |
- * +--------+ +0
- * |        |-----> +------------+ +0
+ * +--------+
+ * |        |       +------------+ +0
+ * +- - - - +       | Linux pt 0 |
+ * |        |       +------------+ +1024
+ * +--------+ +0    | Linux pt 1 |
+ * |        |-----> +------------+ +2048
  * +- - - - + +4    |  h/w pt 0  |
- * |        |-----> +------------+ +1024
+ * |        |-----> +------------+ +3072
  * +--------+ +8    |  h/w pt 1  |
- * |        |       +------------+ +2048
- * +- - - - +       | Linux pt 0 |
- * |        |       +------------+ +3072
- * +--------+       | Linux pt 1 |
  * |        |       +------------+ +4096
  *
  * See L_PTE_xxx below for definitions of bits in the "Linux pt", and
@@ -102,6 +102,10 @@
 #define PTRS_PER_PMD		1
 #define PTRS_PER_PGD		2048
 
+#define PTE_HWTABLE_PTRS	(PTRS_PER_PTE)
+#define PTE_HWTABLE_OFF		(PTE_HWTABLE_PTRS * sizeof(pte_t))
+#define PTE_HWTABLE_SIZE	(PTRS_PER_PTE * sizeof(u32))
+
 /*
  * PMD_SHIFT determines the size of the area a second-level page table can map
  * PGDIR_SHIFT determines what a third-level page table entry can map
@@ -270,8 +274,8 @@ extern struct page *empty_zero_page;
 #define __pte_map(dir)		pmd_page_vaddr(*(dir))
 #define __pte_unmap(pte)	do { } while (0)
 #else
-#define __pte_map(dir)		((pte_t *)kmap_atomic(pmd_page(*(dir))) + PTRS_PER_PTE)
-#define __pte_unmap(pte)	kunmap_atomic((pte - PTRS_PER_PTE))
+#define __pte_map(dir)		(pte_t *)kmap_atomic(pmd_page(*(dir)))
+#define __pte_unmap(pte)	kunmap_atomic(pte)
 #endif
 
 #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext)
@@ -364,11 +368,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 
 static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 {
-	unsigned long ptr;
-
-	ptr = pmd_val(pmd) & ~(PTRS_PER_PTE * sizeof(void *) - 1);
-	ptr += PTRS_PER_PTE * sizeof(void *);
-
+	unsigned long ptr = pmd_val(pmd) & PAGE_MASK;
 	return __va(ptr);
 }
 
arch/arm/mm/fault.c +1 -1
index 1e21e12..f10f9ba 100644
@@ -108,7 +108,7 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
 		pte = pte_offset_map(pmd, addr);
 		printk(", *pte=%08lx", pte_val(*pte));
-		printk(", *ppte=%08lx", pte_val(pte[-PTRS_PER_PTE]));
+		printk(", *ppte=%08lx", pte_val(pte[PTE_HWTABLE_PTRS]));
 		pte_unmap(pte);
 	} while(0);
 
arch/arm/mm/mmu.c +1 -1
index 72ad3e1..9963189 100644
@@ -535,7 +535,7 @@ static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned l
 {
 	if (pmd_none(*pmd)) {
 		pte_t *pte = early_alloc(2 * PTRS_PER_PTE * sizeof(pte_t));
-		__pmd_populate(pmd, __pa(pte) | prot);
+		__pmd_populate(pmd, __pa(pte), prot);
 	}
 	BUG_ON(pmd_bad(*pmd));
 	return pte_offset_kernel(pmd, addr);
arch/arm/mm/proc-macros.S +5 -5
index 7d63bea..cbedf9c 100644
@@ -121,7 +121,7 @@
 	.endm
 
 	.macro	armv6_set_pte_ext pfx
-	str	r1, [r0], #-2048		@ linux version
+	str	r1, [r0], #2048			@ linux version
 
 	bic	r3, r1, #0x000003fc
 	bic	r3, r3, #PTE_TYPE_MASK
@@ -170,7 +170,7 @@
  *  1111  0xff	r/w	r/w
  */
 	.macro	armv3_set_pte_ext wc_disable=1
-	str	r1, [r0], #-2048		@ linux version
+	str	r1, [r0], #2048			@ linux version
 
 	eor	r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
 
@@ -193,7 +193,7 @@
 	bicne	r2, r2, #PTE_BUFFERABLE
 #endif
 	.endif
-	str	r2, [r0]			@ hardware version
+	str	r2, [r0]		@ hardware version
 	.endm
 
 
@@ -213,7 +213,7 @@
  *  1111  11	r/w	r/w
  */
 	.macro	xscale_set_pte_ext_prologue
-	str	r1, [r0], #-2048		@ linux version
+	str	r1, [r0]			@ linux version
 
 	eor	r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
 
@@ -232,7 +232,7 @@
 	tst	r3, #L_PTE_PRESENT | L_PTE_YOUNG	@ present and young?
 	movne	r2, #0				@ no -> fault
 
-	str	r2, [r0]			@ hardware version
+	str	r2, [r0, #2048]!		@ hardware version
 	mov	ip, #0
 	mcr	p15, 0, r0, c7, c10, 1		@ clean L1 D line
 	mcr	p15, 0, ip, c7, c10, 4		@ data write barrier
arch/arm/mm/proc-v7.S +3 -5
index 53cbe22..89c31a6 100644
@@ -124,15 +124,13 @@ ENDPROC(cpu_v7_switch_mm)
  *	Set a level 2 translation table entry.
  *
  *	- ptep  - pointer to level 2 translation table entry
- *		  (hardware version is stored at -1024 bytes)
+ *		  (hardware version is stored at +2048 bytes)
  *	- pte   - PTE value to store
  *	- ext	- value for extended PTE bits
  */
 ENTRY(cpu_v7_set_pte_ext)
 #ifdef CONFIG_MMU
- ARM(	str	r1, [r0], #-2048	)	@ linux version
- THUMB(	str	r1, [r0]		)	@ linux version
- THUMB(	sub	r0, r0, #2048		)
+	str	r1, [r0]			@ linux version
 
 	bic	r3, r1, #0x000003f0
 	bic	r3, r3, #PTE_TYPE_MASK
@@ -158,7 +156,7 @@ ENTRY(cpu_v7_set_pte_ext)
 	tstne	r1, #L_PTE_PRESENT
 	moveq	r3, #0
 
-	str	r3, [r0]
+	str	r3, [r0, #2048]!
 	mcr	p15, 0, r0, c7, c10, 1		@ flush_pte
 #endif
 	mov	pc, lr
#31 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Catalin Marinas
Quoted 19 lines · Catalin Marinas

The LPAE page table format needs to explicitly disable execution or write permissions on a page by setting the corresponding bits (similar to the classic page table format with Access Flag enabled). This patch introduces null definitions for the 2-level format and the actual noexec and nowrite bits for the LPAE format. It also changes several PTE maintenance macros and masks.

---
 arch/arm/include/asm/pgtable-2level.h |    2 +
 arch/arm/include/asm/pgtable.h        |   44 +++++++++++++++++++++------------
 arch/arm/mm/mmu.c                     |    6 ++--
 3 files changed, 33 insertions(+), 19 deletions(-)
arch/arm/include/asm/pgtable-2level.h +0 -0
index 36bdef7..4e21166 100644

arch/arm/include/asm/pgtable-2level.h line 132

Quoted 5 lines
arch/arm/include/asm/pgtable-2level.h +2 -0
@@ -128,6 +128,8 @@
 #define L_PTE_USER		(1 << 8)
 #define L_PTE_EXEC		(1 << 9)
 #define L_PTE_SHARED		(1 << 10)	/* shared(v6), coherent(xsc3) */
+#define L_PTE_NOEXEC		(0)
+#define L_PTE_NOWRITE		(0)

Let's not make this more complicated than it has to be. If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

We're already inverting the write bit for the vast majority of processors, and exec has always been inverted by the ARMv6 and v7 code.

#44 lore raw

Re: [PATCH v2 06/20] ARM: LPAE: Introduce the 3-level page table format definitions

In reply to Catalin Marinas
Quoted 74 lines · Catalin Marinas

This patch introduces the pgtable-3level*.h files with definitions specific to the LPAE page table format (3 levels of page tables).

Each table is 4KB and has 512 64-bit entries. An entry can point to a 40-bit physical address. The young, write and exec software bits share the corresponding hardware bits (negated). Other software bits use spare bits in the PTE.

The patch also changes some variable types from unsigned long or int to pteval_t or pgprot_t.

---
 arch/arm/include/asm/page.h                 |    4 +
 arch/arm/include/asm/pgtable-3level-hwdef.h |   78 ++++++++++++++++++
 arch/arm/include/asm/pgtable-3level-types.h |   55 +++++++++++++
 arch/arm/include/asm/pgtable-3level.h       |  113 +++++++++++++++++++++++++++
 arch/arm/include/asm/pgtable-hwdef.h        |    4 +
 arch/arm/include/asm/pgtable.h              |    6 +-
 arch/arm/mm/mm.h                            |    8 +-
 arch/arm/mm/mmu.c                           |    2 +-
 8 files changed, 264 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/include/asm/pgtable-3level-hwdef.h
 create mode 100644 arch/arm/include/asm/pgtable-3level-types.h
 create mode 100644 arch/arm/include/asm/pgtable-3level.h
arch/arm/include/asm/page.h +4 -0
index 3848105..e5124db 100644
@@ -151,7 +151,11 @@ extern void __cpu_copy_user_highpage(struct page *to, struct page *from,
 #define clear_page(page)	memset((void *)(page), 0, PAGE_SIZE)
 extern void copy_page(void *to, const void *from);
 
+#ifdef CONFIG_ARM_LPAE
+#include <asm/pgtable-3level-types.h>
+#else
 #include <asm/pgtable-2level-types.h>
+#endif
 
 #endif /* CONFIG_MMU */
 
arch/arm/include/asm/pgtable-3level-hwdef.h new file +26 -0
new file mode 100644
index 0000000..2f99c3c
@@ -0,0 +1,78 @@
+/*
+ * arch/arm/include/asm/pgtable-3level-hwdef.h
+ *
+ * Copyright (C) 2010 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _ASM_PGTABLE_3LEVEL_HWDEF_H
+#define _ASM_PGTABLE_3LEVEL_HWDEF_H
+
+#include <linux/const.h>
+#include <asm/pgtable-3level-types.h>
+
+/*
+ * Hardware page table definitions.

arch/arm/include/asm/pgtable-3level-hwdef.h line 36

Quoted 10 lines
arch/arm/include/asm/pgtable-3level-hwdef.h new file +10 -0
+ *
+ * + Level 1/2 descriptor
+ *   - common
+ */
+#define PMD_TYPE_MASK		(_AT(pmd_t, 3) << 0)
+#define PMD_TYPE_FAULT		(_AT(pmd_t, 0) << 0)
+#define PMD_TYPE_TABLE		(_AT(pmd_t, 3) << 0)
+#define PMD_TYPE_SECT		(_AT(pmd_t, 1) << 0)
+#define PMD_BIT4		(_AT(pmd_t, 0))
+#define PMD_DOMAIN(x)		(_AT(pmd_t, 0))

It is really not correct to have these constants type'd as pmd_t. The idea behind pmd_t et.al. is to detect when normal arithmetic or logical operations are performed on page table entries when the accessors instead should be used.

By typing these as pmd_t, it means operations need to be:

	u32 pmdval = pmd_val(foo) | pmd_val(PMD_TYE_TABLE);

which is obviously more complicated than is needed.

Quoted 6 lines
arch/arm/mm/mm.h +0 -0
index 6630620..a62f093 100644
@@ -16,10 +16,10 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
 }

arch/arm/mm/mm.h static inline pmd_t *pmd_off_k(unsigned long virt) · line 22

Quoted 10 lines
arch/arm/mm/mm.h +4 -4
 
 struct mem_type {
-	unsigned int prot_pte;
-	unsigned int prot_l1;
-	unsigned int prot_sect;
-	unsigned int domain;
+	pgprot_t prot_pte;
+	pgprot_t prot_l1;
+	pgprot_t prot_sect;
+	pgprot_t domain;

Again, this is wrong. There's an accessor for pgprot_t typed data. This causes code to violate it.

arch/arm/mm/mmu.c static void __init build_mem_type_table(void) · line 295

Quoted 10 lines
arch/arm/mm/mmu.c +1 -1
index 0ca33dd..7c803c4 100644
@@ -292,7 +292,7 @@ static void __init build_mem_type_table(void)
 {
 	struct cachepolicy *cp;
 	unsigned int cr = get_cr();
-	unsigned int user_pgprot, kern_pgprot, vecs_pgprot;
+	pgprot_t user_pgprot, kern_pgprot, vecs_pgprot;

Ditto.

#29 lore raw

Re: [PATCH v2 04/20] ARM: LPAE: Do not assume Linux PTEs are always at PTRS_PER_PTE offset

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux
Quoted 5 lines · Catalin Marinas

Placing the Linux PTEs at a 2KB offset inside a page is a workaround for the 2-level page table format where not enough spare bits are available. With LPAE this is no longer required. This patch changes such assumption by using a different macro, LINUX_PTE_OFFSET, which is defined to PTRS_PER_PTE for the 2-level page tables.

Quoted 5 lines

Hmm. ?I think we should be doing this a different way - in fact, I think we should switch the order of the linux vs hardware page tables. ?This actually simplifies the code a bit too - notice that we lose the arith. in __pte_map, __pte_unmap, pmd_page_vaddr, which is all page table walking stuff.

It looks like a good clean-up to me (though I need some refactoring on my LPAE patches). Do you plan to push this upstream? If you add a comment and a signed-off line, I can carry it in my LPAE branch until it appears in mainline.

Thanks.

Signature · 1 line
Catalin
#23 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. Generic code cases pte values to (long long) and prints them using %08llx. We should do the same.

Quoted 7 lines
Quoted 5 lines

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Why not just %010llx? That would just be two extra characters.

Not on non-LPAE build, please.

Nicolas

#20 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Quoted 4 lines
Quoted 1 line

Why not just %010llx? That would just be two extra characters.

We still have attributes (like XN, bit 54) stored in the top part of the pte. This may be of interest when debugging.

They will be printed if they exist. The %010 in front of llx only means to have a minimum of 10 zero-paded digits if the value is smaller than that.

However, not having aligned values will be confusing. A macro for the format might be the best compromize.

Nicolas

#6 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Catalin Marinas
Quoted 2 lines · Catalin Marinas

This patch moves page table definitions from asm/page.h, asm/pgtable.h and asm/ptgable-hwdef.h into corresponding *-2level* files.

This also introduces pteval_t. It would be useful to have the introduction of pteval_t as a separate patch, which not only introduces the typedef, but also makes use of it.

arch/arm/include/asm/pgtable-2level-types.h line 30

Quoted 12 lines
arch/arm/include/asm/pgtable-2level-types.h new file +12 -0
+#ifndef _ASM_PGTABLE_2LEVEL_TYPES_H
+#define _ASM_PGTABLE_2LEVEL_TYPES_H
+
+#undef STRICT_MM_TYPECHECKS
+
+typedef unsigned long pteval_t;
+
+#ifdef STRICT_MM_TYPECHECKS
+/*
+ * These are used to make use of C type-checking..
+ */
+typedef struct { unsigned long pte; } pte_t;

This should become:

typedef struct { pteval_t pte; } pte_t;

L_PTE_* can then be declared using linux/const.h stuff to typedef them to pteval_t. shared_pte_mask also needs to be pteval_t.

As far as the __p*_error() functions, these should probably be passed the pte/pmd/pgd value itself, rather than first passing them through __pte_val() et.al.

Of couse, I now have patches for this and my other points... will sort them out into a series in the next few days.

#21 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Nicolas Pitre
Quoted 19 lines · Nicolas Pitre
Quoted 12 lines · Catalin Marinas
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Quoted 4 lines
Quoted 1 line

Why not just %010llx? That would just be two extra characters.

We still have attributes (like XN, bit 54) stored in the top part of the pte. This may be of interest when debugging.

Quoted 6 lines

They will be printed if they exist. The %010 in front of llx only means to have a minimum of 10 zero-paded digits if the value is smaller than that.

However, not having aligned values will be confusing. A macro for the format might be the best compromize.

It's what is done in the generic kernel code for page table entries.

        printk(KERN_ALERT
                "BUG: Bad page map in process %s  pte:%08llx pmd:%08llx\n",
                current->comm,
                (long long)pte_val(pte), (long long)pmd_val(*pmd));

The places where this matters, there isn't any alignment between lines to worry about:

	printk(", *pmd=%08lx", pmd_val(*pmd));
	printk(", *pte=%08lx", pte_val(*pte));
	printk(", *ppte=%08lx", pte_val(pte[-PTRS_PER_PTE]));

in show_pte() are examples of what need changing.

#7 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux
Quoted 2 lines · Catalin Marinas

This patch moves page table definitions from asm/page.h, asm/pgtable.h and asm/ptgable-hwdef.h into corresponding *-2level* files.

This also introduces pteval_t. ?It would be useful to have the introduction of pteval_t as a separate patch, which not only introduces the typedef, but also makes use of it.

I can do this. I missed this while splitting my initial big diff.

Quoted 15 lines

arch/arm/include/asm/pgtable-2level-types.h line 30

Quoted 12 lines
arch/arm/include/asm/pgtable-2level-types.h new file +12 -0
+#ifndef _ASM_PGTABLE_2LEVEL_TYPES_H
+#define _ASM_PGTABLE_2LEVEL_TYPES_H
+
+#undef STRICT_MM_TYPECHECKS
+
+typedef unsigned long pteval_t;
+
+#ifdef STRICT_MM_TYPECHECKS
+/*
+ * These are used to make use of C type-checking..
+ */
+typedef struct { unsigned long pte; } pte_t;

This should become:

Quoted 4 lines

typedef struct { pteval_t pte; } pte_t;

L_PTE_* can then be declared using linux/const.h stuff to typedef them to pteval_t.

I already do this for LPAE but can be done for the 2-level definitions for consistency.

BTW, do you think it's worth adding STRICT_MM_TYPECHECKS for LPAE as well? It would probably spot some issues.

Quoted 1 line

shared_pte_mask also needs to be pteval_t.

That's done in the 3rd version of the series.

Quoted 6 lines

As far as the __p*_error() functions, these should probably be passed the pte/pmd/pgd value itself, rather than first passing them through __pte_val() et.al.

Of couse, I now have patches for this and my other points... will sort them out into a series in the next few days.

Thanks.

Signature · 1 line
Catalin
#22 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Nicolas Pitre
Quoted 19 lines · Nicolas Pitre
Quoted 12 lines · Catalin Marinas
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · On Monday 15 November 2010 10:39:30 Catalin Marinas wrote:
Quoted 3 lines

There will be compiler warnings because u32 is unsigned int, and we print it as %08lx. ?Generic code cases pte values to (long long) and prints them using %08llx. ?We should do the same.

We still need some kind of macro because with LPAE we need %016llx since the phys address can go to 40-bit and there are some additional bits in the top word. Unless you'd like to always print 16 characters even for 32-bit ptes (or if there is some other printk magic I'm not aware of).

Quoted 4 lines
Quoted 1 line

Why not just %010llx? That would just be two extra characters.

We still have attributes (like XN, bit 54) stored in the top part of the pte. This may be of interest when debugging.

Quoted 6 lines

They will be printed if they exist. The %010 in front of llx only means to have a minimum of 10 zero-paded digits if the value is smaller than that.

However, not having aligned values will be confusing. ?A macro for the format might be the best compromize.

We thought about using something like

printk("%0*llx", sizeof(pteval_t) * 2, (long long)pte_val(pte));

but it complicates the code.

Anyway, since these are printed for debugging mainline, we can probably cope with some lack of alignment (as Russell said, there may not be any where it matters).

Signature · 1 line
Catalin
#45 lore raw

Re: [PATCH v2 06/20] ARM: LPAE: Introduce the 3-level page table format definitions

In reply to Russell King - ARM Linux
Quoted 12 lines · Russell King - ARM Linux

Review

Quoted 6 lines · Catalin Marinas
(quoted diff) +6 -0
+#define PMD_TYPE_MASK ? ? ? ? ? ? ? ?(_AT(pmd_t, 3) << 0)
+#define PMD_TYPE_FAULT ? ? ? ? ? ? ? (_AT(pmd_t, 0) << 0)
+#define PMD_TYPE_TABLE ? ? ? ? ? ? ? (_AT(pmd_t, 3) << 0)
+#define PMD_TYPE_SECT ? ? ? ? ? ? ? ?(_AT(pmd_t, 1) << 0)
+#define PMD_BIT4 ? ? ? ? ? ? (_AT(pmd_t, 0))
+#define PMD_DOMAIN(x) ? ? ? ? ? ? ? ?(_AT(pmd_t, 0))

It is really not correct to have these constants type'd as pmd_t. The idea behind pmd_t et.al. is to detect when normal arithmetic or logical operations are performed on page table entries when the accessors instead should be used.

OK, I can add pmdval_t (and pgdval_t) and use it for these definitions.

Quoted 7 lines
Quoted 7 lines
arch/arm/mm/mm.h +0 -0
index 6630620..a62f093 100644
@@ -16,10 +16,10 @@ static inline pmd_t *pmd_off_k(unsigned long virt)
 ?}
 
Quoted 12 lines

arch/arm/mm/mm.h static inline pmd_t *pmd_off_k(unsigned long virt) · line 22

Quoted 9 lines
arch/arm/mm/mm.h +4 -4
 ?struct mem_type {
- ? ? unsigned int prot_pte;
- ? ? unsigned int prot_l1;
- ? ? unsigned int prot_sect;
- ? ? unsigned int domain;
+ ? ? pgprot_t prot_pte;
+ ? ? pgprot_t prot_l1;
+ ? ? pgprot_t prot_sect;
+ ? ? pgprot_t domain;

Again, this is wrong. ?There's an accessor for pgprot_t typed data. ?This causes code to violate it.

OK, I'll define pgprotval_t and accessors.

Signature · 1 line
Catalin
#8 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Catalin Marinas
Quoted 11 lines · Catalin Marinas
Quoted 6 lines · Russell King - ARM Linux

This should become:

typedef struct { pteval_t pte; } pte_t;

L_PTE_* can then be declared using linux/const.h stuff to typedef them to pteval_t.

I already do this for LPAE but can be done for the 2-level definitions for consistency.

No you don't. You define the 2nd level definitions using pmd_t which is _wrong_. pmd_t is the type of the pmd container, not the pmd value.

Quoted 2 lines

BTW, do you think it's worth adding STRICT_MM_TYPECHECKS for LPAE as well? It would probably spot some issues.

Definitely, because it'll throw out warnings for most of your _AT(pmd_t,) definitions.

#9 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

Quoted 7 lines · Russell King - ARM Linux
Quoted 6 lines · Catalin Marinas
Quoted 4 lines · Russell King - ARM Linux

This should become:

typedef struct { pteval_t pte; } pte_t;

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

L_PTE_* can then be declared using linux/const.h stuff to typedef them to pteval_t.

I already do this for LPAE but can be done for the 2-level definitions for consistency.

No you don't. ?You define the 2nd level definitions using pmd_t which is _wrong_. ?pmd_t is the type of the pmd container, not the pmd value.

I was only referring to L_PTE_*. The PMD_* definitions are wrong indeed.

Signature · 1 line
Catalin
#10 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Catalin Marinas
Quoted 4 lines · Catalin Marinas
Quoted 2 lines

Of couse, I now have patches for this and my other points... will sort them out into a series in the next few days.

Thanks.

BTW, don't post another round of patches just because you've had _some_ comments back - your v2 patches are still being looked through, your v3 patches haven't even been looked at yet.

It took some 4 hours for the mailing list to get through last nights posting frenzy that it really isn't worth overloading - is it really worth bringing the list server to its knees when the job is only half done?

#32 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Russell King - ARM Linux
Quoted 13 lines · Russell King - ARM Linux

arch/arm/include/asm/pgtable-2level.h

Quoted 8 lines · Catalin Marinas
arch/arm/include/asm/pgtable-2level.h +0 -0
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

Yes, that's fine.

For PMD, we may still need a dummy PMD_SECT_AP_WRITE for the 3-level definitions unless we change the __pmd() accessor or __pmd_populate().

Signature · 1 line
Catalin
#11 lore raw

Re: [PATCH v2 02/20] ARM: LPAE: Factor out 2-level page table definitions into separate files

In reply to Russell King - ARM Linux
Quoted 9 lines · Russell King - ARM Linux
Quoted 4 lines · Catalin Marinas
Quoted 2 lines

Of couse, I now have patches for this and my other points... will sort them out into a series in the next few days.

Thanks.

BTW, don't post another round of patches just because you've had _some_ comments back - your v2 patches are still being looked through, your v3 patches haven't even been looked at yet.

I'll wait for your patches on the PTE offset and than rebase mine on top. It may be sometime next week as I already have a lot to do.

I posted the v3 patches just to clarify the issues around the 3/20 patch. The other patches are pretty much the same, so you can skip this version and wait for v4.

Signature · 1 line
Catalin
#33 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Russell King - ARM Linux
Quoted 15 lines · Russell King - ARM Linux
Quoted 14 lines · Catalin Marinas

The LPAE page table format needs to explicitly disable execution or write permissions on a page by setting the corresponding bits (similar to the classic page table format with Access Flag enabled). This patch introduces null definitions for the 2-level format and the actual noexec and nowrite bits for the LPAE format. It also changes several PTE maintenance macros and masks.

---

?arch/arm/include/asm/pgtable-2level.h | ? ?2 +
?arch/arm/include/asm/pgtable.h ? ? ? ?| ? 44 +++++++++++++++++++++------------
?arch/arm/mm/mmu.c ? ? ? ? ? ? ? ? ? ? | ? ?6 ++--

?3 files changed, 33 insertions(+), 19 deletions(-)

Quoted 14 lines

arch/arm/include/asm/pgtable-2level.h

Quoted 10 lines
arch/arm/include/asm/pgtable-2level.h +0 -0
index 36bdef7..4e21166 100644
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

This adds an additional instruction in set_pte_ext, unless you can write the bit checking in a better way:

	tst	r1, #L_PTE_NOWRITE
	orrne	r3, r3, #PTE_EXT_APX
	tsteq	r1, #L_PTE_DIRTY
	orreq	r3, r3, #PTE_EXT_APX
Signature · 1 line
Catalin
#34 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 32 lines · Catalin Marinas
Quoted 15 lines · Russell King - ARM Linux
Quoted 14 lines · Catalin Marinas

The LPAE page table format needs to explicitly disable execution or write permissions on a page by setting the corresponding bits (similar to the classic page table format with Access Flag enabled). This patch introduces null definitions for the 2-level format and the actual noexec and nowrite bits for the LPAE format. It also changes several PTE maintenance macros and masks.

---

?arch/arm/include/asm/pgtable-2level.h | ? ?2 +
?arch/arm/include/asm/pgtable.h ? ? ? ?| ? 44 +++++++++++++++++++++------------
?arch/arm/mm/mmu.c ? ? ? ? ? ? ? ? ? ? | ? ?6 ++--

?3 files changed, 33 insertions(+), 19 deletions(-)

Quoted 14 lines

arch/arm/include/asm/pgtable-2level.h

Quoted 10 lines
arch/arm/include/asm/pgtable-2level.h +0 -0
index 36bdef7..4e21166 100644
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

Quoted 7 lines

This adds an additional instruction in set_pte_ext, unless you can write the bit checking in a better way:

? ? ? ?tst ? ? r1, #L_PTE_NOWRITE
? ? ? ?orrne ? r3, r3, #PTE_EXT_APX
? ? ? ?tsteq ? r1, #L_PTE_DIRTY
? ? ? ?orreq ? r3, r3, #PTE_EXT_APX

I think that would work with 3 instructions:

	eor	r1, r1, L_PTE_DIRTY
	tst	r1, #L_PTE_NOWRITE | L_PTE_DIRTY
	orrne	r3, r3, #PTE_EXT_APX
Signature · 1 line
Catalin
#35 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas
Quoted 3 lines · Russell King - ARM Linux

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

This adds an additional instruction in set_pte_ext, unless you can write the bit checking in a better way:

It actually results in the same number of instructions. From memory:

ARMv3-ARMv5:
- eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
- tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ write and dirty?
- orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
+ eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY
+ tst r3, #L_PTE_RDONLY | L_PTE_DIRTY @ write and dirty?
+ orreq r2, r2, #PTE_SMALL_AP_UNO_SRW

and for ARMv6+:

- tst r1, #L_PTE_WRITE
- tstne r1, #L_PTE_DIRTY
- orreq r3, r3, #PTE_EXT_APX
+ eor r1, r1, #L_PTE_DIRTY
+ tst r1, #L_PTE_RDONLY | L_PTE_DIRTY
+ orrne r3, r3, #PTE_EXT_APX

#26 lore raw

Re: [PATCH v2 03/20] ARM: LPAE: use u32 instead of unsigned long for 32-bit ptes

In reply to Catalin Marinas
Quoted 17 lines · Catalin Marinas
Quoted 15 lines · Russell King - ARM Linux
Quoted 9 lines · Catalin Marinas

From: Will Deacon <[email protected]>

When using 2-level paging, pte_t and pmd_t are typedefs for unsigned long but phys_addr_t is a typedef for u32.

This patch uses u32 for the page table entry types when phys_addr_t is not 64-bit, allowing the same conversion specifier to be used for physical addresses and page table entries regardless of LPAE.

However, code which prints the value of page table entries assumes that they are unsigned long, and places where we store the raw pte value also uses 'unsigned long'.

Quoted 6 lines
Quoted 2 lines

If we're going to make this change, we need to change more places than this patch covers. ?grep for pte_val to help find those places.

Patch 19/20 introduces a common macro for formatting but we should probably order the patches a bit to avoid problems if anyone is bisecting ?in the middle of the series.

Actually not a problem since LPAE is only enabled by the last patch. There may be some compiler warnings without 19/20, I need to check.

Signature · 1 line
Catalin
#36 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

In reply to Russell King - ARM Linux
Quoted 13 lines · Russell King - ARM Linux

arch/arm/include/asm/pgtable-2level.h

Quoted 8 lines · Catalin Marinas
arch/arm/include/asm/pgtable-2level.h +0 -0
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

Question on the pgprot_noncached/writecombine/dmacoherent - in the current implementation we pass L_PTE_EXEC on the dmacoherent macro. Do we need to pass L_PTE_NOEXEC to the noncached/writecombine ones? I don't see a reason for any of these to be executable but maybe we can let the code calling them decide.

Thanks.

Signature · 1 line
Catalin
#37 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 16 lines · Catalin Marinas
Quoted 13 lines · Russell King - ARM Linux

arch/arm/include/asm/pgtable-2level.h

Quoted 8 lines · Catalin Marinas
arch/arm/include/asm/pgtable-2level.h +0 -0
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

Quoted 2 lines

Question on the pgprot_noncached/writecombine/dmacoherent - in the current implementation we pass L_PTE_EXEC on the dmacoherent macro.

Erm. Please look at the code again.

#38 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 17 lines · Russell King - ARM Linux
Quoted 16 lines · Catalin Marinas
Quoted 13 lines · Russell King - ARM Linux

arch/arm/include/asm/pgtable-2level.h

Quoted 8 lines · Catalin Marinas
arch/arm/include/asm/pgtable-2level.h +0 -0
@@ -128,6 +128,8 @@
 ?#define L_PTE_USER ? ? ? ? ? (1 << 8)
 ?#define L_PTE_EXEC ? ? ? ? ? (1 << 9)

?#define L_PTE_SHARED ? ? ? ? (1 << 10) ? ? ? /* shared(v6), coherent(xsc3) */

arch/arm/include/asm/pgtable-2level.h +2 -0
+#define L_PTE_NOEXEC ? ? ? ? (0)
+#define L_PTE_NOWRITE ? ? ? ? ? ? ? ?(0)

Let's not make this more complicated than it has to be. ?If we need the inverse of WRITE and EXEC, then that's what we should change everyone to, not invent a new system to work along side the old system.

Quoted 4 lines
Quoted 2 lines

Question on the pgprot_noncached/writecombine/dmacoherent - in the current implementation we pass L_PTE_EXEC on the dmacoherent macro.

Erm. ?Please look at the code again.

Ah, good point, that was the mask.

So for dmacoherent we make sure that L_PTE_EXEC is cleared. I suspect we should now make sure that L_PTE_NOEXEC is set. For the other two, just leave them as they are.

Signature · 1 line
Catalin
#39 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 5 lines · Catalin Marinas

Ah, good point, that was the mask.

So for dmacoherent we make sure that L_PTE_EXEC is cleared. I suspect we should now make sure that L_PTE_NOEXEC is set. For the other two, just leave them as they are.

Already done:

#define pgprot_dmacoherent(prot) \
- __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
+ __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE|L_PTE_XN)
...
#define pgprot_dmacoherent(prot) \
- __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_UNCACHED)
+ __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED|L_PTE_XN)

#40 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 10 lines · Russell King - ARM Linux
Quoted 5 lines · Catalin Marinas

Ah, good point, that was the mask.

So for dmacoherent we make sure that L_PTE_EXEC is cleared. I suspect we should now make sure that L_PTE_NOEXEC is set. For the other two, just leave them as they are.

Already done:

#define pgprot_dmacoherent(prot) \

Review

Quoted 6 lines
(quoted diff) +2 -2
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE|L_PTE_XN)
...
 #define pgprot_dmacoherent(prot) \
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_UNCACHED)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED|L_PTE_XN)

Are you already doing such changes? Just to avoid duplicating effort (and use common naming scheme).

Signature · 1 line
Catalin
#41 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 18 lines · Catalin Marinas
Quoted 10 lines · Russell King - ARM Linux
Quoted 5 lines · Catalin Marinas

Ah, good point, that was the mask.

So for dmacoherent we make sure that L_PTE_EXEC is cleared. I suspect we should now make sure that L_PTE_NOEXEC is set. For the other two, just leave them as they are.

Already done:

#define pgprot_dmacoherent(prot) \

Review

Quoted 6 lines
(quoted diff) +2 -2
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE|L_PTE_XN)
...
 #define pgprot_dmacoherent(prot) \
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_UNCACHED)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED|L_PTE_XN)
Quoted 2 lines

Are you already doing such changes? Just to avoid duplicating effort (and use common naming scheme).

I did say that I had patches for all the issues I raised so far... They're just in the process of being posted (if lists.infradead.org this time can cope with one patch every 20 secs...)

#42 lore raw

Re: [PATCH v2 05/20] ARM: LPAE: Introduce L_PTE_NOEXEC and L_PTE_NOWRITE

Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Catalin Marinas
Quoted 16 lines · Russell King - ARM Linux
Quoted 5 lines · Catalin Marinas

Ah, good point, that was the mask.

So for dmacoherent we make sure that L_PTE_EXEC is cleared. I suspect we should now make sure that L_PTE_NOEXEC is set. For the other two, just leave them as they are.

Already done:

#define pgprot_dmacoherent(prot) \

(quoted diff) +2 -2
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE|L_PTE_XN)
...
 #define pgprot_dmacoherent(prot) \
-       __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_UNCACHED)
+       __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED|L_PTE_XN)
Quoted 6 lines
Quoted 2 lines

Are you already doing such changes? Just to avoid duplicating effort (and use common naming scheme).

I did say that I had patches for all the issues I raised so far... They're just in the process of being posted (if lists.infradead.org this time can cope with one patch every 20 secs...)

I wasn't sure which patches, so I did the XN/RDONLY as well (not big patch though).

I'll rebase my LPAE stuff in the next days and repost.

Thanks.

Signature · 1 line
Catalin
#2 lore raw

Re: [PATCH v2 01/20] ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*

In reply to Catalin Marinas
Quoted 22 lines · Catalin Marinas
arch/arm/kernel/smp.c +2 -2
index 8c19595..40b386c 100644
@@ -78,7 +78,7 @@ static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
 	if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
 		prot |= PMD_BIT4;
 
-	for (addr = start & PGDIR_MASK; addr < end;) {
+	for (addr = start & PMD_MASK; addr < end;) {
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(addr | prot);
 		addr += SECTION_SIZE;
@@ -95,7 +95,7 @@ static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
 	unsigned long addr;
 	pmd_t *pmd;
 
-	for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
+	for (addr = start & PMD_MASK; addr < end; addr += PMD_SIZE) {
 		pmd = pmd_offset(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(0);
 		pmd[1] = __pmd(0);

...

Quoted 6 lines
arch/arm/kernel/smp.c +1 -1
@@ -1068,12 +1068,12 @@ void setup_mm_for_reboot(char mode)
 		base_pmdval |= PMD_BIT4;
 
 	for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
-		unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
+		unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;

arch/arm/kernel/smp.c void setup_mm_for_reboot(char mode) · line 1079

Quoted 10 lines
arch/arm/kernel/smp.c +2 -2
 		pmd_t *pmd;
 
-		pmd = pmd_off(pgd, i << PGDIR_SHIFT);
+		pmd = pmd_off(pgd, i << PMD_SHIFT);
 		pmd[0] = __pmd(pmdval);
-		pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
+		pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
 		flush_pmd_entry(pmd);
 	}
 

This lot really does need unifying - and in any case this last addition should be using 'SECTION SIZE' not something related to PMD shifts.

Strangely, it's something I've done over the weekend...

#47 lore raw

Re: [PATCH v2 07/20] ARM: LPAE: Page table maintenance for the 3-level format

In reply to Catalin Marinas

arch/arm/include/asm/pgtable.h extern pgprot_t pgprot_kernel; · line 131

Quoted 13 lines · Catalin Marinas
arch/arm/include/asm/pgtable.h +4 -0
index 97a5de3..41236f0 100644
@@ -124,7 +124,12 @@ extern pgprot_t		pgprot_kernel;
 extern struct page *empty_zero_page;
 #define ZERO_PAGE(vaddr)	(empty_zero_page)
 
+#ifdef CONFIG_ARM_LPAE
+#define pte_pfn(pte)		((pte_val(pte) & PTE_PFN_MASK) >> PAGE_SHIFT)
+#else
 #define pte_pfn(pte)		(pte_val(pte) >> PAGE_SHIFT)
+#endif

Just make LPAE and non-LPAE both provide PTE_PFN_MASK - for non-LPAE this can be defined as ~0UL to optimize it away. However, PTE_PFN_MASK is the wrong name for this - you're not masking out the PFN, but the physical address. It only becomes a PFN when you shift.

This is important because...

arch/arm/include/asm/pgtable.h extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, · line 257

Quoted 3 lines
arch/arm/include/asm/pgtable.h +3 -0
+static inline pte_t *pmd_page_vaddr(pmd_t pmd)
+{
+	return __va(pmd_val(pmd) & PTE_PFN_MASK);

... here it becomes much more confusing - it suggests that "pmd_val(pmd) & PTE_PFN_MASK" gives you a PFN, which you then pass to a function which takes a physical address.

Also, pmd_page_vaddr() in my patches ends up as:

static inline pte_t *pmd_page_vaddr(pmd_t pmd)
{
+ return __va(pmd_val(pmd) & PAGE_MASK);
}

which is almost the same. I'd suggest that this becomes for both:

static inline pte_t *pmd_page_vaddr(pmd_t pmd)

 {
        return __va(pmd_val(pmd) & PTE_PFN_MASK & PAGE_MASK);

}

but with PTE_PFN_MASK more appropriately named.

Quoted 8 lines
arch/arm/include/asm/pgtable.h +4 -0
+}
+
+#else	/* !CONFIG_ARM_LPAE */
+
 #define pmd_bad(pmd)		(pmd_val(pmd) & 2)
 
 #define copy_pmd(pmdpd,pmdps)		\

arch/arm/include/asm/pgtable.h static inline pte_t *pmd_page_vaddr(pmd_t pmd) · line 294

Quoted 10 lines
arch/arm/include/asm/pgtable.h +6 -0
@@ -252,7 +285,13 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 	return __va(ptr);
 }
 
+#endif	/* CONFIG_ARM_LPAE */
+
+#ifdef CONFIG_ARM_LPAE
+#define pmd_page(pmd)		pfn_to_page(__phys_to_pfn(pmd_val(pmd) & PTE_PFN_MASK))
+#else
 #define pmd_page(pmd)		pfn_to_page(__phys_to_pfn(pmd_val(pmd)))
+#endif

Ditto.

Quoted 24 lines
arch/arm/include/asm/proc-fns.h +12 -0
index 8fdae9b..f00ae99 100644
@@ -263,6 +263,18 @@
 
 #define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)
 
+#ifdef CONFIG_ARM_LPAE
+#define cpu_get_pgd()	\
+	({						\
+		unsigned long pg, pg2;			\
+		__asm__("mrrc	p15, 0, %0, %1, c2"	\
+			: "=r" (pg), "=r" (pg2)		\
+			:				\
+			: "cc");			\
+		pg &= ~(PTRS_PER_PGD*sizeof(pgd_t)-1);	\
+		(pgd_t *)phys_to_virt(pg);		\
+	})
+#else
 #define cpu_get_pgd()	\
 	({						\
 		unsigned long pg;			\

arch/arm/include/asm/proc-fns.h line 283

Quoted 1 line
arch/arm/include/asm/proc-fns.h +0 -0
@@ -271,6 +283,7 @@
 		pg &= ~0x3fff;				\

I think this wants updating to use similar math to the one above.

arch/arm/include/asm/proc-fns.h void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd) · line 94

Quoted 7 lines
arch/arm/include/asm/proc-fns.h +2 -1
@@ -81,7 +90,8 @@ void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd)
 	if (!pgd)
 		return;
 
-	/* pgd is always present and good */
+	if (pgd_none(*pgd))
+		goto free;

This actually wants to become something more like:

+ pgd = pgd_base + pgd_index(0);
+ if (pgd_none_or_clear_bad(pgd))
+ goto no_pgd;

+ pmd = pmd_offset(pgd, 0);
+ if (pmd_none_or_clear_bad(pmd))
+ goto no_pmd;

        pte = pmd_pgtable(*pmd);
        pmd_clear(pmd);
        pte_free(mm, pte);
+no_pmd:
+       pgd_clear(pgd);
        pmd_free(mm, pmd);
+no_pgd:
	free_pgd(pgd_base);
#3 lore raw

Re: [PATCH v2 01/20] ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*

In reply to Russell King - ARM Linux
Quoted 32 lines · Russell King - ARM Linux
Quoted 22 lines · Catalin Marinas
arch/arm/kernel/smp.c +2 -2
index 8c19595..40b386c 100644
@@ -78,7 +78,7 @@ static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
      if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
              prot |= PMD_BIT4;
 
-     for (addr = start & PGDIR_MASK; addr < end;) {
+     for (addr = start & PMD_MASK; addr < end;) {
              pmd = pmd_offset(pgd + pgd_index(addr), addr);
              pmd[0] = __pmd(addr | prot);
              addr += SECTION_SIZE;
@@ -95,7 +95,7 @@ static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
      unsigned long addr;
      pmd_t *pmd;
 
-     for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
+     for (addr = start & PMD_MASK; addr < end; addr += PMD_SIZE) {
              pmd = pmd_offset(pgd + pgd_index(addr), addr);
              pmd[0] = __pmd(0);
              pmd[1] = __pmd(0);

...

Quoted 8 lines
arch/arm/kernel/smp.c +1 -1
@@ -1068,12 +1068,12 @@ void setup_mm_for_reboot(char mode)
              base_pmdval |= PMD_BIT4;
 
      for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
-             unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
+             unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;
              pmd_t *pmd;
 
Quoted 11 lines

arch/arm/kernel/smp.c void setup_mm_for_reboot(char mode) · line 1079

Quoted 8 lines
arch/arm/kernel/smp.c +2 -2
-             pmd = pmd_off(pgd, i << PGDIR_SHIFT);
+             pmd = pmd_off(pgd, i << PMD_SHIFT);
              pmd[0] = __pmd(pmdval);
-             pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
+             pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
              flush_pmd_entry(pmd);
      }
 

This lot really does need unifying - and in any case this last addition should be using 'SECTION SIZE' not something related to PMD shifts.

On the classic page tables, the PMD_SHIFT is 21 while the SECTION_SHIFT is 20. They have slightly different meaning.

But we currently have some hacks to cope with PMD_SHIFT being 21 by writing the pmd[0] and pmd[1] in the same call. The way I see to use SECTION_SHIFT is to drop the pmd[] array (but haven't looked closely enough). With LPAE I have a few #ifndef around pmd[1] setting.

Quoted 1 line

Strangely, it's something I've done over the weekend...

OK, the more clean-up the better.

Signature · 1 line
Catalin
#50 lore raw

Re: [PATCH v2 08/20] ARM: LPAE: MMU setup for the 3-level page table format

In reply to Catalin Marinas
Quoted 28 lines · Catalin Marinas

This patch adds the MMU initialisation for the LPAE page table format. The swapper_pg_dir size with LPAE is 5 rather than 4 pages. The __v7_setup function configures the TTBRx split based on the PAGE_OFFSET and sets the corresponding TTB control and MAIRx bits (similar to PRRR/NMRR for TEX remapping). The 36-bit mappings (supersections) and a few other memory types in mmu.c are conditionally compiled.

---
 arch/arm/kernel/head.S    |   96 +++++++++++++++++++++++++++++++------------
 arch/arm/mm/mmu.c         |   32 ++++++++++++++-
 arch/arm/mm/proc-macros.S |    5 +-
 arch/arm/mm/proc-v7.S     |   99 ++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 193 insertions(+), 39 deletions(-)
arch/arm/kernel/head.S +1 -0
index dd6b369..fd8a29e 100644
@@ -21,6 +21,7 @@
 #include <asm/memory.h>
 #include <asm/thread_info.h>
 #include <asm/system.h>
+#include <asm/pgtable.h>
 
 #ifdef CONFIG_DEBUG_LL
 #include <mach/debug-macro.S>

arch/arm/kernel/head.S line 55

Quoted 10 lines
arch/arm/kernel/head.S +7 -0
@@ -45,11 +46,20 @@
 #error KERNEL_RAM_VADDR must start at 0xXXXX8000
 #endif
 
+#ifdef CONFIG_ARM_LPAE
+	/* LPAE requires an additional page for the PGD */
+#define PG_DIR_SIZE	0x5000
+#define PTE_WORDS	3
+#else
+#define PG_DIR_SIZE	0x4000
+#define PTE_WORDS	2

PTE is not the right prefix here - we don't deal with the lowest level of page tables, which in Linux is called PTE. I think you mean PMD_WORDS instead.

Quoted 76 lines
arch/arm/kernel/head.S +30 -12
+#endif
+
 	.globl	swapper_pg_dir
-	.equ	swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
+	.equ	swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
 
 	.macro	pgtbl, rd
-	ldr	\rd, =(KERNEL_RAM_PADDR - 0x4000)
+	ldr	\rd, =(KERNEL_RAM_PADDR - PG_DIR_SIZE)
 	.endm
 
 #ifdef CONFIG_XIP_KERNEL
@@ -129,11 +139,11 @@ __create_page_tables:
 	pgtbl	r4				@ page table address
 
 	/*
-	 * Clear the 16K level 1 swapper page table
+	 * Clear the swapper page table
 	 */
 	mov	r0, r4
 	mov	r3, #0
-	add	r6, r0, #0x4000
+	add	r6, r0, #PG_DIR_SIZE
 1:	str	r3, [r0], #4
 	str	r3, [r0], #4
 	str	r3, [r0], #4
@@ -141,6 +151,23 @@ __create_page_tables:
 	teq	r0, r6
 	bne	1b
 
+#ifdef CONFIG_ARM_LPAE
+	/*
+	 * Build the PGD table (first level) to point to the PMD table. A PGD
+	 * entry is 64-bit wide and the top 32 bits are 0.
+	 */
+	mov	r0, r4
+	add	r3, r4, #0x1000			@ first PMD table address
+	orr	r3, r3, #3			@ PGD block type
+	mov	r6, #4				@ PTRS_PER_PGD
+1:	str	r3, [r0], #8			@ set PGD entry
+	add	r3, r3, #0x1000			@ next PMD table
+	subs	r6, r6, #1
+	bne	1b
+
+	add	r4, r4, #0x1000			@ point to the PMD tables
+#endif
+
 	ldr	r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
 
 	/*
@@ -152,30 +179,30 @@ __create_page_tables:
 	sub	r0, r0, r3			@ virt->phys offset
 	add	r5, r5, r0			@ phys __enable_mmu
 	add	r6, r6, r0			@ phys __enable_mmu_end
-	mov	r5, r5, lsr #20
-	mov	r6, r6, lsr #20
+	mov	r5, r5, lsr #SECTION_SHIFT
+	mov	r6, r6, lsr #SECTION_SHIFT
 
-1:	orr	r3, r7, r5, lsl #20		@ flags + kernel base
-	str	r3, [r4, r5, lsl #2]		@ identity mapping
-	teq	r5, r6
-	addne	r5, r5, #1			@ next section
-	bne	1b
+1:	orr	r3, r7, r5, lsl #SECTION_SHIFT	@ flags + kernel base
+	str	r3, [r4, r5, lsl #PTE_WORDS]	@ identity mapping
+	cmp	r5, r6
+	addlo	r5, r5, #SECTION_SHIFT >> 20	@ next section
+	blo	1b
 
 	/*
 	 * Now setup the pagetables for our kernel direct
 	 * mapped region.
 	 */
 	mov	r3, pc
-	mov	r3, r3, lsr #20

arch/arm/kernel/head.S __create_page_tables: · line 202

Quoted 10 lines
arch/arm/kernel/head.S +4 -3
-	orr	r3, r7, r3, lsl #20
+	mov	r3, r3, lsr #SECTION_SHIFT
+	orr	r3, r7, r3, lsl #SECTION_SHIFT
 	add	r0, r4,  #(KERNEL_START & 0xff000000) >> 18
-	str	r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!
+	str	r3, [r0, #(KERNEL_START & 0x00e00000) >> 18]!
 	ldr	r6, =(KERNEL_END - 1)
-	add	r0, r0, #4
+	add	r0, r0, #1 << PTE_WORDS
 	add	r6, r4, r6, lsr #18

Are you sure these shifts by 18 places are correct? They're actually (val >> SECTION_SHIFT) << 2, so maybe they should be (SECTION_SHIFT - PMD_WORDS) ?

#55 lore raw

Re: [PATCH v2 09/20] ARM: LPAE: Change setup_mm_for_reboot() to work with LPAE

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
arch/arm/mm/mmu.c +1 -1
index 4147cc6..3784acc 100644
@@ -1098,13 +1098,16 @@ void setup_mm_for_reboot(char mode)
 	if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
 		base_pmdval |= PMD_BIT4;
 
-	for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
+	for (i = 0; i < TASK_SIZE >> PMD_SHIFT; i++) {
 		unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;
 		pmd_t *pmd;

arch/arm/mm/mmu.c void setup_mm_for_reboot(char mode) · line 1112

Quoted 10 lines
arch/arm/mm/mmu.c +4 -1
+		unsigned long addr = i << PMD_SHIFT;
 
-		pmd = pmd_off(pgd, i << PMD_SHIFT);
+		pmd = pmd_off(pgd + pgd_index(addr), addr);
 		pmd[0] = __pmd(pmdval);
+#ifndef CONFIG_ARM_LPAE
 		pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
+#endif
 		flush_pmd_entry(pmd);
 	}

The same is required for the identity mapping code. If this uses that code, the problem becomes localized there.

#57 lore raw

Re: [PATCH v2 10/20] ARM: LPAE: Remove the FIRST_USER_PGD_NR and USER_PTRS_PER_PGD definitions

In reply to Catalin Marinas
Quoted 4 lines · Catalin Marinas

These macros were only used in setup_mm_for_reboot and get_pgd_slow. Both have been modified to no longer use these definitions. One of the reasons is the different meaning that PGD has with the 2-level and 3-level page tables.

We don't actually need this macro anymore, it can be killed (and I've already done so.)

#59 lore raw

Re: [PATCH v2 11/20] ARM: LPAE: Add fault handling support

In reply to Catalin Marinas

arch/arm/mm/fault.c void show_pte(struct mm_struct *mm, unsigned long addr) · line 118

Quoted 7 lines · Catalin Marinas
arch/arm/mm/fault.c +2 -0
@@ -108,7 +113,9 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
 		pte = pte_offset_map(pmd, addr);
 		printk(", *pte=%08lx", pte_val(*pte));
+#ifndef CONFIG_ARM_LPAE
 		printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
+#endif

This is an unrelated change - should it be in a different patch?

#60 lore raw

Re: [PATCH v2 11/20] ARM: LPAE: Add fault handling support

Quoted 10 lines · Russell King - ARM Linux

arch/arm/mm/fault.c void show_pte(struct mm_struct *mm, unsigned long addr) · line 118

Quoted 7 lines · Catalin Marinas
arch/arm/mm/fault.c +2 -0
@@ -108,7 +113,9 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
              pte = pte_offset_map(pmd, addr);
              printk(", *pte=%08lx", pte_val(*pte));
+#ifndef CONFIG_ARM_LPAE
              printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
+#endif

This is an unrelated change - should it be in a different patch?

It was intended to be in this patch as I couldn't find a better place. This patch sorts out the fault handling (and error reporting) for LPAE and we don't need the additional printk here.

Signature · 1 line
Catalin
#4 lore raw

Re: [PATCH v2 01/20] ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*

In reply to Catalin Marinas
Quoted 45 lines · Catalin Marinas
Quoted 32 lines · Russell King - ARM Linux
Quoted 22 lines · Catalin Marinas
arch/arm/kernel/smp.c +2 -2
index 8c19595..40b386c 100644
@@ -78,7 +78,7 @@ static inline void identity_mapping_add(pgd_t *pgd, unsigned long start,
      if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
              prot |= PMD_BIT4;
 
-     for (addr = start & PGDIR_MASK; addr < end;) {
+     for (addr = start & PMD_MASK; addr < end;) {
              pmd = pmd_offset(pgd + pgd_index(addr), addr);
              pmd[0] = __pmd(addr | prot);
              addr += SECTION_SIZE;
@@ -95,7 +95,7 @@ static inline void identity_mapping_del(pgd_t *pgd, unsigned long start,
      unsigned long addr;
      pmd_t *pmd;
 
-     for (addr = start & PGDIR_MASK; addr < end; addr += PGDIR_SIZE) {
+     for (addr = start & PMD_MASK; addr < end; addr += PMD_SIZE) {
              pmd = pmd_offset(pgd + pgd_index(addr), addr);
              pmd[0] = __pmd(0);
              pmd[1] = __pmd(0);

...

Quoted 8 lines
arch/arm/kernel/smp.c +1 -1
@@ -1068,12 +1068,12 @@ void setup_mm_for_reboot(char mode)
              base_pmdval |= PMD_BIT4;
 
      for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
-             unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
+             unsigned long pmdval = (i << PMD_SHIFT) | base_pmdval;
              pmd_t *pmd;
 
Quoted 11 lines

arch/arm/kernel/smp.c void setup_mm_for_reboot(char mode) · line 1079

Quoted 8 lines
arch/arm/kernel/smp.c +2 -2
-             pmd = pmd_off(pgd, i << PGDIR_SHIFT);
+             pmd = pmd_off(pgd, i << PMD_SHIFT);
              pmd[0] = __pmd(pmdval);
-             pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
+             pmd[1] = __pmd(pmdval + (1 << (PMD_SHIFT - 1)));
              flush_pmd_entry(pmd);
      }
 

This lot really does need unifying - and in any case this last addition should be using 'SECTION SIZE' not something related to PMD shifts.

Quoted 2 lines

On the classic page tables, the PMD_SHIFT is 21 while the SECTION_SHIFT is 20. They have slightly different meaning.

Correct, and if you look at the code again and analyze what it's doing, you'll see that it's using the wrong thing. The code pre-exists the SECTION_* macros, and was never fixed up when they were introduced.

SECTION_SIZE is the right thing here - it's setting up sections.

Just look at identity_mapping_add() to see how the code _should_ be.

#61 lore raw

Re: [PATCH v2 11/20] ARM: LPAE: Add fault handling support

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
Quoted 10 lines · Russell King - ARM Linux

arch/arm/mm/fault.c void show_pte(struct mm_struct *mm, unsigned long addr) · line 118

Quoted 7 lines · Catalin Marinas
arch/arm/mm/fault.c +2 -0
@@ -108,7 +113,9 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
              pte = pte_offset_map(pmd, addr);
              printk(", *pte=%08lx", pte_val(*pte));
+#ifndef CONFIG_ARM_LPAE
              printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
+#endif

This is an unrelated change - should it be in a different patch?

Quoted 3 lines

It was intended to be in this patch as I couldn't find a better place. This patch sorts out the fault handling (and error reporting) for LPAE and we don't need the additional printk here.

It doesn't sort the fault error reporting actually. With pte_val() returning u64 constants on LPAE, all the above printk's using %08lx will issue warnings.

Also, as one of your previous patches changed the non-LPAE stuff to use u32, which is 'unsigned int', %08lx is wrong for them too, and will cause the compiler to spit out warnings.

I can only assume this patch hasn't been build-tested, or maybe it has but the warnings ignored?

It seems a larger patch is required here - and as such might as well become a separate "fix fault reporting" patch.

#65 lore raw

Re: [PATCH v2 13/20] ARM: LPAE: Add SMP support for the 3-level page table format

In reply to Catalin Marinas
Quoted 17 lines · Catalin Marinas

With 3-level page tables, starting secondary CPUs required allocating the pgd as well. Since LPAE Linux uses TTBR1 for the kernel page tables, this patch reorders the CPU setup call in the head.S file so that the swapper_pg_dir is used. TTBR0 is set to the value generated by the primary CPU.

---
 arch/arm/kernel/head.S |   10 +++++-----
 arch/arm/kernel/smp.c  |   39 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 7 deletions(-)
arch/arm/kernel/head.S +0 -0
index fd8a29e..b54d00e 100644

arch/arm/kernel/head.S ENTRY(secondary_startup) · line 327

Quoted 7 lines
arch/arm/kernel/head.S +4 -0
@@ -321,6 +321,10 @@ ENTRY(secondary_startup)
 	moveq	r0, #'p'			@ yes, error 'p'
 	beq	__error_p
 
+	pgtbl	r4
+	add	r12, r10, #BSYM(PROCINFO_INITFUNC)
+	blx	r12				@ initialise processor
+						@ (return control reg)

I really don't like this being different in ordering from the boot CPU bring up. If we want to have the init function dealing with split page tables, we should pass in two pointers for it in both paths.

#62 lore raw

Re: [PATCH v2 11/20] ARM: LPAE: Add fault handling support

In reply to Russell King - ARM Linux
Quoted 17 lines · Russell King - ARM Linux
Quoted 12 lines · Catalin Marinas
Quoted 10 lines · Russell King - ARM Linux

arch/arm/mm/fault.c void show_pte(struct mm_struct *mm, unsigned long addr) · line 118

Quoted 7 lines · Catalin Marinas
arch/arm/mm/fault.c +2 -0
@@ -108,7 +113,9 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
              pte = pte_offset_map(pmd, addr);
              printk(", *pte=%08lx", pte_val(*pte));
+#ifndef CONFIG_ARM_LPAE
              printk(", *ppte=%08lx", pte_val(pte[-LINUX_PTE_OFFSET]));
+#endif

This is an unrelated change - should it be in a different patch?

Quoted 3 lines

It was intended to be in this patch as I couldn't find a better place. This patch sorts out the fault handling (and error reporting) for LPAE and we don't need the additional printk here.

Quoted 7 lines

It doesn't sort the fault error reporting actually. With pte_val() returning u64 constants on LPAE, all the above printk's using %08lx will issue warnings.

Also, as one of your previous patches changed the non-LPAE stuff to use u32, which is 'unsigned int', %08lx is wrong for them too, and will cause the compiler to spit out warnings.

This has been fixed in a subsequent version of the series with the conversion to %08llx and long long.

Quoted 2 lines

I can only assume this patch hasn't been build-tested, or maybe it has but the warnings ignored?

Probably the latter. I run the resulting kernels both on VE (with A9) and a model supporting A15.

Signature · 1 line
Catalin
#72 lore raw

Re: [PATCH v2 19/20] ARM: LPAE: define printk format for physical addresses and page table entries

In reply to Catalin Marinas
Quoted 8 lines · Catalin Marinas

From: Will Deacon <[email protected]>

Now that the Kernel supports 2 level and 3 level page tables, physical addresses (and also page table entries) may be 32 or 64-bits depending upon the configuration.

This patch adds a conversion specifier (PHYS_ADDR_FMT) which represents a u32 or u64 depending on the width of a physical address.

I hope this patch is gone in v3.

#73 lore raw

Re: [PATCH v2 19/20] ARM: LPAE: define printk format for physical addresses and page table entries

Quoted 11 lines · Russell King - ARM Linux
Quoted 8 lines · Catalin Marinas

From: Will Deacon <[email protected]>

Now that the Kernel supports 2 level and 3 level page tables, physical addresses (and also page table entries) may be 32 or 64-bits depending upon the configuration.

This patch adds a conversion specifier (PHYS_ADDR_FMT) which represents a u32 or u64 depending on the width of a physical address.

I hope this patch is gone in v3.

Yes, everything is converted to %08llx now.

Once you complete your clean-up, I'll rebase the LPAE patches on top and repost a new v4 version.

Signature · 1 line
Catalin
#51 lore raw

Re: [PATCH v2 08/20] ARM: LPAE: MMU setup for the 3-level page table format

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux
Quoted 6 lines · Catalin Marinas

This patch adds the MMU initialisation for the LPAE page table format. The swapper_pg_dir size with LPAE is 5 rather than 4 pages. The __v7_setup function configures the TTBRx split based on the PAGE_OFFSET and sets the corresponding TTB control and MAIRx bits (similar to PRRR/NMRR for TEX remapping). The 36-bit mappings (supersections) and a few other memory types in mmu.c are conditionally compiled.

[...]

Quoted 14 lines
Quoted 14 lines
arch/arm/kernel/head.S +0 -0
@@ -21,6 +21,7 @@

?#include <asm/memory.h>
?#include <asm/thread_info.h>
?#include <asm/system.h>
+#include <asm/pgtable.h>

?#ifdef CONFIG_DEBUG_LL
?#include <mach/debug-macro.S>

arch/arm/kernel/head.S +0 -0
@@ -45,11 +46,20 @@

?#error KERNEL_RAM_VADDR must start at 0xXXXX8000
?#endif

Quoted 11 lines

arch/arm/kernel/head.S

Quoted 7 lines
arch/arm/kernel/head.S +7 -0
+#ifdef CONFIG_ARM_LPAE
+ ? ? /* LPAE requires an additional page for the PGD */
+#define PG_DIR_SIZE ?0x5000
+#define PTE_WORDS ? ?3
+#else
+#define PG_DIR_SIZE ?0x4000
+#define PTE_WORDS ? ?2

PTE is not the right prefix here - we don't deal with the lowest level of page tables, which in Linux is called PTE. ?I think you mean PMD_WORDS instead.

It should actually be something PMD_ORDER because of the log2 value.

Quoted 71 lines
Quoted 71 lines

?#ifdef CONFIG_XIP_KERNEL

arch/arm/kernel/head.S +0 -0
@@ -129,11 +139,11 @@ __create_page_tables:

? ? ? pgtbl ? r4 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?@ page table address

? ? ? /*
- ? ? ?* Clear the 16K level 1 swapper page table
+ ? ? ?* Clear the swapper page table
? ? ? ?*/
? ? ? mov ? ? r0, r4
? ? ? mov ? ? r3, #0
- ? ? add ? ? r6, r0, #0x4000
+ ? ? add ? ? r6, r0, #PG_DIR_SIZE
?1: ? str ? ? r3, [r0], #4
? ? ? str ? ? r3, [r0], #4
? ? ? str ? ? r3, [r0], #4

arch/arm/kernel/head.S +0 -0
@@ -141,6 +151,23 @@ __create_page_tables:

? ? ? teq ? ? r0, r6
? ? ? bne ? ? 1b

arch/arm/kernel/head.S +17 -0
+#ifdef CONFIG_ARM_LPAE
+ ? ? /*
+ ? ? ?* Build the PGD table (first level) to point to the PMD table. A PGD
+ ? ? ?* entry is 64-bit wide and the top 32 bits are 0.
+ ? ? ?*/
+ ? ? mov ? ? r0, r4
+ ? ? add ? ? r3, r4, #0x1000 ? ? ? ? ? ? ? ? @ first PMD table address
+ ? ? orr ? ? r3, r3, #3 ? ? ? ? ? ? ? ? ? ? ?@ PGD block type
+ ? ? mov ? ? r6, #4 ? ? ? ? ? ? ? ? ? ? ? ? ?@ PTRS_PER_PGD
+1: ? str ? ? r3, [r0], #8 ? ? ? ? ? ? ? ? ? ?@ set PGD entry
+ ? ? add ? ? r3, r3, #0x1000 ? ? ? ? ? ? ? ? @ next PMD table
+ ? ? subs ? ?r6, r6, #1
+ ? ? bne ? ? 1b
+
+ ? ? add ? ? r4, r4, #0x1000 ? ? ? ? ? ? ? ? @ point to the PMD tables
+#endif
+

? ? ? ldr ? ? r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags

? ? ? /*

arch/arm/kernel/head.S +0 -0
@@ -152,30 +179,30 @@ __create_page_tables:

? ? ? sub ? ? r0, r0, r3 ? ? ? ? ? ? ? ? ? ? ?@ virt->phys offset ? ? ? add ? ? r5, r5, r0 ? ? ? ? ? ? ? ? ? ? ?@ phys __enable_mmu ? ? ? add ? ? r6, r6, r0 ? ? ? ? ? ? ? ? ? ? ?@ phys __enable_mmu_end
- ? ? mov ? ? r5, r5, lsr #20
- ? ? mov ? ? r6, r6, lsr #20
+ ? ? mov ? ? r5, r5, lsr #SECTION_SHIFT
+ ? ? mov ? ? r6, r6, lsr #SECTION_SHIFT

-1: ? orr ? ? r3, r7, r5, lsl #20 ? ? ? ? ? ? @ flags + kernel base
- ? ? str ? ? r3, [r4, r5, lsl #2] ? ? ? ? ? ?@ identity mapping
- ? ? teq ? ? r5, r6
- ? ? addne ? r5, r5, #1 ? ? ? ? ? ? ? ? ? ? ?@ next section
- ? ? bne ? ? 1b
+1: ? orr ? ? r3, r7, r5, lsl #SECTION_SHIFT ?@ flags + kernel base
+ ? ? str ? ? r3, [r4, r5, lsl #PTE_WORDS] ? ?@ identity mapping
+ ? ? cmp ? ? r5, r6
+ ? ? addlo ? r5, r5, #SECTION_SHIFT >> 20 ? ?@ next section
+ ? ? blo ? ? 1b

? ? ? /*
? ? ? ?* Now setup the pagetables for our kernel direct ? ? ? ?* mapped region.
? ? ? ?*/
? ? ? mov ? ? r3, pc
- ? ? mov ? ? r3, r3, lsr #20
- ? ? orr ? ? r3, r7, r3, lsl #20
+ ? ? mov ? ? r3, r3, lsr #SECTION_SHIFT
+ ? ? orr ? ? r3, r7, r3, lsl #SECTION_SHIFT
? ? ? add ? ? r0, r4, ?#(KERNEL_START & 0xff000000) >> 18
- ? ? str ? ? r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!
+ ? ? str ? ? r3, [r0, #(KERNEL_START & 0x00e00000) >> 18]!

Quoted 8 lines
Quoted 4 lines

? ? ? ldr ? ? r6, =(KERNEL_END - 1)
- ? ? add ? ? r0, r0, #4
+ ? ? add ? ? r0, r0, #1 << PTE_WORDS
? ? ? add ? ? r6, r4, r6, lsr #18

Are you sure these shifts by 18 places are correct? ?They're actually (val >> SECTION_SHIFT) << 2, so maybe they should be (SECTION_SHIFT - PMD_WORDS) ?

SECTION_SHIFT - PMD_ORDER is (20 - 2) for classic page tables and (21
- 3) for LPAE. But we could change the 18 to some macros for clarification (the line would be long though).

Signature · 1 line
Catalin
#52 lore raw

Re: [PATCH v2 08/20] ARM: LPAE: MMU setup for the 3-level page table format

Quoted 9 lines · Catalin Marinas
Quoted 3 lines · Russell King - ARM Linux

Are you sure these shifts by 18 places are correct? ?They're actually (val >> SECTION_SHIFT) << 2, so maybe they should be (SECTION_SHIFT - PMD_WORDS) ?

SECTION_SHIFT - PMD_ORDER is (20 - 2) for classic page tables and (21
- 3) for LPAE. But we could change the 18 to some macros for clarification (the line would be long though).

So yes, it's SECTION_SHIFT - PMD_ORDER, which is how they should be used IMHO. I don't see why another macro would be necessary.

#53 lore raw

Re: [PATCH v2 08/20] ARM: LPAE: MMU setup for the 3-level page table format

Quoted 7 lines · Russell King - ARM Linux
Quoted 6 lines · Catalin Marinas
Quoted 3 lines · Russell King - ARM Linux

Are you sure these shifts by 18 places are correct? They're actually (val >> SECTION_SHIFT) << 2, so maybe they should be (SECTION_SHIFT - PMD_WORDS) ?

Quoted 6 lines
Quoted 3 lines

SECTION_SHIFT - PMD_ORDER is (20 - 2) for classic page tables and (21
- 3) for LPAE. But we could change the 18 to some macros for clarification (the line would be long though).

So yes, it's SECTION_SHIFT - PMD_ORDER, which is how they should be used IMHO. I don't see why another macro would be necessary.

I didn't mean adding another macro but using (SECTION_SHIFT - PMD_ORDER) on a long line.

Signature · 1 line
Catalin