Currently, page table mapping code is scattered everywhere. Extract public page table mapping code and prepare for 5-level page. this patch is no functionality change. Signed-off-by: Dou Liyang <douly.fnst@xxxxxxxxxxxxxx> --- x86_64.c | 410 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 193 insertions(+), 217 deletions(-) diff --git a/x86_64.c b/x86_64.c index 467b5d7..e3a8db7 100644 --- a/x86_64.c +++ b/x86_64.c @@ -79,6 +79,11 @@ static void x86_64_calc_phys_base(void); static int x86_64_is_module_addr(ulong); static int x86_64_is_kvaddr(ulong); static int x86_64_is_uvaddr(ulong, struct task_context *); +static ulong *x86_64_kpgd_offset(ulong, int, int); +static ulong x86_64_upgd_offset(struct task_context *, ulong, int, int); +static ulong x86_64_pud_offset(ulong, ulong, int, int); +static ulong x86_64_pmd_offset(ulong, ulong, int, int); +static ulong x86_64_pte_offset(ulong, ulong, int, int); void x86_64_compiler_warning_stub(void); static void x86_64_init_kernel_pgd(void); static void x86_64_cpu_pda_init(void); @@ -1575,6 +1580,153 @@ x86_64_is_uvaddr(ulong addr, struct task_context *tc) return (addr < USERSPACE_TOP); } +/* + * Find the kernel pgd entry.. + * pgd = pgd_offset_k(addr); + */ +static ulong * +x86_64_kpgd_offset(ulong kvaddr, int verbose, int IS_XEN) +{ + ulong *pgd; + + FILL_PML4(); + pgd = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr); + if (verbose) { + fprintf(fp, "PGD DIRECTORY: %lx\n", vt->kernel_pgd[0]); + if(IS_XEN) + fprintf(fp, "PAGE DIRECTORY: %lx [machine]\n", *pgd); + else + fprintf(fp, "PAGE DIRECTORY: %lx\n", *pgd); + } + + return pgd; +} + +/* + * Find the user pgd entry.. + * pgd = pgd_offset(mm, address); + */ +static ulong +x86_64_upgd_offset(struct task_context *tc, ulong uvaddr, int verbose, int IS_XEN) +{ + ulong *pgd; + ulong pgd_paddr; + ulong pgd_pte; + + if (task_mm(tc->task, TRUE)) + pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); + else + readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pgd, + sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); + + pgd_paddr = x86_64_VTOP((ulong)pgd); + FILL_UPML(pgd_paddr, PHYSADDR, PAGESIZE()); + pgd = ((ulong *)pgd_paddr) + pml4_index(uvaddr); + pgd_pte = ULONG(machdep->machspec->pml4 + PAGEOFFSET(pgd)); + if (verbose) { + if(IS_XEN) + fprintf(fp, " PGD: %lx => %lx [machine]\n", (ulong)pgd, pgd_pte); + else + fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd, pgd_pte); + } + + return pgd_pte; +} + +/* + * Find an entry in the third-level page table.. + * pud = pud_offset(pgd, address); + */ +static ulong +x86_64_pud_offset(ulong pgd_pte, ulong vaddr, int verbose, int IS_XEN) +{ + ulong *pud; + ulong pud_paddr; + ulong pud_pte; + + pud_paddr = pgd_pte & PHYSICAL_PAGE_MASK; + + if(IS_XEN) { + pud_paddr = xen_m2p(pud_paddr); + if (verbose) + fprintf(fp, " PGD: %lx\n", pud_paddr); + } + + FILL_PUD(pud_paddr, PHYSADDR, PAGESIZE()); + pud = ((ulong *)pud_paddr) + pgd_index(vaddr); + pud_pte = ULONG(machdep->pud + PAGEOFFSET(pud)); + if (verbose) { + if(IS_XEN) + fprintf(fp, " PUD: %lx => %lx [machine]\n", (ulong)pud, pud_pte); + else + fprintf(fp, " PUD: %lx => %lx\n", (ulong)pud, pud_pte); + } + + return pud_pte; +} + +/* + * Find an entry in the middle page table.. + * pmd = pmd_offset(pud, address); + */ +static ulong +x86_64_pmd_offset(ulong pud_pte, ulong vaddr, int verbose, int IS_XEN) +{ + ulong *pmd; + ulong pmd_paddr; + ulong pmd_pte; + + pmd_paddr = pud_pte & PHYSICAL_PAGE_MASK; + + if(IS_XEN) { + pmd_paddr = xen_m2p(pmd_paddr); + if (verbose) + fprintf(fp, " PUD: %lx\n", pmd_paddr); + } + + FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); + pmd = ((ulong *)pmd_paddr) + pmd_index(vaddr); + pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); + if (verbose) { + if(IS_XEN) + fprintf(fp, " PMD: %lx => %lx [machine]\n", (ulong)pmd, pmd_pte); + else + fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd, pmd_pte); + } + return pmd_pte; +} + +/* + * Find an entry in the pet page table.. + * pmd = pmd_offset(pud, address); + */ +static ulong +x86_64_pte_offset(ulong pmd_pte, ulong vaddr, int verbose, int IS_XEN) +{ + ulong *ptep; + ulong pte_paddr; + ulong pte; + + pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; + + if(IS_XEN) { + pte_paddr = xen_m2p(pte_paddr); + if (verbose) + fprintf(fp, " PMD: %lx\n", pte_paddr); + } + + FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); + ptep = ((ulong *)pte_paddr) + pte_index(vaddr); + pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); + if (verbose) { + if(IS_XEN) + fprintf(fp, " PTE: %lx => %lx [machine]\n", (ulong)ptep, pte); + else + fprintf(fp, " PTE: %lx => %lx\n", (ulong)ptep, pte); + } + + return pte; +} /* * Translates a user virtual address to its physical address. cmd_vtop() @@ -1588,18 +1740,9 @@ x86_64_is_uvaddr(ulong addr, struct task_context *tc) static int x86_64_uvtop_level4(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) { - ulong mm; - ulong *pml; - ulong pml_paddr; - ulong pml_pte; - ulong *pgd; - ulong pgd_paddr; ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; + ulong pud_pte; ulong pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; physaddr_t physpage; @@ -1614,43 +1757,25 @@ x86_64_uvtop_level4(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, in if ((machdep->flags & VM_5LEVEL) && x86_64_task_uses_5level(tc)) return x86_64_uvtop_5level(tc, uvaddr, paddr, verbose); - if ((mm = task_mm(tc->task, TRUE))) - pml = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); - else - readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pml, - sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); - - pml_paddr = x86_64_VTOP((ulong)pml); - FILL_UPML(pml_paddr, PHYSADDR, PAGESIZE()); - pml = ((ulong *)pml_paddr) + pml4_index(uvaddr); - pml_pte = ULONG(machdep->machspec->upml + PAGEOFFSET(pml)); - if (verbose) - fprintf(fp, " PML: %lx => %lx\n", (ulong)pml, pml_pte); - if (!(pml_pte & _PAGE_PRESENT)) + pgd_pte = x86_64_upgd_offset(tc, uvaddr, verbose, FALSE); + if (!(pgd_pte & _PAGE_PRESENT)) goto no_upage; - pgd_paddr = pml_pte & PHYSICAL_PAGE_MASK; - FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE()); - pgd = ((ulong *)pgd_paddr) + pgd_index(uvaddr); - pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd)); - if (verbose) - fprintf(fp, " PUD: %lx => %lx\n", (ulong)pgd, pgd_pte); - if (!(pgd_pte & _PAGE_PRESENT)) + /* + * pud = pud_offset(pgd, address); + */ + pud_pte = x86_64_pud_offset(pgd_pte, uvaddr, verbose, FALSE); + if (!(pud_pte & _PAGE_PRESENT)) goto no_upage; /* - * pmd = pmd_offset(pgd, address); + * pmd = pmd_offset(pud, address); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(uvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pud_pte, uvaddr, verbose, FALSE); if (!(pmd_pte & (_PAGE_PRESENT | _PAGE_PROTNONE))) goto no_upage; if (pmd_pte & _PAGE_PSE) { - if (verbose) { + if (verbose) { fprintf(fp, " PAGE: %lx (2MB)\n\n", PAGEBASE(pmd_pte) & PHYSICAL_PAGE_MASK); x86_64_translate_pte(pmd_pte, 0, 0); @@ -1666,13 +1791,7 @@ x86_64_uvtop_level4(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, in * ptep = pte_offset_map(pmd, address); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(uvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx\n", (ulong)ptep, pte); - + pte = x86_64_pte_offset(pmd_pte, uvaddr, verbose, FALSE); if (!(pte & (_PAGE_PRESENT | _PAGE_PROTNONE))) { *paddr = pte; @@ -1714,19 +1833,10 @@ x86_64_uvtop_5level(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, in static int x86_64_uvtop_level4_xen_wpt(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) { - ulong mm; - ulong *pml; - ulong pml_paddr; - ulong pml_pte; - ulong *pgd; - ulong pgd_paddr; ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; + ulong pud_pte; ulong pmd_pte; ulong pseudo_pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; ulong pseudo_pte; physaddr_t physpage; @@ -1740,45 +1850,18 @@ x86_64_uvtop_level4_xen_wpt(struct task_context *tc, ulong uvaddr, physaddr_t *p if (IS_KVADDR(uvaddr)) return x86_64_kvtop(tc, uvaddr, paddr, verbose); - if ((mm = task_mm(tc->task, TRUE))) - pml = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); - else - readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, &pml, - sizeof(long), "mm_struct pgd", FAULT_ON_ERROR); - - pml_paddr = x86_64_VTOP((ulong)pml); - FILL_UPML(pml_paddr, PHYSADDR, PAGESIZE()); - pml = ((ulong *)pml_paddr) + pml4_index(uvaddr); - pml_pte = ULONG(machdep->machspec->upml + PAGEOFFSET(pml)); - if (verbose) - fprintf(fp, " PML: %lx => %lx [machine]\n", (ulong)pml, pml_pte); - if (!(pml_pte & _PAGE_PRESENT)) + pgd_pte = x86_64_upgd_offset(tc, uvaddr, verbose, TRUE); + if (!(pgd_pte & _PAGE_PRESENT)) goto no_upage; - pgd_paddr = pml_pte & PHYSICAL_PAGE_MASK; - pgd_paddr = xen_m2p(pgd_paddr); - if (verbose) - fprintf(fp, " PML: %lx\n", pgd_paddr); - FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE()); - pgd = ((ulong *)pgd_paddr) + pgd_index(uvaddr); - pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd)); - if (verbose) - fprintf(fp, " PUD: %lx => %lx [machine]\n", (ulong)pgd, pgd_pte); - if (!(pgd_pte & _PAGE_PRESENT)) + pud_pte = x86_64_pud_offset(pgd_pte, uvaddr, verbose, TRUE); + if (!(pud_pte & _PAGE_PRESENT)) goto no_upage; /* - * pmd = pmd_offset(pgd, address); + * pmd = pmd_offset(pud, address); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - pmd_paddr = xen_m2p(pmd_paddr); - if (verbose) - fprintf(fp, " PUD: %lx\n", pmd_paddr); - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(uvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx [machine]\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pud_pte, uvaddr, verbose, TRUE); if (!(pmd_pte & _PAGE_PRESENT)) goto no_upage; if (pmd_pte & _PAGE_PSE) { @@ -1817,15 +1900,7 @@ x86_64_uvtop_level4_xen_wpt(struct task_context *tc, ulong uvaddr, physaddr_t *p * ptep = pte_offset_map(pmd, address); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - pte_paddr = xen_m2p(pte_paddr); - if (verbose) - fprintf(fp, " PMD: %lx\n", pte_paddr); - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(uvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx [machine]\n", (ulong)ptep, pte); + pte = x86_64_pte_offset(pmd_pte, uvaddr, verbose, TRUE); if (!(pte & (_PAGE_PRESENT))) { *paddr = pte; @@ -1835,7 +1910,7 @@ x86_64_uvtop_level4_xen_wpt(struct task_context *tc, ulong uvaddr, physaddr_t *p } goto no_upage; } - + pseudo_pte = xen_m2p(pte & PHYSICAL_PAGE_MASK); if (verbose) fprintf(fp, " PTE: %lx\n", pseudo_pte + PAGEOFFSET(pte)); @@ -1864,12 +1939,8 @@ x86_64_uvtop_level4_rhel4_xen_wpt(struct task_context *tc, ulong uvaddr, physadd ulong *pgd; ulong pgd_paddr; ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; ulong pmd_pte; ulong pseudo_pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; ulong pseudo_pte; physaddr_t physpage; @@ -1901,15 +1972,7 @@ x86_64_uvtop_level4_rhel4_xen_wpt(struct task_context *tc, ulong uvaddr, physadd /* * pmd = pmd_offset(pgd, address); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - pmd_paddr = xen_m2p(pmd_paddr); - if (verbose) - fprintf(fp, " PGD: %lx\n", pmd_paddr); - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(uvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx [machine]\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pgd_pte, uvaddr, verbose, TRUE); if (!(pmd_pte & _PAGE_PRESENT)) goto no_upage; if (pmd_pte & _PAGE_PSE) { @@ -1948,15 +2011,7 @@ x86_64_uvtop_level4_rhel4_xen_wpt(struct task_context *tc, ulong uvaddr, physadd * ptep = pte_offset_map(pmd, address); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - pte_paddr = xen_m2p(pte_paddr); - if (verbose) - fprintf(fp, " PMD: %lx\n", pte_paddr); - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(uvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx [machine]\n", (ulong)ptep, pte); + pte = x86_64_pte_offset(pmd_pte, uvaddr, verbose, TRUE); if (!(pte & (_PAGE_PRESENT))) { *paddr = pte; @@ -1995,11 +2050,7 @@ x86_64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbo ulong *pgd; ulong pgd_paddr; ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; ulong pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; physaddr_t physpage; @@ -2032,12 +2083,7 @@ x86_64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbo /* * pmd = pmd_offset(pgd, address); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(uvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pgd_pte, uvaddr, verbose, FALSE); if (!(pmd_pte & _PAGE_PRESENT)) goto no_upage; if (pmd_pte & _PAGE_PSE) { @@ -2057,12 +2103,7 @@ x86_64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbo * ptep = pte_offset_map(pmd, address); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(uvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx\n", (ulong)ptep, pte); + pte = x86_64_pte_offset(pmd_pte, uvaddr, verbose, FALSE); if (!(pte & (_PAGE_PRESENT))) { *paddr = pte; @@ -2088,7 +2129,6 @@ no_upage: return FALSE; } - /* * Translates a kernel virtual address to its physical address. cmd_vtop() * sets the verbose flag so that the pte translation gets displayed; all @@ -2098,14 +2138,8 @@ static int x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) { ulong *pml4; - ulong *pgd; - ulong pgd_paddr; - ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; + ulong pud_pte; ulong pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; physaddr_t physpage; @@ -2116,12 +2150,7 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo * stage phys_base is not initialized yet and x86_64_VTOP() * does not work. Jump to the code of pagetable translation. */ - FILL_PML4(); - pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr); - if (verbose) { - fprintf(fp, "PML4 DIRECTORY: %lx\n", vt->kernel_pgd[0]); - fprintf(fp, "PAGE DIRECTORY: %lx\n", *pml4); - } + pgd = x86_64_kpgd_offset(kvaddr, verbose, FALSE); goto start_vtop_with_pagetable; } @@ -2164,35 +2193,21 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo /* * pgd = pgd_offset_k(addr); */ - FILL_PML4(); - pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr); - if (verbose) { - fprintf(fp, "PML4 DIRECTORY: %lx\n", vt->kernel_pgd[0]); - fprintf(fp, "PAGE DIRECTORY: %lx\n", *pml4); - } + pgd = x86_64_kpgd_offset(kvaddr, verbose, FALSE); } start_vtop_with_pagetable: if (!(*pml4 & _PAGE_PRESENT)) goto no_kpage; - pgd_paddr = (*pml4) & PHYSICAL_PAGE_MASK; - FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE()); - pgd = ((ulong *)pgd_paddr) + pgd_index(kvaddr); - pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd)); - if (verbose) - fprintf(fp, " PUD: %lx => %lx\n", (ulong)pgd, pgd_pte); - if (!(pgd_pte & _PAGE_PRESENT)) + + pud_pte = x86_64_pud_offset(*pml4, kvaddr, verbose, FALSE); + if (!(pud_pte & _PAGE_PRESENT)) goto no_kpage; /* - * pmd = pmd_offset(pgd, addr); + * pmd = pmd_offset(pud, address); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(kvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pud_pte, kvaddr, verbose, FALSE); if (!(pmd_pte & _PAGE_PRESENT)) goto no_kpage; if (pmd_pte & _PAGE_PSE) { @@ -2212,12 +2227,7 @@ start_vtop_with_pagetable: * ptep = pte_offset_map(pmd, addr); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(kvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx\n", (ulong)ptep, pte); + pte = x86_64_pte_offset(pmd_pte, kvaddr, verbose, FALSE); if (!(pte & (_PAGE_PRESENT))) { if (pte && verbose) { fprintf(fp, "\n"); @@ -2251,15 +2261,9 @@ static int x86_64_kvtop_xen_wpt(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) { ulong *pml4; - ulong *pgd; - ulong pgd_paddr; - ulong pgd_pte; - ulong *pmd; - ulong pmd_paddr; + ulong pud_pte; ulong pmd_pte; ulong pseudo_pmd_pte; - ulong *ptep; - ulong pte_paddr; ulong pte; ulong pseudo_pte; physaddr_t physpage; @@ -2268,38 +2272,18 @@ x86_64_kvtop_xen_wpt(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, i /* * pgd = pgd_offset_k(addr); */ - FILL_PML4(); - pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr); - if (verbose) { - fprintf(fp, "PML4 DIRECTORY: %lx\n", vt->kernel_pgd[0]); - fprintf(fp, "PAGE DIRECTORY: %lx [machine]\n", *pml4); - } + pml4 = x86_64_kpgd_offset(kvaddr, verbose, TRUE); if (!(*pml4 & _PAGE_PRESENT)) goto no_kpage; - pgd_paddr = (*pml4) & PHYSICAL_PAGE_MASK; - pgd_paddr = xen_m2p(pgd_paddr); - if (verbose) - fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd_paddr); - FILL_PGD(pgd_paddr, PHYSADDR, PAGESIZE()); - pgd = ((ulong *)pgd_paddr) + pgd_index(kvaddr); - pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(pgd)); - if (verbose) - fprintf(fp, " PUD: %lx => %lx [machine]\n", (ulong)pgd, pgd_pte); - if (!(pgd_pte & _PAGE_PRESENT)) + + pud_pte = x86_64_pud_offset(*pml4, kvaddr, verbose, TRUE); + if (!(pud_pte & _PAGE_PRESENT)) goto no_kpage; /* * pmd = pmd_offset(pgd, addr); */ - pmd_paddr = pgd_pte & PHYSICAL_PAGE_MASK; - pmd_paddr = xen_m2p(pmd_paddr); - if (verbose) - fprintf(fp, " PUD: %lx\n", pmd_paddr); - FILL_PMD(pmd_paddr, PHYSADDR, PAGESIZE()); - pmd = ((ulong *)pmd_paddr) + pmd_index(kvaddr); - pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(pmd)); - if (verbose) - fprintf(fp, " PMD: %lx => %lx [machine]\n", (ulong)pmd, pmd_pte); + pmd_pte = x86_64_pmd_offset(pud_pte, kvaddr, verbose, TRUE); if (!(pmd_pte & _PAGE_PRESENT)) goto no_kpage; if (pmd_pte & _PAGE_PSE) { @@ -2338,15 +2322,7 @@ x86_64_kvtop_xen_wpt(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, i * ptep = pte_offset_map(pmd, addr); * pte = *ptep; */ - pte_paddr = pmd_pte & PHYSICAL_PAGE_MASK; - pte_paddr = xen_m2p(pte_paddr); - if (verbose) - fprintf(fp, " PMD: %lx\n", pte_paddr); - FILL_PTBL(pte_paddr, PHYSADDR, PAGESIZE()); - ptep = ((ulong *)pte_paddr) + pte_index(kvaddr); - pte = ULONG(machdep->ptbl + PAGEOFFSET(ptep)); - if (verbose) - fprintf(fp, " PTE: %lx => %lx [machine]\n", (ulong)ptep, pte); + pte = x86_64_pte_offset(pmd_pte, kvaddr, verbose, TRUE); if (!(pte & (_PAGE_PRESENT))) { if (pte && verbose) { fprintf(fp, "\n"); -- 2.14.3 -- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/crash-utility