Skip to content

Commit

Permalink
arch,pt: add dump_pagetable_va() functions
Browse files Browse the repository at this point in the history
These functionality dumps the current state of page tables for
specified CR3 only for a given virtual address.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Nov 7, 2023
1 parent 5bdded4 commit 5958e59
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
59 changes: 59 additions & 0 deletions arch/x86/pagetables.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,65 @@ void dump_pagetables(cr3_t *cr3_ptr) {
spin_unlock(&vmap_lock);
}

static void dump_pagetable_va(cr3_t *cr3_ptr, void *va) {
paddr_t tab_paddr;
pgentry_t *tab;
#if defined(__x86_64__)
int level = 4;
#else
int level = 3;
#endif

ASSERT(cr3_ptr);
if (mfn_invalid(cr3_ptr->mfn)) {
warning("CR3: 0x%lx is invalid", cr3.paddr);
return;
}

spin_lock(&vmap_lock);

tab = tmp_map_mfn(cr3_ptr->mfn);
#if defined(__x86_64__)
pml4_t *l4e = l4_table_entry((pml4_t *) tab, va);
dump_pte(l4e, cr3_ptr->mfn, level--, l4_table_index(va));

if (mfn_invalid(l4e->mfn))
goto unlock;

tab_paddr = mfn_to_paddr(l4e->mfn);
tab = tmp_map_mfn(l4e->mfn);
#endif
pdpe_t *l3e = l3_table_entry((pdpe_t *) tab, va);
dump_pte(l3e, tab_paddr, level--, l3_table_index(va));

if (mfn_invalid(l3e->mfn) || l3e->PS)
goto unlock;

tab_paddr = mfn_to_paddr(l3e->mfn);
tab = tmp_map_mfn(l3e->mfn);
pde_t *l2e = l2_table_entry((pde_t *) tab, va);
dump_pte(l2e, tab_paddr, level--, l2_table_index(va));

if (mfn_invalid(l2e->mfn) || l2e->PS)
goto unlock;

tab_paddr = mfn_to_paddr(l2e->mfn);
tab = tmp_map_mfn(l2e->mfn);
pte_t *l1e = l1_table_entry((pte_t *) tab, va);
dump_pte(l1e, tab_paddr, level--, l1_table_index(va));

unlock:
spin_unlock(&vmap_lock);
}

void dump_kern_pagetable_va(void *va) {
dump_pagetable_va(&cr3, va);
}

void dump_user_pagetable_va(void *va) {
dump_pagetable_va(&user_cr3, va);
}

static mfn_t get_cr3_mfn(cr3_t *cr3_entry) {
void *cr3_mapped = NULL;

Expand Down
2 changes: 2 additions & 0 deletions include/arch/x86/pagetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ extern pml4_t l4_pt_entries[L4_PT_ENTRIES];

extern void init_pagetables(void);
extern void dump_pagetables(cr3_t *cr3_ptr);
extern void dump_kern_pagetable_va(void *va);
extern void dump_user_pagetable_va(void *va);

#endif /* __ASSEMBLY__ */

Expand Down

0 comments on commit 5958e59

Please sign in to comment.