Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I'm digging into kvm code in order to better understand how EPT is used to map GPA -> HPA in a basic virtualization scenario. Reading Intel SDM vol.3 I've not a clear understanding about the EPT violation exit qualification as follows (see Table 27-7 bit 8 )
If bit 7 is 1:
• Set if the access causing the EPT violation is to a guest-physical address that is the translation of a linear
address.
• Clear if the access causing the EPT violation is to a paging-structure entry as part of a page walk or the
update of an accessed or dirty bit.
Reserved if bit 7 is 0 (cleared to 0).
AFAIU bit 8 is set by the processor if the EPT violation is due to an access to any of the entry of guest paging hierarchy structures (PML4T, PDPT, PT or PG depending of guest translation model used) whereas it is not (clear) only when the translation GVA->GPA has been succesful (it has been able to accomplish the translation) and now the processor is trying to access to the obtained GPA (resulting in an EPT violation)
"whereas it is not (clear) only when the translation GVA->GPA has been succesful (it has been able to accomplish the translation) and now the processor is trying to access to the obtained GPA (resulting in an EPT violation)"
appears to be an edge case but can still happen. I have recommended the Intel Kernel Guard (ikgt) project in other threads on osdev but this time I really mean it...
ikgt is a ring -1 hypervisor designed to allow monitoring of vm events... such as EPT violations... worth a look for you if only to compare against KVM
cheers
Plagiarize. Plagiarize. Let not one line escape thine eyes...
I'm sorry... but I believe my previous statements have to be exchanged as follows:
bit 8 is set by the processor if the translation GVA->GPA has been successful (it has been able to accomplish the GVA->GPA translation) and now the processor is trying to access to the obtained GPA resulting in an EPT violation, whereas is not (clear) only when EPT violation is due to an access to any of the entry of guest paging hierarchy structures (PML4T, PDPT, PT or PG depending of guest translation model used) during guest page walking
kvm-based VM is running a guest OS using 4KB (or even 2MB) page size so I would expect guest physical address (gpa) reported by kvm exit ept_violation handler (via trace_kvm_page_fault tracepoint) should have last 3 hex digits equal to the last 3 hex digits of guest RIP value into VMCS' VM-exit "exit reason" field.
According kvm source code (http://lxr.free-electrons.com/source/arch/x86/kvm/vmx.c), error code reported there (e.g. 181 or 183) should not point to an EPT violation occurrence due to an access to any of guest paging hierarchy entry (PML4T, PDPT, PT or PG depending of guest translation model used) during guest page walking.....thus, why we don not get the same values for the last 3 hex digits ?
If the fault is caused by data access (i.e. not by the fetch of the next instruction), then fault address has nothing to do with the address of the instruction that was accessing some data area.
Nable wrote:If the fault is caused by data access (i.e. not by the fetch of the next instruction), then fault address has nothing to do with the address of the instruction that was accessing some data area.
you are definitely right !
For instance when the error code reported (184) point to the reason "the access causing the EPT violation was an instruction fetch" (see bit position 2 Table 27-7 Intel SDM vol.3) the last 3 hex digits are actually the same (see below):