From nobody Sat Mar 11 16:43:26 2023 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 4PYpdW2jtLz3xqJT; Sat, 11 Mar 2023 16:43:27 +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 4PYpdW0Tzlz3QpS; Sat, 11 Mar 2023 16:43:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678553007; 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=jSewGXPmO/AYoaMNI9uP/8VhulJBoHsAYHP2g3w4p4k=; b=XxW0h8ebNtbAnbfxZZixZtKCDz0d0hufVU62e7w36IH9jrgvszhyA3eHFbxPz9hAYQP/Y5 uF8yxL+MgzVboNYoXSM2HKx8vePOpIvkeFKYOmgu4M8Go1DnlgpgdDYOMg9O0rav4AE3US wZQeeo457ey0iUrc2m4U+freyDiYo5Cal2m40RjRyDlIYuPsQXV90VrGs4DjCUJl6uPRvH E8CZOxIDI84kgFxVo35JGEFoHQr8sLUwPPNIU6RtcN3HWRmhynnQuQIBkVxG/Fs2DVi5fL gJh9sAbpIEz1Kl2OQF2N3Xv6IVP/QolQmEav92rADA4H4CuV1dzyoLMUFw3sCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678553007; 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=jSewGXPmO/AYoaMNI9uP/8VhulJBoHsAYHP2g3w4p4k=; b=vd0Pa9dvfotgcUsQJuDL6TiYjInhVNUOZpM6slI+imroNZdez/Q4n+XC/k4bTSGNdJXLHr BsKr/LLc5qpdB9un8d4feo+c4JE2ajYottDtSHlG7gAA/PFQV2mjO4OWTotfhGOa4wiklR 0QDWpPe916JHgStekat/dHnjRgwcGuxCqX+t7cnlDk4ovqwF34w1ouhNPMRlxKd/vfKkSH BAEKFMPa8kDPDspTsJSG0uo0jLhbXnfVOGza7XczAczcc+eYPsS42R55r12b8Ax6VXU7RQ 3w1XR2tJjqDTvAnnTNE23xATtBuRxrYEJiMPAWt3BpxJa73xbMwqKLhrMZ0aYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678553007; a=rsa-sha256; cv=none; b=ikcjWwyWD5gWuoLMBnVPJIZW0jmc5jVaeFwZAcMjSunq+fkTmCC2gRMmhRGtN4bl+FrGbB chPS1kDgqimjkx8+CzmIzt8TfyhYiVUTC94oAOLMBMBz3qJzoCPcNLJfid7aFlVCSAvnpP FoAHmHV9s28/rz7JBT5lyzNiX5Tjvnvl5wZemXhprKovRezJtUjMUsihjSYjE4OonAv6JB qGXmF8htcA65GZ82xIs2R/LHBalDHtkk+rApx6QIsi/03Idw2ioTrw3cRUPanT/Jg5GI6j 2+6RhtkCke3Jj1bSzsbD5VWAxkJm6I078o4bVzd7jqXZPpnxwlOT53D84FJ40g== 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 4PYpdV6jKHzcG7; Sat, 11 Mar 2023 16:43:26 +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 32BGhQwg087343; Sat, 11 Mar 2023 16:43:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32BGhQ0q087342; Sat, 11 Mar 2023 16:43:26 GMT (envelope-from git) Date: Sat, 11 Mar 2023 16:43:26 GMT Message-Id: <202303111643.32BGhQ0q087342@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 3e1155ade1ba - main - dtrace/powerpc: "Fix" stack traces across trap frames 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3e1155ade1baab51458374efd0295bdf6db455fc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=3e1155ade1baab51458374efd0295bdf6db455fc commit 3e1155ade1baab51458374efd0295bdf6db455fc Author: Justin Hibbits AuthorDate: 2023-03-11 16:30:00 +0000 Commit: Justin Hibbits CommitDate: 2023-03-11 16:35:27 +0000 dtrace/powerpc: "Fix" stack traces across trap frames In function boundary tracing the link register is not yet saved to the save stack location, so the save point contains whatever the previous 'lr' save was, or even garbage, at the time the trap is taken. Address this by explicitly loading the link register from the trap frame instead of the stack, and propagate that out. --- sys/cddl/dev/dtrace/powerpc/dtrace_isa.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c b/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c index cce1c907b5d8..2139be1ccec7 100644 --- a/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c +++ b/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c @@ -97,15 +97,18 @@ dtrace_sp_inkernel(uintptr_t sp) } static __inline void -dtrace_next_sp_pc(uintptr_t sp, uintptr_t *nsp, uintptr_t *pc) +dtrace_next_sp_pc(uintptr_t sp, uintptr_t *nsp, uintptr_t *pc, uintptr_t *lr) { vm_offset_t callpc; struct trapframe *frame; + if (lr != 0 && *lr != 0) + callpc = *lr; + else #ifdef __powerpc64__ - callpc = *(vm_offset_t *)(sp + RETURN_OFFSET64); + callpc = *(vm_offset_t *)(sp + RETURN_OFFSET64); #else - callpc = *(vm_offset_t *)(sp + RETURN_OFFSET); + callpc = *(vm_offset_t *)(sp + RETURN_OFFSET); #endif /* @@ -121,6 +124,8 @@ dtrace_next_sp_pc(uintptr_t sp, uintptr_t *nsp, uintptr_t *pc) *nsp = frame->fixreg[1]; if (pc != NULL) *pc = frame->srr0; + if (lr != NULL) + *lr = frame->lr; return; } @@ -128,6 +133,9 @@ dtrace_next_sp_pc(uintptr_t sp, uintptr_t *nsp, uintptr_t *pc) *nsp = *(uintptr_t *)sp; if (pc != NULL) *pc = callpc; + /* lr is only valid for trap frames */ + if (lr != NULL) + *lr = 0; } void @@ -135,7 +143,7 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *intrpc) { int depth = 0; - uintptr_t osp, sp; + uintptr_t osp, sp, lr = 0; vm_offset_t callpc; pc_t caller = (pc_t) solaris_cpu[curcpu].cpu_dtrace_caller; @@ -154,7 +162,8 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, if (!dtrace_sp_inkernel(sp)) break; osp = sp; - dtrace_next_sp_pc(osp, &sp, &callpc); + dtrace_next_sp_pc(osp, &sp, &callpc, &lr); + //printf("sp: %#lx, pc: %#lx, lr: %#lx\n", sp, callpc, lr); if (aframes > 0) { aframes--; @@ -513,7 +522,7 @@ dtrace_getstackdepth(int aframes) depth++; osp = sp; - dtrace_next_sp_pc(sp, &sp, NULL); + dtrace_next_sp_pc(sp, &sp, NULL, NULL); } if (depth < aframes) return (0);