Skip to contentSkip to conversation

powerpc/mm: Add DEBUG_VM WARN for pmd_clear

PATCH Superseded Aneesh Kumar K.V 3 participants 43 messages Aug 12, 2020 – Aug 19, 2020

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/16 powerpc/mm: Add DEBUG_VM WARN for pmd_clear

With the hash page table, the kernel should not use pmd_clear for clearing huge pte entries. Add a DEBUG_VM WARN to catch the wrong usage.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +14 -0
index 6de56c3b33c4..079211968987 100644
@@ -868,6 +868,13 @@ static inline bool pte_ci(pte_t pte)
 
 static inline void pmd_clear(pmd_t *pmdp)
 {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pmd_val(*pmdp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
 	*pmdp = __pmd(0);
 }
 
@@ -916,6 +923,13 @@ static inline int pmd_bad(pmd_t pmd)
 
 static inline void pud_clear(pud_t *pudp)
 {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pud_val(*pudp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
 	*pudp = __pud(0);
 }
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/16 debug_vm_pgtable/ppc64: Avoid setting top bits in radom value

ppc64 use bit 62 to indicate a pte entry (_PAGE_PTE). Avoid setting that bit in random value.

---
 mm/debug_vm_pgtable.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +4 -1
index 086309fb9b6f..4c32063a8acf 100644
@@ -45,9 +45,12 @@
  * pxx_clear() because of how dynamic page table folding works on s390. So
  * while loading up the entries do not change the lower 4 bits. It does not
  * have affect any other platform.
+ *
+ * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
  */
 #define S390_MASK_BITS	4
-#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define PPC_MASK_BITS	2
+#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)
 #define RANDOM_NZVALUE	GENMASK(7, 0)
 
 static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 02/16] debug_vm_pgtable/ppc64: Avoid setting top bits in radom value

Le 12/08/2020 à 08:33, Aneesh Kumar K.V a écrit :

Quoted 13 lines

ppc64 use bit 62 to indicate a pte entry (_PAGE_PTE). Avoid setting that bit in random value.

---
  mm/debug_vm_pgtable.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 086309fb9b6f..4c32063a8acf 100644

mm/debug_vm_pgtable.c line 53

Quoted 10 lines
mm/debug_vm_pgtable.c +4 -1
@@ -45,9 +45,12 @@
   * pxx_clear() because of how dynamic page table folding works on s390. So
   * while loading up the entries do not change the lower 4 bits. It does not
   * have affect any other platform.
+ *
+ * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
   */
  #define S390_MASK_BITS	4
-#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define PPC_MASK_BITS	2
+#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)

Do you mean:

#define RANDOM_ORVALUE GENMASK(BITS_PER_LONG - 1, PPC_MASK_BITS | S390_MASK_BITS)

Christophe

Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
  #define RANDOM_NZVALUE	GENMASK(7, 0)
 
  static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
#3 lore raw

Re: [PATCH 02/16] debug_vm_pgtable/ppc64: Avoid setting top bits in radom value

Quoted 30 lines · Christophe Leroy

Le 12/08/2020 à 08:33, Aneesh Kumar K.V a écrit :

Quoted 14 lines

ppc64 use bit 62 to indicate a pte entry (_PAGE_PTE). Avoid setting that bit in random value.

---
  mm/debug_vm_pgtable.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 086309fb9b6f..4c32063a8acf 100644
@@ -45,9 +45,12 @@
    * pxx_clear() because of how dynamic page table folding works on s390. So

mm/debug_vm_pgtable.c line 54

Quoted 10 lines
mm/debug_vm_pgtable.c +4 -1
    * while loading up the entries do not change the lower 4 bits. It does not
    * have affect any other platform.
+ *
+ * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
    */
   #define S390_MASK_BITS    4
-#define RANDOM_ORVALUE    GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define PPC_MASK_BITS    2
+#define RANDOM_ORVALUE    GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, 
 S390_MASK_BITS)

Do you mean:

Quoted 1 line

#define RANDOM_ORVALUE    GENMASK(BITS_PER_LONG - 1, PPC_MASK_BITS | S390_MASK_BITS)

IIUC GENMASK(hi, low) generate a mask from hi to low bits. Since i want to avoid bit 62, I am forcing it to generate bits from (61, 4)

-aneesh

#4 lore raw

Re: [PATCH 02/16] debug_vm_pgtable/ppc64: Avoid setting top bits in radom value

In reply to Aneesh Kumar K.V
Quoted 13 lines · Aneesh Kumar K.V

ppc64 use bit 62 to indicate a pte entry (_PAGE_PTE). Avoid setting that bit in random value.

---
 mm/debug_vm_pgtable.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 086309fb9b6f..4c32063a8acf 100644

mm/debug_vm_pgtable.c line 50

Quoted 6 lines
mm/debug_vm_pgtable.c +2 -0
@@ -45,9 +45,12 @@
  * pxx_clear() because of how dynamic page table folding works on s390. So
  * while loading up the entries do not change the lower 4 bits. It does not
  * have affect any other platform.
+ *
+ * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
  */

Please move and fold the above line with the existing paragraph.

mm/debug_vm_pgtable.c line 52

Quoted 3 lines
mm/debug_vm_pgtable.c +1 -1
 #define S390_MASK_BITS	4
-#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define PPC_MASK_BITS	2

s/PPC/PPC64/

mm/debug_vm_pgtable.c line 56

Quoted 5 lines
mm/debug_vm_pgtable.c +1 -0
+#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)
 #define RANDOM_NZVALUE	GENMASK(7, 0)
 
 static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)

With this change, RANDOM_ORVALUE will be (0x3ffffffffffffff0) which discards both bit 63 and 62. If only bit 62 is to be avoided for ppc64 the mask should be (0xbffffffffffffff0) instead. The following change on this patch should do the trick.

mm/debug_vm_pgtable.c +6 -6
index eb059fef89c2..1499181fb0e9 100644
@@ -45,13 +45,13 @@
  * entry type. But these bits might affect the ability to clear entries with
  * pxx_clear() because of how dynamic page table folding works on s390. So
  * while loading up the entries do not change the lower 4 bits. It does not
- * have affect any other platform.
- *
- * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
+ * have affect any other platform. Also avoid the 62nd bit on ppc64 that is
+ * used to mark a pte entry.
  */
-#define S390_MASK_BITS 4
-#define PPC_MASK_BITS  2
-#define RANDOM_ORVALUE GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)
+#define S390_SKIP_MASK GENMASK(3, 0)
+#define PPC64_SKIP_MASK        GENMASK(62, 62)
+#define ARCH_SKIP_MASK (S390_SKIP_MASK | PPC64_SKIP_MASK)
+#define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK)
 #define RANDOM_NZVALUE GENMASK(7, 0)
 
 static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
#5 lore raw

Re: [PATCH 02/16] debug_vm_pgtable/ppc64: Avoid setting top bits in radom value

Quoted 57 lines · Anshuman Khandual
Quoted 13 lines · Aneesh Kumar K.V

ppc64 use bit 62 to indicate a pte entry (_PAGE_PTE). Avoid setting that bit in random value.

---
  mm/debug_vm_pgtable.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 086309fb9b6f..4c32063a8acf 100644

mm/debug_vm_pgtable.c line 50

Quoted 6 lines
mm/debug_vm_pgtable.c +2 -0
@@ -45,9 +45,12 @@
   * pxx_clear() because of how dynamic page table folding works on s390. So
   * while loading up the entries do not change the lower 4 bits. It does not
   * have affect any other platform.
+ *
+ * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
   */

Please move and fold the above line with the existing paragraph.

mm/debug_vm_pgtable.c line 52

Quoted 3 lines
mm/debug_vm_pgtable.c +1 -1
  #define S390_MASK_BITS	4
-#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS)
+#define PPC_MASK_BITS	2

s/PPC/PPC64/

mm/debug_vm_pgtable.c line 57

Quoted 5 lines
mm/debug_vm_pgtable.c +1 -0
+#define RANDOM_ORVALUE	GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)
  #define RANDOM_NZVALUE	GENMASK(7, 0)
 
  static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)

With this change, RANDOM_ORVALUE will be (0x3ffffffffffffff0) which discards both bit 63 and 62. If only bit 62 is to be avoided for ppc64 the mask should be (0xbffffffffffffff0) instead. The following change on this patch should do the trick.

mm/debug_vm_pgtable.c +2 -3
index eb059fef89c2..1499181fb0e9 100644
@@ -45,13 +45,13 @@
   * entry type. But these bits might affect the ability to clear entries with
   * pxx_clear() because of how dynamic page table folding works on s390. So
   * while loading up the entries do not change the lower 4 bits. It does not
- * have affect any other platform.
- *
- * Also avoid the 62nd bit on ppc64 that is used to mark a pte entry.
+ * have affect any other platform. Also avoid the 62nd bit on ppc64 that is
+ * used to mark a pte entry.
   */

mm/debug_vm_pgtable.c line 57

Quoted 10 lines
mm/debug_vm_pgtable.c +4 -3
-#define S390_MASK_BITS 4
-#define PPC_MASK_BITS  2
-#define RANDOM_ORVALUE GENMASK(BITS_PER_LONG - 1 - PPC_MASK_BITS, S390_MASK_BITS)
+#define S390_SKIP_MASK GENMASK(3, 0)
+#define PPC64_SKIP_MASK        GENMASK(62, 62)
+#define ARCH_SKIP_MASK (S390_SKIP_MASK | PPC64_SKIP_MASK)
+#define RANDOM_ORVALUE (GENMASK(BITS_PER_LONG - 1, 0) & ~ARCH_SKIP_MASK)
  #define RANDOM_NZVALUE GENMASK(7, 0)
 
  static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)

I will switch to this.

-aneesh

#6 lore raw

PATCH 3/16 debug_vm_pgtable/set_pte: Don't use set_pte_at to update an existing pte entry

In reply to Aneesh Kumar K.V

set_pte_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pte_at() and hence expect it to be used to set locations that are not a valid PTE.

---
 mm/debug_vm_pgtable.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +4 -4
index 4c32063a8acf..02a7c20aa4a2 100644
@@ -81,8 +81,6 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	pte = ptep_get(ptep);
 	WARN_ON(pte_write(pte));
 
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_get_and_clear(mm, vaddr, ptep);
 	pte = ptep_get(ptep);
 	WARN_ON(!pte_none(pte));
@@ -97,12 +95,14 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	pte = ptep_get(ptep);
 	WARN_ON(!(pte_write(pte) && pte_dirty(pte)));
 
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_get_and_clear_full(mm, vaddr, ptep, 1);
 	pte = ptep_get(ptep);
 	WARN_ON(!pte_none(pte));
 
