From nobody Tue Jan 30 14:19:21 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 4TPS3G3sLGz58w6b; Tue, 30 Jan 2024 14:19:22 +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 4TPS3F6Xp8z4jtB; Tue, 30 Jan 2024 14:19:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706624361; 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=sIovrin/oUHN5YY8y0PyWj27M9Remf8Rfp+J5nGQ+2w=; b=mCwaDf2R3EJTyH4J/aKdGklTFqPqjyHhS0No/bD/VlX2jdwnkdbLESl8xIindAdHUdosuz PUgFQdvuAt+iRTiZTemXSou7UjECmZ8oAbvN2ctrlwx3pC+xnKbfFiWAugNfcJ251vTCDZ tZLM9w8dlBByYDqPJXij14u7u+dOmimj7jrX0QjohqwVsLxVppZey9Y1zZ4lZPQ4Jhki47 yhDH35i+HMfG5aVNcc0fu9LjzGnbqGVMV0Wdq1gbihqseSYckCriBkpN87Sq98o84m4QgR yFlFPOXTdHxqeDu+UwLgsPr8w3JEk3gSPAinNyCdmhDLCL3ucYZpGZmEwDf2VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706624361; 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=sIovrin/oUHN5YY8y0PyWj27M9Remf8Rfp+J5nGQ+2w=; b=qhjDH30wOcs8AbH+Rp0CRmQEvgZyepddyvNCoJjuwygkSgJDii0Kd77Ki3FJBDPboYIKyK H8O044fnt5kJs5DXI6hM3WJvHi1YwXPoASiX6h7ivD4+Yt8ZHwws0tUV7Q1FSfRsWddXyw vWzuOm+Ww6Fx0FneZ3dHo8YxPb6SuGNgeigNTUypDHOOLfvbGeBWneRcfI29AqiVta8zb/ 2L+9tpUzDfvh8BC4ucz4ANFhyRE0Wz7wGmv9eJJdyyiOnCyaeSdcw4SH0tMbC6fb05UTfu 4/jSfzWw4xOFm6TN8vKpS94xdvotyW3mk8C9gNmlpgFl0CKVxH8eMkfbIn6S+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706624361; a=rsa-sha256; cv=none; b=yyiDoH6FeEg5mf/qfE8aRz/fP/BSzdJKzDQgbHNh7dol8Jc1mFZXiukpVhTCOPrUjUzlgq g2W1F+230LzWEpnHvz411TRq5c1pKjJ8QaHczrgYhUDCrx9Xgv/rJt2LHn30TvCL7MXQdx iBc258nINIrDSofsPZB1U7QZ1UyZiJaU8R7X7nCffKBabp7lohfM3VSwIblcORKwbkzfs2 kI73bCnCjIpdV29ul/N02a8JTHADacMrDIGpVVObfyK2LsZvXWRu4duV1VUQEa4lPFLzTh WE1bH/eVmY/xfbkCVh7kv+i3o3p3q2ZH5CZTn3aqzHu/qgGffTXAQgsdmaTjjA== 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 4TPS3F48nWzf5x; Tue, 30 Jan 2024 14:19:21 +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 40UEJL17096583; Tue, 30 Jan 2024 14:19:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40UEJLW8096580; Tue, 30 Jan 2024 14:19:21 GMT (envelope-from git) Date: Tue, 30 Jan 2024 14:19:21 GMT Message-Id: <202401301419.40UEJLW8096580@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 596fe0bdc9f6 - stable/14 - bhyve: Prepare to add arm64 support to the gdb stub 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 596fe0bdc9f656c856c597c1b179317a587e7d86 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=596fe0bdc9f656c856c597c1b179317a587e7d86 commit 596fe0bdc9f656c856c597c1b179317a587e7d86 Author: Mark Johnston AuthorDate: 2024-01-23 16:41:13 +0000 Commit: Mark Johnston CommitDate: 2024-01-30 14:18:55 +0000 bhyve: Prepare to add arm64 support to the gdb stub In particular: - Stop assuming that the breakpoint size is one byte. - Avoid referencing the "rip" field in machine-independent code, use a helper. No functional change intended. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D43483 (cherry picked from commit 5f086566e02a3d21dc840564b90d46f1d3b829bb) --- usr.sbin/bhyve/gdb.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index 1b0049c9e6ae..f2976622c79a 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -70,6 +70,13 @@ */ #define GDB_SIGNAL_TRAP 5 +#define GDB_BP_SIZE 1 +#define GDB_BP_INSTR (uint8_t []){0xcc} +#define GDB_PC_REGNAME VM_REG_GUEST_RIP + +_Static_assert(sizeof(GDB_BP_INSTR) == GDB_BP_SIZE, + "GDB_BP_INSTR has wrong size"); + static void gdb_resume_vcpus(void); static void check_command(int fd); @@ -96,7 +103,7 @@ struct io_buffer { struct breakpoint { uint64_t gpa; - uint8_t shadow_inst; + uint8_t shadow_inst[GDB_BP_SIZE]; TAILQ_ENTRY(breakpoint) link; }; @@ -264,6 +271,12 @@ guest_vaddr2paddr(struct vcpu *vcpu, uint64_t vaddr, uint64_t *paddr) return (1); } +static uint64_t +guest_pc(struct vm_exit *vme) +{ + return (vme->rip); +} + static void io_buffer_reset(struct io_buffer *io) { @@ -932,7 +945,7 @@ gdb_cpu_breakpoint(struct vcpu *vcpu, struct vm_exit *vmexit) } vcpuid = vcpu_id(vcpu); pthread_mutex_lock(&gdb_lock); - error = guest_vaddr2paddr(vcpu, vmexit->rip, &gpa); + error = guest_vaddr2paddr(vcpu, guest_pc(vmexit), &gpa); assert(error == 1); bp = find_breakpoint(gpa); if (bp != NULL) { @@ -941,11 +954,11 @@ gdb_cpu_breakpoint(struct vcpu *vcpu, struct vm_exit *vmexit) assert(vs->stepped == false); assert(vs->hit_swbreak == false); vs->hit_swbreak = true; - vm_set_register(vcpu, VM_REG_GUEST_RIP, vmexit->rip); + vm_set_register(vcpu, GDB_PC_REGNAME, guest_pc(vmexit)); for (;;) { if (stopped_vcpu == -1) { debug("$vCPU %d reporting breakpoint at rip %#lx\n", - vcpuid, vmexit->rip); + vcpuid, guest_pc(vmexit)); stopped_vcpu = vcpuid; gdb_suspend_vcpus(); } @@ -964,7 +977,7 @@ gdb_cpu_breakpoint(struct vcpu *vcpu, struct vm_exit *vmexit) gdb_cpu_resume(vcpu); } else { debug("$vCPU %d injecting breakpoint at rip %#lx\n", vcpuid, - vmexit->rip); + guest_pc(vmexit)); error = vm_set_register(vcpu, VM_REG_GUEST_ENTRY_INST_LENGTH, vmexit->u.bpt.inst_length); assert(error == 0); @@ -1278,8 +1291,8 @@ remove_all_sw_breakpoints(void) TAILQ_FOREACH_SAFE(bp, &breakpoints, link, nbp) { debug("remove breakpoint at %#lx\n", bp->gpa); - cp = paddr_guest2host(ctx, bp->gpa, 1); - *cp = bp->shadow_inst; + cp = paddr_guest2host(ctx, bp->gpa, sizeof(bp->shadow_inst)); + memcpy(cp, bp->shadow_inst, sizeof(bp->shadow_inst)); TAILQ_REMOVE(&breakpoints, bp, link); free(bp); } @@ -1295,7 +1308,7 @@ update_sw_breakpoint(uint64_t gva, int kind, bool insert) uint8_t *cp; int error; - if (kind != 1) { + if (kind != GDB_BP_SIZE) { send_error(EINVAL); return; } @@ -1310,7 +1323,7 @@ update_sw_breakpoint(uint64_t gva, int kind, bool insert) return; } - cp = paddr_guest2host(ctx, gpa, 1); + cp = paddr_guest2host(ctx, gpa, sizeof(bp->shadow_inst)); /* Only permit breakpoints in guest RAM. */ if (cp == NULL) { @@ -1334,15 +1347,15 @@ update_sw_breakpoint(uint64_t gva, int kind, bool insert) } bp = malloc(sizeof(*bp)); bp->gpa = gpa; - bp->shadow_inst = *cp; - *cp = 0xcc; /* INT 3 */ + memcpy(bp->shadow_inst, cp, sizeof(bp->shadow_inst)); + memcpy(cp, GDB_BP_INSTR, sizeof(bp->shadow_inst)); TAILQ_INSERT_TAIL(&breakpoints, bp, link); debug("new breakpoint at %#lx\n", gpa); } } else { if (bp != NULL) { debug("remove breakpoint at %#lx\n", gpa); - *cp = bp->shadow_inst; + memcpy(cp, bp->shadow_inst, sizeof(bp->shadow_inst)); TAILQ_REMOVE(&breakpoints, bp, link); free(bp); if (TAILQ_EMPTY(&breakpoints))