Until now a hypervisor in a guest (L1) had to set "external-interrupt
exiting" and "NMI exiting" for its guests (L2). The controls are not
required by the CPU, and a hypervisor that gives its guest the local
APIC does not set the first one.
- The host still needs L2 to have a VM exit for every interrupt and NMI, so vmcs02 always has both controls.
- An interrupt or NMI for L1 that arrives while L2 runs is injected into L2 when L1 has not set the control for it, as the CPU would deliver it through L2's IDT.
- If L2 cannot take the event (RFLAGS.IF, blocking by STI, MOV SS or NMI, or another event is being injected), the host sets "interrupt-window exiting" or "NMI-window exiting" in vmcs02 and injects the event at that VM exit. L1 does not see a window exit that it has not asked for.
- Without "NMI exiting" L1 cannot use virtual NMIs, so the host uses them in vmcs02 to get the NMI-window exit. For L2 the blocking of NMIs is the same.
- A HLT of L2 that the host emulates is ended by an interrupt whatever L2's RFLAGS.IF only if the interrupt is a VM exit of L2.
- "Virtual NMIs" without "NMI exiting" is now refused, as the SDM says (27.2.1.1).
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