From nobody Mon Jan 23 16:45:17 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 4P0wvL1BBmz30w95; Mon, 23 Jan 2023 16:45: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 4P0wvL0fLGz3x7G; Mon, 23 Jan 2023 16:45:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674492318; 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=zGQ5T5iKRiZukoayDSpBlGtdTeBNVAJhPkZm7oQrW2c=; b=Jtr9hFgJ5YWqoi8awhGO5PInmKg7r+uh6cgi+qCJUFP4eRLUIgYtBJ1uSzhQ1oUsz04Qkx SZe1JlBFWMU/YGqdS8XJivXvjs9NYhqM704XCJXLIi0HQRTilzjoZ5cZhQdqKxdipc3MhV Nh0mStEjZr8GXoAJi32Sk6W9p2+qCW4oitNWnr0vVPiOkCuDeO93Lg7+gbbtEYk+9TlbcJ VQssvo41gx7HvvaSKS0T//NT7xHgpXvijr6P/jwweDcNknB0iVm7woMFGOLY0PqpfT9u9N NPC2Z8WzJ0w3/VhEHoQvL+Nx0O8k+B+7kWfo3RcVL33JfPDlVMqnXKDkcTvJSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674492318; 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=zGQ5T5iKRiZukoayDSpBlGtdTeBNVAJhPkZm7oQrW2c=; b=u2v8aWqnawiUHl/9Y51iYez1jIvuZMRLt9YQFrhDVVgQ5e9EyniZdqT8+9E9CwYRz5xGcp qaaCQALPXTETbJan6s7DiZZCzHNBrOPTIc/OSNex+KjsXfFsB7rO7j9m0GpnbQWLGJNXsE 06ACXddsJWGfsF+K0GyHiF2RcyId5ezaaL0Ei4swG1ikjObJnurJz06T7MPVNmrn5d5Ftz bmMDcrIBdzF/1FTYuTKIRnf6PWNdFB+owC4+ff7Nuxz4w49BvSeQgROg4DwEI4CpQWzqld ZzL9VUF7FKdV5YbO0tKTzgAG783XZNqB0AHL/UptEC6AnwZ7m5u26VfwSCmnJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674492318; a=rsa-sha256; cv=none; b=CUxu199Qe1a4h2Zg/e3JKF8Moq413vXQZ9Jj9yBUbpbUP4dWk7qta9glktvGCdBFwDgWBO Nrc5UsqwFydcjl8FG2OBlv+0/XRWQeE+voGTsPw6ozbT8v0jPmnJz9VjunkfQl7XkjLb2M D7Bfx07l0VDtvCpeptAKVmDlta+tXyrpQm9auDx6G8XQiHWaVj3DEbOvCuvwaD3EE01ZKh PRGuWo0Qgu4y9a7i5O1aUPfl05R+scjvGwzp7BEQhzInARN5XRBBlZGtjGBZZihUm3TFit TMF46XI2nzNFTzXW78mXqr4Vh/ZiIBEDJE1yhiAdR3bMiw6BgaE/YuW9Ldp1oA== 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 4P0wvK6t7Tzbm9; Mon, 23 Jan 2023 16:45:17 +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 30NGjHK8044370; Mon, 23 Jan 2023 16:45:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30NGjHf8044369; Mon, 23 Jan 2023 16:45:17 GMT (envelope-from git) Date: Mon, 23 Jan 2023 16:45:17 GMT Message-Id: <202301231645.30NGjHf8044369@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: 0f95f9c7eadf - stable/13 - dtrace: dtrace_getpcstack() tweaks for riscv 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: 0f95f9c7eadf52754e1dba5df760f00582edc92e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=0f95f9c7eadf52754e1dba5df760f00582edc92e commit 0f95f9c7eadf52754e1dba5df760f00582edc92e Author: Mitchell Horne AuthorDate: 2023-01-11 18:06:02 +0000 Commit: Mitchell Horne CommitDate: 2023-01-23 16:42:26 +0000 dtrace: dtrace_getpcstack() tweaks for riscv Backtraces for fbt probes are missing the caller's frame. Despite what the inherited comment claims, we do need to insert this manually on riscv. In fbt_invop(), set cpu_dtrace_caller to be the return address, not addr. We should not increment aframes within this function, since we begin the main loop by unwinding past the current frame. Plus some very small comment/style tweaks. MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37661 (cherry picked from commit cdfa49f2584ac174648ced04d76a47ad6773f2f0) --- sys/cddl/dev/dtrace/riscv/dtrace_isa.c | 32 ++++++++++++++++++++------------ sys/cddl/dev/fbt/riscv/fbt_isa.c | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c index 1f585aa6fa3c..bc8426a752df 100644 --- a/sys/cddl/dev/dtrace/riscv/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/riscv/dtrace_isa.c @@ -64,42 +64,50 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *intrpc) { struct unwind_state state; - int scp_offset; + uintptr_t caller; register_t sp; + int scp_offset; int depth; depth = 0; + caller = solaris_cpu[curcpu].cpu_dtrace_caller; if (intrpc != 0) { - pcstack[depth++] = (pc_t) intrpc; + pcstack[depth++] = (pc_t)intrpc; } - aframes++; - + /* + * Construct the unwind state, starting from this function. This frame, + * and 'aframes' others will be skipped. + */ __asm __volatile("mv %0, sp" : "=&r" (sp)); state.fp = (uintptr_t)__builtin_frame_address(0); - state.sp = sp; + state.sp = (uintptr_t)sp; state.pc = (uintptr_t)dtrace_getpcstack; while (depth < pcstack_limit) { if (!unwind_frame(curthread, &state)) break; - if (!INKERNEL(state.pc) || !INKERNEL(state.fp)) + if (!INKERNEL(state.pc) || !kstack_contains(curthread, + (vm_offset_t)state.fp, sizeof(uintptr_t))) break; - /* - * NB: Unlike some other architectures, we don't need to - * explicitly insert cpu_dtrace_caller as it appears in the - * normal kernel stack trace rather than a special trap frame. - */ if (aframes > 0) { aframes--; + + /* + * fbt_invop() records the return address at the time + * the FBT probe fires. We need to insert this into the + * backtrace manually, since the stack frame state at + * the time of the probe does not capture it. + */ + if (aframes == 0 && caller != 0) + pcstack[depth++] = caller; } else { pcstack[depth++] = state.pc; } - } for (; depth < pcstack_limit; depth++) { diff --git a/sys/cddl/dev/fbt/riscv/fbt_isa.c b/sys/cddl/dev/fbt/riscv/fbt_isa.c index 659a9d44c81c..a67e83811d9e 100644 --- a/sys/cddl/dev/fbt/riscv/fbt_isa.c +++ b/sys/cddl/dev/fbt/riscv/fbt_isa.c @@ -57,7 +57,7 @@ fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t rval) for (; fbt != NULL; fbt = fbt->fbtp_hashnext) { if ((uintptr_t)fbt->fbtp_patchpoint == addr) { - cpu->cpu_dtrace_caller = addr; + cpu->cpu_dtrace_caller = frame->tf_ra - INSN_SIZE; if (fbt->fbtp_roffset == 0) { dtrace_probe(fbt->fbtp_id, frame->tf_a[0],