powerpc/mm/radix: Update LPCR only if it is powernv
PATCH 1/3 powerpc/mm/radix: Update LPCR only if it is powernv
LPCR cannot be updated when running in guest mode.
--- arch/powerpc/mm/pgtable-radix.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
arch/powerpc/mm/pgtable-radix.c +10 -13
@@ -296,11 +296,6 @@ found:void __init radix__early_init_mmu (void ) {unsigned long lpcr; -/* -* setup LPCR UPRT based on mmu_features -*/ - lpcr =mfspr (SPRN_LPCR ); -mtspr (SPRN_LPCR , lpcr |LPCR_UPRT );#ifdef CONFIG_PPC_64K_PAGES /* PAGE_SIZE mappings */
@@ -343,8 +338,11 @@ void __init radix__early_init_mmu(void) __pte_frag_size_shift =H_PTE_FRAG_SIZE_SHIFT ;radix_init_page_sizes (); -if (!firmware_has_feature (FW_FEATURE_LPAR )) +if (!firmware_has_feature (FW_FEATURE_LPAR )) { + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT );radix_init_partition_table (); + }radix_init_pgtable (); }
@@ -353,16 +351,15 @@ void radix__early_init_mmu_secondary(void) {unsigned long lpcr;/* -* setup LPCR UPRT based on mmu_features +* update partition table control register and UPRT */ - lpcr =mfspr (SPRN_LPCR ); -mtspr (SPRN_LPCR , lpcr |LPCR_UPRT ); -/* -* update partition table control register, 64 K size. -*/ -if (!firmware_has_feature (FW_FEATURE_LPAR )) +if (!firmware_has_feature (FW_FEATURE_LPAR )) { + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT ); +mtspr (SPRN_PTCR ,__pa (partition_tb) | (PATB_SIZE_SHIFT -12 )); + } } void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base,
Signature · 1 line
2.7.4
PATCH 2/3 powerpc/mm/hash: Fix the reference bit update when handling hash fault
When we converted the asm routines to C functions, we missed updating HPTE_R_R based on _PAGE_ACCESSED. ASM code used to copy over the lower bits from pte via.
andi. r3,r30,0x1fe /* Get basic set of flags */
We also update the code such that we won't update the Change bit ('C' bit) always. This was added by
'commit c5cf0e30bf3d8 ("powerpc: Fix buglet with MMU hash management")'
With hash64, we need to make sure that hardware doesn't do a pte update directly. This is because we do end up with entries in TLB with no hash page table entry. This happens because when we find hash bucket full, we "evict" a more/less random entry from it. When we do that we don't invalidate the TLB (hpte_remove) because we assume the old translation is still technically "valid". For more info look at
'commit 0608d692463("powerpc/mm: Always invalidate tlb on hpte invalidate and update")'. Thus it's critical that valid hash PTEs always have reference bit set and writeable ones have change bit set. We do this by hashing a non-dirty linux PTE as read-only and always setting _PAGE_ACCESSED (and thus R) when hashing anything else in. Any attempt by Linux at clearing those bits also removes the corresponding hash entry.
Commitc 5cf0e30bf3d8 did that for 'C' bit by enabling 'C' bit always. We don't really need to do that because we never map a RW pte entry without setting 'C' bit. On READ fault on a RW pte entry, we still map it READ only, hence a store update in the page will still cause a hash pte fault.
This patch reverts the part of the c5cf0e30bf3d8
("[PATCH] powerpc: Fix buglet with MMU hash management") and retain the updatepp part.
- If we hit the updatepp path on native, the old code without that commit, would fail to set C bcause native_hpte_updatepp() was implemented to filter the same bits as H_PROTECT and not let C through thus we would "upgrade" a RO HPTE to RW without setting C thus causing the bug. So the real fix in that commit was the change to native_hpte_updatepp
--- arch/powerpc/mm/hash_utils_64.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
arch/powerpc/mm/hash_utils_64.c +20 -2
@@ -159,6 +159,19 @@ static struct mmu_psize_def mmu_psize_defaults_gp[] = { }, }; +/* +* 'R' and 'C' update notes: +* - Under pHyp or KVM, the updatepp path will not set C, thus it *will* +* create writeable HPTEs without C set, because the hcall H_PROTECT +* that we use in that case will not update C +* - The above is however not a problem, because we also don't do that +* fancy "no flush" variant of eviction and we use H_REMOVE which will +* do the right thing and thus we don't have the race I described earlier +* +* - Under bare metal, we do have the race, so we need R and C set +* - We make sure R is always set and never lost +* - C is _PAGE_DIRTY, and *should* always be set for a writeable mapping +*/ unsigned long htab_convert_pte_flags (unsigned long pteflags) {unsigned long rflags =0 ;
@@ -186,9 +199,14 @@ unsigned long htab_convert_pte_flags(unsigned long pteflags) rflags |=0x1 ; }/* -* Always add "C" bit for perf. Memory coherence is always enabled +* We can't allow hardware to update hpte bits. Hence always +* set 'R' bit and set 'C' if it is a write fault +* Memory coherence is always enabled */ - rflags |=HPTE_R_C |HPTE_R_M ; + rflags |=HPTE_R_R |HPTE_R_M ; + +if (pteflags & _PAGE_DIRTY) + rflags |=HPTE_R_C ;/* * Add in WIG bits */
Signature · 1 line
2.7.4
Re: [2/3] powerpc/mm/hash: Fix the reference bit update when handling hash fault
Quoted 3 lines · Aneesh Kumar K.V
When we converted the asm routines to C functions, we missed updating
HPTE_R_Rbased on_PAGE_ACCESSED. ASM code used to copy over the lower bits from pte via.
...
Quoted 3 lines
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/dc47c0c1f8099fccb2c1e2f377
cheers
PATCH 3/3 powerpc/mm/radix: Add missing tlb flush
In reply to Aneesh Kumar K.VThis should not have any impact on hash, because hash does tlb invalidate with every pte update and we don't implement flush_tlb_* functions for hash. With radix we should make an explicit call to flush tlb outside pte update.
--- arch/powerpc/mm/pgtable-book3s64.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/powerpc/mm/pgtable-book3s64.c +1 -4
@@ -33,10 +33,7 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, changed = !pmd_same (*(pmdp), entry);if (changed) {__ptep_set_access_flags (pmdp_ptep (pmdp),pmd_pte (entry)); -/* -* Since we are not supporting SW TLB systems, we don't -* have any thing similar to flush_tlb_page_nohash() -*/ +flush_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); }return changed; }
Signature · 1 line
2.7.4
Re: [3/3] powerpc/mm/radix: Add missing tlb flush
Quoted 6 lines · Aneesh Kumar K.V
This should not have any impact on hash, because hash does tlb invalidate with every pte update and we don't implement flush_tlb_* functions for hash. With radix we should make an explicit call to flush tlb outside pte update.
Signed-off-by Aneesh Kumar K.V <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/157d4d0620879b7d89ca1e3cd7
cheers
Quoted 12 lines · Aneesh Kumar K.V
LPCR cannot be updated when running in guest mode.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/mm/pgtable-radix.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)arch/powerpc/mm/pgtable-radix.c +0
-0
arch/powerpc/mm/pgtable-radix.c found: · line 298
Quoted 3 lines
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -296,11 +296,6 @@ found:void __init radix__early_init_mmu (void ) {unsigned long lpcr;
Move this to
Quoted 9 lines
arch/powerpc/mm/pgtable-radix.c +0
-5-/* -* setup LPCR UPRT based on mmu_features -*/ - lpcr =mfspr (SPRN_LPCR ); -mtspr (SPRN_LPCR , lpcr |LPCR_UPRT );#ifdef CONFIG_PPC_64K_PAGES /* PAGE_SIZE mappings */
arch/powerpc/mm/pgtable-radix.c void __init radix__early_init_mmu(void) · line 342
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +1
-1@@ -343,8 +338,11 @@ void __init radix__early_init_mmu(void) __pte_frag_size_shift =H_PTE_FRAG_SIZE_SHIFT ;radix_init_page_sizes (); -if (!firmware_has_feature (FW_FEATURE_LPAR )) +if (!firmware_has_feature (FW_FEATURE_LPAR )) {unsigned long lpcr;
Here
arch/powerpc/mm/pgtable-radix.c void radix__early_init_mmu_secondary(void) · line 352
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +3
-0+ lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT );radix_init_partition_table (); + }radix_init_pgtable ();}
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -353,16 +351,15 @@ void radix__early_init_mmu_secondary(void) {unsigned long lpcr;
Same as above
Quoted 11 lines
arch/powerpc/mm/pgtable-radix.c +1
-7/* -* setup LPCR UPRT based on mmu_features +* update partition table control register and UPRT */ - lpcr =mfspr (SPRN_LPCR ); -mtspr (SPRN_LPCR , lpcr |LPCR_UPRT ); -/* -* update partition table control register, 64 K size. -*/ -if (!firmware_has_feature (FW_FEATURE_LPAR ))
arch/powerpc/mm/pgtable-radix.c void radix__early_init_mmu_secondary(void) · line 365
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +5
-0+if (!firmware_has_feature (FW_FEATURE_LPAR )) { + lpcr =mfspr (SPRN_LPCR ); +mtspr (SPRN_LPCR , lpcr |LPCR_UPRT ); +mtspr (SPRN_PTCR ,__pa (partition_tb) | (PATB_SIZE_SHIFT -12 )); + } } void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base,
Balbir Singh.
Quoted 3 lines · Aneesh Kumar K.V
LPCR cannot be updated when running in guest mode.
Signed-off-by Aneesh Kumar K.V <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/d6c886006c948141f24e84aceb
cheers