From nobody Wed Aug 07 19:27:32 2024 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 4WfKv83vn2z5SbHy; Wed, 07 Aug 2024 19:27: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WfKv83JH8z4VbX; Wed, 7 Aug 2024 19:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723058852; 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=EdfAYfwL42odZsX5pUYqIQuJNVxywnd92Td3m/DyZ8I=; b=e0nfqNnHTvqhpm9pD+8SSC9adgHCE8rb6T+0fyd/ZQ+9jqjSdahWn93hNM3VMi6HtidUvy BXttVlmuasSj2TIiYFgqckggfwFVxd+mBBrQ/REpVF6I4VM+fdOKpsO6VW9YX/lz4SbeLE Sdi1ODM24qJFbbEALUf6kq8ZbPYX2sa/r6rOYmIKIS0f5xyEYN6OOSAnqYJa/k8N/KUjE0 uUvZao5gyGOvKcVuxZJFx4y7UTFXWQ7o8mumIA/4w58yN4up1+xYiGb189Ms55ZB59X5RZ ZxQFDbwoR9dTkVkHzq4VBsvL9Xl7OluuWupsn9Dt/6daPqDbKpiMOHYrBeWesg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723058852; a=rsa-sha256; cv=none; b=khPCPwrWjJpcwOe/V7K3v4+0twpgDTGWDNWL0a4GQM0r6/rOcmOUeXU1XF0rnf3xK9jdAN 3Ndndf2ABA8hWhlQS15yNm5CiIkRNEmXqJHhtUEq43Gsft4NUB4oytmaUiPGDf5CAV0nxl 5a2NPeKrcGXpKzp6oWeUWKw73A6UVDyP0A1Li3YBK/BtJOFK/e2RVPw7mvcmb12Llmgwuw 1I/qG0wybHD8RGE/zO9zrtGbBcvbbiAXuU6dU05AISCXLW/Ww7+4mqodPwcQKmdTOPzW9Y eCOtu7jPZWTOftPqXN62XDOeRPYAOBk1gnJSkI/bC/1lXYqNNaJpH8mcUpXH9g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723058852; 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=EdfAYfwL42odZsX5pUYqIQuJNVxywnd92Td3m/DyZ8I=; b=TvdI8o592mP0j7XTXjQXK69qbeNUcnOhykYDEnYuSYiPTCGeadvr8hJF5SVfzppRyOr5pL 3xlgGbMoEnkYv0NFixO7//4hDUIrskjc0j9Y8SCEXr4kpkEGVNx/2Wiq9TNgcdpcMxW03+ EFB8N+pgNgWeOOU/HTK9Hrg00xum8YLVKq9WDroE0I2IEhXdmQxNPfDxJobDowX32Yyi9r obNsRFY7KNLJG/IoZbyXByZIhi+/diADaO4l9Ph2jJxW58oErU5bsFQcbgEIw5e5FAw9LC nAgOAHYBh5kIkV+x5CM7NL8odSf1DpNMRS+KFF0bvwcFNbCtVoZpEhCr0o86JQ== 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 4WfKv82bm2z12T6; Wed, 7 Aug 2024 19:27:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 477JRWm5015302; Wed, 7 Aug 2024 19:27:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 477JRWEg015299; Wed, 7 Aug 2024 19:27:32 GMT (envelope-from git) Date: Wed, 7 Aug 2024 19:27:32 GMT Message-Id: <202408071927.477JRWEg015299@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: a9e4753b4fe2 - main - bhyve: Optionally put vCPUs back in the debug state after resuming 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a9e4753b4fe20d81263f61c4b7e4383739924898 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=a9e4753b4fe20d81263f61c4b7e4383739924898 commit a9e4753b4fe20d81263f61c4b7e4383739924898 Author: Mark Johnston AuthorDate: 2024-08-07 19:27:23 +0000 Commit: Mark Johnston CommitDate: 2024-08-07 19:27:23 +0000 bhyve: Optionally put vCPUs back in the debug state after resuming When the gdb stub is configured to pause guest execution upon boot (i.e., the "w" flag is passed to -G), vCPUs end up suspended in two senses: first, suspended by the GDB stub (marked in the vcpus_suspended set), and suspended by the kernel (because fbsdrun_addcpu() suspends APs before spawning their vCPU threads). When the guest is resumed by the debugger, vCPUs are unsuspended in both senses, but this is not correct for APs. Hack around this problem by re-suspending vCPUs after the debugger resumes guest execution, if they were suspended beforehand. Reviewed by: corvink, jhb MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D46196 --- usr.sbin/bhyve/gdb.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 7c04b0017c80..983e7deb61c9 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -938,8 +938,28 @@ gdb_cpu_add(struct vcpu *vcpu) * executing the first instruction. */ if (!CPU_EMPTY(&vcpus_suspended)) { + cpuset_t suspended; + int error; + + error = vm_debug_cpus(ctx, &suspended); + assert(error == 0); + CPU_SET(vcpuid, &vcpus_suspended); _gdb_cpu_suspend(vcpu, false); + + /* + * In general, APs are started in a suspended mode such that + * they exit with VM_EXITCODE_DEBUG until the BSP starts them. + * In particular, this refers to the kernel's view of the vCPU + * state rather than our own. If the debugger resumes guest + * execution, vCPUs will be unsuspended from the kernel's point + * of view, so we should restore the previous state before + * continuing. + */ + if (CPU_ISSET(vcpuid, &suspended)) { + error = vm_suspend_cpu(vcpu); + assert(error == 0); + } } pthread_mutex_unlock(&gdb_lock); }