From nobody Thu Aug 17 13:29:31 2023 X-Original-To: dev-commits-src-all@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 4RRQpN1ZjGz4qgHv; Thu, 17 Aug 2023 13:29:32 +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 4RRQpN0zs2z4jYG; Thu, 17 Aug 2023 13:29:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692278972; 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=m7ePx43WafxkO2Zaizyxktaba5T/5g3cpsw33bJRaZg=; b=rZa5W0LD13DBoI44hSWxvoSmqHYd51Dk5/aVgHz80zr4Js0XzgZPBzlz/IMGfpuoVLBjp4 M7X0dpwPxoLVAjPTy0pHPBgKEFmNevXdOdcZ8qngzY3e2adaKiFd4zs+DPFR8gYrlPbW2G AN5Dyov6nnBbBX5n3tDvbXdnJgFmmRSmNj3VVxQprIsjro7uLcbJB3EBZ89nm9i5EQDszl wTMpnvbIyyto8dgQmFy0WPg0oSXkgaAPpzbO3USWbMDjK2NXTMMGpEhCk7IRBHiYmcWpE1 IiY7A8/uitl5O29pdpzQ4ooNfQ99xdTPtOGARofrJN4TTVq7IEdwasZ62+jiPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692278972; 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=m7ePx43WafxkO2Zaizyxktaba5T/5g3cpsw33bJRaZg=; b=MwqFmYqlHaYhT1WYvXmV1dBZStjbekHmMwgDpspB1w31M3x/k1El3DM+TxeiM/sBp2/mSa C1vU8wOTA/oEKFmuPfXFhPRGhd1iOC58MkQvkjfyEEz80nJO9H7MbfQ48wl8oQOo3eUTiq rp4/OPf80iX+971iAyjoGCmQI5Wpv3vU/dDy7r42VLGJuF57b8Y1VPmrmJ6XRYvB+pABqs 4wfoY5I9ffOVRKKq5TEGomI41ku5WrW+k4pbD/PoBd7ItF7QqSvLEUnfSInfkrAGzDmSIK XyKcfEIWo/7IAiHZ8qBMZJYnhNZ5TMkv0U2s+50Kyc7qx3xl9QbrSQKPuslKDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692278972; a=rsa-sha256; cv=none; b=NZ1v1F0ZuYMTZur7tYNItf4nlmasHlaXebsqoAaSv4PaNbpfVpx5q0xTKBS4K+ShXVGS5v ZTmFeRhjUW2QVmuCvpaaWL6YPauBadsWhnLmavXT3+rvPYbCnZGEoBWdtrTSYuveG4KigU 25GYmd24U3/4GXa3qlIazJGDtQNtkg/gIzy02DlUmQ5F5sS7L30YSY6cQmr9Styy/JOa7c VNGueMCy0xdlNJQ9Af8fb+3iu6SAeaIqcGXqhCkBSd6fEHz9KG4UGFwwPW9moa5FJ2XOpq kJsGqIjypGr1VIRqlCc2nwkMkHLekao3Hw3cwVjrb+2VpCu8B5RTHFHw8/FqxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RRQpN00fSzbk7; Thu, 17 Aug 2023 13:29:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37HDTVsX030652; Thu, 17 Aug 2023 13:29:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37HDTVsp030649; Thu, 17 Aug 2023 13:29:31 GMT (envelope-from git) Date: Thu, 17 Aug 2023 13:29:31 GMT Message-Id: <202308171329.37HDTVsp030649@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 82eece443ee3 - stable/13 - bhyve: fix vCPU single-stepping on VMX List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 82eece443ee3eed9a04481e7127271985734ddff Auto-Submitted: auto-generated The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=82eece443ee3eed9a04481e7127271985734ddff commit 82eece443ee3eed9a04481e7127271985734ddff Author: Bojan Novković AuthorDate: 2023-05-09 07:02:04 +0000 Commit: Corvin Köhne CommitDate: 2023-08-17 13:06:29 +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 (cherry picked from commit fefac543590db4e1461235b7c936f46026d0f318) --- 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 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; } diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 6c1315a8371d..03f684e002ce 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -795,6 +795,9 @@ gdb_cpu_resume(int vcpu) if (vs->stepping) { error = vm_set_capability(ctx, vcpu, VM_CAP_MTRAP_EXIT, 1); assert(error == 0); + + error = vm_set_capability(ctx, vcpu, VM_CAP_MASK_HWINTR, 1); + assert(error == 0); } } @@ -845,6 +848,8 @@ gdb_cpu_mtrap(int vcpu) vs->stepping = false; vs->stepped = true; vm_set_capability(ctx, vcpu, VM_CAP_MTRAP_EXIT, 0); + vm_set_capability(ctx, vcpu, VM_CAP_MASK_HWINTR, 0); + while (vs->stepped) { if (stopped_vcpu == -1) { debug("$vCPU %d reporting step\n", vcpu);