sparc64: valid physical address bitmap
PATCH 1/1 sparc64: valid physical address bitmap
From: bob picco <[email protected]>
We need to constrain the size of sparc64_valid_addr_bitmap. Historically it has been sized according to maximum physical address and 4Mb DIMM size. This was sufficient with older sparc64 before larger physical address bits.
This patch limits the bitmap to 64Kb by a smaller value for a physical address bits which cover the vast majority of sparc64.
The last_valid_pfn is used to limit the physical address limit within the ktlb miss for identity address checking and increase the megabyte shift granularity of the check for a valid pfn.
An LDOM guest might have an issue with this depending on how the PA to RA ranges were assigned by the control domain. Though this issue already seems to exist for a granularity less than 4Mb which is the current bitmap shift and test.
--- arch/sparc/include/asm/page_64.h | 9 ++++ arch/sparc/include/asm/pgtable_64.h | 10 +++- arch/sparc/kernel/ktlb.S | 6 +++ arch/sparc/kernel/vmlinux.lds.S | 10 ++++ arch/sparc/mm/init_64.c | 86 ++++++++++++++++++++++++++++++++++- arch/sparc/mm/init_64.h | 5 +- 6 files changed, 119 insertions(+), 7 deletions(-)
arch/sparc/include/asm/page_64.h +9 -0
@@ -129,6 +129,15 @@ extern unsigned long PAGE_OFFSET;*/ #define MAX_PHYS_ADDRESS_BITS 47 +/* This represents a subset of the physical address bits. It is used +* to determine how the powerof2 for sparc64_valid_addr_bitmap is changed. +* Basically when max_pfn execeeds this shift value we increase the powerof2 +* for sparc64_valid_addr_bitmap. So increase the power of two one for +* each bit above 41. For example, 51 bits of physical address bits would +* be ILOG2_4MB+10 - 4Gb DIMMs. +*/ +#define MAX_PHYS_ADDRESS_LOBITS 41 +/* These two shift counts are used when indexing sparc64_valid_addr_bitmap * and kpte_linear_bitmap. */
arch/sparc/include/asm/pgtable_64.h +8 -2
@@ -74,13 +74,19 @@#include <linux/sched.h> extern unsigned long sparc64_valid_addr_bitmap[]; +/* These two externs are used specifically for sparc64_valid_addr_bitmap.*/ +extern unsigned int sparc64_lomem_ilog2, sparc64_phys_address_bits_shift;/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */ static inline bool __kern_addr_valid (unsigned long paddr) { -if ((paddr >>MAX_PHYS_ADDRESS_BITS ) !=0UL ) +int bit_set; + +if ((paddr >> sparc64_phys_address_bits_shift) !=0UL )return false; -return test_bit (paddr >>ILOG2_4MB , sparc64_valid_addr_bitmap); + bit_set =test_bit (paddr >> sparc64_lomem_ilog2, + sparc64_valid_addr_bitmap); +return bit_set; }static inline bool kern_addr_valid (unsigned long addr)
arch/sparc/kernel/ktlb.S +6 -0
@@ -165,6 +165,9 @@ .section .page_offset_shift_patch, "ax" .word 661b .previous + .section .phys_max_ilog2_patch, "ax" + .word 661b + .previous brnz,pn %g2, kvmap_dtlb_longpath nop
@@ -187,6 +190,9 @@ .section .page_offset_shift_patch, "ax" .word 661b .previous + .section .phys_lomem_ilog2_patch, "ax" + .word 661b + .previous srlx %g2, 6, %g5 and %g2, 63, %g2
arch/sparc/kernel/vmlinux.lds.S +10 -0
@@ -127,6 +127,16 @@ SECTIONS *(.page_offset_shift_patch) __page_offset_shift_patch_end = .; } + .phys_lomem_ilog2_patch : { + __phys_lomem_ilog2_patch = .; + *(.phys_lomem_ilog2_patch) + __phys_lomem_ilog2_patch_end = .; + } + .phys_max_ilog2_patch : { + __phys_max_ilog2_patch = .; + *(.phys_max_ilog2_patch) + __phys_max_ilog2_patch_end = .; + } .swapper_phys_low_1mb_patch : { __swapper_phys_low_1mb_patch = .; *(.swapper_phys_low_1mb_patch)
arch/sparc/mm/init_64.c +84 -2
129 lines not on this page · raw message
arch/sparc/mm/init_64.h +2 -3
@@ -8,12 +8,11 @@*/ #define MAX_PHYS_ADDRESS (1UL << MAX_PHYS_ADDRESS_BITS) -#define KPTE_BITMAP_CHUNK_SZ (256UL * 1024UL * 1024UL) +#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) + (1UL << (MAX_PHYS_ADDRESS_LOBITS - ILOG2_4MB - 3))extern unsigned long kern_linear_pte_xor[4 ];extern unsigned long kpte_linear_bitmap[KPTE_BITMAP_BYTES /sizeof (unsigned long )];
Signature · 1 line
1.7.1
David Miller
maintainerFrom: Bob Picco <[email protected]>
Date: Tue, 16 Sep 2014 12:52:17 -0400
Quoted 13 lines
From: bob picco <[email protected]>
We need to constrain the size of
sparc64_valid_addr_bitmap. Historically it has been sized according to maximum physical address and 4Mb DIMM size. This was sufficient with older sparc64 before larger physical address bits.This patch limits the bitmap to 64Kb by a smaller value for a physical address bits which cover the vast majority of sparc64.
The
last_valid_pfnis used to limit the physical address limit within the ktlb miss for identity address checking and increase the megabyte shift granularity of the check for a valid pfn.
Quoted 7 lines
An LDOM guest might have an issue with this depending on how the PA to RA ranges were assigned by the control domain. Though this issue already seems to exist for a granularity less than 4Mb which is the current bitmap shift and test.
Signed-off-by Bob Picco <[email protected]>
Let's stop fighting this thing.
Instead, let's just kill the bitmap off completely and scan the 'reg' property of the 'memory' OF node. It's well formed and very small, and now it doesn't matter what granularity works or not for LDOM guests as well.
Bonus is that the BSS section shrinks by 4MB after this change.
This is a really delicate change, the more testing the better. I've only done basic sanity tests on T4-2 so far.
==========
[PATCH] sparc64: Kill sparc64_valid_addr_bitmap.
It keeps growing as we try and increase the number of physical memory bits we support.
We really don't need it, we can just loop over the 'memory' OF node's 'reg' property which represents all valid physical memory. These arrays tend to be well formed, and not very large at all.
Since we are now using this in the kernel TLB miss handler fast path we perform some straightforward transformations on the array. First, we merge as many entries together as we can, there are several prtconf dumps I've seen where this will trigger.
Second, we mark the end of the array with a zero entry, so that the kernel TLB miss handler has to keep less state in registers during the scan.
The BSS section is now 4MB smaller after this change.
--- arch/sparc/include/asm/page_64.h | 3 - arch/sparc/include/asm/pgtable_64.h | 10 +-- arch/sparc/kernel/ktlb.S | 67 +++++---------- arch/sparc/mm/init_64.c | 159 +++++++++++++++++------------------- arch/sparc/mm/init_64.h | 3 - 5 files changed, 97 insertions(+), 145 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 +1 -9
@@ -73,15 +73,7 @@#include <linux/sched.h> -extern unsigned long sparc64_valid_addr_bitmap[]; - -/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */ -static inline bool __kern_addr_valid (unsigned long paddr) -{ -if ((paddr >>MAX_PHYS_ADDRESS_BITS ) !=0UL ) -return false; -return test_bit (paddr >>ILOG2_4MB , sparc64_valid_addr_bitmap); -} +bool __kern_addr_valid (unsigned long paddr);static inline bool kern_addr_valid (unsigned long addr) {
arch/sparc/kernel/ktlb.S +19 -48
87 lines not on this page · raw message
arch/sparc/mm/init_64.c +77 -82
189 lines not on this page · raw message
arch/sparc/mm/init_64.h +0 -3
@@ -11,9 +11,6 @@#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 )];
Signature · 1 line
1.8.1.2
David Miller wrote: [Wed Sep 17 2014, 05:00:48PM EDT]
Quoted 21 lines
From: Bob Picco <[email protected]>
Date: Tue, 16 Sep 2014 12:52:17 -0400Quoted 18 lines
From: bob picco <[email protected]>
We need to constrain the size of
sparc64_valid_addr_bitmap. Historically it has been sized according to maximum physical address and 4Mb DIMM size. This was sufficient with older sparc64 before larger physical address bits.This patch limits the bitmap to 64Kb by a smaller value for a physical address bits which cover the vast majority of sparc64.
The
last_valid_pfnis used to limit the physical address limit within the ktlb miss for identity address checking and increase the megabyte shift granularity of the check for a valid pfn.An LDOM guest might have an issue with this depending on how the PA to RA ranges were assigned by the control domain. Though this issue already seems to exist for a granularity less than 4Mb which is the current bitmap shift and test.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Bob Picco <[email protected]>Let's stop fighting this thing.
Oh do I understand :)
Quoted 5 lines
Instead, let's just kill the bitmap off completely and scan the 'reg' property of the 'memory' OF node. It's well formed and very small, and now it doesn't matter what granularity works or not for LDOM guests as well.
I like the idea.
There might be one issue:
The machine has more reg property entries than this kernel can support (32). Program terminated
. It is a T4-4 LDOM guest configured with an absurd number of PA <-> RA mappings. I haven't examined the issue further than this.
I've invested infinite zero time reviewing your code.
Quoted 5 lines
Bonus is that the BSS section shrinks by 4MB after this change.
This is a really delicate change, the more testing the better. I've only done basic sanity tests on T4-2 so far.
David Miller
maintainerFrom: Bob Picco <[email protected]>
Date: Thu, 18 Sep 2014 06:16:06 -0400
Quoted 5 lines
David Miller wrote: [Wed Sep 17 2014, 05:00:48PM EDT]
Quoted 4 lines
Instead, let's just kill the bitmap off completely and scan the 'reg' property of the 'memory' OF node. It's well formed and very small, and now it doesn't matter what granularity works or not for LDOM guests as well.
Quoted 7 lines
I like the idea.
There might be one issue:
The machine has more reg property entries than this kernel can support (32). Program terminated
. It is a T4-4 LDOM guest configured with an absurd number of PA <-> RA mappings. I haven't examined the issue further than this.
Ok. Given some of the other work I did last night, and after some more consideration, I think I have a better idea of how to handle this.
Let's just use kernel page tables for everything.
We'll put huge PMDs into the kernel page tables for the linear mappings and this will serve two purposes:
1) Physical address validation
2) Huge page size selection
And the kernel page tables deal naturally with sparseness.
We just have to set it up after we take over the trap table from OF. (otherwise we can't actually access any early memory we allocate via memblock or similar) And we have the infrastructure to do that, with instruction patching.
We simply accept all TLB misses to the linear area, strictly use only 4MB TTEs, before we setup the kernel page tables.
I'll see if I can throw something together today.
David Miller
maintainerFrom: Bob Picco <[email protected]>
Date: Thu, 18 Sep 2014 06:16:06 -0400
Quoted 2 lines
The machine has more reg property entries than this kernel can support (32).
Bob, is there some upper bound we can use? I'm happy to enlarge it to whatever reasonable size is necessary.
The 'memory' node properties are the one thing I don't think we can reasonably dynamically allocate memory for, so they have to be statically sized.
With the changes we are discussing here, we are getting several megabytes of BSS space back in the kernel image, so there is lots of room for expanding the value of MAX_BANKS :-)
Also, that debugging message from read_obp_memory() should also print out "ents" so we know how much we might need to expand it in the future.
David Miller wrote: [Thu Sep 18 2014, 01:13:22PM EDT]
Quoted 8 lines
From: Bob Picco <[email protected]>
Date: Thu, 18 Sep 2014 06:16:06 -0400Quoted 2 lines
The machine has more reg property entries than this kernel can support (32).
Bob, is there some upper bound we can use? I'm happy to enlarge it to whatever reasonable size is necessary.
I just sent an email because my knowledge isn't LDOM guest.
Quoted 4 lines
The 'memory' node properties are the one thing I don't think we can reasonably dynamically allocate memory for, so they have to be statically sized.
I agree.
Quoted 4 lines
With the changes we are discussing here, we are getting several megabytes of BSS space back in the kernel image, so there is lots of room for expanding the value of
MAX_BANKS:-)
Indeed.
Quoted 4 lines
Also, that debugging message from
read_obp_memory()should also print out "ents" so we know how much we might need to expand it in the future.
Yes.