From nobody Mon Oct 31 23:12:17 2022 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 4N1TSf1yKqz4gmql; Mon, 31 Oct 2022 23:12:18 +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 4N1TSf1Lgpz3GMD; Mon, 31 Oct 2022 23:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667257938; 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=/kfQv+bRvjHwAYs2qQ567utI8DVwdsOfvYkS5luGiqk=; b=CTBrL4eFFD+vS6JtG3eFoJyPX1ILtl319us5BmDgNoFDHD8pCGvvlNL4hH4q0tGMfRFmLO 34ST64w3mwyc2yn3IvMK1xXQ1RERnRLvQRZPcmTHh9s9NTcyoD8PdlxCjgy4X1iJG6NOlA CbjRNMtRv9WLwJMeQpinu5MhUHp4lbQyV8pxEnJ0eVZhgueqC7/YCgLIJaiPQy/vCExl9M j84y2kgCR9FHhTCwOyyiuwKg2vf6l2krQnpwKxshNlDYEr7w5392eg9EBduZRARX3XWz03 NWhjgx1DVB3HjNpQ9Y+gdaJg8U49kD+KNT8AVJ/gHgG6czPMzW/39T9WEwt9UA== 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 4N1TSf0P7Jztwn; Mon, 31 Oct 2022 23:12:18 +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 29VNCHDi012823; Mon, 31 Oct 2022 23:12:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29VNCH6A012822; Mon, 31 Oct 2022 23:12:17 GMT (envelope-from git) Date: Mon, 31 Oct 2022 23:12:17 GMT Message-Id: <202210312312.29VNCH6A012822@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: 0e69c959150c - main - dtrace: Fix up %rip for invop probes on x86 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: 0e69c959150c0ba38459e9121158016ee34b0d92 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1667257938; 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=/kfQv+bRvjHwAYs2qQ567utI8DVwdsOfvYkS5luGiqk=; b=O6PnKPSyHvv2l+ZNZZPC1h0bG7oX09vouU/Y+6kIhdaq9NRj3wlv5hZ/IMG57da0S06Rxb mFYSNdS3FFoDgPD8+tyOWxkaMAxcO/q5eCOIth6j4cYTiy4059sDjpxq9pPUtTE06Avpj7 LEsW30O+Anrg6EjRiH9kqb9OtNm8qqK/sgPoKu1xHxANNcVwg/EWEeAkt3vl0QJHP7mNP6 6590JFvUHhqj1ZevoPwCHirRJgvi4RYjgpom8cvabCRqNnoAms0x/e2uBBmNLsLPK+AiDB MmKIsv5l9J1T6MY0ha1eUWTN15u0e5sNNaRjDFTWrM9gabwsxomXygs9Hwkmzw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1667257938; a=rsa-sha256; cv=none; b=UnBrMwSpyV1gWgjYp+xwTcwFJ2KL3AkHxJI9GYjOznUP3N2QYtQCYWNBYU9LyZYhRxld+L 1uy6CbSrfelEM/GZSEd7i+gp1ACLSmjSFUYetFdvNRjE+l1s8P22LmulQVPnm91TdeV/vH rKJPh4FtAl0r0rp17M3TTckz/LcEOunBH8wto76uS5wAwdnlyIiVRJT3FkPZGyH+ypvyBZ 9iSJjiSQhHx02mAoo2lKvPXsF4KENL6143p4vwcABJtBMxBJoB2yP5XvhuKnPPckxlw/tk xUlRikAA/5vzKKRgO17mWN8jTgTEJnk5QQUrsTkVn/7UuP/ePROcPg2wVGKgHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0e69c959150c0ba38459e9121158016ee34b0d92 commit 0e69c959150c0ba38459e9121158016ee34b0d92 Author: Mark Johnston AuthorDate: 2022-10-31 23:11:36 +0000 Commit: Mark Johnston CommitDate: 2022-10-31 23:11:36 +0000 dtrace: Fix up %rip for invop probes on x86 When a breakpoint exception is raised, the saved value of %rip points to the instruction following the breakpoint. However, when fetching the value of %rip using regs[], it's more natural to provide the address of the breakpoint itself, so modify the kinst and fbt providers accordingly. Reported by: khng Reviewed by: christos, khng MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D37218 --- sys/cddl/dev/fbt/x86/fbt_isa.c | 8 ++++++++ sys/cddl/dev/kinst/amd64/kinst_isa.c | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sys/cddl/dev/fbt/x86/fbt_isa.c b/sys/cddl/dev/fbt/x86/fbt_isa.c index 05ec87ab437f..b05ae4cb2c44 100644 --- a/sys/cddl/dev/fbt/x86/fbt_isa.c +++ b/sys/cddl/dev/fbt/x86/fbt_isa.c @@ -84,6 +84,12 @@ fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t scratch __unused) if ((uintptr_t)fbt->fbtp_patchpoint != addr) continue; fbtrval = fbt->fbtp_rval; + + /* + * Report the address of the breakpoint for the benefit + * of consumers fetching register values with regs[]. + */ + frame->tf_rip--; for (; fbt != NULL; fbt = fbt->fbtp_tracenext) { ASSERT(fbt->fbtp_rval == fbtrval); if (fbt->fbtp_roffset == 0) { @@ -143,6 +149,8 @@ fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t scratch __unused) cpu->cpu_dtrace_caller = 0; } } + /* Advance to the instruction following the breakpoint. */ + frame->tf_rip++; return (fbtrval); } diff --git a/sys/cddl/dev/kinst/amd64/kinst_isa.c b/sys/cddl/dev/kinst/amd64/kinst_isa.c index 6d8d5d521617..e47cfbbf4d4e 100644 --- a/sys/cddl/dev/kinst/amd64/kinst_isa.c +++ b/sys/cddl/dev/kinst/amd64/kinst_isa.c @@ -139,6 +139,12 @@ kinst_invop(uintptr_t addr, struct trapframe *frame, uintptr_t scratch) if (kp == NULL) return (0); + /* + * Report the address of the breakpoint for the benefit of consumers + * fetching register values with regs[]. + */ + frame->tf_rip--; + DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); cpu->cpu_dtrace_caller = stack[0]; DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT | CPU_DTRACE_BADADDR); @@ -162,7 +168,7 @@ kinst_invop(uintptr_t addr, struct trapframe *frame, uintptr_t scratch) if (kpmd->reg1 == -1 && kpmd->reg2 == -1) { /* rip-relative */ - rval = frame->tf_rip - 1 + kpmd->instlen; + rval = frame->tf_rip + kpmd->instlen; } else { /* indirect */ rval = kinst_regval(frame, kpmd->reg1) +