From nobody Tue May 09 08:05:09 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QFrLF60pgz49sfG; Tue, 9 May 2023 08:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QFrLF5Tfnz3y2t; Tue, 9 May 2023 08:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683619509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=M8DGHrCdAcKnXsaoj0LFOd3u5lq4bzX47VYW6/BQ2pA=; b=hrAnoJLEtJoGhl5HUxxBFL9+jZdzDLVxhA/HxR7KSCTRonijavy/mDAEFZO8X8GMFbGjRi S/qxYvdInKAcLbofy5py1WiqXzOTKXNxAMWeFbwkv1jrgwijh2KMiIvSW/3z2IfFqmjvwu o2Ch3zeIt/Z215ExrjH0IHRzt3mOnPGyLVR+42P/yAx0jK/Pb3kNOWra00lesAlBLAFlhH Zi1o1ndYu+3mZ4gLwpmP4Wvh2ACMeuuGkmNF6x8Ydd6riDXf4GsU6AUxc9oQQ7iy3u3Xvu HjrWSVR7aaf0XxqdH6DxeWx/pR1+dCA9R16A2LsDLPQjKND49xRcZdsMXzSt3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683619509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=M8DGHrCdAcKnXsaoj0LFOd3u5lq4bzX47VYW6/BQ2pA=; b=rGsw7jVK7r2fm/Ntnm7fkvsv0EpX9H8Rd5wdSwPdAnySxAC5u8P51TbtpfElhG4miQNRwl FwX3MRPd/J5E2gCCSjDP0NC1G2qZuf2W4d+KX8VPwMT9S3NXzlC20W6EOpmU1AdpE7NEI0 RLo0b/1WJHE2ojrEfMEMZ+tEBiVby4ZNLpgNzU+UV7kengIjfUjCpYT0kSwDiUL3K6zR8b Ch+1AcD6yJEYmS/chVOn6z+8TeEoqMDr8qVmRzsGaPffGUfbx31+9/z/c6cZiWOSeod/PR uhRXFT0/kOh636oRppwJ2tzXj4H4Iv5HJCDZIqwSDOMzbFK6sh3tsF2I9udssQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683619509; a=rsa-sha256; cv=none; b=bVNJNZ2+edRTNOeRmU9jB65xozOFjVS+AEn9HFQq4XjBBzpvRO2LZYsoF04VKORwCyQ9/h D23u9th5GnEkBWIcdmrJvHT0VcfpgVhrBIP2qGGVocgvB2Rx1OV59DvTmRGHLdLynjWUgh D4W30amLIKudMG+QCDIhM3+EVapKwtzihYxTuL7mLvNRYBXxWwpgKafxfKymzZsQ8kVibY BzP6KGlVntZaQS38RZTH/sCvFkvvzK1fzQF+2Ha7QR/gGQhFJpEHWiV3SkhRwHXr2FPojd ewylEQeFysBos56VJt1+Uhb8s7xOyHw6y0RlX0X/AleR+fVkjCchy80MtqxN+A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QFrLF4GtJzKWr; Tue, 9 May 2023 08:05:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 3498590k090480; Tue, 9 May 2023 08:05:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 349859JE090479; Tue, 9 May 2023 08:05:09 GMT (envelope-from git) Date: Tue, 9 May 2023 08:05:09 GMT Message-Id: <202305090805.349859JE090479@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: fefac543590d - main - bhyve: fix vCPU single-stepping on VMX List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fefac543590db4e1461235b7c936f46026d0f318 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=fefac543590db4e1461235b7c936f46026d0f318 commit fefac543590db4e1461235b7c936f46026d0f318 Author: Bojan Novković AuthorDate: 2023-05-09 07:02:04 +0000 Commit: Corvin Köhne CommitDate: 2023-05-09 08:04:55 +0000 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 --- sys/amd64/include/vmm.h | 1 + sys/amd64/vmm/intel/vmx.c | 7 +++++++ usr.sbin/bhyve/gdb.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h index c3d1aa4f3866..a328404a89d5 100644 --- a/sys/amd64/include/vmm.h +++ b/sys/amd64/include/vmm.h @@ -497,6 +497,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 8b8f8fe6cb25..69391f5b77de 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; } diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 9e50602e92be..7a2c5aec0d86 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -801,6 +801,9 @@ gdb_cpu_resume(struct vcpu *vcpu) if (vs->stepping) { error = vm_set_capability(vcpu, VM_CAP_MTRAP_EXIT, 1); assert(error == 0); + + error = vm_set_capability(vcpu, VM_CAP_MASK_HWINTR, 1); + assert(error == 0); } } @@ -853,6 +856,8 @@ gdb_cpu_mtrap(struct vcpu *vcpu) vs->stepping = false; vs->stepped = true; vm_set_capability(vcpu, VM_CAP_MTRAP_EXIT, 0); + vm_set_capability(vcpu, VM_CAP_MASK_HWINTR, 0); + while (vs->stepped) { if (stopped_vcpu == -1) { debug("$vCPU %d reporting step\n", vcpuid);