+	/*
+	 * We should clear pte before we do set_pte_at
+	 */
+	pte = ptep_get_and_clear(mm, vaddr, ptep);
 	pte = pte_mkyoung(pte);
 	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_test_and_clear_young(vma, vaddr, ptep);
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH 03/16] debug_vm_pgtable/set_pte: Don't use set_pte_at to update an existing pte entry

Quoted 4 lines · Aneesh Kumar K.V

set_pte_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pte_at() and hence expect it to be used to set locations that are not a valid PTE.

Even though set_pte_at() is not really a arch page table helper and very much arch specific, I just wonder why this deviation on ppc64 as compared to other platforms. Detecting such semantics variation across platforms is an objective of this test.

As small nit.

Please follow the existing subject format for all patches in here. It will improve readability and also help understand these changes better, later on.

mm/debug_vm_pgtable: <Specify changes to an individual test>

Quoted 11 lines
---
 mm/debug_vm_pgtable.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +0 -0
index 4c32063a8acf..02a7c20aa4a2 100644

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm, · line 86

Quoted 8 lines
mm/debug_vm_pgtable.c +0 -2
@@ -81,8 +81,6 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	pte = ptep_get(ptep);
 	WARN_ON(pte_write(pte));
 
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_get_and_clear(mm, vaddr, ptep);
 	pte = ptep_get(ptep);
 	WARN_ON(!pte_none(pte));

This makes sense. But could you please fold this code stanza with the previous one in order to imply that 'ptep' did have some valid entry before being cleared and checked against pte_none().

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm, · line 100

Quoted 9 lines
mm/debug_vm_pgtable.c +0 -2
@@ -97,12 +95,14 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	pte = ptep_get(ptep);
 	WARN_ON(!(pte_write(pte) && pte_dirty(pte)));
 
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_get_and_clear_full(mm, vaddr, ptep, 1);
 	pte = ptep_get(ptep);
 	WARN_ON(!pte_none(pte));

Same, please fold back.

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm,

Quoted 9 lines
mm/debug_vm_pgtable.c +4 -0
+	/*
+	 * We should clear pte before we do set_pte_at
+	 */
+	pte = ptep_get_and_clear(mm, vaddr, ptep);
 	pte = pte_mkyoung(pte);
 	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_test_and_clear_young(vma, vaddr, ptep);
 

The comment above should also explain details that are mentioned in the commit message i.e how platforms such as ppc64 expects a clear pte entry for set_pte_at() to work.

#8 lore raw

Re: [PATCH 03/16] debug_vm_pgtable/set_pte: Don't use set_pte_at to update an existing pte entry

Quoted 8 lines · Anshuman Khandual
Quoted 4 lines · Aneesh Kumar K.V

set_pte_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pte_at() and hence expect it to be used to set locations that are not a valid PTE.

Quoted 4 lines

Even though set_pte_at() is not really a arch page table helper and very much arch specific, I just wonder why this deviation on ppc64 as compared to other platforms. Detecting such semantics variation across platforms is an objective of this test.

Not sure what you mean by set_pte_at is not a page table helper. Generic kernel use that helper to set a pte entry.

Now w.r.t ppc64 behavior this was discussed multiple times. I guess Linux kernel always used set_pte_at on a none pte entry. We had some exceptions in the recent past. But all fixed when noticed.

383321ab8578dfe3bbcc0bc5604c0f8ae08a5c98 mm/hugetlb/migration: use set_huge_pte_at instead of set_pte_at

cee216a696b2004017a5ecb583366093d90b1568 mm/autonuma: don't use set_pte_at when updating protnone ptes

56eecdb912b536a4fa97fb5bfe5a940a54d79be6
mm: Use ptep/pmdp_set_numa() for updating _PAGE_NUMA bit

Yes. Having a testcase like this help

Quoted 23 lines

As small nit.

Please follow the existing subject format for all patches in here. It will improve readability and also help understand these changes better, later on.

mm/debug_vm_pgtable: <Specify changes to an individual test>

Quoted 14 lines
---
  mm/debug_vm_pgtable.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +0 -0
index 4c32063a8acf..02a7c20aa4a2 100644
@@ -81,8 +81,6 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
  	pte = ptep_get(ptep);
  	WARN_ON(pte_write(pte));
 
Quoted 10 lines

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm, · line 86

Quoted 5 lines
mm/debug_vm_pgtable.c +0 -2
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
  	ptep_get_and_clear(mm, vaddr, ptep);
  	pte = ptep_get(ptep);
  	WARN_ON(!pte_none(pte));

This makes sense. But could you please fold this code stanza with the previous one in order to imply that 'ptep' did have some valid entry before being cleared and checked against pte_none().

will do that

Quoted 4 lines
Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
@@ -97,12 +95,14 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
  	pte = ptep_get(ptep);
  	WARN_ON(!(pte_write(pte) && pte_dirty(pte)));
 
Quoted 8 lines

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm, · line 100

Quoted 5 lines
mm/debug_vm_pgtable.c +0 -2
-	pte = pfn_pte(pfn, prot);
-	set_pte_at(mm, vaddr, ptep, pte);
  	ptep_get_and_clear_full(mm, vaddr, ptep, 1);
  	pte = ptep_get(ptep);
  	WARN_ON(!pte_none(pte));

Same, please fold back.

ok

Quoted 4 lines
Quoted 4 lines
mm/debug_vm_pgtable.c +4 -0
+	/*
+	 * We should clear pte before we do set_pte_at
+	 */
+	pte = ptep_get_and_clear(mm, vaddr, ptep);
Quoted 9 lines

