From nobody Fri Oct 04 15:57:01 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 4XKtTV0QFGz5Xxfh; Fri, 04 Oct 2024 15:57:02 +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 4XKtTT507sz40qy; Fri, 4 Oct 2024 15:57:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728057421; 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=Cc0rKOhcxbWP70VPZ2vXADyFeEIwXZbXDFd/GJdNYKc=; b=u34Yd0J+82gvkBwPpFjhly390mf8piaWFOufTLjtjid+K05owyWbzoepB6SydA8ySGKoEW CjJohrSeRPSfpvZEjWzuXWP3mgXxF/BcLrDKbqawaK56U5mO/Ler6Lj0cJCBrQm9e65wqo t0jv4jye0lplvF4NiWLB7BVrgFQE3QHTDJeTF1ykb3E+817H1lhbiQsb3sJ9bHFMHkXUVs GlFDEoY9/StF9KG3r8uvij+HAN39w8f3VSnN6TPHwKr/QuywTn2NKHxscFEGAj78VlPr01 hU7ig0PTmVC9Zymbmn6eqoSRdLiPOaYTCdKqCle1c5GRC9s0HuM1yFxzT17lNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728057421; 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=Cc0rKOhcxbWP70VPZ2vXADyFeEIwXZbXDFd/GJdNYKc=; b=Nop5Bx6Ak3l74HdaKS222W+rOeJcGEtkFJ8VY8phaQmhz1Fh/iudg98xk0wxeRy5IEK8ub bE9yvFEkHvhDkh+ij/55dZXDILmi5izmN7XT7CPGtr4U0/uNyhIaQA7DOcwINAOVCvicXy EBJCpx2nfpqp7OZilGgoLDYEHIqzqLYxSnNxfvARnX14v6aEIPxLJWhGbMzz+NoTZKH8lL bg20H4u0P1UhfkTb7zMS8kib8osQbknpZfEwaGZ9QmOycCYmieyNgeJ4m+pBdRTaPqXwyR KJDJ5+xaFQqUnng+LYWbQu1zZi5++2UDMUYeIKn9Kr5z7KZTpgwGf6X/+GRBCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728057421; a=rsa-sha256; cv=none; b=eixVfMDODBPhajlsB8CEcImX/ScEWZ69Kf18efXkHKlGQhSkfUo29DoR37eygtVsS2T3Go PG0ehuD215x1LU/boCnErQgh0R8bMaTlv0E19lpH/PpuFaxqbLC2VpHdibWoFwmF79sNf5 J3NRyddjL5EcwlCxnX0QYOy28SPXxbGnQcHTso+qfF8agaE7Wzu2PJDTfPdp1cGA4VhacR FRs5B2fO9+l0kqm3pikqRcPP+8gDHvFk9ukhPElv88k+aRYCJzaDPyQOBffyQUyIljzIWj 2egIkOsCwQUsQuBi+yniGsO3hUjw3/4s2JrNplRUtf8MvWibdkWZxrmoHAf8dg== 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 4XKtTT4KBJzhG0; Fri, 4 Oct 2024 15:57:01 +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 494Fv1Qk048375; Fri, 4 Oct 2024 15:57:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 494Fv10p048372; Fri, 4 Oct 2024 15:57:01 GMT (envelope-from git) Date: Fri, 4 Oct 2024 15:57:01 GMT Message-Id: <202410041557.494Fv10p048372@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: 8b1d908cdeb7 - stable/14 - dtrace/amd64: Fix probe argument fetching 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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: 8b1d908cdeb7fb236011ed9c42517ce0ee9c9613 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8b1d908cdeb7fb236011ed9c42517ce0ee9c9613 commit 8b1d908cdeb7fb236011ed9c42517ce0ee9c9613 Author: Mark Johnston AuthorDate: 2024-09-19 09:21:38 +0000 Commit: Mark Johnston CommitDate: 2024-10-04 15:56:42 +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 (cherry picked from commit 9aabab09c4e163fa8187b265d6836d822516b1c9) --- 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()