*
* Author: Anshuman Khandual <anshuman.khandual@arm.com>
*/
-#define pr_fmt(fmt) "debug_vm_pgtable: %s: " fmt, __func__
+#define pr_fmt(fmt) "debug_vm_pgtable: [%-25s]: " fmt, __func__
#include <linux/gfp.h>
#include <linux/highmem.h>
{
pte_t pte = pfn_pte(pfn, prot);
+ pr_debug("Validating PTE basic\n");
WARN_ON(!pte_same(pte, pte));
WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte))));
WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte))));
{
pte_t pte = pfn_pte(pfn, prot);
+ pr_debug("Validating PTE advanced\n");
pte = pfn_pte(pfn, prot);
set_pte_at(mm, vaddr, ptep, pte);
ptep_set_wrprotect(mm, vaddr, ptep);
{
pte_t pte = pfn_pte(pfn, prot);
+ pr_debug("Validating PTE saved write\n");
WARN_ON(!pte_savedwrite(pte_mk_savedwrite(pte_clear_savedwrite(pte))));
WARN_ON(pte_savedwrite(pte_clear_savedwrite(pte_mk_savedwrite(pte))));
}
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PMD basic\n");
WARN_ON(!pmd_same(pmd, pmd));
WARN_ON(!pmd_young(pmd_mkyoung(pmd_mkold(pmd))));
WARN_ON(!pmd_dirty(pmd_mkdirty(pmd_mkclean(pmd))));
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PMD advanced\n");
/* Align the address wrt HPAGE_PMD_SIZE */
vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
{
pmd_t pmd = pfn_pmd(pfn, prot);
+ pr_debug("Validating PMD leaf\n");
/*
* PMD based THP is a leaf entry.
*/
if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
return;
+
+ pr_debug("Validating PMD huge\n");
/*
* X86 defined pmd_set_huge() verifies that the given
* PMD is not a populated non-leaf entry.
{
pmd_t pmd = pfn_pmd(pfn, prot);
+ pr_debug("Validating PMD saved write\n");
WARN_ON(!pmd_savedwrite(pmd_mk_savedwrite(pmd_clear_savedwrite(pmd))));
WARN_ON(pmd_savedwrite(pmd_clear_savedwrite(pmd_mk_savedwrite(pmd))));
}
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PUD basic\n");
WARN_ON(!pud_same(pud, pud));
WARN_ON(!pud_young(pud_mkyoung(pud_mkold(pud))));
WARN_ON(!pud_write(pud_mkwrite(pud_wrprotect(pud))));
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PUD advanced\n");
/* Align the address wrt HPAGE_PUD_SIZE */
vaddr = (vaddr & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE;
{
pud_t pud = pfn_pud(pfn, prot);
+ pr_debug("Validating PUD leaf\n");
/*
* PUD based THP is a leaf entry.
*/
if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMAP))
return;
+
+ pr_debug("Validating PUD huge\n");
/*
* X86 defined pud_set_huge() verifies that the given
* PUD is not a populated non-leaf entry.
{
p4d_t p4d;
+ pr_debug("Validating P4D basic\n");
memset(&p4d, RANDOM_NZVALUE, sizeof(p4d_t));
WARN_ON(!p4d_same(p4d, p4d));
}
{
pgd_t pgd;
+ pr_debug("Validating PGD basic\n");
memset(&pgd, RANDOM_NZVALUE, sizeof(pgd_t));
WARN_ON(!pgd_same(pgd, pgd));
}
if (mm_pmd_folded(mm))
return;
+ pr_debug("Validating PUD clear\n");
pud = __pud(pud_val(pud) | RANDOM_ORVALUE);
WRITE_ONCE(*pudp, pud);
pud_clear(pudp);
if (mm_pmd_folded(mm))
return;
+
+ pr_debug("Validating PUD populate\n");
/*
* This entry points to next level page table page.
* Hence this must not qualify as pud_bad().
if (mm_pud_folded(mm))
return;
+ pr_debug("Validating P4D clear\n");
p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE);
WRITE_ONCE(*p4dp, p4d);
p4d_clear(p4dp);
if (mm_pud_folded(mm))
return;
+ pr_debug("Validating P4D populate\n");
/*
* This entry points to next level page table page.
* Hence this must not qualify as p4d_bad().
if (mm_p4d_folded(mm))
return;
+ pr_debug("Validating PGD clear\n");
pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE);
WRITE_ONCE(*pgdp, pgd);
pgd_clear(pgdp);
if (mm_p4d_folded(mm))
return;
+ pr_debug("Validating PGD populate\n");
/*
* This entry points to next level page table page.
* Hence this must not qualify as pgd_bad().
{
pte_t pte = ptep_get(ptep);
+ pr_debug("Validating PTE clear\n");
pte = __pte(pte_val(pte) | RANDOM_ORVALUE);
set_pte_at(mm, vaddr, ptep, pte);
barrier();
{
pmd_t pmd = READ_ONCE(*pmdp);
+ pr_debug("Validating PMD clear\n");
pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE);
WRITE_ONCE(*pmdp, pmd);
pmd_clear(pmdp);
{
pmd_t pmd;
+ pr_debug("Validating PMD populate\n");
/*
* This entry points to next level page table page.
* Hence this must not qualify as pmd_bad().
if (!IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL))
return;
+ pr_debug("Validating PTE special\n");
WARN_ON(!pte_special(pte_mkspecial(pte)));
}
if (!IS_ENABLED(CONFIG_NUMA_BALANCING))
return;
+ pr_debug("Validating PTE protnone\n");
WARN_ON(!pte_protnone(pte));
WARN_ON(!pte_present(pte));
}
if (!IS_ENABLED(CONFIG_NUMA_BALANCING))
return;
+ pr_debug("Validating PMD protnone\n");
WARN_ON(!pmd_protnone(pmd));
WARN_ON(!pmd_present(pmd));
}
{
pte_t pte = pfn_pte(pfn, prot);
+ pr_debug("Validating PTE devmap\n");
WARN_ON(!pte_devmap(pte_mkdevmap(pte)));
}
{
pmd_t pmd = pfn_pmd(pfn, prot);
+ pr_debug("Validating PMD devmap\n");
WARN_ON(!pmd_devmap(pmd_mkdevmap(pmd)));
}
{
pud_t pud = pfn_pud(pfn, prot);
+ pr_debug("Validating PUD devmap\n");
WARN_ON(!pud_devmap(pud_mkdevmap(pud)));
}
#else /* !CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
return;
+ pr_debug("Validating PTE soft dirty\n");
WARN_ON(!pte_soft_dirty(pte_mksoft_dirty(pte)));
WARN_ON(pte_soft_dirty(pte_clear_soft_dirty(pte)));
}
if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
return;
+ pr_debug("Validating PTE swap soft dirty\n");
WARN_ON(!pte_swp_soft_dirty(pte_swp_mksoft_dirty(pte)));
WARN_ON(pte_swp_soft_dirty(pte_swp_clear_soft_dirty(pte)));
}
if (!IS_ENABLED(CONFIG_MEM_SOFT_DIRTY))
return;
+ pr_debug("Validating PMD soft dirty\n");
WARN_ON(!pmd_soft_dirty(pmd_mksoft_dirty(pmd)));
WARN_ON(pmd_soft_dirty(pmd_clear_soft_dirty(pmd)));
}
!IS_ENABLED(CONFIG_ARCH_ENABLE_THP_MIGRATION))
return;
+ pr_debug("Validating PMD swap soft dirty\n");
WARN_ON(!pmd_swp_soft_dirty(pmd_swp_mksoft_dirty(pmd)));
WARN_ON(pmd_swp_soft_dirty(pmd_swp_clear_soft_dirty(pmd)));
}
swp_entry_t swp;
pte_t pte;
+ pr_debug("Validating PTE swap\n");
pte = pfn_pte(pfn, prot);
swp = __pte_to_swp_entry(pte);
pte = __swp_entry_to_pte(swp);
swp_entry_t swp;
pmd_t pmd;
+ pr_debug("Validating PMD swap\n");
pmd = pfn_pmd(pfn, prot);
swp = __pmd_to_swp_entry(pmd);
pmd = __swp_entry_to_pmd(swp);
if (!IS_ENABLED(CONFIG_MIGRATION))
return;
+
+ pr_debug("Validating swap migration\n");
/*
* swap_migration_tests() requires a dedicated page as it needs to
* be locked before creating a migration entry from it. Locking the
struct page *page;
pte_t pte;
+ pr_debug("Validating HugeTLB basic\n");
/*
* Accessing the page associated with the pfn is safe here,
* as it was previously derived from a real kernel symbol.
pte_t pte = ptep_get(ptep);
unsigned long paddr = __pfn_to_phys(pfn) & PMD_MASK;
+ pr_debug("Validating HugeTLB advanced\n");
pte = pte_mkhuge(mk_pte(pfn_to_page(PHYS_PFN(paddr)), prot));
set_huge_pte_at(mm, vaddr, ptep, pte);
barrier();
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PMD based THP\n");
/*
* pmd_trans_huge() and pmd_present() must return positive after
* MMU invalidation with pmd_mkinvalid(). This behavior is an
if (!has_transparent_hugepage())
return;
+ pr_debug("Validating PUD based THP\n");
pud = pfn_pud(pfn, prot);
WARN_ON(!pud_trans_huge(pud_mkhuge(pud)));