mm/debug_vm_pgtable.c static void __init pte_advanced_tests(struct mm_struct *mm,

Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
  	pte = pte_mkyoung(pte);
  	set_pte_at(mm, vaddr, ptep, pte);
  	ptep_test_and_clear_young(vma, vaddr, ptep);
 

The comment above should also explain details that are mentioned in the commit message i.e how platforms such as ppc64 expects a clear pte entry for set_pte_at() to work.

I don't think it is specific to ppc64. There is nothing specific to ppc64 architecture in there. It is an optimization used in kernel to help architecture avoid TLB flush. I will update the comment as below

/* We should clear pte before we do set_pte_at so that set_pte_at don't find a valid pte at ptep *?

is that good?

-aneesh

#9 lore raw

PATCH 4/16 debug_vm_pgtables/hugevmap: Use the arch helper to identify huge vmap support.

In reply to Aneesh Kumar K.V

ppc64 supports huge vmap only with radix translation. Hence use arch helper to determine the huge vmap support.

---
 mm/debug_vm_pgtable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_vm_pgtable.c +1 -1
index 02a7c20aa4a2..679bb3d289a3 100644
@@ -206,7 +206,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot)
 {
 	pmd_t pmd;
 
-	if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
+	if (!arch_ioremap_pmd_supported())
 		return;
 
 	pr_debug("Validating PMD huge\n");
Signature · 1 line
2.26.2
#10 lore raw

Re: [PATCH 04/16] debug_vm_pgtables/hugevmap: Use the arch helper to identify huge vmap support.

Quoted 14 lines · Aneesh Kumar K.V

ppc64 supports huge vmap only with radix translation. Hence use arch helper to determine the huge vmap support.

---
 mm/debug_vm_pgtable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 02a7c20aa4a2..679bb3d289a3 100644

mm/debug_vm_pgtable.c static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) · line 212

Quoted 8 lines
mm/debug_vm_pgtable.c +1 -1
@@ -206,7 +206,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot)
 {
 	pmd_t pmd;
 
-	if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
+	if (!arch_ioremap_pmd_supported())
 		return;
 
 	pr_debug("Validating PMD huge\n");

Problem is arch_ioremap_pmd_supported() symbol which should also be explicitly included via <linux/io.h>, is not available without the config CONFIG_HAVE_ARCH_HUGE_VMAP. ioremap_pmd_enabled() should have been better here and has a fallback for !CONFIG_HAVE_ARCH_HUGE_VMAP. But then the symbol is local to that file. Unless we would like to make ioremap_pxx_enabled generally available, the remaining option would be to wrap pxx_huge_tests() with CONFIG_HAVE_ARCH_HUGE_VMAP. Similar changes should also be done for pud_huge_tests() as well.

#11 lore raw

PATCH 5/16 debug_vm_pgtable/savedwrite: Enable savedwrite test with CONFIG_NUMA_BALANCING

In reply to Aneesh Kumar K.V

Saved write support was added to track the write bit of a pte after marking the pte protnone. This was done so that AUTONUMA can convert a write pte to protnone and still track the old write bit. When converting it back we set the pte write bit correctly thereby avoiding a write fault again. Hence enable the test only when CONFIG_NUMA_BALANCING is enabled.

---
 mm/debug_vm_pgtable.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/debug_vm_pgtable.c +7 -0
index 679bb3d289a3..de8a62d0a931 100644
@@ -110,6 +110,7 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	WARN_ON(pte_young(pte));
 }
 
+#ifdef CONFIG_NUMA_BALANCING
 static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
 	pte_t pte = pfn_pte(pfn, prot);
@@ -118,6 +119,8 @@ static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));
 	WARN_ON(pte_savedwrite(pte_clear_savedwrite(pte_mk_savedwrite(pte))));
 }
+#endif
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
 {
@@ -221,6 +224,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pmd_none(pmd));
 }
 
+#ifdef CONFIG_NUMA_BALANCING
 static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
 	pmd_t pmd = pfn_pmd(pfn, prot);
@@ -229,6 +233,7 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd))));
 	WARN_ON(pmd_savedwrite(pmd_clear_savedwrite(pmd_mk_savedwrite(pmd))));
 }
+#endif
 
 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
 static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)
@@ -1005,8 +1010,10 @@ static int __init debug_vm_pgtable(void)
 	pmd_huge_tests(pmdp, pmd_aligned, prot);
 	pud_huge_tests(pudp, pud_aligned, prot);
 
+#ifdef CONFIG_NUMA_BALANCING
 	pte_savedwrite_tests(pte_aligned, prot);
 	pmd_savedwrite_tests(pmd_aligned, prot);
+#endif
 
 	pte_unmap_unlock(ptep, ptl);
 
Signature · 1 line
2.26.2
#12 lore raw

Re: [PATCH 05/16] debug_vm_pgtable/savedwrite: Enable savedwrite test with CONFIG_NUMA_BALANCING

Quoted 5 lines · Aneesh Kumar K.V

Saved write support was added to track the write bit of a pte after marking the pte protnone. This was done so that AUTONUMA can convert a write pte to protnone and still track the old write bit. When converting it back we set the pte write bit correctly thereby avoiding a write fault again. Hence enable the test only when CONFIG_NUMA_BALANCING is enabled.

This has not been a problem on architectures that do not define pxx_savedwrite() as they fallback on standard pxx_write() helpers. But ppc64 defines a fall back for pte_savedwrite() when !CONFIG_NUMA_BALANCING, which always returns false. Agreed, it makes sense to add CONFIG_NUMA_BALANCING check. But a simple runtime check will do as the functions are always visible/defined.

if (!IS_ENABLED(CONFIG_NUMA_BALANCING))

	return;
Quoted 44 lines
---
 mm/debug_vm_pgtable.c | 7 +++++++
 1 file changed, 7 insertions(+)
mm/debug_vm_pgtable.c +5 -0
index 679bb3d289a3..de8a62d0a931 100644
@@ -110,6 +110,7 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	WARN_ON(pte_young(pte));
 }
 
+#ifdef CONFIG_NUMA_BALANCING
 static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
 	pte_t pte = pfn_pte(pfn, prot);
@@ -118,6 +119,8 @@ static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));
 	WARN_ON(pte_savedwrite(pte_clear_savedwrite(pte_mk_savedwrite(pte))));
 }
+#endif
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
 {
@@ -221,6 +224,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pmd_none(pmd));
 }
 
+#ifdef CONFIG_NUMA_BALANCING
 static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
 	pmd_t pmd = pfn_pmd(pfn, prot);
@@ -229,6 +233,7 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 	WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd))));
 	WARN_ON(pmd_savedwrite(pmd_clear_savedwrite(pmd_mk_savedwrite(pmd))));
 }
+#endif
 
 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
 static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)

mm/debug_vm_pgtable.c static int __init debug_vm_pgtable(void) · line 1016

Quoted 7 lines
mm/debug_vm_pgtable.c +2 -0
@@ -1005,8 +1010,10 @@ static int __init debug_vm_pgtable(void)
 	pmd_huge_tests(pmdp, pmd_aligned, prot);
 	pud_huge_tests(pudp, pud_aligned, prot);
 
+#ifdef CONFIG_NUMA_BALANCING
 	pte_savedwrite_tests(pte_aligned, prot);
 	pmd_savedwrite_tests(pmd_aligned, prot);
+#endif

BTW, config wrappers should be avoided at the call site. If and when needed a stub is defined for !CONFIG_XXX_XXX.

Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
 	pte_unmap_unlock(ptep, ptl);
 
 
#13 lore raw

PATCH 6/16 debug_vm_pgtable/THP: Mark the pte entry huge before using set_pmd_at

In reply to Aneesh Kumar K.V

kernel expect entries to be marked huge before we use set_pmd_at().

---
 mm/debug_vm_pgtable.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +4 -4
index de8a62d0a931..b6aca2526e01 100644
@@ -149,7 +149,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 				      unsigned long pfn, unsigned long vaddr,
 				      pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd;
 
 	if (!has_transparent_hugepage())
 		return;
@@ -158,19 +158,19 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	/* Align the address wrt HPAGE_PMD_SIZE */
 	vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
 
-	pmd = pfn_pmd(pfn, prot);
+	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_set_wrprotect(mm, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_write(pmd));
 
-	pmd = pfn_pmd(pfn, prot);
+	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
 
-	pmd = pfn_pmd(pfn, prot);
+	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	pmd = pmd_wrprotect(pmd);
 	pmd = pmd_mkclean(pmd);
 	set_pmd_at(mm, vaddr, pmdp, pmd);
Signature · 1 line
2.26.2
#14 lore raw

PATCH 7/16 debug_vm_pgtable/THP: Mark the pte entry huge before using set_pud_at

In reply to Aneesh Kumar K.V

kernel expect entries to be marked huge before we use set_pud_at().

---
 mm/debug_vm_pgtable.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +7 -4
index b6aca2526e01..cd609a212dd4 100644
@@ -265,7 +265,7 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 				      unsigned long pfn, unsigned long vaddr,
 				      pgprot_t prot)
 {
-	pud_t pud = pfn_pud(pfn, prot);
+	pud_t pud;
 
 	if (!has_transparent_hugepage())
 		return;
@@ -274,25 +274,28 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	/* Align the address wrt HPAGE_PUD_SIZE */
 	vaddr = (vaddr & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE;
 
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_set_wrprotect(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_write(pud));
 
 #ifndef __PAGETABLE_PMD_FOLDED
-	pud = pfn_pud(pfn, prot);
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_huge_get_and_clear(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
 
-	pud = pfn_pud(pfn, prot);
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_huge_get_and_clear_full(mm, vaddr, pudp, 1);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
 #endif /* __PAGETABLE_PMD_FOLDED */
-	pud = pfn_pud(pfn, prot);
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	pud = pud_wrprotect(pud);
 	pud = pud_mkclean(pud);
 	set_pud_at(mm, vaddr, pudp, pud);
Signature · 1 line
2.26.2
#15 lore raw

Re: [PATCH 07/16] debug_vm_pgtable/THP: Mark the pte entry huge before using set_pud_at

Quoted 43 lines · Aneesh Kumar K.V

kernel expect entries to be marked huge before we use set_pud_at().

---
 mm/debug_vm_pgtable.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
mm/debug_vm_pgtable.c +5 -3
index b6aca2526e01..cd609a212dd4 100644
@@ -265,7 +265,7 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 				      unsigned long pfn, unsigned long vaddr,
 				      pgprot_t prot)
 {
-	pud_t pud = pfn_pud(pfn, prot);
+	pud_t pud;
 
 	if (!has_transparent_hugepage())
 		return;
@@ -274,25 +274,28 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	/* Align the address wrt HPAGE_PUD_SIZE */
 	vaddr = (vaddr & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE;
 
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_set_wrprotect(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_write(pud));
 
 #ifndef __PAGETABLE_PMD_FOLDED
-	pud = pfn_pud(pfn, prot);
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_huge_get_and_clear(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
 
-	pud = pfn_pud(pfn, prot);
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	set_pud_at(mm, vaddr, pudp, pud);

mm/debug_vm_pgtable.c static void __init pud_advanced_tests(struct mm_struct *mm, · line 301

Quoted 10 lines
mm/debug_vm_pgtable.c +2 -1
 	pudp_huge_get_and_clear_full(mm, vaddr, pudp, 1);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
 #endif /* __PAGETABLE_PMD_FOLDED */
-	pud = pfn_pud(pfn, prot);
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	pud = pud_wrprotect(pud);
 	pud = pud_mkclean(pud);
 	set_pud_at(mm, vaddr, pudp, pud);

Looks very similar to the previous patch, hence please fold it back. Seems fair enough that pxx_set_at() expects given entry to be huge. But would need to run them across enabled platforms to be sure.

#16 lore raw

PATCH 8/16 debug_vm_pgtable/set_pmd: Don't use set_pmd_at to update an existing pmd entry

In reply to Aneesh Kumar K.V

set_pmd_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pmd_at() and hence expect it to be used to set locations that are not a valid PTE.

---
 mm/debug_vm_pgtable.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/debug_vm_pgtable.c +1 -4
index cd609a212dd4..60bf876081b8 100644
@@ -164,8 +164,6 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_write(pmd));
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
-	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
@@ -180,12 +178,11 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!(pmd_write(pmd) && pmd_dirty(pmd)));
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
-	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_huge_get_and_clear_full(vma, vaddr, pmdp, 1);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
 
+	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	pmd = pmd_mkyoung(pmd);
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_test_and_clear_young(vma, vaddr, pmdp);
Signature · 1 line
2.26.2
#17 lore raw

Re: [PATCH 08/16] debug_vm_pgtable/set_pmd: Don't use set_pmd_at to update an existing pmd entry

Quoted 28 lines · Aneesh Kumar K.V

set_pmd_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pmd_at() and hence expect it to be used to set locations that are not a valid PTE.

---
 mm/debug_vm_pgtable.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/debug_vm_pgtable.c +0 -2
index cd609a212dd4..60bf876081b8 100644
@@ -164,8 +164,6 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_write(pmd));
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
-	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
@@ -180,12 +178,11 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!(pmd_write(pmd) && pmd_dirty(pmd)));
 

mm/debug_vm_pgtable.c static void __init pmd_advanced_tests(struct mm_struct *mm, · line 188

Quoted 10 lines
mm/debug_vm_pgtable.c +1 -2
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
-	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_huge_get_and_clear_full(vma, vaddr, pmdp, 1);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
 
+	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	pmd = pmd_mkyoung(pmd);
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_test_and_clear_young(vma, vaddr, pmdp);

Very similar to [PATCH 3/16] wrt set_pte_at(), please fold it.

#18 lore raw

PATCH 9/16 debug_vm_pgtable/set_pud: Don't use set_pud_at to update an existing pud entry

In reply to Aneesh Kumar K.V

set_pud_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pud_at() and hence expect it to be used to set locations that are not a valid PTE.

---
 mm/debug_vm_pgtable.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/debug_vm_pgtable.c +5 -3
index 60bf876081b8..644d28861ce9 100644
@@ -278,9 +278,6 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	WARN_ON(pud_write(pud));
 
 #ifndef __PAGETABLE_PMD_FOLDED
-
-	pud = pud_mkhuge(pfn_pud(pfn, prot));
-	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_huge_get_and_clear(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
@@ -302,6 +299,11 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!(pud_write(pud) && pud_dirty(pud)));
 
+	pudp_huge_get_and_clear_full(vma, vaddr, pudp, 1);
+	pud = READ_ONCE(*pudp);
+	WARN_ON(!pud_none(pud));
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	pud = pud_mkyoung(pud);
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_test_and_clear_young(vma, vaddr, pudp);
Signature · 1 line
2.26.2
#19 lore raw

Re: [PATCH 09/16] debug_vm_pgtable/set_pud: Don't use set_pud_at to update an existing pud entry

Quoted 26 lines · Aneesh Kumar K.V

set_pud_at() should not be used to set a pte entry at locations that already holds a valid pte entry. Architectures like ppc64 don't do TLB invalidate in set_pud_at() and hence expect it to be used to set locations that are not a valid PTE.

---
 mm/debug_vm_pgtable.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/debug_vm_pgtable.c +0 -3
index 60bf876081b8..644d28861ce9 100644
@@ -278,9 +278,6 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	WARN_ON(pud_write(pud));
 
 #ifndef __PAGETABLE_PMD_FOLDED
-
-	pud = pud_mkhuge(pfn_pud(pfn, prot));
-	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_huge_get_and_clear(mm, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(!pud_none(pud));
@@ -302,6 +299,11 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	pud = READ_ONCE(*pudp);

mm/debug_vm_pgtable.c static void __init pud_advanced_tests(struct mm_struct *mm, · line 309

Quoted 10 lines
mm/debug_vm_pgtable.c +5 -0
 	WARN_ON(!(pud_write(pud) && pud_dirty(pud)));
 
+	pudp_huge_get_and_clear_full(vma, vaddr, pudp, 1);
+	pud = READ_ONCE(*pudp);
+	WARN_ON(!pud_none(pud));
+
+	pud = pud_mkhuge(pfn_pud(pfn, prot));
 	pud = pud_mkyoung(pud);
 	set_pud_at(mm, vaddr, pudp, pud);
 	pudp_test_and_clear_young(vma, vaddr, pudp);

Very similar to [PATCH 3/16] wrt set_pte_at(), please fold it.

#20 lore raw

PATCH 10/16 debug_vm_pgtable/thp: Use page table depost/withdraw with THP

In reply to Aneesh Kumar K.V

Architectures like ppc64 use deposited page table while updating the huge pte entries.

---
 mm/debug_vm_pgtable.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/debug_vm_pgtable.c +6 -2
index 644d28861ce9..48475d288df1 100644
@@ -147,7 +147,7 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
 static void __init pmd_advanced_tests(struct mm_struct *mm,
 				      struct vm_area_struct *vma, pmd_t *pmdp,
 				      unsigned long pfn, unsigned long vaddr,
-				      pgprot_t prot)
+				      pgprot_t prot, pgtable_t pgtable)
 {
 	pmd_t pmd;
 
@@ -158,6 +158,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	/* Align the address wrt HPAGE_PMD_SIZE */
 	vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
 
+	pgtable_trans_huge_deposit(mm, pmdp, pgtable);
+
 	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_set_wrprotect(mm, vaddr, pmdp);
@@ -188,6 +190,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmdp_test_and_clear_young(vma, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_young(pmd));
+
+	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
 }
 
 static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot)
@@ -1002,7 +1006,7 @@ static int __init debug_vm_pgtable(void)
 	pgd_clear_tests(mm, pgdp);
 
 	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot);
+	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
 	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
 	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
 
Signature · 1 line
2.26.2
#21 lore raw

Re: [PATCH 10/16] debug_vm_pgtable/thp: Use page table depost/withdraw with THP

Quoted 41 lines · Aneesh Kumar K.V

Architectures like ppc64 use deposited page table while updating the huge pte entries.

---
 mm/debug_vm_pgtable.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/debug_vm_pgtable.c +5 -1
index 644d28861ce9..48475d288df1 100644
@@ -147,7 +147,7 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
 static void __init pmd_advanced_tests(struct mm_struct *mm,
 				      struct vm_area_struct *vma, pmd_t *pmdp,
 				      unsigned long pfn, unsigned long vaddr,
-				      pgprot_t prot)
+				      pgprot_t prot, pgtable_t pgtable)
 {
 	pmd_t pmd;
 
@@ -158,6 +158,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	/* Align the address wrt HPAGE_PMD_SIZE */
 	vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
 
+	pgtable_trans_huge_deposit(mm, pmdp, pgtable);
+
 	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_set_wrprotect(mm, vaddr, pmdp);
@@ -188,6 +190,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmdp_test_and_clear_young(vma, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_young(pmd));
+
+	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
 }
 
 static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot)

