Skip to contentSkip to conversation

powerpc/mm/hash: Clear the invalid slot information correctly

PATCH Superseded Aneesh Kumar K.V 4 participants 7 messages Feb 18, 2016 – Feb 20, 2016 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/mm/hash: Clear the invalid slot information correctly

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear the existing slot information from the old pte. Fix this correctly

With THP, we also clear the slot information with respect to all the 64K hash pte mapping that 16MB page. They are all invalid now. This make sure we don't find the slot valid when we fault with 4k base page size. Finding the slot valid should not result in any wrong behavior because we do check again in hash page table for the validity. But we can avoid that check completely.

Fixes a43c0eb8364c022 ("powerpc/mm: Convert 4k hash insert to C")
---
 arch/powerpc/mm/hash64_4k.c       |  2 +-
 arch/powerpc/mm/hash64_64k.c      | 12 +++++++++---
 arch/powerpc/mm/hugepage-hash64.c |  7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
arch/powerpc/mm/hash64_4k.c +1 -1
index e7c04542ba62..e3e76b929f33 100644
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hash64_64k.c +9 -3
index 0762c1e08c88..b3895720edb0 100644
@@ -111,7 +111,13 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 */
 	if (!(old_pte & _PAGE_COMBO)) {
 		flush_hash_page(vpn, rpte, MMU_PAGE_64K, ssize, flags);
-		old_pte &= ~_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND;
+		/*
+		 * clear the old slot details from the old and new pte.
+		 * On hash insert failure we use old pte value and we don't
+		 * want slot information there if we have a insert failure.
+		 */
+		old_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
+		new_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
 		goto htab_insert_hpte;
 	}
 	/*
@@ -182,7 +188,7 @@ repeat:
 		}
 	}
 	/*
-	 * Hypervisor failure. Restore old pmd and return -1
+	 * Hypervisor failure. Restore old pte and return -1
 	 * similar to __hash_page_*
 	 */
 	if (unlikely(slot == -2)) {
@@ -305,7 +311,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hugepage-hash64.c +6 -1
index 49b152b0f926..8424f46c2bf7 100644
@@ -78,9 +78,14 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 		 * base page size. This is because demote_segment won't flush
 		 * hash page table entries.
 		 */
-		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO))
+		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO)) {
 			flush_hash_hugepage(vsid, ea, pmdp, MMU_PAGE_64K,
 					    ssize, flags);
+			/*
+			 * clear the old slot information 
+			 */
+			memset(hpte_slot_array, 0, PTE_FRAG_SIZE);
+		}
 	}
 
 	valid = hpte_valid(hpte_slot_array, index);
Signature · 1 line
2.5.0
#1 lore raw
Quoted 2 lines · Aneesh Kumar K.V

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear

Can you please elaborate on this ? What are those situations when we have 64K base page size on the PTE but we had inserted HPTE with base page size as 4K ?

Quoted 8 lines

the existing slot information from the old pte. Fix this correctly

With THP, we also clear the slot information with respect to all the 64K hash pte mapping that 16MB page. They are all invalid now. This make sure we don't find the slot valid when we fault with 4k base page size. Finding the slot valid should not result in any wrong behavior because we do check again in hash page table for the validity. But we can avoid that check completely.

Makes sense.

Quoted 15 lines
Fixes a43c0eb8364c022 ("powerpc/mm: Convert 4k hash insert to C")
---
 arch/powerpc/mm/hash64_4k.c       |  2 +-
 arch/powerpc/mm/hash64_64k.c      | 12 +++++++++---
 arch/powerpc/mm/hugepage-hash64.c |  7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
arch/powerpc/mm/hash64_4k.c +0 -0
index e7c04542ba62..e3e76b929f33 100644

arch/powerpc/mm/hash64_4k.c repeat: · line 109

Quoted 5 lines
arch/powerpc/mm/hash64_4k.c +1 -1
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

Quoted 9 lines
arch/powerpc/mm/hash64_4k.c +0 -0
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hash64_64k.c +0 -0
index 0762c1e08c88..b3895720edb0 100644
@@ -111,7 +111,13 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 */

arch/powerpc/mm/hash64_64k.c int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid, · line 120

Quoted 10 lines
arch/powerpc/mm/hash64_64k.c +7 -1
 	if (!(old_pte & _PAGE_COMBO)) {
 		flush_hash_page(vpn, rpte, MMU_PAGE_64K, ssize, flags);
-		old_pte &= ~_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND;
+		/*
+		 * clear the old slot details from the old and new pte.
+		 * On hash insert failure we use old pte value and we don't
+		 * want slot information there if we have a insert failure.
+		 */
+		old_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
+		new_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);

But why we need clear the bits on new_pte as well ?

arch/powerpc/mm/hash64_64k.c repeat: · line 191

