A hypervisor in a guest (L1) can give the CPU three lists of MSRs: to load on VM entry, to store on VM exit and to load on VM exit. With D61708 a VM entry with a list that is not empty fails. This change adds the three areas. It is the first step of "What comes next" in D61708.
- An area that has entries must be aligned to 16 bytes and must be at addresses that the CPU has, or VMLAUNCH and VMRESUME fail.
- The entries are handled as the SDM says (27.4, 28.4, 28.6). A VM entry that cannot load an MSR fails with exit reason 34 and the number of the entry. A VM exit that cannot store or load an MSR is a VMX abort: the indicator is written to L1's VMCS and the VM is suspended like after a triple fault.
- Only some MSRs can be in an area: the ones that a guest writes without a VM exit (STAR, LSTAR, CSTAR, SF_MASK, KERNEL_GS_BASE), the ones that are in the VMCS (SYSENTER_CS/ESP/EIP; FS_BASE and GS_BASE can only be stored, as on a CPU) and the TSC. The values are checked as WRMSR would, because they are later given to the CPU as they are. Any other MSR makes the load or the store fail. This is narrower than a CPU, which takes any MSR that WRMSR takes; EFER and PAT are the ones a hypervisor is most likely to miss, and both have VMCS controls (EFER's are offered to L1).
- The TSC that is stored on a VM exit is read right after the exit and is L1's TSC, without the offset that L1 has set for L2. A TSC that is loaded sets L1's TSC offset, as a WRMSR of L1 does.
- An area has at most 512 entries, which is what IA32_VMX_MISC says to L1.
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, working from the SDM. The tests in the test plan were run on real hardware.
Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Sponsored by: keelos.dev