mm/debug_vm_pgtable.c static int __init debug_vm_pgtable(void) · line 1012

Quoted 8 lines
mm/debug_vm_pgtable.c +1 -1
@@ -1002,7 +1006,7 @@ static int __init debug_vm_pgtable(void)
 	pgd_clear_tests(mm, pgdp);
 
 	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot);
+	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
 	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
 	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
 

Makes sense, if it is required for THP to work correctly but needs to be tested across enabled platforms. Why should not the same apply for pud_advanced_tests() on platforms that supports PUD based THP.

#22 lore raw

Re: [PATCH 10/16] debug_vm_pgtable/thp: Use page table depost/withdraw with THP

Quoted 43 lines · Anshuman Khandual
Quoted 42 lines · Aneesh Kumar K.V

Architectures like ppc64 use deposited page table while updating the huge pte entries.

---
  mm/debug_vm_pgtable.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
mm/debug_vm_pgtable.c +5 -1
index 644d28861ce9..48475d288df1 100644
@@ -147,7 +147,7 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
  static void __init pmd_advanced_tests(struct mm_struct *mm,
  				      struct vm_area_struct *vma, pmd_t *pmdp,
  				      unsigned long pfn, unsigned long vaddr,
-				      pgprot_t prot)
+				      pgprot_t prot, pgtable_t pgtable)
  {
  	pmd_t pmd;
 
@@ -158,6 +158,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
  	/* Align the address wrt HPAGE_PMD_SIZE */
  	vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
 
+	pgtable_trans_huge_deposit(mm, pmdp, pgtable);
+
  	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
  	set_pmd_at(mm, vaddr, pmdp, pmd);
  	pmdp_set_wrprotect(mm, vaddr, pmdp);
@@ -188,6 +190,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
  	pmdp_test_and_clear_young(vma, vaddr, pmdp);
  	pmd = READ_ONCE(*pmdp);
  	WARN_ON(pmd_young(pmd));
+
+	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
  }
 
  static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot)
@@ -1002,7 +1006,7 @@ static int __init debug_vm_pgtable(void)
  	pgd_clear_tests(mm, pgdp);
 
Quoted 12 lines

mm/debug_vm_pgtable.c static int __init debug_vm_pgtable(void) · line 1012

Quoted 7 lines
mm/debug_vm_pgtable.c +1 -1
  	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot);
+	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
  	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
  	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
 

Makes sense, if it is required for THP to work correctly but needs to be tested across enabled platforms. Why should not the same apply for pud_advanced_tests() on platforms that supports PUD based THP.

pud doesn't have page table deposit/withdraw semantics. We use that to support hugepage split. With pud mapping we don't split, we just drop the hugepage and expect it to be faulted back in as regular page.

-aneesh

#23 lore raw

PATCH 11/16 debug_vm_pgtable/locks: Move non page table modifying test together

In reply to Aneesh Kumar K.V

This will help in adding proper locks in a later patch

---
 mm/debug_vm_pgtable.c | 53 +++++++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 24 deletions(-)
mm/debug_vm_pgtable.c +29 -24
index 48475d288df1..90e9c2d3a092 100644
@@ -979,7 +979,7 @@ static int __init debug_vm_pgtable(void)
 	p4dp = p4d_alloc(mm, pgdp, vaddr);
 	pudp = pud_alloc(mm, p4dp, vaddr);
 	pmdp = pmd_alloc(mm, pudp, vaddr);
-	ptep = pte_alloc_map_lock(mm, pmdp, vaddr, &ptl);
+	ptep = pte_alloc_map(mm, pmdp, vaddr);
 
 	/*
 	 * Save all the page table page addresses as the page table
@@ -999,35 +999,13 @@ static int __init debug_vm_pgtable(void)
 	p4d_basic_tests(p4d_aligned, prot);
 	pgd_basic_tests(pgd_aligned, prot);
 
-	pte_clear_tests(mm, ptep, vaddr);
-	pmd_clear_tests(mm, pmdp);
-	pud_clear_tests(mm, pudp);
-	p4d_clear_tests(mm, p4dp);
-	pgd_clear_tests(mm, pgdp);
-
-	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
-	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
-	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-
 	pmd_leaf_tests(pmd_aligned, prot);
 	pud_leaf_tests(pud_aligned, prot);
 
-	pmd_huge_tests(pmdp, pmd_aligned, prot);
-	pud_huge_tests(pudp, pud_aligned, prot);
-
 #ifdef CONFIG_NUMA_BALANCING
 	pte_savedwrite_tests(pte_aligned, prot);
 	pmd_savedwrite_tests(pmd_aligned, prot);
 #endif
-
-	pte_unmap_unlock(ptep, ptl);
-
-	pmd_populate_tests(mm, pmdp, saved_ptep);
-	pud_populate_tests(mm, pudp, saved_pmdp);
-	p4d_populate_tests(mm, p4dp, saved_pudp);
-	pgd_populate_tests(mm, pgdp, saved_p4dp);
-
 	pte_special_tests(pte_aligned, prot);
 	pte_protnone_tests(pte_aligned, protnone);
 	pmd_protnone_tests(pmd_aligned, protnone);
@@ -1045,11 +1023,38 @@ static int __init debug_vm_pgtable(void)
 	pmd_swap_tests(pmd_aligned, prot);
 
 	swap_migration_tests();
-	hugetlb_basic_tests(pte_aligned, prot);
 
 	pmd_thp_tests(pmd_aligned, prot);
 	pud_thp_tests(pud_aligned, prot);
 
+	/*
+	 * Page table modifying tests
+	 */
+	pte_clear_tests(mm, ptep, vaddr);
+	pmd_clear_tests(mm, pmdp);
+	pud_clear_tests(mm, pudp);
+	p4d_clear_tests(mm, p4dp);
+	pgd_clear_tests(mm, pgdp);
+
+	ptep = pte_alloc_map_lock(mm, pmdp, vaddr, &ptl);
+	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
+	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
+	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+
+
+	pmd_huge_tests(pmdp, pmd_aligned, prot);
+	pud_huge_tests(pudp, pud_aligned, prot);
+
+	pte_unmap_unlock(ptep, ptl);
+
+	pmd_populate_tests(mm, pmdp, saved_ptep);
+	pud_populate_tests(mm, pudp, saved_pmdp);
+	p4d_populate_tests(mm, p4dp, saved_pudp);
+	pgd_populate_tests(mm, pgdp, saved_p4dp);
+
+	hugetlb_basic_tests(pte_aligned, prot);
+
 	p4d_free(mm, saved_p4dp);
 	pud_free(mm, saved_pudp);
 	pmd_free(mm, saved_pmdp);
Signature · 1 line
2.26.2
#24 lore raw

PATCH 12/16 debug_vm_pgtable/locks: Take correct page table lock

In reply to Aneesh Kumar K.V

Make sure we call pte accessors with correct lock held.

---
 mm/debug_vm_pgtable.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
mm/debug_vm_pgtable.c +20 -14
index 90e9c2d3a092..061c19bba7f0 100644
@@ -1027,33 +1027,39 @@ static int __init debug_vm_pgtable(void)
 	pmd_thp_tests(pmd_aligned, prot);
 	pud_thp_tests(pud_aligned, prot);
 
+	hugetlb_basic_tests(pte_aligned, prot);
+
 	/*
 	 * Page table modifying tests
 	 */
-	pte_clear_tests(mm, ptep, vaddr);
-	pmd_clear_tests(mm, pmdp);
-	pud_clear_tests(mm, pudp);
-	p4d_clear_tests(mm, p4dp);
-	pgd_clear_tests(mm, pgdp);
 
 	ptep = pte_alloc_map_lock(mm, pmdp, vaddr, &ptl);