Quoted 9 lines
arch/powerpc/mm/hash64_64k.c +1 -1
 		goto htab_insert_hpte;
 	}
 	/*
@@ -182,7 +188,7 @@ repeat:
 		}
 	}
 	/*
-	 * Hypervisor failure. Restore old pmd and return -1
+	 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

arch/powerpc/mm/hash64_64k.c repeat: · line 315

Quoted 10 lines
arch/powerpc/mm/hash64_64k.c +1 -1
 	 * similar to __hash_page_*
 	 */
 	if (unlikely(slot == -2)) {
@@ -305,7 +311,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*

Ditto.

#2 lore raw
Quoted 3 lines · Anshuman Khandual
Quoted 2 lines · Aneesh Kumar K.V

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear

...

Quoted 13 lines

arch/powerpc/mm/hash64_4k.c repeat: · line 109

Quoted 11 lines
arch/powerpc/mm/hash64_4k.c +1 -1
index e7c04542ba62..e3e76b929f33 100644
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

Yeah.

If it was -rc1 then I would probably let it go, but this will land in rc6 so the fixes need to be tight.

cheers

#5 lore raw
In reply to Aneesh Kumar K.V
Quoted 75 lines · Aneesh Kumar K.V

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear the existing slot information from the old pte. Fix this correctly

With THP, we also clear the slot information with respect to all the 64K hash pte mapping that 16MB page. They are all invalid now. This make sure we don't find the slot valid when we fault with 4k base page size. Finding the slot valid should not result in any wrong behavior because we do check again in hash page table for the validity. But we can avoid that check completely.

Fixes a43c0eb8364c022 ("powerpc/mm: Convert 4k hash insert to C")
---
 arch/powerpc/mm/hash64_4k.c       |  2 +-
 arch/powerpc/mm/hash64_64k.c      | 12 +++++++++---
 arch/powerpc/mm/hugepage-hash64.c |  7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
arch/powerpc/mm/hash64_4k.c +1 -1
index e7c04542ba62..e3e76b929f33 100644
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hash64_64k.c +9 -3
index 0762c1e08c88..b3895720edb0 100644
@@ -111,7 +111,13 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 */
 	if (!(old_pte & _PAGE_COMBO)) {
 		flush_hash_page(vpn, rpte, MMU_PAGE_64K, ssize, flags);
-		old_pte &= ~_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND;
+		/*
+		 * clear the old slot details from the old and new pte.
+		 * On hash insert failure we use old pte value and we don't
+		 * want slot information there if we have a insert failure.
+		 */
+		old_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
+		new_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
 		goto htab_insert_hpte;
 	}
 	/*
@@ -182,7 +188,7 @@ repeat:
 		}
 	}
 	/*
-	 * Hypervisor failure. Restore old pmd and return -1
+	 * Hypervisor failure. Restore old pte and return -1
 	 * similar to __hash_page_*
 	 */
 	if (unlikely(slot == -2)) {
@@ -305,7 +311,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hugepage-hash64.c +0 -0
index 49b152b0f926..8424f46c2bf7 100644

arch/powerpc/mm/hugepage-hash64.c int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, · line 86

Quoted 10 lines
arch/powerpc/mm/hugepage-hash64.c +4 -1
@@ -78,9 +78,14 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 		 * base page size. This is because demote_segment won't flush
 		 * hash page table entries.
 		 */
-		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO))
+		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO)) {
 			flush_hash_hugepage(vsid, ea, pmdp, MMU_PAGE_64K,
 					    ssize, flags);
+			/*
+			 * clear the old slot information 
+			 */

Redundant comment, something more useful? why clear it?

Quoted 5 lines
arch/powerpc/mm/hugepage-hash64.c +2 -0
+			memset(hpte_slot_array, 0, PTE_FRAG_SIZE);
+		}
 	}
 
 	valid = hpte_valid(hpte_slot_array, index);
#3 lore raw
In reply to Michael Ellerman
Quoted 19 lines · Michael Ellerman
Quoted 3 lines · Anshuman Khandual
Quoted 2 lines · Aneesh Kumar K.V

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear

...

Quoted 13 lines

arch/powerpc/mm/hash64_4k.c repeat: · line 109

Quoted 11 lines
arch/powerpc/mm/hash64_4k.c +1 -1
index e7c04542ba62..e3e76b929f33 100644
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

Quoted 5 lines

Yeah.

If it was -rc1 then I would probably let it go, but this will land in rc6 so the fixes need to be tight.

You want me to do an upate with those changes dropped ?.

-aneesh

#6 lore raw
In reply to Balbir Singh

Balbir Singh <[email protected]> writes:

...........
............

Quoted 16 lines
Quoted 5 lines
arch/powerpc/mm/hugepage-hash64.c +0 -0
index 49b152b0f926..8424f46c2bf7 100644

arch/powerpc/mm/hugepage-hash64.c int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, · line 86

