mm/debug_vm_pgtable: Some minor updates
Subsystems (2)
cover mm/debug_vm_pgtable: Some minor updates
This series contains some cleanups and new test suggestions from Catalin from an earlier discussion.
https://lore.kernel.org/linux-mm/20201123142237.GF17833@gaia/
This series is based on v5.10-rc5 and has been tested on arm64 and x86 but has only been build tested on riscv, s390, arc etc. It would be great if folks could test this on these platforms as well. Thank you.
Anshuman Khandual (2):
mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect mm/debug_vm_pgtable/basic: Iterate over entire protection_map[]
Documentation/vm/arch_pgtable_helpers.rst | 8 ++-- mm/debug_vm_pgtable.c | 50 +++++++++++++++++------ 2 files changed, 42 insertions(+), 16 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes pxx_wrprotect() related typos in the documentation file.
--- Documentation/vm/arch_pgtable_helpers.rst | 8 ++++---- mm/debug_vm_pgtable.c | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-)
Documentation/vm/arch_pgtable_helpers.rst +4 -4
@@ -50,7 +50,7 @@ PTE Page Table Helpers +---------------------------+--------------------------------------------------+ | pte_mkwrite | Creates a writable PTE | +---------------------------+--------------------------------------------------+ -| pte_mkwrprotect | Creates a write protected PTE | +| pte_wrprotect | Creates a write protected PTE | +---------------------------+--------------------------------------------------+ | pte_mkspecial | Creates a special PTE | +---------------------------+--------------------------------------------------+
@@ -120,7 +120,7 @@ PMD Page Table Helpers +---------------------------+--------------------------------------------------+ | pmd_mkwrite | Creates a writable PMD | +---------------------------+--------------------------------------------------+ -| pmd_mkwrprotect | Creates a write protected PMD | +| pmd_wrprotect | Creates a write protected PMD | +---------------------------+--------------------------------------------------+ | pmd_mkspecial | Creates a special PMD | +---------------------------+--------------------------------------------------+
@@ -186,7 +186,7 @@ PUD Page Table Helpers +---------------------------+--------------------------------------------------+ | pud_mkwrite | Creates a writable PUD | +---------------------------+--------------------------------------------------+ -| pud_mkwrprotect | Creates a write protected PUD | +| pud_wrprotect | Creates a write protected PUD | +---------------------------+--------------------------------------------------+ | pud_mkdevmap | Creates a ZONE_DEVICE mapped PUD | +---------------------------+--------------------------------------------------+
@@ -224,7 +224,7 @@ HugeTLB Page Table Helpers +---------------------------+--------------------------------------------------+ | huge_pte_mkwrite | Creates a writable HugeTLB | +---------------------------+--------------------------------------------------+ -| huge_pte_mkwrprotect | Creates a write protected HugeTLB | +| huge_pte_wrprotect | Creates a write protected HugeTLB | +---------------------------+--------------------------------------------------+ | huge_ptep_get_and_clear | Clears a HugeTLB | +---------------------------+--------------------------------------------------+
mm/debug_vm_pgtable.c +3 -0
@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte))); } static void __init pte_advanced_tests(struct mm_struct *mm,
@@ -144,6 +145,7 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pmd_young (pmd_mkold (pmd_mkyoung (pmd))));WARN_ON (pmd_dirty (pmd_mkclean (pmd_mkdirty (pmd))));WARN_ON (pmd_write (pmd_wrprotect (pmd_mkwrite (pmd)))); +WARN_ON (pmd_dirty (pmd_wrprotect (pmd)));/* * A huge page does not point to next level page table * entry. Hence this must qualify as pmd_bad().
@@ -262,6 +264,7 @@ static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (!pud_write (pud_mkwrite (pud_wrprotect (pud))));WARN_ON (pud_write (pud_wrprotect (pud_mkwrite (pud))));WARN_ON (pud_young (pud_mkold (pud_mkyoung (pud)))); +WARN_ON (pud_dirty (pud_wrprotect (pud)));if (mm_pmd_folded (mm))return ;
Signature · 1 line
2.20.1
PATCH 2/2 mm/debug_vm_pgtable/basic: Iterate over entire protection_map[]
In reply to Anshuman KhandualCurrently the basic tests just validate various page table transformations after starting with vm_get_page_prot(VM_READ|VM_WRITE|VM_EXEC) protection. Instead scan over the entire protection_map[] for better coverage. It also makes sure that all these basic page table tranformations checks hold true irrespective of the starting protection value for the page table entry. There is also a slight change in the debug print format for basic tests to capture the protection value it is being tested with. The modified output looks something like
[pte_basic_tests ]: Validating PTE basic () [pte_basic_tests ]: Validating PTE basic (read) [pte_basic_tests ]: Validating PTE basic (write) [pte_basic_tests ]: Validating PTE basic (read|write) [pte_basic_tests ]: Validating PTE basic (exec) [pte_basic_tests ]: Validating PTE basic (read|exec) [pte_basic_tests ]: Validating PTE basic (write|exec) [pte_basic_tests ]: Validating PTE basic (read|write|exec) [pte_basic_tests ]: Validating PTE basic (shared) [pte_basic_tests ]: Validating PTE basic (read|shared) [pte_basic_tests ]: Validating PTE basic (write|shared) [pte_basic_tests ]: Validating PTE basic (read|write|shared) [pte_basic_tests ]: Validating PTE basic (exec|shared) [pte_basic_tests ]: Validating PTE basic (read|exec|shared) [pte_basic_tests ]: Validating PTE basic (write|exec|shared) [pte_basic_tests ]: Validating PTE basic (read|write|exec|shared)
This adds a missing argument 'struct mm_struct *' in pud_basic_tests() test . This never got exposed before as PUD based THP is available only on X86 platform where mm_pmd_folded(mm) call gets macro replaced without requiring the mm_struct i.e __is_defined(__PAGETABLE_PMD_FOLDED).
--- mm/debug_vm_pgtable.c | 47 ++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-)
mm/debug_vm_pgtable.c +35 -12
@@ -58,11 +58,13 @@#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) +static void __init pte_basic_tests (unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pte_t pte =pfn_pte (pfn, prot); +unsigned long val = idx, *ptr = &val; -pr_debug ("Validating PTE basic\n" ); +pr_debug ("Validating PTE basic (%pGv)\n" , ptr);WARN_ON (!pte_same (pte, pte));WARN_ON (!pte_young (pte_mkyoung (pte_mkold (pte))));WARN_ON (!pte_dirty (pte_mkdirty (pte_mkclean (pte))));
@@ -130,14 +132,16 @@ 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) +static void __init pmd_basic_tests (unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pmd_t pmd =pfn_pmd (pfn, prot); +unsigned long val = idx, *ptr = &val;if (!has_transparent_hugepage ())return ; -pr_debug ("Validating PMD basic\n" ); +pr_debug ("Validating PMD basic (%pGv)\n" , ptr);WARN_ON (!pmd_same (pmd, pmd));WARN_ON (!pmd_young (pmd_mkyoung (pmd_mkold (pmd))));WARN_ON (!pmd_dirty (pmd_mkdirty (pmd_mkclean (pmd))));
@@ -251,14 +255,16 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) }#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pud_t pud =pfn_pud (pfn, prot); +unsigned long val = idx, *ptr = &val;if (!has_transparent_hugepage ())return ; -pr_debug ("Validating PUD basic\n" ); +pr_debug ("Validating PUD basic (%pGv)\n" , ptr);WARN_ON (!pud_same (pud, pud));WARN_ON (!pud_young (pud_mkyoung (pud_mkold (pud))));WARN_ON (!pud_write (pud_mkwrite (pud_wrprotect (pud))));
@@ -362,7 +368,7 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot)#endif /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr,
@@ -375,8 +381,8 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_basic_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_basic_tests (unsigned long pfn,int idx) { } +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } static void __init pmd_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmdp, unsigned long pfn, unsigned long vaddr,
@@ -902,6 +908,7 @@ static int __init debug_vm_pgtable(void)unsigned long vaddr, pte_aligned, pmd_aligned;unsigned long pud_aligned, p4d_aligned, pgd_aligned;spinlock_t *ptl =NULL ; +int idx;pr_info ("Validating architecture page table helpers\n" ); prot =vm_get_page_prot (VMFLAGS );
@@ -966,9 +973,25 @@ static int __init debug_vm_pgtable(void) saved_pmdp =pmd_offset (pudp,0UL ); saved_ptep =pmd_pgtable (pmd); -pte_basic_tests (pte_aligned, prot); -pmd_basic_tests (pmd_aligned, prot); -pud_basic_tests (pud_aligned, prot); +/* +* Iterate over the protection_map[] to make sure that all +* the basic page table transformation validations just hold +* true irrespective of the starting protection value for a +* given page table entry. +*/ +for (idx =0 ; idx <ARRAY_SIZE (protection_map); idx++) { +pte_basic_tests (pte_aligned, idx); +pmd_basic_tests (pmd_aligned, idx); +pud_basic_tests (mm, pud_aligned, idx); + } + +/* +* Both P4D and PGD level tests are very basic which do not +* involve creating page table entries from the protection +* value and the given pfn. Hence just keep them out from +* the above iteration for now to save some test execution +* time. +*/ p4d_basic_tests (p4d_aligned, prot);pgd_basic_tests (pgd_aligned, prot);
Signature · 1 line
2.20.1
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
In reply to Anshuman KhandualLe 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 12 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0
mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));
Wondering what you are testing here exactly.
Do you expect that if PTE has the dirty bit, it gets cleared by pte_wrprotect() ?
Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call pte_mkclean() explicitely.
Quoted 13 lines
mm/debug_vm_pgtable.c +1
-0} static void __init pte_advanced_tests(struct mm_struct *mm,@@ -144,6 +145,7 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pmd_young (pmd_mkold (pmd_mkyoung (pmd))));WARN_ON (pmd_dirty (pmd_mkclean (pmd_mkdirty (pmd))));WARN_ON (pmd_write (pmd_wrprotect (pmd_mkwrite (pmd)))); +WARN_ON (pmd_dirty (pmd_wrprotect (pmd)));/* * A huge page does not point to next level page table * entry. Hence this must qualify as pmd_bad().
mm/debug_vm_pgtable.c static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) · line 270
Quoted 7 lines
mm/debug_vm_pgtable.c +1
-0@@ -262,6 +264,7 @@ static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (!pud_write (pud_mkwrite (pud_wrprotect (pud))));WARN_ON (pud_write (pud_wrprotect (pud_mkwrite (pud))));WARN_ON (pud_young (pud_mkold (pud_mkyoung (pud)))); +WARN_ON (pud_dirty (pud_wrprotect (pud)));if (mm_pmd_folded (mm))return ;
Christophe
Re: [PATCH 2/2] mm/debug_vm_pgtable/basic: Iterate over entire protection_map[]
In reply to Anshuman KhandualQuoted 31 lines · Anshuman Khandual
Currently the basic tests just validate various page table transformations after starting with
vm_get_page_prot(VM_READ|VM_WRITE|VM_EXEC)protection. Instead scan over the entire protection_map[] for better coverage. It also makes sure that all these basic page table tranformations checks hold true irrespective of the starting protection value for the page table entry. There is also a slight change in the debug print format for basic tests to capture the protection value it is being tested with. The modified output looks something like[pte_basic_tests ]: Validating PTE basic () [pte_basic_tests ]: Validating PTE basic (read) [pte_basic_tests ]: Validating PTE basic (write) [pte_basic_tests ]: Validating PTE basic (read|write) [pte_basic_tests ]: Validating PTE basic (exec) [pte_basic_tests ]: Validating PTE basic (read|exec) [pte_basic_tests ]: Validating PTE basic (write|exec) [pte_basic_tests ]: Validating PTE basic (read|write|exec) [pte_basic_tests ]: Validating PTE basic (shared) [pte_basic_tests ]: Validating PTE basic (read|shared) [pte_basic_tests ]: Validating PTE basic (write|shared) [pte_basic_tests ]: Validating PTE basic (read|write|shared) [pte_basic_tests ]: Validating PTE basic (exec|shared) [pte_basic_tests ]: Validating PTE basic (read|exec|shared) [pte_basic_tests ]: Validating PTE basic (write|exec|shared) [pte_basic_tests ]: Validating PTE basic (read|write|exec|shared)This adds a missing argument 'struct
mm_struct*' inpud_basic_tests()test . This never got exposed before as PUD based THP is available only on X86 platform wheremm_pmd_folded(mm)call gets macro replaced without requiring themm_structi.e__is_defined(__PAGETABLE_PMD_FOLDED).
Quoted 5 lines
Cc Andrew Morton <[email protected]>Suggested-by Catalin Marinas <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>
Quoted 120 lines
--- mm/debug_vm_pgtable.c | 47 ++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-)mm/debug_vm_pgtable.c +35
-12@@ -58,11 +58,13 @@#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) +static void __init pte_basic_tests (unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pte_t pte =pfn_pte (pfn, prot); +unsigned long val = idx, *ptr = &val; -pr_debug ("Validating PTE basic\n" ); +pr_debug ("Validating PTE basic (%pGv)\n" , ptr);WARN_ON (!pte_same (pte, pte));WARN_ON (!pte_young (pte_mkyoung (pte_mkold (pte))));WARN_ON (!pte_dirty (pte_mkdirty (pte_mkclean (pte))));@@ -130,14 +132,16 @@ 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) +static void __init pmd_basic_tests (unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pmd_t pmd =pfn_pmd (pfn, prot); +unsigned long val = idx, *ptr = &val;if (!has_transparent_hugepage ())return ; -pr_debug ("Validating PMD basic\n" ); +pr_debug ("Validating PMD basic (%pGv)\n" , ptr);WARN_ON (!pmd_same (pmd, pmd));WARN_ON (!pmd_young (pmd_mkyoung (pmd_mkold (pmd))));WARN_ON (!pmd_dirty (pmd_mkdirty (pmd_mkclean (pmd))));@@ -251,14 +255,16 @@ static void __init pmd_savedwrite_tests(unsigned long pfn, pgprot_t prot) }#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { +pgprot_t prot = protection_map[idx];pud_t pud =pfn_pud (pfn, prot); +unsigned long val = idx, *ptr = &val;if (!has_transparent_hugepage ())return ; -pr_debug ("Validating PUD basic\n" ); +pr_debug ("Validating PUD basic (%pGv)\n" , ptr);WARN_ON (!pud_same (pud, pud));WARN_ON (!pud_young (pud_mkyoung (pud_mkold (pud))));WARN_ON (!pud_write (pud_mkwrite (pud_wrprotect (pud))));@@ -362,7 +368,7 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot)#endif /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ #else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } static void __init pud_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pud_t *pudp, unsigned long pfn, unsigned long vaddr,@@ -375,8 +381,8 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) }#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */ #else /* !CONFIG_TRANSPARENT_HUGEPAGE */ -static void __init pmd_basic_tests (unsigned long pfn,pgprot_t prot) { } -static void __init pud_basic_tests (unsigned long pfn,pgprot_t prot) { } +static void __init pmd_basic_tests (unsigned long pfn,int idx) { } +static void __init pud_basic_tests (struct mm_struct *mm,unsigned long pfn,int idx) { } static void __init pmd_advanced_tests(struct mm_struct *mm, struct vm_area_struct *vma, pmd_t *pmdp, unsigned long pfn, unsigned long vaddr,@@ -902,6 +908,7 @@ static int __init debug_vm_pgtable(void)unsigned long vaddr, pte_aligned, pmd_aligned;unsigned long pud_aligned, p4d_aligned, pgd_aligned;spinlock_t *ptl =NULL ; +int idx;pr_info ("Validating architecture page table helpers\n" ); prot =vm_get_page_prot (VMFLAGS );@@ -966,9 +973,25 @@ static int __init debug_vm_pgtable(void) saved_pmdp =pmd_offset (pudp,0UL ); saved_ptep =pmd_pgtable (pmd); -pte_basic_tests (pte_aligned, prot); -pmd_basic_tests (pmd_aligned, prot); -pud_basic_tests (pud_aligned, prot); +/* +* Iterate over the protection_map[] to make sure that all +* the basic page table transformation validations just hold +* true irrespective of the starting protection value for a +* given page table entry. +*/ +for (idx =0 ; idx <ARRAY_SIZE (protection_map); idx++) { +pte_basic_tests (pte_aligned, idx); +pmd_basic_tests (pmd_aligned, idx); +pud_basic_tests (mm, pud_aligned, idx); + } + +/* +* Both P4D and PGD level tests are very basic which do not +* involve creating page table entries from the protection +* value and the given pfn. Hence just keep them out from +* the above iteration for now to save some test execution +* time. +*/ p4d_basic_tests (p4d_aligned, prot);pgd_basic_tests (pgd_aligned, prot);
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
In reply to Christophe LeroyQuoted 18 lines · Christophe Leroy
Le 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 10 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));Wondering what you are testing here exactly.
Quoted 4 lines
Do you expect that if PTE has the dirty bit, it gets cleared by
pte_wrprotect()?Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call
pte_mkclean()explicitely.
Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the PTE_RDONLY bit. The pte_wrprotect() sets the PTE_RDONLY bit back and we can lose the dirty information. Will found this and posted patches to fix the arm64 pte_wprotect() to set a software PTE_DIRTY if !PTE_RDONLY (we do this for ptep_set_wrprotect() already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test.
That said, I think we also need a test in the other direction, pte_wrprotect() should preserve any dirty information:
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
If pte_mkwrite() makes a pte truly writable and potentially dirty, we could also add a test as below. However, I think that's valid for arm64, other architectures with a separate hardware dirty bit would fail this:
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkwrite(pte))));
Signature · 1 line
Catalin
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
Quoted 32 lines · Catalin Marinas
Quoted 18 lines · Christophe Leroy
Le 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 10 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));Wondering what you are testing here exactly.
Quoted 4 lines
Do you expect that if PTE has the dirty bit, it gets cleared by
pte_wrprotect()?Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call
pte_mkclean()explicitely.Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the
PTE_RDONLYbit. Thepte_wrprotect()sets thePTE_RDONLYbit back and we can lose the dirty information. Will found this and posted patches to fix the arm64pte_wprotect()to set a softwarePTE_DIRTYif !PTE_RDONLY (we do this forptep_set_wrprotect()already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test.
Quoted 4 lines
That said, I think we also need a test in the other direction,
pte_wrprotect()should preserve any dirty information:WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
This seems like a generic enough principle which all platforms should adhere to. But the proposed test WARN_ON(pte_dirty(pte_wrprotect(pte))) might fail on some platforms if the page table entry came in as a dirty one and pte_wrprotect() is not expected to alter the dirty state.
Instead, should we just add the following two tests, which would ensure that pte_wrprotect() never alters the dirty state of a page table entry.
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
Quoted 6 lines
If
pte_mkwrite()makes a pte truly writable and potentially dirty, we could also add a test as below. However, I think that's valid for arm64, other architectures with a separate hardware dirty bit would fail this:WARN_ON(!pte_dirty(pte_wrprotect(pte_mkwrite(pte))));
Right.
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
Quoted 37 lines · Anshuman Khandual
Quoted 36 lines · Catalin Marinas
Quoted 18 lines · Christophe Leroy
Le 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 10 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));Wondering what you are testing here exactly.
Quoted 5 lines
Do you expect that if PTE has the dirty bit, it gets cleared by
pte_wrprotect()?Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call
pte_mkclean()explicitely.Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the
PTE_RDONLYbit. Thepte_wrprotect()sets thePTE_RDONLYbit back and we can lose the dirty information. Will found this and posted patches to fix the arm64pte_wprotect()to set a softwarePTE_DIRTYif !PTE_RDONLY (we do this forptep_set_wrprotect()already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test.That said, I think we also need a test in the other direction,
pte_wrprotect()should preserve any dirty information:
Quoted 6 lines
Quoted 1 line
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));This seems like a generic enough principle which all platforms should adhere to. But the proposed test WARN_ON(pte_dirty(pte_wrprotect(pte))) might fail on some platforms if the page table entry came in as a dirty one and
pte_wrprotect()is not expected to alter the dirty state.
Ah, so do we have architectures where entries in protection_map[] are already dirty? If those are valid, maybe the check should be:
WARN_ON(!pte_dirty(pte) && pte_dirty(pte_wrprotect(pte)));
Quoted 5 lines
Instead, should we just add the following two tests, which would ensure that
pte_wrprotect()never alters the dirty state of a page table entry.WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
These should be added as additional tests. However, my initial thought was to check whether pte_wrprotect() on a new pte created from a protection_map[] entry directly would inadvertently dirty it. On arm64, that means a protection_map[] entry missing PTE_RDONLY. A pte_mkclean() would set PTE_RDONLY, so we'd miss such check.
Signature · 1 line
Catalin
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
Quoted 40 lines · Catalin Marinas
Quoted 39 lines · Anshuman Khandual
Quoted 37 lines · Catalin Marinas
Quoted 18 lines · Christophe Leroy
Le 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 10 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));Wondering what you are testing here exactly.
Quoted 5 lines
Do you expect that if PTE has the dirty bit, it gets cleared by
pte_wrprotect()?Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call
pte_mkclean()explicitely.Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the
PTE_RDONLYbit. Thepte_wrprotect()sets thePTE_RDONLYbit back and we can lose the dirty information. Will found this and posted patches to fix the arm64pte_wprotect()to set a softwarePTE_DIRTYif !PTE_RDONLY (we do this forptep_set_wrprotect()already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test.That said, I think we also need a test in the other direction,
pte_wrprotect()should preserve any dirty information:WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
Quoted 7 lines
Quoted 4 lines
This seems like a generic enough principle which all platforms should adhere to. But the proposed test WARN_ON(pte_dirty(pte_wrprotect(pte))) might fail on some platforms if the page table entry came in as a dirty one and
pte_wrprotect()is not expected to alter the dirty state.Ah, so do we have architectures where entries in protection_map[] are already dirty? If those are valid, maybe the check should be:
Okay, I did not imply that actually. The current position for these new tests in respective pxx_basic_tests() functions is right at the end and hence the pxx might have already gone through some changes from the time it was originally created with pfn_pxx(). The entry here is not starting from the beginning. It is not expected as well, per design. So dirty bit might or might not be there depending on all the previous test sequences leading upto these new ones.
IIUC, Christophe mentioned the fact that on platforms like powerpc, dirty bit just remains unchanged during pte_wprotect(). So the current test WARN_ON(pte_dirty(pte_wrprotect(pte))) will not work on powerpc if the previous tests leading upto that point has got the dirty bit set. This is irrespective of how it was created with pfn_pte() from protection_map[] originally at the beginning.
Quoted 10 lines
WARN_ON(!pte_dirty(pte) && pte_dirty(pte_wrprotect(pte)));Quoted 5 lines
Instead, should we just add the following two tests, which would ensure that
pte_wrprotect()never alters the dirty state of a page table entry.WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
These should be added as additional tests. However, my initial thought
Okay, will add them.
Quoted 5 lines
was to check whether
pte_wrprotect()on a new pte created from a protection_map[] entry directly would inadvertently dirty it. On arm64, that means a protection_map[] entry missingPTE_RDONLY. Apte_mkclean()would setPTE_RDONLY, so we'd miss such check.
To achieve this, we could move the test right at the beginning just after the pxx gets created from protection_map[], with a comment explaining the rationale.
Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect
Quoted 63 lines · Anshuman Khandual
Quoted 40 lines · Catalin Marinas
Quoted 39 lines · Anshuman Khandual
Quoted 37 lines · Catalin Marinas
Quoted 18 lines · Christophe Leroy
Le 27/11/2020 à 06:06, Anshuman Khandual a écrit :
Quoted 10 lines
This adds validation tests for dirtiness after write protect conversion for each page table level. This is important for platforms such as arm64 that removes the hardware dirty bit while making it an write protected one. This also fixes
pxx_wrprotect()related typos in the documentation file.mm/debug_vm_pgtable.c +0
-0mm/debug_vm_pgtable.c static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) · line 73
Quoted 4 lines
mm/debug_vm_pgtable.c +1
-0@@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot)WARN_ON (pte_young (pte_mkold (pte_mkyoung (pte))));WARN_ON (pte_dirty (pte_mkclean (pte_mkdirty (pte))));WARN_ON (pte_write (pte_wrprotect (pte_mkwrite (pte)))); +WARN_ON (pte_dirty (pte_wrprotect (pte)));Wondering what you are testing here exactly.
Quoted 5 lines
Do you expect that if PTE has the dirty bit, it gets cleared by
pte_wrprotect()?Powerpc doesn't do that, it only clears the RW bit but the dirty bit remains if it is set, until you call
pte_mkclean()explicitely.Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the
PTE_RDONLYbit. Thepte_wrprotect()sets thePTE_RDONLYbit back and we can lose the dirty information. Will found this and posted patches to fix the arm64pte_wprotect()to set a softwarePTE_DIRTYif !PTE_RDONLY (we do this forptep_set_wrprotect()already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test.That said, I think we also need a test in the other direction,
pte_wrprotect()should preserve any dirty information:WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));Quoted 7 lines
Quoted 4 lines
This seems like a generic enough principle which all platforms should adhere to. But the proposed test WARN_ON(pte_dirty(pte_wrprotect(pte))) might fail on some platforms if the page table entry came in as a dirty one and
pte_wrprotect()is not expected to alter the dirty state.Ah, so do we have architectures where entries in protection_map[] are already dirty? If those are valid, maybe the check should be:
Okay, I did not imply that actually. The current position for these new tests in respective
pxx_basic_tests()functions is right at the end and hence the pxx might have already gone through some changes from the time it was originally created withpfn_pxx(). The entry here is not starting from the beginning. It is not expected as well, per design. So dirty bit might or might not be there depending on all the previous test sequences leading upto these new ones.IIUC, Christophe mentioned the fact that on platforms like powerpc, dirty bit just remains unchanged during
pte_wprotect(). So the current test WARN_ON(pte_dirty(pte_wrprotect(pte))) will not work on powerpc if the previous tests leading upto that point has got the dirty bit set. This is irrespective of how it was created withpfn_pte()from protection_map[] originally at the beginning.
[...]
Quoted 3 lines
To achieve this, we could move the test right at the beginning just after the pxx gets created from protection_map[], with a comment explaining the rationale.
OK, this makes sense. Thanks for the clarification.
Signature · 1 line
Catalin