From nobody Tue Jan 23 16:45:33 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 4TKCd949Mpz57gKm; Tue, 23 Jan 2024 16:45:33 +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 4TKCd91npWz4vdj; Tue, 23 Jan 2024 16:45:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706028333; 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=cWKoqLJhSSUwRa2j7MUUIqPtiqSRZNXESxf6doUEy+M=; b=EcTth+D5bRq0EwbJFwl6CZWinCfOczt1jQ5egQp28jQLjpzwu+HUVX3FtW2f75B1S/Tryy QGwr4SIzdpA59JfeOipTNAAqUBrDHEblsywQ8uFetCOKIf332wHY5v/wFOJlMjcE1wVzcE TRePi4ECLS04OpjFuFEqkrYA9pYYA3fDlY9RZAKcuGomP/2FwGrVLxwueS0l9buQkxr5bx LtwPvVBb0DEBtRWNQWqSgujbtwSkRWaVWWAztK7zH8LB6LIHEUlMSRUB9qt5GgBHx27sHZ FOP5V6OMxFzYrwxibaIssMpUap0P1EsfoeS4Te9Fz2qYevLsBaV43b8qQDjuhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706028333; 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=cWKoqLJhSSUwRa2j7MUUIqPtiqSRZNXESxf6doUEy+M=; b=fX2jn1Vh217+IuhnrB0BuR6HgWHlM/IQj6Pky8suQbraZMhbDaGOn3ofpurldeuY4r0JGQ M4ARsgo10ZUiFORK0IAdmPRT7WSezlaQwxpPKI4akzb1XJ93dHWQ8gkZAJ82iES6uyPLCm G2e9kwbQLTvRcHDp5GfXQR2goTL+3ubaANfjaJN9EfOiVtsDLP0D48fTbJS/XqbiZDRKuc JykU8mZvlxcTqQRZTo1HqbuHqXUiPV+ON00BaPDcuvaOqkO/LWYCrx/vMyOldXvIwcgRPE ErYYOoh6JLcrQHh5A0UdyUebtrkg7waVk0fkkM9RxbT95/4Oi/2XZ9o8fdAv8g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706028333; a=rsa-sha256; cv=none; b=cyjDhJjCHkiXRx3VZ3TPuVSzNWaN79BfSqLH2+75W4hO0Cy7juRDhpWnD1+TXLaonRP8ub fDpyfehTF4FI0wzZ5sWq52HeuMZbB8vCWa4jh5RgNqm6BnNlcXEJedxpfAw0Gwpk8raEPq 1Ljv2KOYSpVrxlanGP7jnKDsHEZe+V9xeVSmyGRufJDpEe5yn07fF1GsimOQrfOOdUjNiu 2g+wtwZ55OXXMnmY8Y7MhPbqxQOWUKwfOaaSv4ME0Oe9/S+5iNf78W2g+jfVc3ZygawMib X/EjGZVY5RvMt3/EG3Hk+IeBKplMH4fjLSpoQc70/v8UxK5SH+krIx8On1OJAQ== 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 4TKCd90rMJzf31; Tue, 23 Jan 2024 16:45:33 +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 40NGjXdv074350; Tue, 23 Jan 2024 16:45:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NGjXjZ074347; Tue, 23 Jan 2024 16:45:33 GMT (envelope-from git) Date: Tue, 23 Jan 2024 16:45:33 GMT Message-Id: <202401231645.40NGjXjZ074347@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: 5f086566e02a - main - 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/main X-Git-Reftype: branch X-Git-Commit: 5f086566e02a3d21dc840564b90d46f1d3b829bb Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5f086566e02a3d21dc840564b90d46f1d3b829bb commit 5f086566e02a3d21dc840564b90d46f1d3b829bb Author: Mark Johnston AuthorDate: 2024-01-23 16:41:13 +0000 Commit: Mark Johnston CommitDate: 2024-01-23 16:41:13 +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 --- 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 2ef684e82c4b..4f427b1a0863 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -69,6 +69,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); @@ -95,7 +102,7 @@ struct io_buffer { struct breakpoint { uint64_t gpa; - uint8_t shadow_inst; + uint8_t shadow_inst[GDB_BP_SIZE]; TAILQ_ENTRY(breakpoint) link; }; @@ -263,6 +270,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) { @@ -931,7 +944,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) { @@ -940,11 +953,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(); } @@ -963,7 +976,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); @@ -1277,8 +1290,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); } @@ -1294,7 +1307,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; } @@ -1309,7 +1322,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) { @@ -1333,15 +1346,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))