+	pte_clear_tests(mm, ptep, vaddr);
 	pte_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
-	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
-	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
-
+	pte_unmap_unlock(ptep, ptl);
 
+	ptl = pmd_lock(mm, pmdp);
+	pmd_clear_tests(mm, pmdp);
+	pmd_advanced_tests(mm, vma, pmdp, pmd_aligned, vaddr, prot, saved_ptep);
 	pmd_huge_tests(pmdp, pmd_aligned, prot);
+	pmd_populate_tests(mm, pmdp, saved_ptep);
+	spin_unlock(ptl);
+
+	ptl = pud_lock(mm, pudp);
+	pud_clear_tests(mm, pudp);
+	pud_advanced_tests(mm, vma, pudp, pud_aligned, vaddr, prot);
 	pud_huge_tests(pudp, pud_aligned, prot);
+	pud_populate_tests(mm, pudp, saved_pmdp);
+	spin_unlock(ptl);
 
-	pte_unmap_unlock(ptep, ptl);
+	//hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
 
-	pmd_populate_tests(mm, pmdp, saved_ptep);
-	pud_populate_tests(mm, pudp, saved_pmdp);
+	spin_lock(&mm->page_table_lock);
+	p4d_clear_tests(mm, p4dp);
+	pgd_clear_tests(mm, pgdp);
 	p4d_populate_tests(mm, p4dp, saved_pudp);
 	pgd_populate_tests(mm, pgdp, saved_p4dp);
-
-	hugetlb_basic_tests(pte_aligned, prot);
+	spin_unlock(&mm->page_table_lock);
 
 	p4d_free(mm, saved_p4dp);
 	pud_free(mm, saved_pudp);
Signature · 1 line
2.26.2
#25 lore raw

PATCH 13/16 debug_vm_pgtable/pmd_clear: Don't use pmd/pud_clear on pte entries

In reply to Aneesh Kumar K.V

pmd_clear() should not be used to clear pmd level pte entries.

---
 mm/debug_vm_pgtable.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/debug_vm_pgtable.c +4 -3
index 061c19bba7f0..529892b9be2f 100644
@@ -191,6 +191,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_young(pmd));
 
+	/*  Clear the pte entries  */
+	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
 	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
 }
 
@@ -313,6 +315,8 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	pudp_test_and_clear_young(vma, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_young(pud));
+
+	pudp_huge_get_and_clear(mm, vaddr, pudp);
 }
 
 static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot)
@@ -431,8 +435,6 @@ static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp,
 	 * This entry points to next level page table page.
 	 * Hence this must not qualify as pud_bad().
 	 */
-	pmd_clear(pmdp);
-	pud_clear(pudp);
 	pud_populate(mm, pudp, pmdp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_bad(pud));
@@ -564,7 +566,6 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp,
 	 * This entry points to next level page table page.
 	 * Hence this must not qualify as pmd_bad().
 	 */
-	pmd_clear(pmdp);
 	pmd_populate(mm, pmdp, pgtable);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_bad(pmd));
Signature · 1 line
2.26.2
#26 lore raw

Re: [PATCH 13/16] debug_vm_pgtable/pmd_clear: Don't use pmd/pud_clear on pte entries

Quoted 1 line · Aneesh Kumar K.V

pmd_clear() should not be used to clear pmd level pte entries.

Could you please elaborate on this. The proposed change set does not match the description here.

Quoted 29 lines
---
 mm/debug_vm_pgtable.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/debug_vm_pgtable.c +4 -0
index 061c19bba7f0..529892b9be2f 100644
@@ -191,6 +191,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_young(pmd));
 
+	/*  Clear the pte entries  */
+	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
 	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
 }
 
@@ -313,6 +315,8 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
 	pudp_test_and_clear_young(vma, vaddr, pudp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_young(pud));
+
+	pudp_huge_get_and_clear(mm, vaddr, pudp);
 }
 
 static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot)

mm/debug_vm_pgtable.c static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, · line 435

Quoted 5 lines
mm/debug_vm_pgtable.c +0 -2
@@ -431,8 +435,6 @@ static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp,
 	 * This entry points to next level page table page.
 	 * Hence this must not qualify as pud_bad().
 	 */
-	pmd_clear(pmdp);
-	pud_clear(pudp);

Both entires are cleared before creating a fresh page table entry. Why that is a problem.

mm/debug_vm_pgtable.c static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, · line 567

Quoted 8 lines
mm/debug_vm_pgtable.c +0 -1
 	pud_populate(mm, pudp, pmdp);
 	pud = READ_ONCE(*pudp);
 	WARN_ON(pud_bad(pud));
@@ -564,7 +566,6 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp,
 	 * This entry points to next level page table page.
 	 * Hence this must not qualify as pmd_bad().
 	 */
-	pmd_clear(pmdp);

Ditto.

Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
 	pmd_populate(mm, pmdp, pgtable);
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(pmd_bad(pmd));
#27 lore raw

Re: [PATCH 13/16] debug_vm_pgtable/pmd_clear: Don't use pmd/pud_clear on pte entries

Quoted 8 lines · Anshuman Khandual
Quoted 1 line · Aneesh Kumar K.V

pmd_clear() should not be used to clear pmd level pte entries.

Could you please elaborate on this. The proposed change set does not match the description here.

pmd_clear is implemented such that we don't use that to clear a huge pte entry. We use pmdp_huge_get_and_clear() for that. Hence we have check in pmd_clear which add a WARN if we find a _PAGE_PTE set on the entry.

In the test we follow a hugepmd usage with a pmd_clear. We should instead at the end of the advanced pmd test use pmdp_huge_get_and_clear().

Quoted 53 lines
Quoted 29 lines
---
  mm/debug_vm_pgtable.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
mm/debug_vm_pgtable.c +4 -0
index 061c19bba7f0..529892b9be2f 100644
@@ -191,6 +191,8 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
  	pmd = READ_ONCE(*pmdp);
  	WARN_ON(pmd_young(pmd));
 
+	/*  Clear the pte entries  */
+	pmdp_huge_get_and_clear(mm, vaddr, pmdp);
  	pgtable = pgtable_trans_huge_withdraw(mm, pmdp);
  }
 
@@ -313,6 +315,8 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
  	pudp_test_and_clear_young(vma, vaddr, pudp);
  	pud = READ_ONCE(*pudp);
  	WARN_ON(pud_young(pud));
+
+	pudp_huge_get_and_clear(mm, vaddr, pudp);
  }
 
  static void __init pud_leaf_tests(unsigned long pfn, pgprot_t prot)

mm/debug_vm_pgtable.c static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp, · line 435

Quoted 5 lines
mm/debug_vm_pgtable.c +0 -2
@@ -431,8 +435,6 @@ static void __init pud_populate_tests(struct mm_struct *mm, pud_t *pudp,
  	 * This entry points to next level page table page.
  	 * Hence this must not qualify as pud_bad().
  	 */
-	pmd_clear(pmdp);
-	pud_clear(pudp);

Both entires are cleared before creating a fresh page table entry. Why that is a problem.

mm/debug_vm_pgtable.c static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp, · line 567

Quoted 8 lines
mm/debug_vm_pgtable.c +0 -1
  	pud_populate(mm, pudp, pmdp);
  	pud = READ_ONCE(*pudp);
  	WARN_ON(pud_bad(pud));
@@ -564,7 +566,6 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp,
  	 * This entry points to next level page table page.
  	 * Hence this must not qualify as pmd_bad().
  	 */
-	pmd_clear(pmdp);

Ditto.

Quoted 4 lines
mm/debug_vm_pgtable.c +0 -0
  	pmd_populate(mm, pmdp, pgtable);
  	pmd = READ_ONCE(*pmdp);
  	WARN_ON(pmd_bad(pmd));
#28 lore raw

PATCH 14/16 debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

In reply to Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

---
 mm/debug_vm_pgtable.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +5 -1
index 529892b9be2f..3e112d0ba1b2 100644
@@ -800,6 +800,7 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot)
 #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
 }
 
+#ifndef CONFIG_PPC_BOOK3S_64
 static void __init hugetlb_advanced_tests(struct mm_struct *mm,
 					  struct vm_area_struct *vma,
 					  pte_t *ptep, unsigned long pfn,
@@ -842,6 +843,7 @@ static void __init hugetlb_advanced_tests(struct mm_struct *mm,
 	pte = huge_ptep_get(ptep);
 	WARN_ON(!(huge_pte_write(pte) && huge_pte_dirty(pte)));
 }
+#endif
 #else  /* !CONFIG_HUGETLB_PAGE */
 static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { }
 static void __init hugetlb_advanced_tests(struct mm_struct *mm,
@@ -1053,7 +1055,9 @@ static int __init debug_vm_pgtable(void)
 	pud_populate_tests(mm, pudp, saved_pmdp);
 	spin_unlock(ptl);
 
-	//hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#ifndef CONFIG_PPC_BOOK3S_64
+	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#endif
 
 	spin_lock(&mm->page_table_lock);
 	p4d_clear_tests(mm, p4dp);
Signature · 1 line
2.26.2
#29 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 6 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

Quoted 38 lines
---
 mm/debug_vm_pgtable.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +5 -1
index 529892b9be2f..3e112d0ba1b2 100644
@@ -800,6 +800,7 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot)
 #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
 }
 
+#ifndef CONFIG_PPC_BOOK3S_64
 static void __init hugetlb_advanced_tests(struct mm_struct *mm,
 					  struct vm_area_struct *vma,
 					  pte_t *ptep, unsigned long pfn,
@@ -842,6 +843,7 @@ static void __init hugetlb_advanced_tests(struct mm_struct *mm,
 	pte = huge_ptep_get(ptep);
 	WARN_ON(!(huge_pte_write(pte) && huge_pte_dirty(pte)));
 }
+#endif
 #else  /* !CONFIG_HUGETLB_PAGE */
 static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { }
 static void __init hugetlb_advanced_tests(struct mm_struct *mm,
@@ -1053,7 +1055,9 @@ static int __init debug_vm_pgtable(void)
 	pud_populate_tests(mm, pudp, saved_pmdp);
 	spin_unlock(ptl);
 
-	//hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#ifndef CONFIG_PPC_BOOK3S_64
+	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#endif
 
 	spin_lock(&mm->page_table_lock);
 	p4d_clear_tests(mm, p4dp);
#30 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 7 lines · Anshuman Khandual
Quoted 4 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

Quoted 9 lines
Quoted 2 lines

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

As mentioned the test is broken. For hugetlb, the pgtable_t pages should be allocated by huge_pte_alloc(). We need to hold huget_pte_lock() before updating huge tlb pte. That takes hugepage size, which is mostly derived out of vma. Hence vma need to be a hugetlb vma. Some of the functions also depend on hstate. Also we should use set_huge_pte_at() when setting up hugetlb pte entries. I was tempted to remove that test completely marking it broken. But avoided that by marking it broken on only PPC64.

Quoted 37 lines
Quoted 37 lines
---
  mm/debug_vm_pgtable.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +5 -1
index 529892b9be2f..3e112d0ba1b2 100644
@@ -800,6 +800,7 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot)
  #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
  }
 
