From nobody Thu Sep 19 09:53:35 2024 X-Original-To: dev-commits-src-main@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 4X8W741gjTz5VnDF; Thu, 19 Sep 2024 09:53:36 +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 4X8W736S9cz4Q5l; Thu, 19 Sep 2024 09:53:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726739615; 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=dr6oJwghEWLPVq1paVBamX/HoNRa8mvdGnmBRaiOFfw=; b=kXhqj69EuzGgHMnwt12S2f8UsezSPpkbVdO+UJkfZXTlrG9IZXsqpYYb/qzZm1muG5xJPU u6P7b6k3/JbxAdeKVCiJo90PZeE8rIBAJzmxhfCRdGX4ltZ1nbM/6YDz3NwmvE5OIPz59b NK3LGHtWTn6zG+/qDpvPPSb/T9C9QeIoAWuQiR6hIz+0vk2f0QOA44ocbspoFDusHJnTlb JbwnG25Fc4DRfFBHOPvcDaiCXsGCyu7yPD8JGrLD7LndirJu/5gDBlBWv9mxMmYa6RtaRe G8Zhf/XvzDRzREIbeGAY0r2NwburWIyQ/6UMkkajdN2TNqSfT8EzvB3h1+AwgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726739615; a=rsa-sha256; cv=none; b=LNfatVUSZy84OwFk+PbeznaQKyjNpcXZdnKBHvlUkxS4hPNCIcRBv4j0lXzyL3jcd3PJ5O btliGcDI+LI7AuopP16uXaAovSfAFOI8C9n+2G3pIclCxo+vhlJYwha5A81odsoWf6neje EwEcDE8AkAMvRWVk208NRmGFcSVzThlazwzQyFzDiPthEHqY9vETxa65GSEs/7JzzesxqM 2rWAHoGc6GpfwYI6z3vqz4Y9y9hgKcwj5Z3E5u5pAUsa94E9rRn42JD0zsXxLyEGuidX8v HlES0bCXlT5ohpUobwqyMJHkBqXo4IIua4hyVGLvPCxDp4N4sPi0Hl5MTI+9jg== 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=1726739615; 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=dr6oJwghEWLPVq1paVBamX/HoNRa8mvdGnmBRaiOFfw=; b=Arz6QiO70lFPn/qA13rnq9BGzAf/SbT9yPXmtA4AAoliNmmGHKFZSyKk3seVEqDNffjH2V 72M1YKqtulN/qpsRehN2U0jfLsB+fwQTiheLO5J+seRfETF4YHFzeQ5ZxIv74XLxbdxre0 /edIzyEQrghM3uFuQnGGCPHMNvD4VTLCsxGfAnTNRYXsj6qNjCxn9vWzl5Z3q7L5YGBqY6 cjvnUecuoOIiiVzoEiRaMsN63oIKc9cZ9H/NRg9htck9b9oU/JI+iceJ34zeaHV35W/+wZ iIV2eu0GpCWz6N/qYb1furSOFWOAJJyUWh4WEpy0VDAhd9D3aghSFlbbleePoQ== 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 4X8W735vfmz11lD; Thu, 19 Sep 2024 09:53:35 +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 48J9rZIV075298; Thu, 19 Sep 2024 09:53:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48J9rZw2075295; Thu, 19 Sep 2024 09:53:35 GMT (envelope-from git) Date: Thu, 19 Sep 2024 09:53:35 GMT Message-Id: <202409190953.48J9rZw2075295@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: 9aabab09c4e1 - main - dtrace/amd64: Fix probe argument fetching List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 9aabab09c4e163fa8187b265d6836d822516b1c9 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9aabab09c4e163fa8187b265d6836d822516b1c9 commit 9aabab09c4e163fa8187b265d6836d822516b1c9 Author: Mark Johnston AuthorDate: 2024-09-19 09:21:38 +0000 Commit: Mark Johnston CommitDate: 2024-09-19 09:21:38 +0000 dtrace/amd64: Fix probe argument fetching dtrace_getarg() previously walked the call stack looking for a frame matching the dtrace_invop_callsite symbol, in order to look for a trapframe corresponding to an invop (i.e., FBT or kinst) probe. Commit 3ba8e9dc4a0e broke this in some cases by breaking the expected alignment of the dtrace_invop_callsite symbol. Rather than groveling around the stack to find invop probe arguments, simply use the trapframe reference saved by dtrace_invop(). This is simpler and less fragile. Reported by: avg Reviewed by: avg MFC after: 2 weeks Fixes: 3ba8e9dc4a0e ("dtrace/amd64: Implement emulation of call instructions") Differential Revision: https://reviews.freebsd.org/D46672 --- sys/cddl/dev/dtrace/amd64/dtrace_isa.c | 77 ++++++++++++++-------------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/sys/cddl/dev/dtrace/amd64/dtrace_isa.c b/sys/cddl/dev/dtrace/amd64/dtrace_isa.c index 9db5a16190db..83d34abbd270 100644 --- a/sys/cddl/dev/dtrace/amd64/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/amd64/dtrace_isa.c @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -355,6 +357,7 @@ zero: uint64_t dtrace_getarg(int arg, int aframes) { + struct thread *td; uintptr_t val; struct amd64_frame *fp = (struct amd64_frame *)dtrace_getfp(); uintptr_t *stack; @@ -366,57 +369,39 @@ dtrace_getarg(int arg, int aframes) */ int inreg = 5; - for (i = 1; i <= aframes; i++) { - fp = fp->f_frame; - - if (roundup2(fp->f_retaddr, 16) == - (long)dtrace_invop_callsite) { - /* - * In the case of amd64, we will use the pointer to the - * regs structure that was pushed when we took the - * trap. To get this structure, we must increment - * beyond the frame structure, and then again beyond - * the calling RIP stored in dtrace_invop(). If the - * argument that we're seeking is passed on the stack, - * we'll pull the true stack pointer out of the saved - * registers and decrement our argument by the number - * of arguments passed in registers; if the argument - * we're seeking is passed in registers, we can just - * load it directly. - */ - struct trapframe *tf = (struct trapframe *)&fp[1]; - - if (arg <= inreg) { - switch (arg) { - case 0: - stack = (uintptr_t *)&tf->tf_rdi; - break; - case 1: - stack = (uintptr_t *)&tf->tf_rsi; - break; - case 2: - stack = (uintptr_t *)&tf->tf_rdx; - break; - case 3: - stack = (uintptr_t *)&tf->tf_rcx; - break; - case 4: - stack = (uintptr_t *)&tf->tf_r8; - break; - case 5: - stack = (uintptr_t *)&tf->tf_r9; - break; - } - arg = 0; - } else { - stack = (uintptr_t *)(tf->tf_rsp); - arg -= inreg; + /* + * Did we arrive here via dtrace_invop()? We can simply fetch arguments + * from the trap frame if so. + */ + td = curthread; + if (td->t_dtrace_trapframe != NULL) { + struct trapframe *tf = td->t_dtrace_trapframe; + + if (arg <= inreg) { + switch (arg) { + case 0: + return (tf->tf_rdi); + case 1: + return (tf->tf_rsi); + case 2: + return (tf->tf_rdx); + case 3: + return (tf->tf_rcx); + case 4: + return (tf->tf_r8); + case 5: + return (tf->tf_r9); } - goto load; } + arg -= inreg; + stack = (uintptr_t *)tf->tf_rsp; + goto load; } + for (i = 1; i <= aframes; i++) + fp = fp->f_frame; + /* * We know that we did not come through a trap to get into * dtrace_probe() -- the provider simply called dtrace_probe()