sparc64: 5-Level page table support for sparc
PATCH 2/3 sparc64: 5-Level page table support for sparc
From: Vijay Kumar <[email protected]>
Added 5-Level paging for sparc.
--- arch/sparc/Kconfig | 2 +- arch/sparc/include/asm/page_64.h | 6 +++ arch/sparc/include/asm/pgalloc_64.h | 25 +++++++++-- arch/sparc/include/asm/pgtable_64.h | 49 +++++++++++++++++---- arch/sparc/include/asm/tsb.h | 10 +++++ arch/sparc/kernel/signal32.c | 6 ++- arch/sparc/kernel/smp_64.c | 13 +++++- arch/sparc/mm/fault_64.c | 8 +++- arch/sparc/mm/gup.c | 28 ++++++++++-- arch/sparc/mm/hugetlbpage.c | 88 +++++++++++++++++++++++++++---------- arch/sparc/mm/init_64.c | 37 +++++++++++++--- 11 files changed, 222 insertions(+), 50 deletions(-)
arch/sparc/Kconfig +1 -1
@@ -159,7 +159,7 @@ config ARCH_SUPPORTS_DEBUG_PAGEALLOC def_bool y if SPARC64 config PGTABLE_LEVELS - default 4 if 64BIT + default 5 if 64BIT default 3 config ARCH_SUPPORTS_UPROBES
arch/sparc/include/asm/page_64.h +6 -0
@@ -62,6 +62,7 @@typedef struct {unsigned long iopte; }iopte_t ;typedef struct {unsigned long pmd; }pmd_t ;typedef struct {unsigned long pud; }pud_t ; +typedef struct {unsigned long p4d; }p4d_t ;typedef struct {unsigned long pgd; }pgd_t ;typedef struct {unsigned long pgprot; }pgprot_t ;
@@ -69,6 +70,7 @@#define iopte_val (x) ((x).iopte)#define pmd_val (x) ((x).pmd)#define pud_val (x) ((x).pud) +#define p4d_val (x) ((x).p4d)#define pgd_val (x) ((x).pgd)#define pgprot_val (x) ((x).pgprot)
@@ -76,6 +78,7 @@#define __iopte (x) ((iopte_t) { (x) } )#define __pmd (x) ((pmd_t) { (x) } )#define __pud (x) ((pud_t) { (x) } ) +#define __p4d (x) ((p4d_t) { (x) } )#define __pgd (x) ((pgd_t) { (x) } )#define __pgprot (x) ((pgprot_t) { (x) } )
@@ -85,6 +88,7 @@typedef unsigned long iopte_t ;typedef unsigned long pmd_t ;typedef unsigned long pud_t ; +typedef unsigned long p4d_t ;typedef unsigned long pgd_t ;typedef unsigned long pgprot_t ;
@@ -92,6 +96,7 @@#define iopte_val (x) (x)#define pmd_val (x) (x)#define pud_val (x) (x) +#define p4d_val (x) (x)#define pgd_val (x) (x)#define pgprot_val (x) (x)
@@ -99,6 +104,7 @@#define __iopte (x) (x)#define __pmd (x) (x)#define __pud (x) (x) +#define __p4d (x) (x)#define __pgd (x) (x)#define __pgprot (x) (x)
arch/sparc/include/asm/pgalloc_64.h +22 -3
@@ -15,12 +15,12 @@extern struct kmem_cache *pgtable_cache; -static inline void __pgd_populate (pgd_t *pgd,pud_t *pud) +static inline void __pgd_populate (pgd_t *pgd,p4d_t *p4d) { -pgd_set (pgd, pud); +pgd_set (pgd, p4d); } +#define pgd_populate (MM ,PGD ,P4D ) __pgd_populate(PGD, P4D) -#define pgd_populate (MM ,PGD ,PUD ) __pgd_populate(PGD, PUD)static inline pgd_t *pgd_alloc (struct mm_struct *mm) {
@@ -32,6 +32,22 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)kmem_cache_free (pgtable_cache, pgd); } +static inline void __p4d_populate (p4d_t *p4d,pud_t *pud) +{ +p4d_set (p4d, pud); +} +#define p4d_populate (MM ,P4D ,PUD ) __p4d_populate(P4D, PUD) + +static inline p4d_t *p4d_alloc_one (struct mm_struct *mm,unsigned long addr) +{ +return kmem_cache_alloc (pgtable_cache,GFP_KERNEL ); +} + +static inline void p4d_free (struct mm_struct *mm,p4d_t *p4d) +{ +kmem_cache_free (pgtable_cache, p4d); +} +static inline void __pud_populate (pud_t *pud,pmd_t *pmd) {pud_set (pud, pmd);
@@ -115,4 +131,7 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pte_t *pte,#define __pud_free_tlb (tlb, pud, addr) \ pgtable_free_tlb(tlb, pud, false) +#define __p4d_free_tlb (tlb, p4d, addr) \ + pgtable_free_tlb(tlb, p4d, false) +#endif /* _SPARC64_PGALLOC_H */
arch/sparc/include/asm/pgtable_64.h +40 -9
111 lines not on this page · raw message
arch/sparc/include/asm/tsb.h +10 -0
@@ -160,6 +160,11 @@ struct tsb_phys_patch_entry { andn REG2, 0x7, REG2; \ ldx [REG1 +REG2 ],REG1 ; \ brz,pn REG1, FAIL_LABEL; \ + sllx VADDR, 64 - (P4D_SHIFT + P4D_BITS), REG2; \ + srlx REG2, 64 - PAGE_SHIFT, REG2; \ + andn REG2, 0x7, REG2; \ + ldxa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \ + brz,pn REG1, FAIL_LABEL; \ sllx VADDR, 64 - (PUD_SHIFT + PUD_BITS), REG2; \ srlx REG2, 64 - PAGE_SHIFT, REG2; \ andn REG2, 0x7, REG2; \
@@ -238,6 +243,11 @@ struct tsb_phys_patch_entry { andn REG2, 0x7, REG2; \ ldxa [PHYS_PGD + REG2] ASI_PHYS_USE_EC, REG1; \ brz,pn REG1, FAIL_LABEL; \ + sllx VADDR, 64 - (P4D_SHIFT + P4D_BITS), REG2; \ + srlx REG2, 64 - PAGE_SHIFT, REG2; \ + andn REG2, 0x7, REG2; \ + ldxa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \ + brz,pn REG1, FAIL_LABEL; \ sllx VADDR, 64 - (PUD_SHIFT + PUD_BITS), REG2; \ srlx REG2, 64 - PAGE_SHIFT, REG2; \ andn REG2, 0x7, REG2; \
arch/sparc/kernel/signal32.c +5 -1
@@ -369,6 +369,7 @@ static void flush_signal_insns(unsigned long address)unsigned long pstate, paddr;pte_t *ptep, pte;pgd_t *pgdp; +p4d_t *p4dp;pud_t *pudp;pmd_t *pmdp;
@@ -388,7 +389,10 @@ static void flush_signal_insns(unsigned long address) pgdp =pgd_offset (current->mm, address);if (pgd_none (*pgdp)) goto out_irqs_on; - pudp =pud_offset (pgdp, address); + p4dp =p4d_offset (pgdp, address); +if (p4d_none (*p4dp)) + goto out_irqs_on; + pudp =pud_offset (p4dp, address);if (pud_none (*pudp)) goto out_irqs_on; pmdp =pmd_offset (pudp, address);
arch/sparc/kernel/smp_64.c +11 -2
@@ -1546,17 +1546,26 @@ static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)static void __init pcpu_populate_pte (unsigned long addr) {pgd_t *pgd =pgd_offset_k (addr); +p4d_t *p4d;pud_t *pud;pmd_t *pmd;if (pgd_none (*pgd)) { -pud_t *new; +p4d_t *new; new =__alloc_bootmem (PAGE_SIZE ,PAGE_SIZE ,PAGE_SIZE );pgd_populate (&init_mm, pgd, new); } - pud =pud_offset (pgd, addr); + p4d =p4d_offset (pgd, addr); +if (p4d_none (*p4d)) { +pud_t *new; + + new =__alloc_bootmem (PAGE_SIZE ,PAGE_SIZE ,PAGE_SIZE ); +p4d_populate (&init_mm, p4d, new); + } + + pud =pud_offset (p4d, addr);if (pud_none (*pud)) {pmd_t *new;
arch/sparc/mm/fault_64.c +7 -1
@@ -93,6 +93,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)static unsigned int get_user_insn (unsigned long tpc) {pgd_t *pgdp =pgd_offset (current->mm, tpc); +p4d_t *p4dp;pud_t *pudp;pmd_t *pmdp;pte_t *ptep, pte;
@@ -101,7 +102,12 @@ static unsigned int get_user_insn(unsigned long tpc)if (pgd_none (*pgdp) ||unlikely (pgd_bad (*pgdp))) goto out; - pudp =pud_offset (pgdp, tpc); + + p4dp =p4d_offset (pgdp, tpc); +if (p4d_none (*p4dp) ||unlikely (p4d_bad (*p4dp))) + goto out; + + pudp =pud_offset (p4dp, tpc);if (pud_none (*pudp) ||unlikely (pud_bad (*pudp))) goto out;
arch/sparc/mm/gup.c +24 -4
@@ -128,13 +128,13 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,return 1 ; } -static int gup_pud_range (pgd_t pgd,unsigned long addr,unsigned long end, +static int gup_pud_range (p4d_t p4d,unsigned long addr,unsigned long end,int write,struct page **pages,int *nr) {unsigned long next;pud_t *pudp; - pudp =pud_offset (&pgd, addr); + pudp =pud_offset (&p4d, addr); do { pud_t pud = *pudp;
@@ -148,6 +148,26 @@ static int gup_pud_range(pgd_t pgd, unsigned long addr, unsigned long end,return 1 ; } +static int gup_p4d_range (pgd_t pgd,unsigned long addr,unsigned long end, +int write,struct page **pages,int *nr) +{ +unsigned long next; +p4d_t *p4dp; + + p4dp =p4d_offset (&pgd, addr); +do { +p4d_t p4d = *p4dp; + + next =p4d_addr_end (addr, end); +if (p4d_none (p4d)) +return 0 ; +if (!gup_pud_range (p4d, addr, next, write, pages, nr)) +return 0 ; + }while (p4dp++, addr = next, addr != end); + +return 1 ; +} +int __get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages) {
@@ -170,7 +190,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write, next =pgd_addr_end (addr, end);if (pgd_none (pgd))break ; -if (!gup_pud_range (pgd, addr, next, write, pages, &nr)) +if (!gup_p4d_range (pgd, addr, next, write, pages, &nr))break ; }while (pgdp++, addr = next, addr != end);local_irq_restore (flags);
@@ -218,7 +238,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, next =pgd_addr_end (addr, end);if (pgd_none (pgd)) goto slow; -if (!gup_pud_range (pgd, addr, next, write, pages, &nr)) +if (!gup_p4d_range (pgd, addr, next, write, pages, &nr)) goto slow; }while (pgdp++, addr = next, addr != end);
arch/sparc/mm/hugetlbpage.c +65 -23
141 lines not on this page · raw message
arch/sparc/mm/init_64.c +31 -6
@@ -467,7 +467,8 @@ void __kprobes flush_icache_range(unsigned long start, unsigned long end) paddr = kaddr & mask; else {pgd_t *pgdp =pgd_offset_k (kaddr); -pud_t *pudp =pud_offset (pgdp, kaddr); +p4d_t *p4dp =p4d_offset (pgdp, kaddr); +pud_t *pudp =pud_offset (p4dp, kaddr);pmd_t *pmdp =pmd_offset (pudp, kaddr);pte_t *ptep =pte_offset_kernel (pmdp, kaddr);
@@ -1591,6 +1592,7 @@ static unsigned long __init bootmem_init(unsigned long phys_base)bool kern_addr_valid (unsigned long addr) {pgd_t *pgd; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;
@@ -1612,7 +1614,11 @@ bool kern_addr_valid(unsigned long addr)if (pgd_none (*pgd))return 0 ; - pud =pud_offset (pgd, addr); + p4d =p4d_offset (pgd, addr); +if (p4d_none (*p4d)) +return 0 ; + + pud =pud_offset (p4d, addr);if (pud_none (*pud))return 0 ;
@@ -1738,18 +1744,27 @@ static unsigned long __ref kernel_map_range(unsigned long pstart,while (vstart < vend) {unsigned long this_end, paddr =__pa (vstart);pgd_t *pgd =pgd_offset_k (vstart); +p4d_t *p4d;pud_t *pud;pmd_t *pmd;pte_t *pte;if (pgd_none (*pgd)) { -pud_t *new; +p4d_t *new; new =__alloc_bootmem (PAGE_SIZE ,PAGE_SIZE ,PAGE_SIZE ); alloc_bytes +=PAGE_SIZE ;pgd_populate (&init_mm, pgd, new); } - pud =pud_offset (pgd, vstart); + p4d =p4d_offset (pgd, vstart); +if (p4d_none (*p4d)) { +pud_t *new; + + new =__alloc_bootmem (PAGE_SIZE ,PAGE_SIZE ,PAGE_SIZE ); + alloc_bytes +=PAGE_SIZE ; +p4d_populate (&init_mm, p4d, new); + } + pud =pud_offset (p4d, vstart);if (pud_none (*pud)) {pmd_t *new;
@@ -2565,18 +2580,28 @@ int __meminit vmemmap_populate(unsigned long vstart, unsigned long vend,for (; vstart < vend; vstart +=PMD_SIZE ) {pgd_t *pgd =pgd_offset_k (vstart);unsigned long pte; +p4d_t *p4d;pud_t *pud;pmd_t *pmd;if (pgd_none (*pgd)) { -pud_t *new =vmemmap_alloc_block (PAGE_SIZE , node); +p4d_t *new =vmemmap_alloc_block (PAGE_SIZE , node);if (!new)return -ENOMEM ;pgd_populate (&init_mm, pgd, new); } - pud =pud_offset (pgd, vstart); + p4d =p4d_offset (pgd, vstart); +if (p4d_none (*p4d)) { +pud_t *new =vmemmap_alloc_block (PAGE_SIZE , node); + +if (!new) +return -ENOMEM ; +p4d_populate (&init_mm, p4d, new); + } + + pud =pud_offset (p4d, vstart);if (pud_none (*pud)) {pmd_t *new =vmemmap_alloc_block (PAGE_SIZE , node);
Signature · 1 line
1.9.1
David Miller
maintainerFrom: Allen Pais <[email protected]>
Date: Thu, 20 Jul 2017 13:10:36 +0530
Quoted 7 lines
From: Vijay Kumar <[email protected]>
Added 5-Level paging for sparc.
Signed-off-by Vijay Kumar <[email protected]>Reviewed-by Bob Picco <[email protected]>Signed-off-by Allen Pais <[email protected]>
So for one chip, we're going to unconditonally eat an entire level of page table traversal on every PTE lookup?
Either stick to what 4-level page tables support for M8 or make it run time selectable.
Thanks.
Quoted 10 lines · David Miller
From: Allen Pais <[email protected]>
Date: Thu, 20 Jul 2017 13:10:36 +0530Quoted 7 lines
From: Vijay Kumar <[email protected]>
Added 5-Level paging for sparc.
Signed-off-by Vijay Kumar <[email protected]>Reviewed-by Bob Picco <[email protected]>Signed-off-by Allen Pais <[email protected]>
Quoted 7 lines
So for one chip, we're going to unconditonally eat an entire level of page table traversal on every PTE lookup?
Either stick to what 4-level page tables support for M8 or make it run time selectable.
Thanks.
I will look into it. Thanks for your input.
Thanks,
Vijay