+#ifndef CONFIG_PPC_BOOK3S_64
  static void __init hugetlb_advanced_tests(struct mm_struct *mm,
  					  struct vm_area_struct *vma,
  					  pte_t *ptep, unsigned long pfn,
@@ -842,6 +843,7 @@ static void __init hugetlb_advanced_tests(struct mm_struct *mm,
  	pte = huge_ptep_get(ptep);
  	WARN_ON(!(huge_pte_write(pte) && huge_pte_dirty(pte)));
  }
+#endif
  #else  /* !CONFIG_HUGETLB_PAGE */
  static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { }
  static void __init hugetlb_advanced_tests(struct mm_struct *mm,
@@ -1053,7 +1055,9 @@ static int __init debug_vm_pgtable(void)
  	pud_populate_tests(mm, pudp, saved_pmdp);
  	spin_unlock(ptl);
 
-	//hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#ifndef CONFIG_PPC_BOOK3S_64
+	hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#endif
 
  	spin_lock(&mm->page_table_lock);
  	p4d_clear_tests(mm, p4dp);
#31 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 11 lines · Aneesh Kumar K.V
Quoted 10 lines · Anshuman Khandual
Quoted 6 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

Quoted 8 lines
Quoted 6 lines

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

As mentioned the test is broken. For hugetlb, the pgtable_t pages should be allocated by huge_pte_alloc(). We need to hold huget_pte_lock() before  updating huge tlb pte. That takes hugepage size, which is mostly derived out of vma. Hence vma need to be a hugetlb vma. Some of the functions also depend on hstate. Also we should use set_huge_pte_at() when setting up hugetlb pte entries. I was tempted to remove that test completely marking it broken. But avoided that by marking it broken on only PPC64.

The test is not broken, hugetlb helpers on multiple platforms dont complain about this at all. The tests here emulate 'enough' MM objects required for the helpers on enabled platforms, to perform the primary task i.e page table transformation it is expected to do. The test does not claim to emulate a perfect MM environment for a given subsystem's (like HugeTLB) arch helpers. Now in this case, the MM objects being emulated for the HugeTLB advanced tests does not seem to be sufficient for ppc64 but it can be improved. But that does not mean it is broken in it's current form for other platforms.

Quoted 39 lines
Quoted 37 lines
Quoted 37 lines

---
  mm/debug_vm_pgtable.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
mm/debug_vm_pgtable.c +0 -0
index 529892b9be2f..3e112d0ba1b2 100644
@@ -800,6 +800,7 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot)
   #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
   }

  +#ifndef CONFIG_PPC_BOOK3S_64
  static void __init hugetlb_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pte_t *ptep, unsigned long pfn,

mm/debug_vm_pgtable.c +4 -0
@@ -842,6 +843,7 @@ static void __init hugetlb_advanced_tests(struct mm_struct *mm,
       pte = huge_ptep_get(ptep);
       WARN_ON(!(huge_pte_write(pte) && huge_pte_dirty(pte)));
   }
+#endif
   #else  /* !CONFIG_HUGETLB_PAGE */
   static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot) { }
   static void __init hugetlb_advanced_tests(struct mm_struct *mm,
@@ -1053,7 +1055,9 @@ static int __init debug_vm_pgtable(void)
       pud_populate_tests(mm, pudp, saved_pmdp);
       spin_unlock(ptl);
   -    //hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#ifndef CONFIG_PPC_BOOK3S_64
+    hugetlb_advanced_tests(mm, vma, ptep, pte_aligned, vaddr, prot);
+#endif
         spin_lock(&mm->page_table_lock);
       p4d_clear_tests(mm, p4dp);
 
#32 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 23 lines · Anshuman Khandual
Quoted 11 lines · Aneesh Kumar K.V
Quoted 10 lines · Anshuman Khandual
Quoted 6 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

Quoted 8 lines
Quoted 6 lines

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

As mentioned the test is broken. For hugetlb, the pgtable_t pages should be allocated by huge_pte_alloc(). We need to hold huget_pte_lock() before  updating huge tlb pte. That takes hugepage size, which is mostly derived out of vma. Hence vma need to be a hugetlb vma. Some of the functions also depend on hstate. Also we should use set_huge_pte_at() when setting up hugetlb pte entries. I was tempted to remove that test completely marking it broken. But avoided that by marking it broken on only PPC64.

Quoted 9 lines

The test is not broken, hugetlb helpers on multiple platforms dont complain about this at all. The tests here emulate 'enough' MM objects required for the helpers on enabled platforms, to perform the primary task i.e page table transformation it is expected to do. The test does not claim to emulate a perfect MM environment for a given subsystem's (like HugeTLB) arch helpers. Now in this case, the MM objects being emulated for the HugeTLB advanced tests does not seem to be sufficient for ppc64 but it can be improved. But that does not mean it is broken in it's current form for other platforms.

There is nothing ppc64 specific here. It is just that we have CONFIG_DEBUG_VM based checks for different possibly wrong usages of these functions. This was done because we have different page sizes, two different translations to support and we want to avoid any wrong usage. IMHO expecting hugetlb page table helpers to work with a non hugetlb VMA and without holding hugeTLB pte lock is a clear violation of hugetlb interface.

-aneesh

#33 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 34 lines · Aneesh Kumar K.V
Quoted 23 lines · Anshuman Khandual
Quoted 11 lines · Aneesh Kumar K.V
Quoted 10 lines · Anshuman Khandual
Quoted 6 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

Quoted 8 lines
Quoted 6 lines

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

As mentioned the test is broken. For hugetlb, the pgtable_t pages should be allocated by huge_pte_alloc(). We need to hold huget_pte_lock() before  updating huge tlb pte. That takes hugepage size, which is mostly derived out of vma. Hence vma need to be a hugetlb vma. Some of the functions also depend on hstate. Also we should use set_huge_pte_at() when setting up hugetlb pte entries. I was tempted to remove that test completely marking it broken. But avoided that by marking it broken on only PPC64.

Quoted 9 lines

The test is not broken, hugetlb helpers on multiple platforms dont complain about this at all. The tests here emulate 'enough' MM objects required for the helpers on enabled platforms, to perform the primary task i.e page table transformation it is expected to do. The test does not claim to emulate a perfect MM environment for a given subsystem's (like HugeTLB) arch helpers. Now in this case, the MM objects being emulated for the HugeTLB advanced tests does not seem to be sufficient for ppc64 but it can be improved. But that does not mean it is broken in it's current form for other platforms.

Quoted 1 line

There is nothing ppc64 specific here. It is just that we have CONFIG_DEBUG_VM based checks for different possibly wrong usages of these functions. This was done because we have different page sizes, two different translations to support and we want to avoid any wrong usage. IMHO expecting hugetlb page table helpers to work with a non hugetlb VMA and  without holding hugeTLB pte lock is a clear violation of hugetlb interface.

Do you have a modified version of the test with HugeTLB marked VMA and with pte lock held, which works on ppc664 ?

#34 lore raw

Re: [PATCH 14/16] debug_vm_pgtable/hugetlb: Disable hugetlb test on ppc64

Quoted 35 lines · Anshuman Khandual
Quoted 34 lines · Aneesh Kumar K.V
Quoted 32 lines · Anshuman Khandual
Quoted 11 lines · Aneesh Kumar K.V
Quoted 10 lines · Anshuman Khandual
Quoted 6 lines · Aneesh Kumar K.V

The seems to be missing quite a lot of details w.r.t allocating the correct pgtable_t page (huge_pte_alloc()), holding the right lock (huge_pte_lock()) etc. The vma used is also not a hugetlb VMA.

ppc64 do have runtime checks within CONFIG_DEBUG_VM for most of these. Hence disable the test on ppc64.

Quoted 8 lines
Quoted 6 lines

This test is free from any platform specific #ifdefs which should never be broken. If hugetlb_advanced_tests() does not work or is not detailed enough for ppc64, then it would be great if you could suggest some improvements so that it works for all enabled platforms.

As mentioned the test is broken. For hugetlb, the pgtable_t pages should be allocated by huge_pte_alloc(). We need to hold huget_pte_lock() before  updating huge tlb pte. That takes hugepage size, which is mostly derived out of vma. Hence vma need to be a hugetlb vma. Some of the functions also depend on hstate. Also we should use set_huge_pte_at() when setting up hugetlb pte entries. I was tempted to remove that test completely marking it broken. But avoided that by marking it broken on only PPC64.

The test is not broken, hugetlb helpers on multiple platforms dont complain about this at all. The tests here emulate 'enough' MM objects required for the helpers on enabled platforms, to perform the primary task i.e page table transformation it is expected to do. The test does not claim to emulate a perfect MM environment for a given subsystem's (like HugeTLB) arch helpers. Now in this case, the MM objects being emulated for the HugeTLB advanced tests does not seem to be sufficient for ppc64 but it can be improved. But that does not mean it is broken in it's current form for other platforms.

Quoted 4 lines
Quoted 1 line

There is nothing ppc64 specific here. It is just that we have CONFIG_DEBUG_VM based checks for different possibly wrong usages of these functions. This was done because we have different page sizes, two different translations to support and we want to avoid any wrong usage. IMHO expecting hugetlb page table helpers to work with a non hugetlb VMA and  without holding hugeTLB pte lock is a clear violation of hugetlb interface.

Do you have a modified version of the test with HugeTLB marked VMA and with pte lock held, which works on ppc664 ?

Nope. That is one of the reason I commented that out. We can sort that out slowly.

-aneesh

#35 lore raw

PATCH 15/16 debug_vm_pgtable/savedwrite: Use savedwrite test with protnone ptes

In reply to Aneesh Kumar K.V

Saved write support was added to track the write bit of a pte after marking the pte protnone. This was done so that AUTONUMA can convert a write pte to protnone and still track the old write bit. When converting it back we set the pte write bit correctly thereby avoiding a write fault again.

---
 mm/debug_vm_pgtable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_vm_pgtable.c +2 -2
index 3e112d0ba1b2..eea62d5e503b 100644
@@ -1006,8 +1006,8 @@ static int __init debug_vm_pgtable(void)
 	pud_leaf_tests(pud_aligned, prot);
 
 #ifdef CONFIG_NUMA_BALANCING
-	pte_savedwrite_tests(pte_aligned, prot);
-	pmd_savedwrite_tests(pmd_aligned, prot);
+	pte_savedwrite_tests(pte_aligned, protnone);
+	pmd_savedwrite_tests(pmd_aligned, protnone);
 #endif
 	pte_special_tests(pte_aligned, prot);
 	pte_protnone_tests(pte_aligned, protnone);
Signature · 1 line
2.26.2
#36 lore raw

Re: [PATCH 15/16] debug_vm_pgtable/savedwrite: Use savedwrite test with protnone ptes

Quoted 16 lines · Aneesh Kumar K.V

Saved write support was added to track the write bit of a pte after marking the pte protnone. This was done so that AUTONUMA can convert a write pte to protnone and still track the old write bit. When converting it back we set the pte write bit correctly thereby avoiding a write fault again.

---
 mm/debug_vm_pgtable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/debug_vm_pgtable.c +0 -0
index 3e112d0ba1b2..eea62d5e503b 100644

mm/debug_vm_pgtable.c static int __init debug_vm_pgtable(void) · line 1013

Quoted 10 lines
mm/debug_vm_pgtable.c +2 -2
@@ -1006,8 +1006,8 @@ static int __init debug_vm_pgtable(void)
 	pud_leaf_tests(pud_aligned, prot);
 
 #ifdef CONFIG_NUMA_BALANCING
-	pte_savedwrite_tests(pte_aligned, prot);
-	pmd_savedwrite_tests(pmd_aligned, prot);
+	pte_savedwrite_tests(pte_aligned, protnone);
+	pmd_savedwrite_tests(pmd_aligned, protnone);
 #endif
 	pte_special_tests(pte_aligned, prot);
 	pte_protnone_tests(pte_aligned, protnone);

This can be folded back with [PATCH 5/16] which now checks for CONFIG_NUMA_BALANCING in pxx_savedwrite_tests().

#37 lore raw

PATCH 16/16 debug_vm_pgtable/ppc64: Add a variant of pfn_pte/pmd

In reply to Aneesh Kumar K.V

The tests do expect _PAGE_PTE bit set by different page table accessors. This is not true for the kernel. Within the kernel, _PAGE_PTE bits are usually set by set_pte_at(). To make the below tests work correctly add test specific pfn_pte/pmd helpers that set _PAGE_PTE bit.

pte_t pte = pfn_pte(pfn, prot); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));