Quoted 10 lines
arch/powerpc/mm/hugepage-hash64.c +4 -1
@@ -78,9 +78,14 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid,
 		 * base page size. This is because demote_segment won't flush
 		 * hash page table entries.
 		 */
-		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO))
+		if ((old_pmd & _PAGE_HASHPTE) && !(old_pmd & _PAGE_COMBO)) {
 			flush_hash_hugepage(vsid, ea, pmdp, MMU_PAGE_64K,
 					    ssize, flags);
+			/*
+			 * clear the old slot information 
+			 */

Redundant comment, something more useful? why clear it?

Quoted 4 lines

arch/powerpc/mm/hugepage-hash64.c int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, · line 90

Quoted 4 lines
arch/powerpc/mm/hugepage-hash64.c +2 -0
+			memset(hpte_slot_array, 0, PTE_FRAG_SIZE);
+		}
 	}
 

explained in the commit message.

With THP, we also clear the slot information with respect to all the 64K hash pte mapping that 16MB page. They are all invalid now. This make sure we don't find the slot valid when we fault with 4k base page size. Finding the slot valid should not result in any wrong behavior because we do check again in hash page table for the validity. But we can avoid that check completely.

Quoted 1 line
Quoted 1 line
arch/powerpc/mm/hugepage-hash64.c +0 -0
 	valid = hpte_valid(hpte_slot_array, index);
#4 lore raw
In reply to Anshuman Khandual
Quoted 7 lines · Anshuman Khandual
Quoted 2 lines · Aneesh Kumar K.V

We can get a hash pte fault with 4k base page size and find the pte already inserted with 64K base page size. In that case we need to clear

Can you please elaborate on this ? What are those situations when we have 64K base page size on the PTE but we had inserted HPTE with base page size as 4K ?

when we demote a segment.

Quoted 48 lines
Quoted 9 lines

the existing slot information from the old pte. Fix this correctly

With THP, we also clear the slot information with respect to all the 64K hash pte mapping that 16MB page. They are all invalid now. This make sure we don't find the slot valid when we fault with 4k base page size. Finding the slot valid should not result in any wrong behavior because we do check again in hash page table for the validity. But we can avoid that check completely.

Makes sense.

Quoted 15 lines
Fixes a43c0eb8364c022 ("powerpc/mm: Convert 4k hash insert to C")
---
 arch/powerpc/mm/hash64_4k.c       |  2 +-
 arch/powerpc/mm/hash64_64k.c      | 12 +++++++++---
 arch/powerpc/mm/hugepage-hash64.c |  7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)
arch/powerpc/mm/hash64_4k.c +0 -0
index e7c04542ba62..e3e76b929f33 100644

arch/powerpc/mm/hash64_4k.c repeat: · line 109

Quoted 5 lines
arch/powerpc/mm/hash64_4k.c +1 -1
@@ -106,7 +106,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

Quoted 13 lines
arch/powerpc/mm/hash64_4k.c +0 -0
 		 * similar to __hash_page_*
 		 */
 		if (unlikely(slot == -2)) {
arch/powerpc/mm/hash64_64k.c +1 -1
index 0762c1e08c88..b3895720edb0 100644
@@ -111,7 +111,13 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,
 	 */
 	if (!(old_pte & _PAGE_COMBO)) {
 		flush_hash_page(vpn, rpte, MMU_PAGE_64K, ssize, flags);
-		old_pte &= ~_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND;
+		/*
Quoted 8 lines

arch/powerpc/mm/hash64_64k.c int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid, · line 120

Quoted 6 lines
arch/powerpc/mm/hash64_64k.c +6 -0
+		 * clear the old slot details from the old and new pte.
+		 * On hash insert failure we use old pte value and we don't
+		 * want slot information there if we have a insert failure.
+		 */
+		old_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);
+		new_pte &= ~(_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND);

But why we need clear the bits on new_pte as well ?

we use new pte when updating the actual pte towards the end of that function.

Quoted 14 lines

arch/powerpc/mm/hash64_64k.c repeat: · line 191

Quoted 10 lines
arch/powerpc/mm/hash64_64k.c +1 -1
 		goto htab_insert_hpte;
 	}
 	/*
@@ -182,7 +188,7 @@ repeat:
 		}
 	}
 	/*
-	 * Hypervisor failure. Restore old pmd and return -1
+	 * Hypervisor failure. Restore old pte and return -1

This change is not relevant here. Should be a separate patch.

Quoted 12 lines

arch/powerpc/mm/hash64_64k.c repeat: · line 315

Quoted 10 lines
arch/powerpc/mm/hash64_64k.c +1 -1
 	 * similar to __hash_page_*
 	 */
 	if (unlikely(slot == -2)) {
@@ -305,7 +311,7 @@ repeat:
 			}
 		}
 		/*
-		 * Hypervisor failure. Restore old pmd and return -1
+		 * Hypervisor failure. Restore old pte and return -1
 		 * similar to __hash_page_*

Ditto.

-anessh