From nobody Tue Nov 1 13:36:20 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 4N1rdp739sz4gLXp; Tue, 1 Nov 2022 13:36:30 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4N1rdm5Qz4z3cnb; Tue, 1 Nov 2022 13:36:28 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 2A1DaKAJ038333 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 1 Nov 2022 15:36:23 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 2A1DaKDr038332; Tue, 1 Nov 2022 15:36:20 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 1 Nov 2022 15:36:20 +0200 From: Konstantin Belousov To: Mark Johnston Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 0e69c959150c - main - dtrace: Fix up %rip for invop probes on x86 Message-ID: References: <202210312312.29VNCH6A012822@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202210312312.29VNCH6A012822@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on tom.home X-Rspamd-Queue-Id: 4N1rdm5Qz4z3cnb X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FREEMAIL_FROM(0.00)[gmail.com]; HAS_XAW(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On Mon, Oct 31, 2022 at 11:12:17PM +0000, Mark Johnston wrote: > 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) + I am somewhat curious. Is the breakpoint used there means INT3? If yes, then %eip++ most likely points into the middle of the overwritten multibyte instruction.