---
 mm/debug_vm_pgtable.c | 65 +++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 24 deletions(-)
mm/debug_vm_pgtable.c +41 -24
index eea62d5e503b..153c925b5273 100644
@@ -31,6 +31,23 @@
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 
+#ifdef CONFIG_PPC_BOOK3S_64
+static inline pte_t debug_vm_pfn_pte(unsigned long pfn, pgprot_t pgprot)
+{
+	pte_t pte = pfn_pte(pfn, pgprot);
+	return __pte(pte_val(pte) | _PAGE_PTE);
+
+}
+static inline pmd_t debug_vm_pfn_pmd(unsigned long pfn, pgprot_t pgprot)
+{
+	pmd_t pmd = pfn_pmd(pfn, pgprot);
+	return __pmd(pmd_val(pmd) | _PAGE_PTE);
+}
+#else
+#define debug_vm_pfn_pte(pfn, pgprot) pfn_pte(pfn, pgprot)
+#define debug_vm_pfn_pmd(pfn, pgprot) pfn_pmd(pfn, pgprot)
+#endif
+
 /*
  * Please refer Documentation/vm/arch_pgtable_helpers.rst for the semantics
  * expectations that are being validated here. All future changes in here
@@ -55,7 +72,7 @@
 
 static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	pr_debug("Validating PTE basic\n");
 	WARN_ON(!pte_same(pte, pte));
@@ -72,10 +89,10 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 				      unsigned long pfn, unsigned long vaddr,
 				      pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	pr_debug("Validating PTE advanced\n");
-	pte = pfn_pte(pfn, prot);
+	pte = debug_vm_pfn_pte(pfn, prot);
 	set_pte_at(mm, vaddr, ptep, pte);
 	ptep_set_wrprotect(mm, vaddr, ptep);
 	pte = ptep_get(ptep);
@@ -85,7 +102,7 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 	pte = ptep_get(ptep);
 	WARN_ON(!pte_none(pte));
 
-	pte = pfn_pte(pfn, prot);
+	pte = debug_vm_pfn_pte(pfn, prot);
 	pte = pte_wrprotect(pte);
 	pte = pte_mkclean(pte);
 	set_pte_at(mm, vaddr, ptep, pte);
@@ -113,7 +130,7 @@ static void __init pte_advanced_tests(struct mm_struct *mm,
 #ifdef CONFIG_NUMA_BALANCING
 static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	pr_debug("Validating PTE saved write\n");
 	WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));
@@ -124,7 +141,7 @@ static void __init pte_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	if (!has_transparent_hugepage())
 		return;
@@ -160,7 +177,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 
 	pgtable_trans_huge_deposit(mm, pmdp, pgtable);
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
+	pmd = pmd_mkhuge(debug_vm_pfn_pmd(pfn, prot));
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_set_wrprotect(mm, vaddr, pmdp);
 	pmd = READ_ONCE(*pmdp);
@@ -170,7 +187,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
+	pmd = pmd_mkhuge(debug_vm_pfn_pmd(pfn, prot));
 	pmd = pmd_wrprotect(pmd);
 	pmd = pmd_mkclean(pmd);
 	set_pmd_at(mm, vaddr, pmdp, pmd);
@@ -184,7 +201,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 	pmd = READ_ONCE(*pmdp);
 	WARN_ON(!pmd_none(pmd));
 
-	pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
+	pmd = pmd_mkhuge(debug_vm_pfn_pmd(pfn, prot));
 	pmd = pmd_mkyoung(pmd);
 	set_pmd_at(mm, vaddr, pmdp, pmd);
 	pmdp_test_and_clear_young(vma, vaddr, pmdp);
@@ -198,7 +215,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
 
 static void __init pmd_leaf_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	pr_debug("Validating PMD leaf\n");
 	/*
@@ -230,7 +247,7 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot)
 #ifdef CONFIG_NUMA_BALANCING
 static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	pr_debug("Validating PMD saved write\n");
 	WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd))));
@@ -573,7 +590,7 @@ static void __init pmd_populate_tests(struct mm_struct *mm, pmd_t *pmdp,
 
 static void __init pte_special_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL))
 		return;
@@ -584,7 +601,7 @@ static void __init pte_special_tests(unsigned long pfn, pgprot_t prot)
 
 static void __init pte_protnone_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_NUMA_BALANCING))
 		return;
@@ -597,7 +614,7 @@ static void __init pte_protnone_tests(unsigned long pfn, pgprot_t prot)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pmd_mkhuge(pfn_pmd(pfn, prot));
+	pmd_t pmd = pmd_mkhuge(debug_vm_pfn_pmd(pfn, prot));
 
 	if (!IS_ENABLED(CONFIG_NUMA_BALANCING))
 		return;
@@ -613,7 +630,7 @@ static void __init pmd_protnone_tests(unsigned long pfn, pgprot_t prot) { }
 #ifdef CONFIG_ARCH_HAS_PTE_DEVMAP
 static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	pr_debug("Validating PTE devmap\n");
 	WARN_ON(!pte_devmap(pte_mkdevmap(pte)));
@@ -622,7 +639,7 @@ static void __init pte_devmap_tests(unsigned long pfn, pgprot_t prot)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_devmap_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	pr_debug("Validating PMD devmap\n");
 	WARN_ON(!pmd_devmap(pmd_mkdevmap(pmd)));
@@ -651,7 +668,7 @@ static void __init pud_devmap_tests(unsigned long pfn, pgprot_t prot) { }
 
 static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
 		return;
@@ -663,7 +680,7 @@ static void __init pte_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 
 static void __init pte_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 {
-	pte_t pte = pfn_pte(pfn, prot);
+	pte_t pte = debug_vm_pfn_pte(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
 		return;
@@ -676,7 +693,7 @@ static void __init pte_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
 		return;
@@ -688,7 +705,7 @@ static void __init pmd_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 
 static void __init pmd_swap_soft_dirty_tests(unsigned long pfn, pgprot_t prot)
 {
-	pmd_t pmd = pfn_pmd(pfn, prot);
+	pmd_t pmd = debug_vm_pfn_pmd(pfn, prot);
 
 	if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY) ||
 		!IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION))
@@ -711,7 +728,7 @@ static void __init pte_swap_tests(unsigned long pfn, pgprot_t prot)
 	pte_t pte;
 
 	pr_debug("Validating PTE swap\n");
-	pte = pfn_pte(pfn, prot);
+	pte = debug_vm_pfn_pte(pfn, prot);
 	swp = __pte_to_swp_entry(pte);
 	pte = __swp_entry_to_pte(swp);
 	WARN_ON(pfn != pte_pfn(pte));
@@ -724,7 +741,7 @@ static void __init pmd_swap_tests(unsigned long pfn, pgprot_t prot)
 	pmd_t pmd;
 
 	pr_debug("Validating PMD swap\n");
-	pmd = pfn_pmd(pfn, prot);
+	pmd = debug_vm_pfn_pmd(pfn, prot);
 	swp = __pmd_to_swp_entry(pmd);
 	pmd = __swp_entry_to_pmd(swp);
 	WARN_ON(pfn != pmd_pfn(pmd));
@@ -794,7 +811,7 @@ static void __init hugetlb_basic_tests(unsigned long pfn, pgprot_t prot)
 	WARN_ON(huge_pte_write(huge_pte_wrprotect(huge_pte_mkwrite(pte))));
 
 #ifdef CONFIG_ARCH_WANT_GENERAL_HUGETLB
-	pte = pfn_pte(pfn, prot);
+	pte = debug_vm_pfn_pte(pfn, prot);
 
 	WARN_ON(!pte_huge(pte_mkhuge(pte)));
 #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
@@ -874,7 +891,7 @@ static void __init pmd_thp_tests(unsigned long pfn, pgprot_t prot)
 	 * needs to return true. pmd_present() should be true whenever
 	 * pmd_trans_huge() returns true.
 	 */
-	pmd = pfn_pmd(pfn, prot);
+	pmd = debug_vm_pfn_pmd(pfn, prot);
 	WARN_ON(!pmd_trans_huge(pmd_mkhuge(pmd)));
 
 #ifndef __HAVE_ARCH_PMDP_INVALIDATE
Signature · 1 line
2.26.2
#38 lore raw

Re: [PATCH 16/16] debug_vm_pgtable/ppc64: Add a variant of pfn_pte/pmd

Quoted 28 lines · Aneesh Kumar K.V

