CPA: Add reference count debugging code Signed-off-by: Andi Kleen --- arch/x86/mm/pageattr_64.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) Index: linux/arch/x86/mm/pageattr_64.c =================================================================== --- linux.orig/arch/x86/mm/pageattr_64.c +++ linux/arch/x86/mm/pageattr_64.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -345,6 +346,34 @@ __change_page_attr(unsigned long address return 0; } +void print_level(char *what, void *pg) +{ + struct page *p = virt_to_page(pg); + printk("%s %c%c %lu ", what, + PageReserved(p) ? 'R' : '.', + PagePrivate(p) ? 'P' : '.', + page_private(p)); +} + +void print_addr(unsigned long address) +{ + pmd_t *pmd; + pud_t *pud; + + printk("TREE %lx: ", address); + pud = pud_offset(pgd_offset_k(address), address); + print_level("pud", pud); + + if (!pud_large(*pud)) { + pmd = pmd_offset(pud, address); + print_level("pmd", pmd); + + if (!pmd_large(*pmd)) + print_level("pte", pte_offset_kernel(pmd, address)); + } + printk("\n"); +} + /** * change_page_attr_addr - Change page table attributes in linear mapping * @address: Virtual address in linear mapping. @@ -369,6 +398,13 @@ int change_page_attr_addr(unsigned long kernel_map = 1; } + printk("cpa %lx-%lx %u pages to %lx from ", address, + address+(numpages*PAGE_SIZE), numpages, + pgprot_val(prot)); + print_symbol("%s\n", __builtin_return_address(0)); + for (i = 0; i < (numpages * PAGE_SIZE); i += PMD_PAGE_SIZE) + print_addr(address + i); + down_write(&init_mm.mmap_sem); for (i = 0; i < numpages; i++, address += PAGE_SIZE) { unsigned long pfn = __pa(address) >> PAGE_SHIFT; @@ -391,6 +427,11 @@ int change_page_attr_addr(unsigned long } } up_write(&init_mm.mmap_sem); + + printk("after\n"); + for (i = 0; i < (numpages * PAGE_SIZE); i += PMD_PAGE_SIZE) + print_addr(address + i); + return err; }