sparc64: Fix physical memory management regressions with large max_phys_bits.
David Miller
maintainerPATCH 2/6 sparc64: Fix physical memory management regressions with large max_phys_bits.
If max_phys_bits needs to be > 43 (f.e. for T4 chips), things like DEBUG_PAGEALLOC stop working because the 3-level page tables only can cover up to 43 bits.
Another problem is that when we increased MAX_PHYS_ADDRESS_BITS up to 47, several statically allocated tables became enormous.
Compounding this is that we will need to support up to 49 bits of physical addressing for M7 chips.
The two tables in question are sparc64_valid_addr_bitmap and kpte_linear_bitmap.
The first holds a bitmap, with 1 bit for each 4MB chunk of physical memory, indicating whether that chunk actually exists in the machine and is valid.
The second table is a set of 2-bit values which tell how large of a mapping (4MB, 256MB, 2GB, 16GB, respectively) we can use at each 256MB chunk of ram in the system.
These tables are huge and take up an enormous amount of the BSS section of the sparc64 kernel image. Specifically, the sparc64_valid_addr_bitmap is 4MB, and the kpte_linear_bitmap is 128K.
So let's solve the space wastage and the DEBUG_PAGEALLOC problem at the same time, by using the kernel page tables (as designed) to manage this information.
But, as we mentioned, the 3-level sparc64 page tables can only handle up to 43-bits. So we solve this by adding a 4th level above the PGDs but _only_ for managing the PAGE_OFFSET linear mappings. The cost of this "pgd demux" table is one page.
The rest of the kernel page table walks go via init_mm.pgd (swapper_pg_dir) and are oblivious to this 4th page table level. This works because everything the generic kernel code tries to map using the kernel page tables stays within what swapper_pg_dir maps.
We have to keep using large mappings when DEBUG_PAGEALLOC is disabled, and we do this by encoding huge PMDs and PUDs.
On a T4-2 with 256GB of ram the kernel page table takes up 16K with DEBUG_PAGEALLOC disabled and 256MB with it enabled. Furthermore, this memory is dynamically allocated at run time rather than coded statically into the kernel image.
--- arch/sparc/include/asm/page_64.h | 3 - arch/sparc/include/asm/pgtable_64.h | 61 +++--- arch/sparc/include/asm/tsb.h | 35 +++- arch/sparc/kernel/ktlb.S | 108 +---------- arch/sparc/mm/init_64.c | 364 +++++++++++++++++++----------------- arch/sparc/mm/init_64.h | 7 - 6 files changed, 261 insertions(+), 317 deletions(-)
arch/sparc/include/asm/page_64.h +0 -3
@@ -129,9 +129,6 @@ extern unsigned long PAGE_OFFSET;*/ #define MAX_PHYS_ADDRESS_BITS 47 -/* These two shift counts are used when indexing sparc64_valid_addr_bitmap -* and kpte_linear_bitmap. -*/ #define ILOG2_4MB 22#define ILOG2_256MB 28
arch/sparc/include/asm/pgtable_64.h +34 -27
127 lines not on this page · raw message
arch/sparc/include/asm/tsb.h +29 -6
@@ -133,27 +133,50 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end; sub TSB, 0x8, TSB; \TSB_STORE (TSB ,TAG ); -/* Do a kernel page table walk. Leaves physical PTE pointer in +/* Do a kernel page table walk. Leaves valid PTE value in * REG1. Jumps to FAIL_LABEL on early page table walk termination. * VADDR will not be clobbered, but REG2 will. */ #define KERN_PGTABLE_WALK (VADDR ,REG1 ,REG2 ,FAIL_LABEL ) \ - sethi %hi(swapper_pg_dir), REG1; \ - or REG1, %lo(swapper_pg_dir), REG1; \ - sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \ + sethi %hi(kpgd_demux), REG1; \ + or REG1, %lo(kpgd_demux), REG1; \ + sllx VADDR, 64 - (KPGD_SHIFT + KPGD_BITS), REG2; \ srlx REG2, 64 - PAGE_SHIFT, REG2; \ andn REG2, 0x7, REG2; \ ldx [REG1 + REG2], REG1; \ brz,pn REG1, FAIL_LABEL; \ + sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \ + srlx REG2, 64 - PAGE_SHIFT, REG2; \ + andn REG2, 0x7, REG2; \ + ldxa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \ + sethi %uhi(_PAGE_PUD_HUGE), REG2; \ + brz,pn REG1, FAIL_LABEL; \ + sllx REG2, 32, REG2; \ + andcc REG1, REG2, %g0; \ + bne,pt %xcc, 697f; \ sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \ srlx REG2, 64 - PAGE_SHIFT, REG2; \ andn REG2, 0x7, REG2; \ ldxa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \ + sethi %uhi(_PAGE_PMD_HUGE), REG2; \ brz,pn REG1, FAIL_LABEL; \ - sllx VADDR, 64 - PMD_SHIFT, REG2; \ + sllx REG2, 32, REG2; \ + andcc REG1, REG2, %g0; \ + be,pn %xcc, 698f; \ +697: sethi %hi(0xffe00000), REG2; \ + sllx REG2, 1, REG2; \ + brgez,pn REG1, FAIL_LABEL; \ + andn REG1, REG2, REG1; \ + and VADDR, REG2, REG2; \ + ba,pt %xcc, 699f; \ + or REG1, REG2, REG1; \ +698: sllx VADDR, 64 - PMD_SHIFT, REG2; \ srlx REG2, 64 - PAGE_SHIFT, REG2; \ andn REG2, 0x7, REG2; \ - add REG1, REG2, REG1; + ldxa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \ + brgez,pn REG1, FAIL_LABEL; \ + nop; \ +699:/* PMD has been loaded into REG1, interpret the value, seeing * if it is a HUGE PMD or a normal one. If it is not valid
arch/sparc/kernel/ktlb.S +9 -99
134 lines not on this page · raw message
arch/sparc/mm/init_64.c +189 -175
493 lines not on this page · raw message
arch/sparc/mm/init_64.h +0 -7
@@ -8,15 +8,8 @@*/ #define MAX_PHYS_ADDRESS (1UL << MAX_PHYS_ADDRESS_BITS) -#define KPTE_BITMAP_CHUNK_SZ (256UL * 1024UL * 1024UL) -#define KPTE_BITMAP_BYTES \ - ((MAX_PHYS_ADDRESS / KPTE_BITMAP_CHUNK_SZ) / 4) -#define VALID_ADDR_BITMAP_CHUNK_SZ (4UL * 1024UL * 1024UL) -#define VALID_ADDR_BITMAP_BYTES \ - ((MAX_PHYS_ADDRESS / VALID_ADDR_BITMAP_CHUNK_SZ) / 8)extern unsigned long kern_linear_pte_xor[4 ]; -extern unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES /sizeof (unsigned long )];extern unsigned int sparc64_highest_unlocked_tlb_ent;extern unsigned long sparc64_kern_pri_context;extern unsigned long sparc64_kern_pri_nuc_bits;
Signature · 1 line
1.8.1.2
David Miller
maintainerWhile re-auditing this patch, I noticed that page_offset_shift_patch becomes completely unused by this change. So I'm going to kill that patching section from vmlinux.lds.S and the code that processes it in init_64.c
Just FYI...
David Miller wrote: [Fri Sep 26 2014, 12:07:43AM EDT]
Quoted 7 lines
While re-auditing this patch, I noticed that
page_offset_shift_patchbecomes completely unused by this change. So I'm going to kill that patching section fromvmlinux.lds.Sand the code that processes it ininit_64.cJust FYI...
Yes, sorry I saw this on first version but didn't comment because of expected changes.