Without EPT a hypervisor in a guest (L1) has to keep shadow page tables
for its guests (L2), and every page fault, change of CR3 and INVLPG of
L2 is a VM exit to L1, which the host has to hand over. L1 is now
offered "enable EPT" and INVEPT.
- When L1 uses EPT for L2, L2's memory is what L1's EPT tables make of L1's memory, which is what the host's EPT tables (the pmap of the VM) make of the host's. L2 runs on a third set of tables that has the two put together. It belongs to the vCPU and is for one EPTP of L1 at a time.
- The tables are filled when L2 has an EPT violation on them. L1's tables are walked as the CPU does: an entry that is not present or does not allow the access is an EPT violation for L1, one that is set up wrongly an EPT misconfiguration. What the walk gives is looked up in the pmap, with the pmap locked, after the host has mapped it for the access as it does for L1. Only pages of 4 KB are entered.
- The tables are emptied when L1 enters L2 with another EPTP, when L1 executes INVEPT, when they are full (hw.vmm.vmx.nested_ept_pages), and when the pmap has changed: every change that takes something away counts up pm_eptgen and gets the vCPUs out of the guest, and the generation is compared before L2 runs. L1's tables are not write-protected: L1 has to use INVEPT after a change, as on a CPU.
- L1 is told: a page walk of 4 levels, 2 MB pages, INVEPT with both types. Not offered: execute-only, 1 GB pages, accessed and dirty flags, unrestricted guest.
- With EPT the PDPTEs of an L2 with PAE paging are in L1's VMCS.
- Not implemented: an L2 that gets through L1's tables to something that is not memory of the VM, such as a device of L1. L1 is told that L2 had a triple fault. For the same reason INS and OUTS of an L2 with EPT are always given to L1: the host cannot get to L2's memory without L1's tables.
AI assistance: as D61708, this change was developed with an AI assistant (Anthropic's Claude) under my direction. The assistant wrote the code and this description. The tests in the test plan were run on real hardware.
Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Sponsored by: keelos.dev