This patch fixes virtual machine single stepping on VMX hosts.
Currently, when using bhyve's gdb stub, each attempt at single-stepping a vCPU lands in a timer interrupt. The current single-stepping mechanism uses the Monitor Trap Flag feature to cause VMEXIT after a single instruction is executed. Unfortunately, the SDM states that MTF causes VMEXITs for the //next// instruction that gets executed, which is often not what the person using the debugger expects. [1]
This patch adds a new VM capability that uses the RFLAGS.IF bit to mask interrupts while single-stepping a vCPU, and modifies the gdb stub to use the newly added capability.
I have tinkered with other VMCS fields in an attempt to mask interrupt delivery, but this is the only mechanism that worked so far. That being said, I'd be glad to modify the patch with a less intrusive mechanism if anyone has a suggestion.
Caveats:
Since there is no way of intercepting instructions that use or modify the IF bit, stepping over STI, CLI, POPF and PUSHF will corrupt the IF bit and crash the guest.
While this is an issue, I believe that this patch will still be of great use for debugging machine-independent parts of the kernel.
[1] Intel SDM 25-14 Vol. 3C