The tests do expect _PAGE_PTE bit set by different page table accessors. This is not true for the kernel. Within the kernel, _PAGE_PTE bits are usually set by set_pte_at(). To make the below tests work correctly add test specific pfn_pte/pmd helpers that set _PAGE_PTE bit.

pte_t pte = pfn_pte(pfn, prot); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));

---
 mm/debug_vm_pgtable.c | 65 +++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 24 deletions(-)
mm/debug_vm_pgtable.c +6 -0
index eea62d5e503b..153c925b5273 100644
@@ -31,6 +31,23 @@
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 
+#ifdef CONFIG_PPC_BOOK3S_64
+static inline pte_t debug_vm_pfn_pte(unsigned long pfn, pgprot_t pgprot)
+{
+	pte_t pte = pfn_pte(pfn, pgprot);
+	return __pte(pte_val(pte) | _PAGE_PTE);
+

mm/debug_vm_pgtable.c line 49

Quoted 10 lines
mm/debug_vm_pgtable.c +10 -0
+}
+static inline pmd_t debug_vm_pfn_pmd(unsigned long pfn, pgprot_t pgprot)
+{
+	pmd_t pmd = pfn_pmd(pfn, pgprot);
+	return __pmd(pmd_val(pmd) | _PAGE_PTE);
+}
+#else
+#define debug_vm_pfn_pte(pfn, pgprot) pfn_pte(pfn, pgprot)
+#define debug_vm_pfn_pmd(pfn, pgprot) pfn_pmd(pfn, pgprot)
+#endif

Again, no platform specific constructs please. This defeats the whole purpose of this test. If __PAGE_PTE is required for the helpers, then pfn_pmd/pte() could be modified to accommodate that. We dont see similar issues on other platforms, hence could you please explain why ppc64 is different here.

#39 lore raw

Re: [PATCH 16/16] debug_vm_pgtable/ppc64: Add a variant of pfn_pte/pmd

Quoted 37 lines · Anshuman Khandual
Quoted 35 lines · Aneesh Kumar K.V

The tests do expect _PAGE_PTE bit set by different page table accessors. This is not true for the kernel. Within the kernel, _PAGE_PTE bits are usually set by set_pte_at(). To make the below tests work correctly add test specific pfn_pte/pmd helpers that set _PAGE_PTE bit.

pte_t pte = pfn_pte(pfn, prot); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));

---
  mm/debug_vm_pgtable.c | 65 +++++++++++++++++++++++++++----------------
  1 file changed, 41 insertions(+), 24 deletions(-)
mm/debug_vm_pgtable.c +13 -0
index eea62d5e503b..153c925b5273 100644
@@ -31,6 +31,23 @@
  #include <asm/pgalloc.h>
  #include <asm/tlbflush.h>
 
+#ifdef CONFIG_PPC_BOOK3S_64
+static inline pte_t debug_vm_pfn_pte(unsigned long pfn, pgprot_t pgprot)
+{
+	pte_t pte = pfn_pte(pfn, pgprot);
+	return __pte(pte_val(pte) | _PAGE_PTE);
+
+}
+static inline pmd_t debug_vm_pfn_pmd(unsigned long pfn, pgprot_t pgprot)
+{
+	pmd_t pmd = pfn_pmd(pfn, pgprot);
+	return __pmd(pmd_val(pmd) | _PAGE_PTE);
+}
+#else
Quoted 9 lines

mm/debug_vm_pgtable.c line 49

Quoted 3 lines
mm/debug_vm_pgtable.c +3 -0
+#define debug_vm_pfn_pte(pfn, pgprot) pfn_pte(pfn, pgprot)
+#define debug_vm_pfn_pmd(pfn, pgprot) pfn_pmd(pfn, pgprot)
+#endif

Again, no platform specific constructs please. This defeats the whole purpose of this test. If __PAGE_PTE is required for the helpers, then pfn_pmd/pte() could be modified to accommodate that. We dont see similar issues on other platforms, hence could you please explain why ppc64 is different here.

It is not platform specific. set_pte_at is the one that set the _PAGE_PTE bit. We don't call that in the test. The test seems to make the assumption that pfn_pte returns a proper pte which is not true.

-aneesh

#40 lore raw

Re: [PATCH 16/16] debug_vm_pgtable/ppc64: Add a variant of pfn_pte/pmd

Quoted 47 lines · Aneesh Kumar K.V
Quoted 36 lines · Anshuman Khandual
Quoted 34 lines · Aneesh Kumar K.V

The tests do expect _PAGE_PTE bit set by different page table accessors. This is not true for the kernel. Within the kernel, _PAGE_PTE bits are usually set by set_pte_at(). To make the below tests work correctly add test specific pfn_pte/pmd helpers that set _PAGE_PTE bit.

pte_t pte = pfn_pte(pfn, prot); WARN_ON(!pte_devmap(pte_mkdevmap(pte))); WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));

---
  mm/debug_vm_pgtable.c | 65 +++++++++++++++++++++++++++----------------

  1 file changed, 41 insertions(+), 24 deletions(-)
mm/debug_vm_pgtable.c +0 -0
index eea62d5e503b..153c925b5273 100644
@@ -31,6 +31,23 @@
   #include <asm/pgalloc.h>
   #include <asm/tlbflush.h>

  +#ifdef CONFIG_PPC_BOOK3S_64

mm/debug_vm_pgtable.c +12 -0
+static inline pte_t debug_vm_pfn_pte(unsigned long pfn, pgprot_t pgprot)
+{
+    pte_t pte = pfn_pte(pfn, pgprot);
+    return __pte(pte_val(pte) | _PAGE_PTE);
+
+}
+static inline pmd_t debug_vm_pfn_pmd(unsigned long pfn, pgprot_t pgprot)
+{
+    pmd_t pmd = pfn_pmd(pfn, pgprot);
+    return __pmd(pmd_val(pmd) | _PAGE_PTE);
+}
+#else
Quoted 9 lines

mm/debug_vm_pgtable.c line 49

Quoted 3 lines
mm/debug_vm_pgtable.c +3 -0
+#define debug_vm_pfn_pte(pfn, pgprot) pfn_pte(pfn, pgprot)
+#define debug_vm_pfn_pmd(pfn, pgprot) pfn_pmd(pfn, pgprot)
+#endif

Again, no platform specific constructs please. This defeats the whole purpose of this test. If __PAGE_PTE is required for the helpers, then pfn_pmd/pte() could be modified to accommodate that. We dont see similar issues on other platforms, hence could you please explain why ppc64 is different here.

Quoted 1 line

It is not platform specific. set_pte_at is the one that set the _PAGE_PTE bit. We don't call that in the test.  The test seems to make the assumption that pfn_pte returns a proper pte which is not true.

'#ifdef CONFIG_PPC_BOOK3S_64' definitely makes it platform specific. Here is how set_pte_at() updates an entry on other platforms without changing the pte value. _PAGE_PTE bit update during set_pte_at() on ppc64 seems to be a deviation.

1. set_pte_at() on arm64 directly update the entry after TLB, cache maintenance
2. set_pte_at() on s390 directly updates the entry for !CONFIG_PGSTE
3. set_pte_at() on arc directly updates the entry via set_pte()
4. set_pte_at() on x86 directly update the entry via native_set_pte()

set_pte_at() does take a pte created with pfn_pte().

As an example do_anonymous_page() does the same.

......
entry = mk_pte(page, vma->vm_page_prot); /* Call pfn_pte() */
entry = pte_sw_mkyoung(entry);
if (vma->vm_flags & VM_WRITE)

	entry = pte_mkwrite(pte_mkdirty(entry));

.....
set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry);
.....

#41 lore raw
In reply to Aneesh Kumar K.V
Quoted 4 lines · Aneesh Kumar K.V

With the hash page table, the kernel should not use pmd_clear for clearing huge pte entries. Add a DEBUG_VM WARN to catch the wrong usage.

This particular change is very much powerpc specific. Hence please drop it from the series which otherwise changes the page table test. Also, this series which is not a RFC, still lacks a proper cover letter with diff stats, tree/tag on which this applies, summary about the proposal etc. All those information will be helpful in reviewing this series better. For now, assuming that this applies cleanly on current master branch. But again, please do include a cover letter in the next version.

Quoted 37 lines
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +14 -0
index 6de56c3b33c4..079211968987 100644
@@ -868,6 +868,13 @@ static inline bool pte_ci(pte_t pte)
 
 static inline void pmd_clear(pmd_t *pmdp)
 {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pmd_val(*pmdp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
 	*pmdp = __pmd(0);
 }
 
@@ -916,6 +923,13 @@ static inline int pmd_bad(pmd_t pmd)
 
 static inline void pud_clear(pud_t *pudp)
 {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pud_val(*pudp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
 	*pudp = __pud(0);
 }
 
#42 lore raw
Quoted 6 lines · Anshuman Khandual
Quoted 4 lines · Aneesh Kumar K.V

With the hash page table, the kernel should not use pmd_clear for clearing huge pte entries. Add a DEBUG_VM WARN to catch the wrong usage.

Quoted 7 lines

This particular change is very much powerpc specific. Hence please drop it from the series which otherwise changes the page table test. Also, this series which is not a RFC, still lacks a proper cover letter with diff stats, tree/tag on which this applies, summary about the proposal etc. All those information will be helpful in reviewing this series better. For now, assuming that this applies cleanly on current master branch. But again, please do include a cover letter in the next version.

The patch series include all sort of fixes. There is no special theme for the series. So all that the cover letter would have is "fixes to make debug_vm_pgtable work on ppc64"

I tried to keep each patch simpler explaining why the current code is wrong.

Quoted 25 lines
Quoted 25 lines
---
  arch/powerpc/include/asm/book3s/64/pgtable.h | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +7 -0
index 6de56c3b33c4..079211968987 100644
@@ -868,6 +868,13 @@ static inline bool pte_ci(pte_t pte)
 
  static inline void pmd_clear(pmd_t *pmdp)
  {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pmd_val(*pmdp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
  	*pmdp = __pmd(0);
  }
 
@@ -916,6 +923,13 @@ static inline int pmd_bad(pmd_t pmd)
 
Quoted 13 lines

arch/powerpc/include/asm/book3s/64/pgtable.h static inline int pmd_bad(pmd_t pmd) · line 935

Quoted 13 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +7 -0
  static inline void pud_clear(pud_t *pudp)
  {
+	if (IS_ENABLED(CONFIG_DEBUG_VM) && !radix_enabled()) {
+		/*
+		 * Don't use this if we can possibly have a hash page table
+		 * entry mapping this.
+		 */
+		WARN_ON((pud_val(*pudp) & (H_PAGE_HASHPTE | _PAGE_PTE)) == (H_PAGE_HASHPTE | _PAGE_PTE));
+	}
  	*pudp = __pud(0);
  }
 

-aneesh