From 82eece443ee3eed9a04481e7127271985734ddff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20Novkovi=C4=87?= Date: Tue, 9 May 2023 09:02:04 +0200 Subject: bhyve: fix vCPU single-stepping on VMX 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 masks interrupts on a vCPU by blocking interrupt injection and modifies the gdb stub to use the newly added capability while single-stepping a vCPU. [1] Intel SDM 26.5.2 Vol. 3C Reviewed by: corvink, jbh MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39949 (cherry picked from commit fefac543590db4e1461235b7c936f46026d0f318) --- sys/amd64/include/vmm.h | 1 + sys/amd64/vmm/intel/vmx.c | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'sys/amd64') diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h index 29797ad04e0d..84b689dd7391 100644 --- a/sys/amd64/include/vmm.h +++ b/sys/amd64/include/vmm.h @@ -500,6 +500,7 @@ enum vm_cap_type { VM_CAP_RDPID, VM_CAP_RDTSCP, VM_CAP_IPI_EXIT, + VM_CAP_MASK_HWINTR, VM_CAP_MAX }; diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index 3a0693a29e80..9c2672c9ae23 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -1439,6 +1439,10 @@ vmx_inject_interrupts(struct vmx_vcpu *vcpu, struct vlapic *vlapic, uint64_t rflags, entryinfo; uint32_t gi, info; + if (vcpu->cap.set & (1 << VM_CAP_MASK_HWINTR)) { + return; + } + if (vcpu->state.nextrip != guestrip) { gi = vmcs_read(VMCS_GUEST_INTERRUPTIBILITY); if (gi & HWINTR_BLOCKING) { @@ -3634,6 +3638,9 @@ vmx_setcap(void *vcpui, int type, int val) vlapic = vm_lapic(vcpu->vcpu); vlapic->ipi_exit = val; break; + case VM_CAP_MASK_HWINTR: + retval = 0; + break; default: break; } -- cgit v1.2.3