The function of traversing MMU in the client page table is as follows: the Virtual Machine address is converted to the physical address. The following function simulates this process. 1. Data Structure structguest_walker {intlevel; gfn_ttable_gfn [PT_MAX_FULL_LEVELS]; pt_element_tptes [PT_MAX_FULL_LEVELS]; gpa_tpte_gpa [Signature]; unsign
The MMU traversal function of the client page table: the Virtual Machine address is converted to a physical address. The following function simulates this process. 1. Data Structure struct guest_walker {int level; gfn_t table_gfn [PT_MAX_FULL_LEVELS]; pt_element_t ptes [bytes]; gpa_t pte_gpa [PT_MAX_FULL_LEVELS]; unsign
CustomerPage table Traversal
MMU functions:VirtualThe machine address is converted to a physical address. The following function simulates this process.
1. Data Structure
Struct guest_walker {
Int level;
Gfn_t table_gfn [PT_MAX_FULL_LEVELS];
Pt_element_t ptes [PT_MAX_FULL_LEVELS];
Gpa_t pte_gpa [PT_MAX_FULL_LEVELS];
Unsigned pt_access;
Unsigned pte_access;
Gfn_t gfn;
U32 error_code;
};
+ ------- +
|
+ ------- +
| C |
| ------- | <----- B
|
+ ------- +
| ------- |
| ------- |
+ ------- + <-----
A level of page table
A: base address of the page table entry
B: index address
C: Address content of the index
After the traversal is complete, the data structure content is
Gfn:
CustomerThe number of the physical address page after page table conversion
Assume PT_MAX_FULL_LEVELS = 4
Table_gfn [0-3] stores the base address of table items with four levels of pages
Pte_gpa [0-3] stores the base index address of table items on four levels of pages.
Ptes [0-3] stores the index base address in table items on four levels.
Pt_access: gfn access permission
Pte_access: gfn access permission
2:
CustomerPage table traversal is also
VirtualMMU
Static int FNAME (performance_addr) (struct guest_walker * walker,
Struct kvm_vcpu * vcpu, gva_t addr,
Int write_fault, int user_fault, int fetch_fault)
Walker-> level = vcpu-> arch. mmu. root_level; // 64-bit
CustomerThe page table level is 4.
Pte = vcpu-> arch. 333. // page Directory base address
For (;) {// 64-bit
CustomerThe machine page Directory starts to traverse, and finally to the page table
Index = PT_INDEX (addr, walker-> level );
Table_gfn = gpte_to_gfn (pte );
Pte_gpa = gfn_to_gpa (table_gfn );
Pte_gpa + = index * sizeof (pt_element_t );
Walker-> table_gfn [walker-> level-1] = table_gfn; // The base address of the page table.
Walker-> pte_gpa [walker-> level-1] = pte_gpa; // store the base address of the page table index
If (kvm_read_guest (vcpu-> kvm, pte_gpa, & pte, sizeof (pte) // obtain the index base address page items of the page table
Goto not_present;
Pte_access = pt_access & FNAME (gpte_access) (vcpu, pte); // obtain the permission to store the index base address of the page table
Walker-> ptes [walker-> level-1] = pte; // store the index base address page items of the page table
If (walker-> level = PT_PAGE_TABLE_LEVEL) // last-level storage of the page table
CustomerHost physical page address
{
Int lvl = walker-> level;
Walker-> gfn = gpte_to_gfn_lvl (pte, lvl); // Conversion
CustomerThe host physical page address is
CustomerHost physical Page No.
Walker-> gfn + = (addr & PT_LVL_OFFSET_MASK (lvl ))
> PAGE_SHIFT;
Break;
}
Pt_access = pte_access;
-- Walker-> level; // traverses the next level page table
}
// After page table traversal, obtain the access permission of the page table and store it in the data structure.
Walker-> pt_access = pt_access;
Walker-> pte_access = pte_access;
Puplintk ("% s: pte % llx pte_access % x pt_access % x \ n ",
_ Func __, (u64) pte, pt_access, pte_access );
Return 1;
}
Share: