ARM: Add support for the Large Physical Address Extensions
v4 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:
- Rebased on 2.6.38-rc1. This kernel includes Russell's refactoring of the page table maintenance.
- PTE_PFN_MASK renamed to PHYS_MASK and some of the functions using this macro have been unified between classic and LPAE page table format.
- Fixes for modules/pkmap page table entries - the corresponding PMD is preallocated in pgd_alloc() and cleaned-up in pgd_free().
- Identity mapping support following mainline changes.
Catalin Marinas (14):
ARM: Make the argument to virt_to_phys() "const volatile"
ARM: LPAE: Fix early_pte_alloc() assumption about the Linux PTE
ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*
ARM: LPAE: Factor out 2-level page table definitions into separate
files
ARM: LPAE: Add (pte|pmd|pgd|pgprot)val_t type definitions as u32
ARM: LPAE: Use a mask for physical addresses in page table entries
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: Add fault handling support
ARM: LPAE: Add context switching support
ARM: LPAE: Add identity mapping support for the 3-level page table
format
ARM: LPAE: Add SMP support for the 3-level page table format
ARM: LPAE: Add the Kconfig entries
Will Deacon (5):
ARM: LPAE: use long long format when printing physical addresses and
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: add support for ATAG_MEM64
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.h | 44 +----- arch/arm/include/asm/pgalloc.h | 28 ++++- arch/arm/include/asm/pgtable-2level-hwdef.h | 93 ++++++++++++ arch/arm/include/asm/pgtable-2level-types.h | 67 +++++++++ arch/arm/include/asm/pgtable-2level.h | 148 +++++++++++++++++++ arch/arm/include/asm/pgtable-3level-hwdef.h | 81 ++++++++++ arch/arm/include/asm/pgtable-3level-types.h | 68 +++++++++ arch/arm/include/asm/pgtable-3level.h | 106 ++++++++++++++ arch/arm/include/asm/pgtable-hwdef.h | 81 +---------- arch/arm/include/asm/pgtable.h | 211 +++++++++------------------ arch/arm/include/asm/proc-fns.h | 13 ++ arch/arm/include/asm/setup.h | 12 ++- arch/arm/include/asm/tlbflush.h | 4 +- arch/arm/include/asm/types.h | 20 +--- arch/arm/kernel/compat.c | 4 +- arch/arm/kernel/head.S | 125 +++++++++++----- arch/arm/kernel/module.c | 2 +- arch/arm/kernel/setup.c | 19 ++- arch/arm/kernel/traps.c | 6 +- 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 | 90 +++++++++++- arch/arm/mm/idmap.c | 39 ++++-- arch/arm/mm/init.c | 6 +- arch/arm/mm/ioremap.c | 8 +- arch/arm/mm/mm.h | 4 +- arch/arm/mm/mmu.c | 88 ++++++++---- arch/arm/mm/pgd.c | 64 ++++++-- arch/arm/mm/proc-macros.S | 5 +- arch/arm/mm/proc-v7.S | 120 ++++++++++++++-- 37 files changed, 1212 insertions(+), 434 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
PATCH v4 1/19 ARM: Make the argument to virt_to_phys() "const volatile"
Changing the virt_to_phys() argument to "const volatile void *" avoids compiler warnings in some situations where this function is used.
--- arch/arm/include/asm/memory.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/include/asm/memory.h +1 -1
@@ -188,7 +188,7 @@* 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 unsigned long virt_to_phys (const volatile void *x) {return __virt_to_phys ((unsigned long )(x)); }
PATCH v4 2/19 ARM: LPAE: Fix early_pte_alloc() assumption about the Linux PTE
In reply to Catalin MarinasWith LPAE we no longer have software bits in a separate Linux PTE and the early_pte_alloc() function should pass PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE to early_alloc() to avoid allocating extra memory.
--- arch/arm/mm/mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mm/mmu.c +1 -1
@@ -533,7 +533,7 @@ 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 (PTE_HWTABLE_OFF +PTE_HWTABLE_SIZE );__pmd_populate (pmd,__pa (pte), prot); }BUG_ON (pmd_bad (*pmd));
PATCH v4 3/19 ARM: LPAE: use long long format when printing physical addresses and ptes
In reply to Catalin MarinasFrom: 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 uses the %08llx conversion specifier for physical addresses and page table entries, ensuring that they are cast to (long long) so that common code can be used regardless of the datatype widths.
--- arch/arm/kernel/setup.c | 2 +- arch/arm/kernel/traps.c | 6 +++--- arch/arm/mm/fault.c | 10 ++++++---- arch/arm/mm/mmu.c | 30 +++++++++++++++--------------- 4 files changed, 25 insertions(+), 23 deletions(-)
arch/arm/kernel/setup.c +1 -1
@@ -449,7 +449,7 @@ static int __init arm_add_memory(unsigned long 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 %#08llx\n" , (long long )start);return -EINVAL ; }
arch/arm/kernel/traps.c +3 -3
@@ -712,17 +712,17 @@ EXPORT_SYMBOL(__readwrite_bug);void __pte_error (const char *file,int line,pte_t pte) { -printk ("%s:%d: bad pte %08lx.\n" , file, line,pte_val (pte)); +printk ("%s:%d: bad pte %08llx.\n" , file, line, (long long )pte_val (pte)); }void __pmd_error (const char *file,int line,pmd_t pmd) { -printk ("%s:%d: bad pmd %08lx.\n" , file, line,pmd_val (pmd)); +printk ("%s:%d: bad pmd %08llx.\n" , file, line, (long long )pmd_val (pmd)); }void __pgd_error (const char *file,int line,pgd_t pgd) { -printk ("%s:%d: bad pgd %08lx.\n" , file, line,pgd_val (pgd)); +printk ("%s:%d: bad pgd %08llx.\n" , file, line, (long long )pgd_val (pgd)); } asmlinkage void __div0(void)
arch/arm/mm/fault.c +6 -4
@@ -76,7 +76,8 @@ 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=%08llx" , + addr, (long long )pgd_val (*pgd)); do { pmd_t *pmd;
@@ -92,7 +93,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=%08llx" , (long long )pmd_val (*pmd));if (pmd_none (*pmd))break ;
@@ -107,8 +108,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 (", *ppte=%08lx" ,pte_val (pte[PTE_HWTABLE_PTRS ])); +printk (", *pte=%08llx" , (long long )pte_val (*pte)); +printk (", *ppte=%08llx" , + (long long )pte_val (pte[PTE_HWTABLE_PTRS ]));pte_unmap (pte); }while (0 );
arch/arm/mm/mmu.c +15 -15
@@ -597,8 +597,8 @@ 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" , -__pfn_to_phys ((u64 )md->pfn), addr); +"mapping for %#08llx at %#08lx\n" , + (long long )__pfn_to_phys ((u64 )md->pfn), addr);return ; }
@@ -610,15 +610,15 @@ 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" , -__pfn_to_phys ((u64 )md->pfn), addr); +"mapping for %#08llx at %#08lx\n" , + (long long )__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" , -__pfn_to_phys ((u64 )md->pfn), addr); +printk (KERN_ERR "MM: cannot create mapping for %#08llx" +" at %#08lx invalid alignment\n" , + (long long )__pfn_to_phys ((u64 )md->pfn), addr);return ; }
@@ -657,17 +657,17 @@ 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@0x%08lx in user region\n" , -__pfn_to_phys ((u64 )md->pfn), md->virtual); +printk (KERN_WARNING "BUG: not creating mapping for %#08llx" +" at %#08lx in user region\n" , + (long long )__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@0x%08lx " -"overlaps vmalloc space\n" , -__pfn_to_phys ((u64 )md->pfn), md->virtual); +printk (KERN_WARNING "BUG: mapping for %#08llx" +" at %#08lx overlaps vmalloc space\n" , + (long long )__pfn_to_phys ((u64 )md->pfn), md->virtual); } type = &mem_types[md->type];
@@ -685,9 +685,9 @@ 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 %#08llx at %#08lx can not " "be mapped using pages, ignoring.\n" , -__pfn_to_phys (md->pfn), addr); + (long long )__pfn_to_phys (md->pfn), addr);return ; }
PATCH v4 4/19 ARM: LPAE: Use PMD_(SHIFT|SIZE|MASK) instead of PGDIR_*
In reply to Catalin MarinasPGDIR_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 so that LPAE builds can reuse the same code.
--- arch/arm/kernel/module.c | 2 +- arch/arm/mm/dma-mapping.c | 6 +++--- arch/arm/mm/mmu.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-)
arch/arm/kernel/module.c +1 -1
@@ -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/mm/dma-mapping.c +3 -3
@@ -121,8 +121,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
@@ -172,7 +172,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 +5 -5
@@ -857,14 +857,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));/*
@@ -879,7 +879,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)); }
@@ -920,7 +920,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));/*
PATCH v4 5/19 ARM: LPAE: Factor out 2-level page table definitions into separate files
In reply to Catalin MarinasThis 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 | 42 +-------- 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 | 143 +++++++++++++++++++++++++++ arch/arm/include/asm/pgtable-hwdef.h | 77 +-------------- arch/arm/include/asm/pgtable.h | 135 +------------------------- 6 files changed, 302 insertions(+), 250 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 -41
@@ -151,47 +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); -typedef unsigned long pteval_t ; - -#undef STRICT_MM_TYPECHECKS - -#ifdef STRICT_MM_TYPECHECKS -/* -* These are used to make use of C type-checking.. -*/ -typedef struct {pteval_t 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 pteval_t 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 +143 -0
143 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 -133
159 lines not on this page · raw message
PATCH v4 6/19 ARM: LPAE: Add (pte|pmd|pgd|pgprot)val_t type definitions as u32
In reply to Catalin MarinasThis patch defines the (pte|pmd|pgd|pgprot)val_t as u32 and changes the page table types to be based on these. The PMD bits are converted to the corresponding type using the _AT macro.
The flush_pmd_entry/clean_pmd_entry argument was changed to (void *) to allow them to be used with both PGD and PMD pointers and avoid code duplication.
--- arch/arm/include/asm/pgalloc.h | 4 +- arch/arm/include/asm/pgtable-2level-hwdef.h | 82 +++++++++++++------------- arch/arm/include/asm/pgtable-2level-types.h | 17 +++-- arch/arm/include/asm/tlbflush.h | 4 +- arch/arm/mm/mm.h | 4 +- arch/arm/mm/mmu.c | 2 +- 6 files changed, 58 insertions(+), 55 deletions(-)
arch/arm/include/asm/pgalloc.h +2 -2
@@ -103,9 +103,9 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte) }static inline void __pmd_populate (pmd_t *pmdp,phys_addr_t pte, -unsigned long prot) +pmdval_t prot) { -unsigned long pmdval = (pte +PTE_HWTABLE_OFF ) | prot; +pmdval_t pmdval = (pte +PTE_HWTABLE_OFF ) | prot; pmdp[0 ] =__pmd (pmdval); pmdp[1 ] =__pmd (pmdval +256 *sizeof (pte_t));flush_pmd_entry (pmdp);
arch/arm/include/asm/pgtable-2level-hwdef.h +41 -41
108 lines not on this page · raw message
arch/arm/include/asm/pgtable-2level-types.h +10 -7
@@ -19,7 +19,10 @@#ifndef _ASM_PGTABLE_2LEVEL_TYPES_H#define _ASM_PGTABLE_2LEVEL_TYPES_H -typedef unsigned long pteval_t ; +typedef u32 pteval_t ; +typedef u32 pmdval_t ; +typedef u32 pgdval_t ; +typedef u32 pgprotval_t ;#undef STRICT_MM_TYPECHECKS
@@ -28,9 +31,9 @@ typedef unsigned long pteval_t;* These are used to make use of C type-checking.. */ typedef struct {pteval_t 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 {pmdval_t pmd; }pmd_t ; +typedef struct {pgdval_t pgd[2 ]; }pgd_t ; +typedef struct {pgprotval_t pgprot; }pgprot_t ;#define pte_val (x) ((x).pte)#define pmd_val (x) ((x).pmd)
@@ -46,9 +49,9 @@ typedef struct { unsigned long pgprot; } pgprot_t;* .. while these make it easier on the compiler */ typedef pteval_t pte_t ; -typedef unsigned long pmd_t ; -typedef unsigned long pgd_t [2 ]; -typedef unsigned long pgprot_t ; +typedef pmdval_t pmd_t ; +typedef pgdval_t pgd_t [2 ]; +typedef pgprotval_t pgprot_t ;#define pte_val (x) (x)#define pmd_val (x) (x)
arch/arm/include/asm/tlbflush.h +2 -2
@@ -514,7 +514,7 @@ static inline void local_flush_tlb_kernel_page(unsigned long kaddr)* these operations. This is typically used when we are removing * PMD entries. */ -static inline void flush_pmd_entry (pmd_t *pmd) +static inline void flush_pmd_entry (void *pmd) {const unsigned int __tlb_flag = __cpu_tlb_flags;
@@ -530,7 +530,7 @@ static inline void flush_pmd_entry(pmd_t *pmd)dsb (); } -static inline void clean_pmd_entry (pmd_t *pmd) +static inline void clean_pmd_entry (void *pmd) {const unsigned int __tlb_flag = __cpu_tlb_flags;
arch/arm/mm/mm.h +2 -2
@@ -17,8 +17,8 @@ static inline pmd_t *pmd_off_k(unsigned long virt)struct mem_type {pteval_t prot_pte; -unsigned int prot_l1; -unsigned int prot_sect; +pgprotval_t prot_l1; +pgprotval_t prot_sect;unsigned int domain; };
arch/arm/mm/mmu.c +1 -1
@@ -290,7 +290,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; +pgprotval_t user_pgprot, kern_pgprot, vecs_pgprot;int cpu_arch =cpu_architecture ();int i;
PATCH v4 7/19 ARM: LPAE: Use a mask for physical addresses in page table entries
In reply to Catalin MarinasWith LPAE, the physical address mask is 40-bit while the page table entry is 64-bit. This patch introduces PHYS_MASK for the 2-level page table format, defined as ~0UL.
--- arch/arm/include/asm/pgtable-2level-hwdef.h | 2 ++ arch/arm/include/asm/pgtable.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-)
arch/arm/include/asm/pgtable-2level-hwdef.h +2 -0
@@ -88,4 +88,6 @@#define PTE_SMALL_AP_URO_SRW (_AT(pteval_t, 0xaa) << 4)#define PTE_SMALL_AP_URW_SRW (_AT(pteval_t, 0xff) << 4) +#define PHYS_MASK (~0UL) +#endif
arch/arm/include/asm/pgtable.h +3 -3
@@ -195,10 +195,10 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD];static inline pte_t *pmd_page_vaddr (pmd_t pmd) { -return __va (pmd_val (pmd) &PAGE_MASK ); +return __va (pmd_val (pmd) &PHYS_MASK & (s32 )PAGE_MASK ); } -#define pmd_page (pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd))) +#define pmd_page (pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd) & PHYS_MASK))/* we don't need complex calculations here as the pmd is folded into the pgd */ #define pmd_addr_end (addr,end) (end)
@@ -219,7 +219,7 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)#define pte_offset_map (pmd,addr) (__pte_map(pmd) + pte_index(addr))#define pte_unmap (pte) __pte_unmap(pte) -#define pte_pfn (pte) (pte_val(pte) >> PAGE_SHIFT) +#define pte_pfn (pte) ((pte_val(pte) & PHYS_MASK) >> PAGE_SHIFT)#define pfn_pte (pfn,prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))#define pte_page (pte) pfn_to_page(pte_pfn(pte))
PATCH v4 8/19 ARM: LPAE: Introduce the 3-level page table format definitions
In reply to Catalin MarinasThis 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 | 81 +++++++++++++++++++++ arch/arm/include/asm/pgtable-3level-types.h | 68 ++++++++++++++++++ arch/arm/include/asm/pgtable-3level.h | 101 +++++++++++++++++++++++++++ arch/arm/include/asm/pgtable-hwdef.h | 4 + arch/arm/include/asm/pgtable.h | 4 + 6 files changed, 262 insertions(+), 0 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
@@ -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 +81 -0
81 lines not on this page · raw message
arch/arm/include/asm/pgtable-3level-types.h new file +68 -0
68 lines not on this page · raw message
arch/arm/include/asm/pgtable-3level.h new file +101 -0
101 lines not on this page · raw message
arch/arm/include/asm/pgtable-hwdef.h +4 -0
@@ -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 +4 -0
@@ -24,7 +24,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
PATCH v4 9/19 ARM: LPAE: Page table maintenance for the 3-level format
In reply to Catalin MarinasThis 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.
The patch also introduces the L_PGD_SWAPPER flag to mark pgd entries pointing to pmd tables pre-allocated in the swapper_pg_dir and avoid trying to free them at run-time. This flag is 0 with the classic page table format.
--- arch/arm/include/asm/cpu-multi32.h | 8 ++++ arch/arm/include/asm/cpu-single.h | 4 ++ arch/arm/include/asm/pgalloc.h | 24 ++++++++++++ arch/arm/include/asm/pgtable-2level.h | 5 +++ arch/arm/include/asm/pgtable-3level.h | 5 +++ arch/arm/include/asm/pgtable.h | 60 ++++++++++++++++++++++++++++++- arch/arm/include/asm/proc-fns.h | 13 +++++++ arch/arm/mm/ioremap.c | 8 +++-- arch/arm/mm/pgd.c | 64 +++++++++++++++++++++++++-------- arch/arm/mm/proc-v7.S | 8 ++++ 10 files changed, 180 insertions(+), 19 deletions(-)
arch/arm/include/asm/cpu-multi32.h +8 -0
@@ -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
@@ -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 +24 -0
@@ -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 *pgd_alloc (struct mm_struct *mm);extern void pgd_free (struct mm_struct *mm,pgd_t *pgd);
@@ -107,7 +129,9 @@ static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte, {pmdval_t pmdval = (pte +PTE_HWTABLE_OFF ) | prot; 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-2level.h +5 -0
@@ -140,4 +140,9 @@#define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 0x0b) << 2)/* 1011 */ #define L_PTE_MT_MASK (_AT(pteval_t, 0x0f) << 2) +/* +* Software PGD flags. +*/ +#define L_PGD_SWAPPER (_AT(pgdval_t, 0))/* compatibility with LPAE */ +#endif /* _ASM_PGTABLE_2LEVEL_H */
arch/arm/include/asm/pgtable-3level.h +5 -0
@@ -98,4 +98,9 @@#define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 3) << 2)/* normal inner write-back */ #define L_PTE_MT_MASK (_AT(pteval_t, 7) << 2) +/* +* Software PGD flags. +*/ +#define L_PGD_SWAPPER (_AT(pgdval_t, 1) << 55)/* swapper_pg_dir entry */ +#endif /* _ASM_PGTABLE_3LEVEL_H */
arch/arm/include/asm/pgtable.h +59 -1
92 lines not on this page · raw message
arch/arm/include/asm/proc-fns.h +13 -0
@@ -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
@@ -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+
@@ -221,7 +223,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 &&
@@ -292,7 +294,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 +49 -15
107 lines not on this page · raw message
arch/arm/mm/proc-v7.S +8 -0
@@ -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_RDONLY +1: strd r2, r3, [r0] +#else /* !CONFIG_ARM_LPAE */ str r1, [r0] @ linux version bic r3, r1, #0x000003f0
@@ -162,6 +169,7 @@ ENTRY(cpu_v7_set_pte_ext) ARM( str r3, [r0, #2048]! ) THUMB( add r0, r0, #2048 ) THUMB( str r3, [r0] ) +#endif /* CONFIG_ARM_LPAE */ mcr p15, 0, r0, c7, c10, 1 @ flush_pte #endif mov pc, lr
PATCH v4 10/19 ARM: LPAE: MMU setup for the 3-level page table format
In reply to Catalin MarinasThis 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 | 115 +++++++++++++++++++++++++++++++-------------- arch/arm/mm/mmu.c | 32 ++++++++++++- arch/arm/mm/proc-macros.S | 5 +- arch/arm/mm/proc-v7.S | 104 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 207 insertions(+), 49 deletions(-)
arch/arm/kernel/head.S +79 -36
@@ -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 PMD_ORDER 3 +#else +#define PG_DIR_SIZE 0x4000 +#define PMD_ORDER 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
@@ -136,11 +146,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
@@ -148,6 +158,24 @@ __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 + mov r7, #1 << (55 - 32) @ L_PGD_SWAPPER +1: strd r3, r7, [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 /*
@@ -159,30 +187,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 #PMD_ORDER] @ 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 - add r0, r4, #(KERNEL_START & 0xff000000) >> 18 - str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]! + mov r3, r3, lsr #SECTION_SHIFT + orr r3, r7, r3, lsl #SECTION_SHIFT + add r0, r4, #(KERNEL_START & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER) + str r3, [r0, #(KERNEL_START & 0x00e00000) >> (SECTION_SHIFT - PMD_ORDER)]! ldr r6, =(KERNEL_END - 1) - add r0, r0, #4 - add r6, r4, r6, lsr #18 + add r0, r0, #1 << PMD_ORDER + add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER) 1: cmp r0, r6 - add r3, r3, #1 << 20 - strls r3, [r0], #4 + add r3, r3, #1 << SECTION_SHIFT + strls r3, [r0], #1 << PMD_ORDER bls 1b #ifdef CONFIG_XIP_KERNEL
@@ -193,11 +221,11 @@ __create_page_tables: .if (KERNEL_RAM_PADDR & 0x00f00000) orr r3, r3, #(KERNEL_RAM_PADDR & 0x00f00000) .endif - add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> 18 - str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> 18]! + add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER) + str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> (SECTION_SHIFT - PMD_ORDER)]! ldr r6, =(_end - 1) add r0, r0, #4 - add r6, r4, r6, lsr #18 + add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER) 1: cmp r0, r6 add r3, r3, #1 << 20 strls r3, [r0], #4
@@ -205,12 +233,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 + add r0, r4, #PAGE_OFFSET >> (SECTION_SHIFT - PMD_ORDER) 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]
@@ -223,21 +252,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 #PMD_ORDER 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 */
@@ -249,7 +284,7 @@ __create_page_tables: * If we're using the NetWinder or CATS, we also need to map * in the 16550-type serial port for the debug messages */ - add r0, r4, #0xff000000 >> 18 + add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ORDER) orr r3, r7, #0x7c000000 str r3, [r0] #endif
@@ -259,13 +294,16 @@ __create_page_tables: * Similar reasons here - for debug. This is * only for Acorn RiscPC architectures. */ - add r0, r4, #0x02000000 >> 18 + add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ORDER) orr r3, r7, #0x02000000 str r3, [r0] - add r0, r4, #0xd8000000 >> 18 + add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ORDER) 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
@@ -355,12 +393,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
@@ -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_RDONLY,
@@ -423,6 +427,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.
@@ -430,6 +435,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 ()) {/*
@@ -468,6 +474,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);
@@ -584,6 +602,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) {
@@ -642,6 +661,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
@@ -672,6 +692,7 @@ static void __init create_mapping(struct map_desc *md) type = &mem_types[md->type]; +#ifndef CONFIG_ARM_LPAE /* * Catch 36-bit addresses */
@@ -679,6 +700,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);
@@ -883,6 +905,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 */
@@ -892,7 +922,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
@@ -91,8 +91,9 @@ #if L_PTE_SHARED != PTE_EXT_SHARED #error PTE shared bit mismatch #endif -#if (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+L_PTE_DIRTY+L_PTE_YOUNG+\ - L_PTE_FILE+L_PTE_PRESENT) > L_PTE_SHARED +#if !defined (CONFIG_ARM_LPAE) && \ + (L_PTE_XN+L_PTE_USER+L_PTE_RDONLY+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 +94 -10
182 lines not on this page · raw message
PATCH v4 11/19 ARM: LPAE: Add fault handling support
In reply to Catalin MarinasThe 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
@@ -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
134 lines not on this page · raw message
PATCH v4 12/19 ARM: LPAE: Add context switching support
In reply to Catalin MarinasWith 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
@@ -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
@@ -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
PATCH v4 13/19 ARM: LPAE: Add identity mapping support for the 3-level page table format
In reply to Catalin MarinasWith LPAE, the pgd is a separate page table with entries pointing to the pmd. The identity_mapping_add() function needs to ensure that the pgd is populated before populating the pmd level. The do..while blocks now loop over the pmd in order to have the same implementation for the two page table formats. The pmd_addr_end() definition has been removed and the generic one used instead. The pmd clean-up is done in the pgd_free() function.
--- arch/arm/include/asm/pgtable.h | 4 ---- arch/arm/mm/idmap.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-)
arch/arm/include/asm/pgtable.h +0 -4
@@ -257,10 +257,6 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)#define pmd_page (pmd) pfn_to_page(__phys_to_pfn(pmd_val(pmd) & PHYS_MASK)) -/* we don't need complex calculations here as the pmd is folded into the pgd */ -#define pmd_addr_end (addr,end) (end) - -#ifndef CONFIG_HIGHPTE #define __pte_map (pmd) pmd_page_vaddr(*(pmd))#define __pte_unmap (pte) do { } while (0)
arch/arm/mm/idmap.c +28 -11
@@ -1,3 +1,5 @@ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/kernel.h> #include <asm/cputype.h>
@@ -7,12 +9,25 @@static void idmap_add_pmd (pgd_t *pgd,unsigned long addr,unsigned long end,unsigned long prot) { -pmd_t *pmd =pmd_offset (pgd, addr); +pmd_t *pmd; + +if (pgd_none_or_clear_bad (pgd) || (pgd_val (*pgd) &L_PGD_SWAPPER )) { + pmd =pmd_alloc_one (NULL , addr); +if (!pmd) { +pr_warning ("Failed to allocate identity pmd.\n" ); +return ; + } +pgd_populate (NULL , pgd, pmd); + pmd +=pmd_index (addr); + }else + pmd =pmd_offset (pgd, addr); addr = (addr &PMD_MASK ) | prot; pmd[0 ] =__pmd (addr); +#ifndef CONFIG_ARM_LPAE addr +=SECTION_SIZE ; pmd[1 ] =__pmd (addr); +#endif flush_pmd_entry (pmd); }
@@ -20,21 +35,24 @@ void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end) {unsigned long prot, next; - prot =PMD_TYPE_SECT |PMD_SECT_AP_WRITE ; + prot =PMD_TYPE_SECT |PMD_SECT_AP_WRITE |PMD_SECT_AF ;if (cpu_architecture () <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale ()) prot |=PMD_BIT4 ; - pgd +=pgd_index (addr);do { - next =pgd_addr_end (addr, end); -idmap_add_pmd (pgd, addr, next, prot); - }while (pgd++, addr = next, addr != end); + next =pmd_addr_end (addr, end); +idmap_add_pmd (pgd +pgd_index (addr), addr, next, prot); + }while (addr = next, addr < end); }#ifdef CONFIG_SMP static void idmap_del_pmd (pgd_t *pgd,unsigned long addr,unsigned long end) { -pmd_t *pmd =pmd_offset (pgd, addr); +pmd_t *pmd; + +if (pgd_none_or_clear_bad (pgd)) +return ; + pmd =pmd_offset (pgd, addr);pmd_clear (pmd); }
@@ -42,11 +60,10 @@ void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end) {unsigned long next; - pgd +=pgd_index (addr);do { - next =pgd_addr_end (addr, end); -idmap_del_pmd (pgd, addr, next); - }while (pgd++, addr = next, addr != end); + next =pmd_addr_end (addr, end); +idmap_del_pmd (pgd +pgd_index (addr), addr, next); + }while (addr = next, addr < end); }#endif
PATCH v4 14/19 ARM: LPAE: Add SMP support for the 3-level page table format
In reply to Catalin MarinasWith 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.
---
There was a comment that secondary_startup hunk below should not reorder the code but pass two registers for TTBR0 and TTBR1. I still find this approach simpler __v7_setup never programs TTBR0 so it would ignore one of the registers.
arch/arm/kernel/head.S | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/arm/kernel/head.S +5 -5
@@ -331,6 +331,10 @@ ENTRY(secondary_startup) THUMB( it eq ) @ force fixup-able long branch encoding 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. */
@@ -338,12 +342,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) /*
PATCH v4 15/19 ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Catalin MarinasFrom: 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/pgtable.h | 2 +- arch/arm/include/asm/setup.h | 2 +- arch/arm/kernel/setup.c | 5 +++-- arch/arm/mm/init.c | 6 +++--- arch/arm/mm/mmu.c | 7 ++++--- 7 files changed, 29 insertions(+), 24 deletions(-)
arch/arm/include/asm/memory.h +9 -8
@@ -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 (const volatile void *x) +static inline phys_addr_t virt_to_phys (const volatile 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
@@ -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/pgtable.h +1 -1
@@ -273,7 +273,7 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)#define pte_unmap (pte) __pte_unmap(pte)#define pte_pfn (pte) ((pte_val(pte) & PHYS_MASK) >> PAGE_SHIFT) -#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_page (pte) pfn_to_page(pte_pfn(pte))#define mk_pte (page,prot) pfn_pte(page_to_pfn(page), prot)
arch/arm/include/asm/setup.h +1 -1
@@ -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/kernel/setup.c +3 -2
@@ -443,7 +443,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];
@@ -479,7 +479,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;/*
arch/arm/mm/init.c +3 -3
@@ -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 +4 -3
@@ -611,7 +611,7 @@ static void __init create_36bit_mapping(struct map_desc *md,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 ())) {
@@ -672,7 +672,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;
@@ -703,7 +704,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 )) {
PATCH v4 16/19 ARM: LPAE: Use generic dma_addr_t type definition
In reply to Catalin MarinasFrom: 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
@@ -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
PATCH v4 17/19 ARM: LPAE: mark memory banks with start > ULONG_MAX as highmem
In reply to Catalin MarinasFrom: 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
@@ -782,7 +782,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;
@@ -791,7 +792,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, "
PATCH v4 18/19 ARM: LPAE: add support for ATAG_MEM64
In reply to Catalin MarinasFrom: 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
@@ -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
@@ -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
@@ -588,11 +588,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,
PATCH v4 19/19 ARM: LPAE: Add the Kconfig entries
In reply to Catalin MarinasThis 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
@@ -1656,7 +1656,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
@@ -621,6 +621,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 to 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
Re: [PATCH v4 01/19] ARM: Make the argument to virt_to_phys() "const volatile"
In reply to Catalin MarinasQuoted 7 lines · Catalin Marinas
Changing the
virt_to_phys()argument to "const volatile void *" avoids compiler warnings in some situations where this function is used.Signed-off-by Catalin Marinas <[email protected]>Cc Stephen Boyd <[email protected]>Cc Arnd Bergmann <[email protected]>---
Any chance we can get this one patch into 2.6.38? It fixes a warning for MSM.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
In reply to Catalin MarinasToo bad about the PAE thing; my condolences.
Quoted 2 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).
Seeing as you're shaking up these definitions, what do you think about switching from 4level-fixup.h to pgtable-nopud.h / pgtable-nopmd.h headers? One day eventually it would be nice to get rid of the fixup mode.
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
Quoted 11 lines · Nick Piggin
Too bad about the PAE thing; my condolences.
Quoted 2 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).
Seeing as you're shaking up these definitions, what do you think about switching from
4level-fixup.htopgtable-nopud.h/pgtable-nopmd.hheaders? One day eventually it would be nice to get rid of the fixup mode.
I have patches to do this which I de-queued for the last merge window. It's not entirely trivial and without problem. You can find the patches in linux-next now.
I was waiting for the new set of patches from Catalin before going back and working out the solutions to some of those problems.
Re: [PATCH v4 01/19] ARM: Make the argument to virt_to_phys() "const volatile"
In reply to Stephen BoydQuoted 9 lines · Stephen Boyd
Quoted 7 lines · Catalin Marinas
Changing the
virt_to_phys()argument to "const volatile void *" avoids compiler warnings in some situations where this function is used.Signed-off-by Catalin Marinas <[email protected]>Cc Stephen Boyd <[email protected]>Cc Arnd Bergmann <[email protected]>---
Quoted 4 lines
Acked-by Stephen Boyd <[email protected]>Any chance we can get this one patch into 2.6.38? It fixes a warning for MSM.
I don't see any reason why this can't. Catalin, can you put it in the patch system with Stephen's ack please?
Arnd Bergmann
Acked-byRe: [PATCH v4 01/19] ARM: Make the argument to virt_to_phys() "const volatile"
In reply to Stephen BoydQuoted 7 lines · Stephen Boyd
Quoted 6 lines · Catalin Marinas
Changing the
virt_to_phys()argument to "const volatile void *" avoids compiler warnings in some situations where this function is used.Signed-off-by Catalin Marinas <[email protected]>Cc Stephen Boyd <[email protected]>Cc Arnd Bergmann <[email protected]>
Quoted 4 lines
Acked-by Stephen Boyd <[email protected]>Any chance we can get this one patch into 2.6.38? It fixes a warning for MSM.
Stephen, you might want to have a look at why the warning even appears on MSM. Most uses of 'volatile' are misguided, and there could be an actual bug in there.
Arnd
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
In reply to Russell King - ARM LinuxQuoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Nick Piggin
Quoted 2 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).
Seeing as you're shaking up these definitions, what do you think about switching from
4level-fixup.htopgtable-nopud.h/pgtable-nopmd.hheaders? One day eventually it would be nice to get rid of the fixup mode.
Quoted 6 lines
I have patches to do this which I de-queued for the last merge window. It's not entirely trivial and without problem. You can find the patches in linux-next now.
I was waiting for the new set of patches from Catalin before going back and working out the solutions to some of those problems.
I'm fine with going this route but I haven't had time to review your patches yet (have they been posted to the list, I've been busy lately and haven't followed everything).
Thanks.
Signature · 1 line
Catalin
Re: [PATCH v4 01/19] ARM: Make the argument to virt_to_phys() "const volatile"
In reply to Arnd BergmannQuoted 11 lines · Arnd Bergmann
Quoted 7 lines · Stephen Boyd
Quoted 6 lines · Catalin Marinas
Changing the
virt_to_phys()argument to "const volatile void *" avoids compiler warnings in some situations where this function is used.Signed-off-by Catalin Marinas <[email protected]>Cc Stephen Boyd <[email protected]>Cc Arnd Bergmann <[email protected]>Acked-by Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 4 lines
Acked-by Stephen Boyd <[email protected]>Any chance we can get this one patch into 2.6.38? It fixes a warning for MSM.
Stephen, you might want to have a look at why the warning even appears on MSM. Most uses of 'volatile' are misguided, and there could be an actual bug in there.
It's actually the right thing - look at x86's definition:
static inline phys_addr_t virt_to_phys(volatile void *address)
Re: [PATCH v4 01/19] ARM: Make the argument to virt_to_phys() "const volatile"
Quoted 7 lines · Russell King - ARM Linux
Quoted 3 lines
Stephen, you might want to have a look at why the warning even appears on MSM. Most uses of 'volatile' are misguided, and there could be an actual bug in there.
It's actually the right thing - look at x86's definition:
static inline
phys_addr_tvirt_to_phys(volatile void *address)
Yes, the definition of virt_to_phys using a volatile pointer makes sense because it allows you to pass volatile pointers, even if it doesn't make any volatile accesses itself, hence my Acked-by.
However, marking variables as volatile needs to be done very carefully, and the particular use in arch/arm/mach-msm/smd.c looks suspicious. I don't think it can cause any actual harm to add volatile to the smd_half_channel variables, but it disables some optimizations that gcc can otherwise make, and it's not a replacement for locking or atomic accesses.
Arnd
Re: [PATCH v4 09/19] ARM: LPAE: Page table maintenance for the 3-level format
In reply to Catalin MarinasQuoted 24 lines · Catalin Marinas
arch/arm/mm/pgd.c +7
-9@@ -80,20 +98,36 @@ void pgd_free(struct mm_struct *mm, pgd_t *pgd_base)if (!pgd_base)return ; - pgd = pgd_base +pgd_index (0 ); -if (pgd_none_or_clear_bad (pgd)) - goto no_pgd; +if (!vectors_high ()) { + 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; + 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);
arch/arm/mm/pgd.c void pgd_free(struct mm_struct *mm, pgd_t *pgd_base) · line 117
Quoted 10 lines
arch/arm/mm/pgd.c +6
-2+ pte =pmd_pgtable (*pmd); +pmd_clear (pmd); +pte_free (mm, pte); no_pmd: -pgd_clear (pgd); -pmd_free (mm, pmd); +pgd_clear (pgd); +pmd_free (mm, pmd); + } no_pgd:
I pushed some fixups to the arm-lpae branch mentioned in the cover letter.
The hunk above doesn't need to be applied since FIRST_USER_ADDRESS is non-zero on ARM and free_pgtables() misses the first PMD when cleaning up user page tables (hence leaking some memory).
Signature · 1 line
Catalin
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
In reply to Catalin MarinasQuoted 3 lines · Catalin Marinas
arch/arm/include/asm/pgtable-3level-hwdef.h new file +0
-0@@ -0,0 +1,81 @@
[...]
arch/arm/include/asm/pgtable-3level-hwdef.h line 60
Quoted 5 lines
arch/arm/include/asm/pgtable-3level-hwdef.h new file +5
-0+#define PMD_SECT_UNCACHED (_AT(pteval_t, 0) << 2)/* strongly ordered */ +#define PMD_SECT_BUFFERED (_AT(pteval_t, 1) << 2)/* normal non-cacheable */ +#define PMD_SECT_WT (_AT(pteval_t, 2) << 2)/* normal inner write-through */ +#define PMD_SECT_WB (_AT(pteval_t, 3) << 2)/* normal inner write-back */ +#define PMD_SECT_WBWA (_AT(pteval_t, 7) << 2)/* normal inner write-alloc */
The above definitions should use pmdval_t rather than pteval_t (fixup pushed to the arm-lpae branch).
Signature · 1 line
Catalin
Re: [PATCH v4 06/19] ARM: LPAE: Add (pte|pmd|pgd|pgprot)val_t type definitions as u32
In reply to Catalin Marinasarch/arm/mm/mmu.c static void __init build_mem_type_table(void) · line 295
Quoted 10 lines · Catalin Marinas
arch/arm/mm/mmu.c +1
-1@@ -290,7 +290,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; +pgprotval_t user_pgprot, kern_pgprot, vecs_pgprot;int cpu_arch =cpu_architecture ();int i;
I have an additional hunk for this file as pmd's have are 64-bit long with LPAE (fixup pushed to the arm-lpae branch):
@@ -62,7 +62,7 @@ EXPORT_SYMBOL(pgprot_kernel);
struct cachepolicy {
const char policy[16];
unsigned int cr_mask;
- unsigned int pmd;
+ pmdval_t pmd;
pteval_t pte;
};
Signature · 1 line
Catalin
Re: [PATCH v4 09/19] ARM: LPAE: Page table maintenance for the 3-level format
In reply to Catalin MarinasQuoted 4 lines · Catalin Marinas
The patch also introduces the
L_PGD_SWAPPERflag to mark pgd entries pointing to pmd tables pre-allocated in theswapper_pg_dirand avoid trying to free them at run-time. This flag is 0 with the classic page table format.
This shouldn't be necessary.
Quoted 37 lines
arch/arm/mm/pgd.c +10
-1@@ -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,6 +18,14 @@#include "mm.h" +#ifdef CONFIG_ARM_LPAE +#define __pgd_alloc () kmalloc(PTRS_PER_PGD * sizeof(pgd_t), GFP_KERNEL) +#define __pgd_free (pgd) kfree(pgd) +#else +#define __pgd_alloc () (pgd_t *)__get_free_pages(GFP_KERNEL, 2) +#define __pgd_free (pgd) free_pages((unsigned long)pgd, 2) +#endif +/* * need to get a 16k page for level 1 */ @@ -26,7 +35,7 @@ pgd_t *pgd_alloc(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 =__pgd_alloc ();if (!new_pgd) goto no_pgd;
arch/arm/mm/pgd.c pgd_t *pgd_alloc(struct mm_struct *mm) · line 59
Quoted 10 lines
arch/arm/mm/pgd.c +7
-0@@ -41,12 +50,21 @@ pgd_t *pgd_alloc(struct mm_struct *mm)clean_dcache_area (new_pgd,PTRS_PER_PGD *sizeof (pgd_t)); +#ifdef CONFIG_ARM_LPAE +/* +* Allocate PMD table for modules and pkmap mappings. +*/ + new_pmd =pmd_alloc (mm, new_pgd +pgd_index (MODULES_VADDR ),0 ); +if (!new_pmd) + goto no_pmd;
This should be a copy of the same page tables found in swapper_pg_dir - that's what the memcpy() above is doing.
arch/arm/mm/pgd.c pgd_t *pgd_alloc(struct mm_struct *mm) · line 67
Quoted 9 lines
arch/arm/mm/pgd.c +3
-1+#endif +if (!vectors_high ()) {/* * On ARM, first page must always be allocated since it * contains the machine vectors. */ - new_pmd =pmd_alloc (mm, new_pgd,0 ); + new_pmd =pmd_alloc (mm, new_pgd +pgd_index (0 ),0 );
However, the first pmd table, and the first pte table only need to be present for the reason stated in the comment, and these need to be allocated.
Quoted 13 lines
arch/arm/mm/pgd.c +1
-1if (!new_pmd) goto no_pmd;@@ -66,7 +84,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm) no_pte:pmd_free (mm, new_pmd); no_pmd: -free_pages ((unsigned long )new_pgd,2 ); +__pgd_free (new_pgd); no_pgd:return NULL ; }
arch/arm/mm/pgd.c void pgd_free(struct mm_struct *mm, pgd_t *pgd_base) · line 101
Quoted 7 lines
arch/arm/mm/pgd.c +1
-3@@ -80,20 +98,36 @@ void pgd_free(struct mm_struct *mm, pgd_t *pgd_base)if (!pgd_base)return ; - pgd = pgd_base +pgd_index (0 ); -if (pgd_none_or_clear_bad (pgd)) - goto no_pgd; +if (!vectors_high ()) {
No, that's wrong. As FIRST_USER_ADDRESS is nonzero, the first pmd and pte table will remain allocated in spite of free_pgtables(), so this results in a memory leak.
Quoted 29 lines
arch/arm/mm/pgd.c +16
-9+ 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; + 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); + pte =pmd_pgtable (*pmd); +pmd_clear (pmd); +pte_free (mm, pte); no_pmd: -pgd_clear (pgd); -pmd_free (mm, pmd); +pgd_clear (pgd); +pmd_free (mm, pmd); + } no_pgd: -free_pages ((unsigned long ) pgd_base,2 ); +#ifdef CONFIG_ARM_LPAE +/* +* Free modules/pkmap or identity pmd tables. +*/
arch/arm/mm/pgd.c void pgd_free(struct mm_struct *mm, pgd_t *pgd_base) · line 131
Quoted 10 lines
arch/arm/mm/pgd.c +10
-0+for (pgd = pgd_base; pgd < pgd_base +PTRS_PER_PGD ; pgd++) { +if (pgd_none_or_clear_bad (pgd)) +continue ; +if (pgd_val (*pgd) &L_PGD_SWAPPER ) +continue ; + pmd =pmd_offset (pgd,0 ); +pgd_clear (pgd); +pmd_free (mm, pmd); + } +#endif
And as kernel mappings in the pgd above TASK_SIZE are supposed to be identical across all page tables, this shouldn't be necessary.
Re: [PATCH v4 09/19] ARM: LPAE: Page table maintenance for the 3-level format
Quoted 7 lines · Russell King - ARM Linux
Quoted 4 lines · Catalin Marinas
The patch also introduces the
L_PGD_SWAPPERflag to mark pgd entries pointing to pmd tables pre-allocated in theswapper_pg_dirand avoid trying to free them at run-time. This flag is 0 with the classic page table format.This shouldn't be necessary.
I tried hard to find a simple way around this but couldn't, so any suggestion is welcomed. Basically we have two situations where pgd_alloc/pgd_free are called: (1) new user mm and (2) identity mapping. As long as we allocate a PMD for the modules/pkmap mappings, we need to make sure it is freed (more why this allocation is needed below).
For (1), we can (safely?) assume that we always have a vma in the same 1GB range with the MODULES_VADDR. I suspect the stack always gets at the top of TASK_SIZE.
For (2), there is no guarantee that this PMD is freed, so we need to explicit freeing in pgd_free().
But we can't simply try to free the previously allocated PMD corresponding to MODULES_VADDR. There is a situation when the user page tables had been cleared and we get an abort for modules/pkmap. We than copy (safely, that's only temporarily used) the corresponding pgd_k entry (1GB) into the soon to be freed pgd. At this point pgd_free() would try to free the PMD from swapper_pg_dir and that's not possible.
The L_PGD_SWAPPER also comes in handy when setting up identity mappings. Since the top PGD entries (starting with PAGE_OFFSET >> PGDIR_SHIFT) are copied by pgd_alloc from swapper_pg_dir, we don't want the init pgd being corrupted when PHYS_OFFSET > PAGE_OFFSET. Hence we check L_PGD_SWAPPER and allocate another PMD if necessary. But at some point we need to free such PMD and can't blindly try to free the swapper_pg_dir pages.
Quoted 40 lines
Quoted 40 lines
arch/arm/mm/pgd.c +0
-0@@ -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>arch/arm/mm/pgd.c +0
-0@@ -17,6 +18,14 @@?#include "
mm.h"arch/arm/mm/pgd.c +8
-0+#ifdef CONFIG_ARM_LPAE +#define __pgd_alloc () ? ? ? ?kmalloc(PTRS_PER_PGD * sizeof(pgd_t), GFP_KERNEL) +#define __pgd_free (pgd) ? ? ?kfree(pgd) +#else +#define __pgd_alloc () ? ? ? ?(pgd_t *)__get_free_pages(GFP_KERNEL, 2) +#define __pgd_free (pgd) ? ? ?free_pages((unsigned long)pgd, 2) +#endif +?/*
? * need to get a 16k page for level 1
? */arch/arm/mm/pgd.c +1
-1@@ -26,7 +35,7 @@ pgd_t *pgd_alloc(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 = __pgd_alloc(); ? ? ? if (!new_pgd) ? ? ? ? ? ? ? goto no_pgd;@@ -41,12 +50,21 @@ pgd_t *pgd_alloc(struct mm_struct *mm) ? ? ? clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
Quoted 10 lines
arch/arm/mm/pgd.c pgd_t *pgd_alloc(struct mm_struct *mm) · line 59
Quoted 7 lines
arch/arm/mm/pgd.c +7
-0+#ifdef CONFIG_ARM_LPAE + ? ? /* + ? ? ?* Allocate PMD table for modules and pkmap mappings. + ? ? ?*/ + ? ? new_pmd = pmd_alloc(mm, new_pgd + pgd_index(MODULES_VADDR), 0); + ? ? if (!new_pmd) + ? ? ? ? ? ? goto no_pmd;This should be a copy of the same page tables found in
swapper_pg_dir- that's what thememcpy()above is doing.
The memcpy() above only copied between 1 and 3 entries in the pgd_k (corresponding to 1 to 3GB kernel space). It doesn't copy the entry corresponding to 1GB below PAGE_OFFSET that would be used by modules. We need to allocate a new PMD for that.
The problem with the current memory map is that one PGD entry covers 1GB and the one corresponding to MODULES_VADDR is shared between user and kernel. An alternative would be to move the kernel a bit higher (and allow MODULES_VADDR at a 1GB boundary. The PAGE_OFFSET would be something like 3GB + 16M, though I'm not sure what other implications this would have.
Yet another alternative which I don't like at all is to pretend that we only have 2 levels of page tables and always allocate 4 PMD pages + 1 PGD.
Quoted 5 lines
Quoted 5 lines
arch/arm/mm/pgd.c +2
-0+#endif + ? ? ? if (!vectors_high()) {? ? ? ? ? ? ? /*
? ? ? ? ? ? ? ?* On ARM, first page must always be allocated since it
Quoted 8 lines
Quoted 4 lines
? ? ? ? ? ? ? ?* contains the machine vectors.
? ? ? ? ? ? ? ?*/
- ? ? ? ? ? ?new_pmd=pmd_alloc(mm, new_pgd, 0);
+ ? ? ? ? ? ?new_pmd=pmd_alloc(mm, new_pgd + pgd_index(0), 0);However, the first pmd table, and the first pte table only need to be present for the reason stated in the comment, and these need to be allocated.
The above change is harmless, I just added it for correctness.
Quoted 16 lines
Quoted 16 lines
? ? ? ? ? ? ? if (!new_pmd)
? ? ? ? ? ? ? ? ? ? ? gotono_pmd;arch/arm/mm/pgd.c +0
-0@@ -66,7 +84,7 @@ pgd_t *pgd_alloc(struct mm_struct *mm)?no_pte:
? ? ?pmd_free(mm, new_pmd);
?no_pmd:
- ? ?free_pages((unsigned long)new_pgd, 2);
+ ? ?__pgd_free(new_pgd);
?no_pgd:
? ? ? return NULL;
?}arch/arm/mm/pgd.c +0
-0@@ -80,20 +98,36 @@ void pgd_free(struct mm_struct *mm, pgd_t *pgd_base) ? ? ? if (!pgd_base) ? ? ? ? ? ? ? return;
Quoted 8 lines
arch/arm/mm/pgd.c void pgd_free(struct mm_struct *mm, pgd_t *pgd_base) · line 101
Quoted 4 lines
arch/arm/mm/pgd.c +1
-3- ? ? pgd = pgd_base + pgd_index(0); - ? ? if (pgd_none_or_clear_bad(pgd)) - ? ? ? ? ? ? goto no_pgd; + ? ? if (!vectors_high()) {No, that's wrong. ?As
FIRST_USER_ADDRESSis nonzero, the first pmd and pte table will remain allocated in spite offree_pgtables(), so this results in a memory leak.
I agree (and I replied to my own post earlier today), we found the leak in testing. It is safe to remove this hunk (I had a thought that it may trigger a bad pmd because of the identity mapping but that's cleared already via identity_mapping_del().
Quoted 34 lines
Quoted 34 lines
arch/arm/mm/pgd.c +9
-6+ ? ? ? ? ? ? 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; + ? ? ? ? ? ? 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); + ? ? ? ? ? ? pte = pmd_pgtable(*pmd); + ? ? ? ? ? ? pmd_clear(pmd); + ? ? ? ? ? ? pte_free(mm, pte);?no_pmd:
- ? ?pgd_clear(pgd);
- ? ?pmd_free(mm, pmd);
+ ? ? ? ? ? ?pgd_clear(pgd);
+ ? ? ? ? ? ?pmd_free(mm, pmd);
+ ? ? }
?no_pgd:
- ? ?free_pages((unsigned long) pgd_base, 2);
+#ifdefCONFIG_ARM_LPAE
+ ? ? /*
+ ? ? ?* Free modules/pkmap or identity pmd tables.
+ ? ? ?*/
+ ? ? for (pgd =pgd_base; pgd <pgd_base+PTRS_PER_PGD; pgd++) {
+ ? ? ? ? ? ? if (pgd_none_or_clear_bad(pgd))
+ ? ? ? ? ? ? ? ? ? ? continue;
+ ? ? ? ? ? ? if (pgd_val(*pgd)&L_PGD_SWAPPER)
+ ? ? ? ? ? ? ? ? ? ? continue;
Quoted 8 lines
Quoted 5 lines
+ ? ? ? ? ? ? pmd =
pmd_offset(pgd, 0);
+ ? ? ? ? ? ?pgd_clear(pgd);
+ ? ? ? ? ? ?pmd_free(mm, pmd);
+ ? ? }
+#endifAnd as kernel mappings in the pgd above
TASK_SIZEare supposed to be identical across all page tables, this shouldn't be necessary.
For tasks yes, but what about the identity mapping allocations? We could change the name of pgd_alloc() and add another parameter to distinguish between these two scenarios.
Signature · 1 line
Catalin
Re: [PATCH v4 02/19] ARM: LPAE: Fix early_pte_alloc() assumption about the Linux PTE
In reply to Catalin MarinasQuoted 3 lines · Catalin Marinas
With LPAE we no longer have software bits in a separate Linux PTE and the
early_pte_alloc()function should passPTE_HWTABLE_OFF+PTE_HWTABLE_SIZEtoearly_alloc()to avoid allocating extra memory.
This one can also go to the patch system too.
Re: [PATCH v4 03/19] ARM: LPAE: use long long format when printing physical addresses and ptes
In reply to Catalin Marinasarch/arm/kernel/setup.c static int __init arm_add_memory(unsigned long start, unsigned long size) · line 452
Quoted 10 lines · Catalin Marinas
arch/arm/kernel/setup.c +1
-1@@ -449,7 +449,7 @@ static int __init arm_add_memory(unsigned long 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 %#08llx\n" , (long long )start);
This is not equivalent. %#lx produces '0x0'. %#08llx produces '0x000000' not '0x00000000' - the '0x' is included in the field width. So you want '%#010llx' or '0x%08llx' - there's no real advantage to either. Or just convert '%#lx' to '%#llx'.
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Catalin MarinasQuoted 8 lines · Catalin Marinas
arch/arm/include/asm/memory.h | 17 +++++++++-------- arch/arm/include/asm/outercache.h | 14 ++++++++------ arch/arm/include/asm/pgtable.h | 2 +- arch/arm/include/asm/setup.h | 2 +- arch/arm/kernel/setup.c | 5 +++-- arch/arm/mm/init.c | 6 +++--- arch/arm/mm/mmu.c | 7 ++++--- 7 files changed, 29 insertions(+), 24 deletions(-)
If this is split up into four separate patches, we can probably sort out merging this for the upcoming window.
asm/memory.h will conflict non-trivially with p2v patch set, but I think we can merge the changes to everything but __virt_to_phys/__phys_to_virt.
asm/outercache.h changes are stand-alone.
asm/pgtable.h looks like it could use __pfn_to_phys(pfn) rather than adding the cast, and can be combined with mm/init.c and mm/mmu.c.
asm/setup.h and arch/arm/kernel/setup.c form another logical group.
Re: [PATCH v4 16/19] ARM: LPAE: Use generic dma_addr_t type definition
In reply to Catalin MarinasQuoted 7 lines · Catalin Marinas
From: Will Deacon <[email protected]>
This patch uses the
types.himplementation in asm-generic to define thedma_addr_ttype as the same width asphys_addr_t.NOTE: this is a temporary patch until the corresponding patches unifying the
dma_addr_tand removing thedma64_addr_tare merged into mainline.
I'm not too sure about this patch. All of the DMA devices we have only take 32-bit addresses for their DMA, so making dma_addr_t 64-bit seems wrong as we'll implicitly truncate these addresses.
As ARM platforms don't (sanely) support DMA, I think dropping this patch for the time being would be a good idea, and stick with 32-bit dma_addr_t, especially as we need to first do a sweep for dma_addr_t usage in device driver structures (such as dma engine scatter lists.) These really should use __le32/__be32/u32 depending on whether they're little endian, big endian or native endian.
Re: [PATCH v4 17/19] ARM: LPAE: mark memory banks with start > ULONG_MAX as highmem
In reply to Catalin Marinasarch/arm/mm/mmu.c static void __init sanity_check_meminfo(void) · line 786
Quoted 7 lines · Catalin Marinas
arch/arm/mm/mmu.c +2
-1@@ -782,7 +782,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 )
I think this check should be first, so that we don't try to evaluate __va() on phys addresses > ULONG_MAX, possibly resulting in truncation.
Re: [PATCH v4 12/19] ARM: LPAE: Add context switching support
In reply to Catalin Marinasarch/arm/mm/context.c unsigned int cpu_last_asid = ASID_FIRST_VERSION; · line 32
Quoted 8 lines · Catalin Marinas
arch/arm/mm/context.c +8
-0+#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)); \
This is wrong:
1. It does nothing with %2 (the new asid)
2. it shifts the high address bits of TTBR0 left 16 places each time its called.
Quoted 32 lines
arch/arm/mm/context.c +8
-2+} +#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 +0
-0
arch/arm/mm/proc-v7.S ENTRY(cpu_v7_switch_mm) · line 119
Quoted 3 lines
arch/arm/mm/proc-v7.S +0
-0@@ -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
How about swapping the order here to avoid r1 being referenced in the very next instruction?
Quoted 26 lines
arch/arm/mm/proc-v7.S +7
-1+#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_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 16/19] ARM: LPAE: Use generic dma_addr_t type definition
In reply to Russell King - ARM LinuxQuoted 6 lines · Russell King - ARM Linux
Quoted 5 lines · Catalin Marinas
From: Will Deacon <[email protected]>
This patch uses the
types.himplementation in asm-generic to define thedma_addr_ttype as the same width asphys_addr_t.
Quoted 6 lines
Quoted 2 lines
NOTE: this is a temporary patch until the corresponding patches unifying the
dma_addr_tand removing thedma64_addr_tare merged into mainline.I'm not too sure about this patch. All of the DMA devices we have only take 32-bit addresses for their DMA, so making
dma_addr_t64-bit seems wrong as we'll implicitly truncate these addresses.
If we don't enable LPAE, the dma_addr_t is 32-bit, so existing platforms are not affected. With Cortex-A15, new platforms may have PCIe and be able to access memory beyond 32-bit (if they don't support >32-bit DMA at least for some critical devices, I'm not sure why they would use A15).
For things like hard drives for example, it becomes problematic as pages are allocated by the VFS layer from highmem and passed to the driver for DMA. If we keep dma_addr_t to 32-bit you would need to use DMA bounce even if the PCIe device supports >32-bit physical addresses.
Quoted 6 lines
As ARM platforms don't (sanely) support DMA, I think dropping this patch for the time being would be a good idea, and stick with 32-bit
dma_addr_t, especially as we need to first do a sweep fordma_addr_tusage in device driver structures (such as dma engine scatter lists.) These really should use __le32/__be32/u32 depending on whether they're little endian, big endian or native endian.
Maybe we could make the dma_addr_t size configurable (and disabled by default) since I expect there'll be platforms capable of >32-bit DMA.
Signature · 1 line
Catalin
Re: [PATCH v4 12/19] ARM: LPAE: Add context switching support
In reply to Russell King - ARM LinuxQuoted 14 lines · Russell King - ARM Linux
arch/arm/mm/context.c unsigned int cpu_last_asid = ASID_FIRST_VERSION; · line 32
Quoted 8 lines · Catalin Marinas
arch/arm/mm/context.c +8
-0+#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)); \This is wrong:
1. It does nothing with %2 (the new asid)
2. it shifts the high address bits of TTBR0 left 16 places each time its called.
It was worse actually, not even compiled in because it had output arguments but it wasn't volatile. Some early clobber is also needed. What about this:
#define cpu_set_asid(asid) { \
unsigned long ttbl, ttbh; \
asm volatile( \
" mrrc p15, 0, %0, %1, c2 @ read TTBR0\n" \
" mov %1, %2, lsl #(48 - 32) @ set ASID\n" \
" mcrr p15, 0, %0, %1, c2 @ set TTBR0\n" \
: "=&r" (ttbl), "=&r" (ttbh) \
: "r" (asid & ~ASID_MASK)); \
}Signature · 1 line
Catalin
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Russell King - ARM LinuxHi Russell,
Quoted 10 lines · Russell King - ARM Linux
Quoted 8 lines · Catalin Marinas
arch/arm/include/asm/memory.h | 17 +++++++++-------- arch/arm/include/asm/outercache.h | 14 ++++++++------ arch/arm/include/asm/pgtable.h | 2 +- arch/arm/include/asm/setup.h | 2 +- arch/arm/kernel/setup.c | 5 +++-- arch/arm/mm/init.c | 6 +++--- arch/arm/mm/mmu.c | 7 ++++--- 7 files changed, 29 insertions(+), 24 deletions(-)
Quoted 3 lines
If this is split up into four separate patches, we can probably sort out merging this for the upcoming window.
Excellent! I've split the patch up into four distinct parts, as per your suggestions. I've submitted these to your patch system (6670/1-6673/1) alongside a fixed version of the printf format patch (6669/1) because without that, you get a bunch of compiler warnings.
Will
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 4 lines · Will Deacon
Excellent! I've split the patch up into four distinct parts, as per your suggestions. I've submitted these to your patch system (6670/1-6673/1) alongside a fixed version of the printf format patch (6669/1) because without that, you get a bunch of compiler warnings.
Except 6669/1 still suffers from "%#08llx". For a value of one, that prints:
0x000001
five zeros following the 0x rather than seven. The width in the format string includes the 0x prefix.
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 6 lines · Russell King - ARM Linux
Quoted 4 lines · Will Deacon
Excellent! I've split the patch up into four distinct parts, as per your suggestions. I've submitted these to your patch system (6670/1-6673/1) alongside a fixed version of the printf format patch (6669/1) because without that, you get a bunch of compiler warnings.
Quoted 6 lines
Except 6669/1 still suffers from "%#08llx". For a value of one, that prints:
0x000001five zeros following the 0x rather than seven. The width in the format string includes the 0x prefix.
Ah, sorry, I only fixed one case and forgot about the rest (and misleading Will).
Signature · 1 line
Catalin
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 9 lines · Catalin Marinas
Quoted 8 lines · Russell King - ARM Linux
Quoted 4 lines · Will Deacon
Excellent! I've split the patch up into four distinct parts, as per your suggestions. I've submitted these to your patch system (6670/1-6673/1) alongside a fixed version of the printf format patch (6669/1) because without that, you get a bunch of compiler warnings.
Except 6669/1 still suffers from "%#08llx". For a value of one, that prints:
Quoted 8 lines
Quoted 4 lines
0x000001five zeros following the 0x rather than seven. The width in the format string includes the 0x prefix.
Ah, sorry, I only fixed one case and forgot about the rest (and misleading Will).
I should've spotted this either way. I've superseded the old patch with 6674/1.
Apologies for the confusion,
Will
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 2 lines · Will Deacon
I should've spotted this either way. I've superseded the old patch with 6674/1.
One additional thing that I think has been lost. I said in the original reply to Catalin:
| asm/memory.h will conflict non-trivially with p2v patch set, but I think | we can merge the changes to everything but __virt_to_phys/__phys_to_virt.
So 6670/1 which I'm intending to apply to the p2v branch can't be merged as-is. The ideal solution would be a version of 6670/1 to apply on top of the existing p2v branch.
Thanks.
Re: [PATCH v4 16/19] ARM: LPAE: Use generic dma_addr_t type definition
In reply to Catalin MarinasQuoted 2 lines · Catalin Marinas
Maybe we could make the
dma_addr_tsize configurable (and disabled by default) since I expect there'll be platforms capable of >32-bit DMA.
It would be far better to fix the dma_addr_t abuses. I've already fixed those in the pl08x driver:
struct lli {
dma_addr_t src;
dma_addr_t dst;
dma_addr_t next;
u32 cctl;
};became:
struct pl08x_lli {
u32 src;
u32 dst;
u32 lli;
u32 cctl;
};and similar needs to be done elsewhere in ARM specific drivers. dma_addr_t has no business being in structures that describe data which hardware accesses.
Re: [PATCH v4 16/19] ARM: LPAE: Use generic dma_addr_t type definition
Quoted 5 lines · Russell King - ARM Linux
Quoted 2 lines · Catalin Marinas
Maybe we could make the
dma_addr_tsize configurable (and disabled by default) since I expect there'll be platforms capable of >32-bit DMA.It would be far better to fix the
dma_addr_tabuses.
That's not a simple task, I have no idea how many drivers get used on ARM systems. We can defer this until people start using Cortex-A15 in real hardware and only fix the drivers they need.
BTW, can sparse help here (I haven't used it much)?
Signature · 1 line
Catalin
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Russell King - ARM LinuxHi Russell,
Quoted 4 lines · Russell King - ARM Linux
Quoted 2 lines · Will Deacon
I should've spotted this either way. I've superseded the old patch with 6674/1.
Quoted 9 lines
One additional thing that I think has been lost. I said in the original reply to Catalin:
|asm/memory.hwill conflict non-trivially with p2v patch set, but I think | we can merge the changes to everything but __virt_to_phys/__phys_to_virt.So 6670/1 which I'm intending to apply to the p2v branch can't be merged as-is. The ideal solution would be a version of 6670/1 to apply on top of the existing p2v branch.
The conflict with the p2v branch is fairly hefty, but something like this should do (if you're happy I'll submit it to replace 6670/1):
Note that because the v2p macros only work for lowmem, I've not bothered to add casts for the __v2p macros (rather, I've just changed the types of the static inline functions). This simplifies the code and means we can stay clear of the runtime fixup stuff.
arch/arm/include/asm/memory.h +5 -4
@@ -15,6 +15,7 @@#include <linux/compiler.h> #include <linux/const.h> +#include <linux/types.h> #include <mach/memory.h> #include <asm/sizes.h>
@@ -135,8 +136,8 @@/* * 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
@@ -234,12 +235,12 @@ static inline unsigned long __phys_to_virt(unsigned long x)* 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))); }
Cheers,
Will
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 2 lines · Will Deacon
The conflict with the p2v branch is fairly hefty, but something like this should do (if you're happy I'll submit it to replace 6670/1):
I was thinking that was the case - which is why I wanted this split up so this can be tackled separately.
Quoted 4 lines
Note that because the v2p macros only work for lowmem, I've not bothered to add casts for the
__v2pmacros (rather, I've just changed the types of the static inline functions). This simplifies the code and means we can stay clear of the runtime fixup stuff.
This patch looks good enough, thanks.
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Catalin MarinasQuoted 5 lines · Catalin Marinas
From: Will Deacon <[email protected]>
The unsigned long datatype is not sufficient for mapping physical addresses
Quoted 1 line
= 4GB.
Quoted 7 lines
This patch ensures that the
phys_addr_tdatatype 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.Signed-off-by Will Deacon <[email protected]>Signed-off-by Catalin Marinas <[email protected]>
This patch needs some more things fixed to prevent warnings:
arch/arm/mm/mmu.c +8 -6
@@ -809,9 +809,10 @@ static void __init sanity_check_meminfo(void)*/ if (__va (bank->start) >= vmalloc_min ||__va (bank->start) < (void *)PAGE_OFFSET ) { -printk (KERN_NOTICE "Ignoring RAM at %.8lx-%.8lx " +printk (KERN_NOTICE "Ignoring RAM@%.8llx-%.8llx " "(vmalloc region overlap).\n" , - bank->start, bank->start + bank->size -1 ); + (unsigned long long )bank->start, + (unsigned long long )bank->start + bank->size -1 );continue ; }
@@ -822,10 +823,11 @@ static void __init sanity_check_meminfo(void)if (__va (bank->start + bank->size) > vmalloc_min ||__va (bank->start + bank->size) <__va (bank->start)) {unsigned long newsize = vmalloc_min -__va (bank->start); -printk (KERN_NOTICE "Truncating RAM at %.8lx-%.8lx " -"to -%.8lx (vmalloc region overlap).\n" , - bank->start, bank->start + bank->size -1 , - bank->start + newsize -1 ); +printk (KERN_NOTICE "Truncating RAM at %.8llx-%.8llx " +"to -%.8llx (vmalloc region overlap).\n" , + (unsigned long long )bank->start, + (unsigned long long )bank->start + bank->size -1 , + (unsigned long long )bank->start + newsize -1 ); bank->size = newsize; }#endif
Re: [PATCH v4 12/19] ARM: LPAE: Add context switching support
In reply to Catalin MarinasQuoted 20 lines · Catalin Marinas
Quoted 14 lines · Russell King - ARM Linux
arch/arm/mm/context.c unsigned int cpu_last_asid = ASID_FIRST_VERSION; · line 32
Quoted 8 lines · Catalin Marinas
arch/arm/mm/context.c +8
-0+#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)); \This is wrong:
1. It does nothing with %2 (the new asid)
2. it shifts the high address bits of TTBR0 left 16 places each time its called.It was worse actually, not even compiled in because it had output arguments but it wasn't volatile. Some early clobber is also needed. What about this:
Quoted 9 lines
#define cpu_set_asid(asid) { \
unsigned long ttbl, ttbh; \
asm volatile( \
" mrrc p15, 0, %0, %1, c2 @ read TTBR0\n" \
" mov %1, %2, lsl #(48 - 32) @ set ASID\n" \
" mcrr p15, 0, %0, %1, c2 @ set TTBR0\n" \
: "=&r" (ttbl), "=&r" (ttbh) \
: "r" (asid & ~ASID_MASK)); \
}So we don't care about the low 16 bits of ttbh which can be simply zeroed?
Re: [PATCH v4 12/19] ARM: LPAE: Add context switching support
Quoted 31 lines · Russell King - ARM Linux
Quoted 20 lines · Catalin Marinas
Quoted 14 lines · Russell King - ARM Linux
Review
Quoted 8 lines · Catalin Marinas
(quoted diff) +8
-0+#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)); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \This is wrong:
1. It does nothing with %2 (the new asid)
2. it shifts the high address bits of TTBR0 left 16 places each time its ? ?called.It was worse actually, not even compiled in because it had output arguments but it wasn't volatile. Some early clobber is also needed. What about this:
Quoted 9 lines
#define
cpu_set_asid(asid){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
? ? ? unsigned long ttbl, ttbh; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
? ? ? asm volatile( ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
? ? ? " ? ? ? mrrc ? ?p15, 0, %0, %1, c2 ? ? ? ? ? ? ?@ read TTBR0\n" \
? ? ? " ? ? ? mov ? ? %1, %2, lsl #(48 - 32) ? ? ? ? ?@ set ASID\n" ? \
? ? ? " ? ? ? mcrr ? ?p15, 0, %0, %1, c2 ? ? ? ? ? ? ?@ set TTBR0\n" ?\
? ? ? : "=&r" (ttbl), "=&r" (ttbh) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\
? ? ? : "r" (asid & ~ASID_MASK)); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
}
Quoted 1 line
So we don't care about the low 16 bits of ttbh which can be simply zeroed?
Since the pgd is always allocated from lowmem, it is within 32-bit of physical address and we can safely ignore ttbh. I could write a comment here to this.
Catalin
Signature · 1 line
Catalin
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
In reply to Russell King - ARM LinuxHi Russell,
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · 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_tdatatype 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.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Will Deacon <[email protected]>Signed-off-by Catalin Marinas <[email protected]>This patch needs some more things fixed to prevent warnings:
Ah yes, this is for the non-HIGHMEM case which I hadn't considered for LPAE. It's a perfectly reasonable configuration I suppose so this needs fixing.
Quoted 23 lines
arch/arm/mm/mmu.c +3
-4@@ -809,9 +809,10 @@ static void __init sanity_check_meminfo(void)*/ if (__va (bank->start) >= vmalloc_min ||__va (bank->start) < (void *)PAGE_OFFSET ) { -printk (KERN_NOTICE "Ignoring RAM at %.8lx-%.8lx " +printk (KERN_NOTICE "Ignoring RAM at %.8llx-%.8llx " "(vmalloc region overlap).\n" , - bank->start, bank->start + bank->size -1 ); + (unsigned long long )bank->start, + (unsigned long long )bank->start + bank->size -1 );continue ; }@@ -822,10 +823,11 @@ static void __init sanity_check_meminfo(void)if (__va (bank->start + bank->size) > vmalloc_min ||__va (bank->start + bank->size) <__va (bank->start)) {unsigned long newsize = vmalloc_min -__va (bank->start); - printk(KERN_NOTICE "Truncating RAM at %.8lx-%.8lx " - "to -%.8lx (vmalloc region overlap).\n",
arch/arm/mm/mmu.c static void __init sanity_check_meminfo(void) · line 833
Quoted 10 lines
arch/arm/mm/mmu.c +5
-2- bank->start, bank->start + bank->size -1 , - bank->start + newsize - 1); +printk (KERN_NOTICE "Truncating RAM at %.8llx-%.8llx " +"to -%.8llx (vmalloc region overlap).\n" , + (unsigned long long )bank->start, + (unsigned long long )bank->start + bank->size -1 , + (unsigned long long )bank->start + newsize -1 ); bank->size = newsize; }#endif
Would you like me to submit an additional patch or are you happy merging this diff in with my ack?
Cheers,
Will
Re: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 2 lines · Will Deacon
Would you like me to submit an additional patch or are you happy merging this diff in with my ack?
The latter - I've already merged it and if you give an ack I'll add that.
Thanks.
Will Deacon
Acked-byRe: [PATCH v4 15/19] ARM: LPAE: use phys_addr_t instead of unsigned long for physical addresses
Quoted 6 lines · Russell King - ARM Linux
Quoted 2 lines · Will Deacon
Would you like me to submit an additional patch or are you happy merging this diff in with my ack?
The latter - I've already merged it and if you give an ack I'll add that.
Thanks,
Will
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
In reply to Russell King - ARM LinuxHi Russell,
Quoted 13 lines · Russell King - ARM Linux
Quoted 11 lines · Nick Piggin
Too bad about the PAE thing; my condolences.
Quoted 2 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).
Seeing as you're shaking up these definitions, what do you think about switching from
4level-fixup.htopgtable-nopud.h/pgtable-nopmd.hheaders? One day eventually it would be nice to get rid of the fixup mode.
Quoted 6 lines
I have patches to do this which I de-queued for the last merge window. It's not entirely trivial and without problem. ?You can find the patches in linux-next now.
I was waiting for the new set of patches from Catalin before going back and working out the solutions to some of those problems.
Any plans for the nopmd patches? I haven't seen them in -next or on the list.
Thanks.
Signature · 1 line
Catalin
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
Quoted 1 line · Catalin Marinas
Any plans for the nopmd patches? I haven't seen them in -next or on the list.
I dropped them again because of those pesky warnings, so again I'm not planning to push them this window as I don't wish to be deluged in people reporting the warnings.
They really need fixing once we know how the LPAE stuff interacts with the change. At the moment I've no idea whether the existing section support ends up at pgd or pmd level with LPAE.
Obviously that matters as with LPAE, pgd and pmd are different hardware levels, but without LPAE they're the same hardware level.
Re: [PATCH v4 08/19] ARM: LPAE: Introduce the 3-level page table format definitions
Quoted 10 lines · Russell King - ARM Linux
Quoted 1 line · Catalin Marinas
Any plans for the nopmd patches? I haven't seen them in -next or on the list.
I dropped them again because of those pesky warnings, so again I'm not planning to push them this window as I don't wish to be deluged in people reporting the warnings.
They really need fixing once we know how the LPAE stuff interacts with the change. ?At the moment I've no idea whether the existing section support ends up at pgd or pmd level with LPAE.
With LPAE, the section should be at the pmd level (2nd level page table) as the PGDIR_SHIFT is 30. But if we standardise on using the pmd in both cases, macros like pmd_val() would expand to the right level with classic page tables (it goes up to pgd_val).
PMD_SHIFT also gets defined as PGDIR_SHIFT for the classic page tables. One of my patches in the series converts the existing code to PMD_SHIFT from PGDIR_SHIFT.
I'm happy to give this a try if you have some existing patches for the classic page tables (I can even start from scratch but I don't want to duplicate work).
Signature · 1 line
Catalin