From nobody Wed Feb 15 16:43:07 2023 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 4PH3mC6RCNz3qXhx; Wed, 15 Feb 2023 16:43:07 +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 4PH3mC5cBvz3pF0; Wed, 15 Feb 2023 16:43:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676479387; 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=Na1zwhMhCCndu7d25ISZ3Ms8eWvxc2fuC0z65o91sy0=; b=rs1bnMpXQtLNUZaNgepCMi92JdI3gNUCK5eHgiqc9f3wwDZKzNLq6Zigq3a8VtK47mGLv5 yFd+TIPZXno/nzYISPTt5F/4LE95yMcad8Bgjv8quZDy72gxTorK0AybFkthnTMZR/CNa7 AwRIfohPKDubAhRiCsaw8VJOSq6pGP88XOnM3VGn2uQtpVg3/IBdnDhbpsvfsvNrt1+6Ug GI3ewo03w5GgT2nmfulLYOe1QyplCTxb+4pxA1fKc97gQEcJ1WAwl4zluE8H71z1WzVyXT mZFVSwnjeTwL1uvkz3+i+b0Cin1nBaT1bZM8fV7TLHkGjVCCRK3wAwY/LMR/qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676479387; 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=Na1zwhMhCCndu7d25ISZ3Ms8eWvxc2fuC0z65o91sy0=; b=HxZWiGvt1PfI1bld3tv7OrmPx05SmqLchHuUtsqViOL38Z1uHGu5wDcT/vah553JY9scbW /IEklLc3J6Fy89ZjcC5/j6Jp2leE8DDapG9TJLJYUCFQS9IHsVadgxaf+aaG4X6PdfPshZ uFv6StMwEMOa7Iea//ZGSUQiC3J4oOSutnMg4qlssVUWvFv62x2n8+zQzTtPWIheoEtoo7 PL/icHKfFuSgpCdefPferrJv/Bu/3eI6mjR58FzMwXbs1J2d3DC9jSE8xsh1SQwHgeHmeo S7Pd3xHzwNm8dHGCoi19FPUXLlNs/YUdDRIgg4xI1pglwkFcXMDK0RUtavBgmg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676479387; a=rsa-sha256; cv=none; b=IIgecVd3UxR0LHIa7YVGDv4XzPsGCGFhUkiqh7U4ByosGYxeoKGuMFH468i688yhPJc/Dz gROJnyHfJnUMTSAPcXJsZL1quWWmrlhBKAYp7zLhzkcJiEjdNsADkDs96wsIeZf4AeVzZZ 14fWQcRLM/mw2pNXXQ/fsg+6c6Qjb2kOoml0D3I6KPz5bAhHY8ajqS17X4LeQWOwWy7WSE CaMi0pInhg+Pzl5L0oWKX7pEHvIyADJBm005GKhmsGXIbwHzj8NT/i1uU57B0ZNMN0K3bO HD2mYJs+dsax9BK+EjuSPGKI0TAVVGvb33Rd4TGMcIQ0ea97mU+0ubLJU48Qpw== 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 4PH3mC4jclzWMg; Wed, 15 Feb 2023 16:43:07 +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 31FGh73q002156; Wed, 15 Feb 2023 16:43:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31FGh79w002155; Wed, 15 Feb 2023 16:43:07 GMT (envelope-from git) Date: Wed, 15 Feb 2023 16:43:07 GMT Message-Id: <202302151643.31FGh79w002155@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 3b0fb298fec6 - stable/13 - dtrace: implement riscv dtrace_getustackdepth() 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3b0fb298fec6f1e82bec178e78be6072f310c28d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=3b0fb298fec6f1e82bec178e78be6072f310c28d commit 3b0fb298fec6f1e82bec178e78be6072f310c28d Author: Mitchell Horne AuthorDate: 2023-02-06 18:23:42 +0000 Commit: Mitchell Horne CommitDate: 2023-02-15 16:41:39 +0000 dtrace: implement riscv dtrace_getustackdepth() Pretty trivial following other implementations. The existing dtrace_getustack_common() does most of the work. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38303 (cherry picked from commit c6943b44f7d73176acd2e36e0615e1b2ded02c0a) --- sys/cddl/dev/dtrace/riscv/dtrace_isa.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c index 6d44a0cee9ee..6e6459a8ce74 100644 --- a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c @@ -169,7 +169,7 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) { volatile uint16_t *flags; struct trapframe *tf; - uintptr_t pc, sp, fp; + uintptr_t pc, fp; proc_t *p; int n; @@ -195,7 +195,6 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) return; pc = tf->tf_sepc; - sp = tf->tf_sp; fp = tf->tf_s[0]; if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { @@ -207,7 +206,6 @@ dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) * at the current stack pointer address since the call * instruction puts it there right before the branch. */ - *pcstack++ = (uint64_t)pc; pcstack_limit--; if (pcstack_limit <= 0) @@ -231,8 +229,33 @@ zero: int dtrace_getustackdepth(void) { + struct trapframe *tf; + uintptr_t pc, fp; + int n = 0; - printf("IMPLEMENT ME: %s\n", __func__); + if (curproc == NULL || (tf = curthread->td_frame) == NULL) + return (0); + + if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT)) + return (-1); + + pc = tf->tf_sepc; + fp = tf->tf_s[0]; + + if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_ENTRY)) { + /* + * In an entry probe. The frame pointer has not yet been + * pushed (that happens in the function prologue). The + * best approach is to add the current pc as a missing top + * of stack and back the pc up to the caller, which is stored + * at the current stack pointer address since the call + * instruction puts it there right before the branch. + */ + pc = tf->tf_ra; + n++; + } + + n += dtrace_getustack_common(NULL, 0, pc, fp); return (0); }