[Query] Reverse mapping on KVM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am in pursuit of a mechanism to obtain a Guest Virtual Address (gVA)
given a Guest Physical Address (gPA) in KVM. I am completely new to
this area with very limited knowledge of KVM/linux memory management,
so please bear with me while I try to elaborate on the problem
statement.

Since linux-2.6, I understand that a mechanism called Object-based
Reverse Mapping (objrmap) is being used to invalidate the all the PTEs
referencing to a page frame before swapping the page out from memory.
I understand that the anon_vma data structure cleverly collects all
memory region descriptors relative to a given page frame - and one
basically uses the fact that these memory region descriptors have a
pointer to the page table containing all PTEs referencing the page
frame, to invalidate them. In a native setting (no virtualization),
one could easily use the anon_vma data structure to find a virtual
address for a given page frame within the process linear address space
by doing some simple arithmetic: Combine the vm_start from the region
descriptor (vm_area_struct) and the page->index from the page
descriptor (struct page).

I was hoping to do something similar to find the gVA given a gPA
within KVM assuming Two-Dimensional Paging (TDP) is enabled. However,
as I skimmed through the KVM code, I see that KVM implements a reverse
mapping scheme wherein in stores a pointer to all the PTEs that refer
to a GFN (Guest Frame Number), as opposed to implementing objrmap.
Since it needs to support 3 different page sizes on x86 (4kB, 2MB,
1GB), it stores pointers to L1, L2 and L3 guest PTEs. As I cannot
obtain the memory region descriptor, I cannot use the aforementioned
mechanism wherein I combine vm_start and page_index.

I have the following questions.

1) If only I had access to the L4 guest PTE, I was planning to do the
following arithmetic to determine the guest virtual address:

gVA[47:39] = (Address of L4 PTE  - guest CR3)/PTE size

gVA[38:30] = (Address of L3 PTE - L4 PTE PFN)/PTE size

gVA[29:21] = (Address of L2 PTE -  L3 PTE PFN)/PTE size

gVA[20:12] = (Address of L1 PTE - L2 PTE PFN)/PTE size

Is this approach correct? If so, is there any way to obtain the L4 guest PTE?

2) Is there any other easy approach to do this which involve
exploiting fields in kvm_mmu_page? I can't seem to think of any.
I appreciate any help that may come my way. Thanks a bunch.

-- 
Regards,
Yashwant Marathe
Graduate Research Assistant
University of Texas at Austin



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux