From owner-svn-src-all@freebsd.org Wed Jul 3 19:21:04 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6F65315DE03F; Wed, 3 Jul 2019 19:21:04 +0000 (UTC) (envelope-from jhibbits@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 117FE8B9DC; Wed, 3 Jul 2019 19:21:04 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E1C5618228; Wed, 3 Jul 2019 19:21:03 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x63JL3qd059748; Wed, 3 Jul 2019 19:21:03 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x63JL3YB059747; Wed, 3 Jul 2019 19:21:03 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201907031921.x63JL3YB059747@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Wed, 3 Jul 2019 19:21:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r349675 - stable/12/sys/cddl/dev/dtrace/powerpc X-SVN-Group: stable-12 X-SVN-Commit-Author: jhibbits X-SVN-Commit-Paths: stable/12/sys/cddl/dev/dtrace/powerpc X-SVN-Commit-Revision: 349675 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 117FE8B9DC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jul 2019 19:21:04 -0000 Author: jhibbits Date: Wed Jul 3 19:21:03 2019 New Revision: 349675 URL: https://svnweb.freebsd.org/changeset/base/349675 Log: MFC r346173,r347943 r346173: powerpc/dtrace: Fix dtrace powerpc asm, and simplify stack walking r347943: powerpc/dtrace: Actually fix stack traces Modified: stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S ============================================================================== --- stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S Wed Jul 3 19:07:42 2019 (r349674) +++ stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S Wed Jul 3 19:21:03 2019 (r349675) @@ -148,14 +148,19 @@ dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_ volatile uint16_t *flags) */ ASENTRY_NOPROF(dtrace_copystr) - addme %r7,%r3 - addme %r8,%r4 + subi %r7,%r3,1 + subi %r8,%r4,1 1: lbzu %r3,1(%r7) stbu %r3,1(%r8) - addme %r5,%r5 + subi %r5,%r5,1 +#ifdef __powerpc64__ + cmpldi %r5,0 +#else + cmplwi %r5,0 +#endif beq 2f - or %r3,%r3,%r3 + cmplwi %r3,0 beq 2f andi. %r0,%r5,0x0fff beq 2f @@ -174,3 +179,13 @@ ASENTRY_NOPROF(dtrace_caller) li %r3, -1 blr END(dtrace_caller) + +/* +greg_t +dtrace_getfp(void) +*/ +ASENTRY_NOPROF(dtrace_getfp) + mr %r3,%r31 + blr +END(dtrace_getfp) + Modified: stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c ============================================================================== --- stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c Wed Jul 3 19:07:42 2019 (r349674) +++ stable/12/sys/cddl/dev/dtrace/powerpc/dtrace_isa.c Wed Jul 3 19:21:03 2019 (r349675) @@ -61,8 +61,10 @@ #define FRAME_OFFSET 8 #endif -#define INKERNEL(x) ((x) <= VM_MAX_KERNEL_ADDRESS && \ - (x) >= VM_MIN_KERNEL_ADDRESS) +#define INKERNEL(x) (((x) <= VM_MAX_KERNEL_ADDRESS && \ + (x) >= VM_MIN_KERNEL_ADDRESS) || \ + (PMAP_HAS_DMAP && (x) >= DMAP_BASE_ADDRESS && \ + (x) <= DMAP_MAX_ADDRESS)) static __inline int dtrace_sp_inkernel(uintptr_t sp) @@ -70,6 +72,9 @@ dtrace_sp_inkernel(uintptr_t sp) struct trapframe *frame; vm_offset_t callpc; + /* Not within the kernel, or not aligned. */ + if (!INKERNEL(sp) || (sp & 0xf) != 0) + return (0); #ifdef __powerpc64__ callpc = *(vm_offset_t *)(sp + RETURN_OFFSET64); #else @@ -84,8 +89,6 @@ dtrace_sp_inkernel(uintptr_t sp) */ if (callpc + OFFSET == (vm_offset_t) &trapexit || callpc + OFFSET == (vm_offset_t) &asttrapexit) { - if (sp == 0) - return (0); frame = (struct trapframe *)(sp + FRAME_OFFSET); return ((frame->srr1 & PSL_PR) == 0); @@ -94,11 +97,10 @@ dtrace_sp_inkernel(uintptr_t sp) return (1); } -static __inline uintptr_t -dtrace_next_sp(uintptr_t sp) +static __inline void +dtrace_next_sp_pc(uintptr_t sp, uintptr_t *nsp, uintptr_t *pc) { vm_offset_t callpc; - uintptr_t *r1; struct trapframe *frame; #ifdef __powerpc64__ @@ -115,47 +117,20 @@ dtrace_next_sp(uintptr_t sp) callpc + OFFSET == (vm_offset_t) &asttrapexit)) { /* Access the trap frame */ frame = (struct trapframe *)(sp + FRAME_OFFSET); - r1 = (uintptr_t *)frame->fixreg[1]; - if (r1 == NULL) - return (0); - return (*r1); - } - return (*(uintptr_t*)sp); -} - -static __inline uintptr_t -dtrace_get_pc(uintptr_t sp) -{ - struct trapframe *frame; - vm_offset_t callpc; - -#ifdef __powerpc64__ - callpc = *(vm_offset_t *)(sp + RETURN_OFFSET64); -#else - callpc = *(vm_offset_t *)(sp + RETURN_OFFSET); -#endif - - /* - * trapexit() and asttrapexit() are sentinels - * for kernel stack tracing. - */ - if ((callpc + OFFSET == (vm_offset_t) &trapexit || - callpc + OFFSET == (vm_offset_t) &asttrapexit)) { - /* Access the trap frame */ - frame = (struct trapframe *)(sp + FRAME_OFFSET); - return (frame->srr0); + if (nsp != NULL) + *nsp = frame->fixreg[1]; + if (pc != NULL) + *pc = frame->srr0; + return; } - return (callpc); + if (nsp != NULL) + *nsp = *(uintptr_t *)sp; + if (pc != NULL) + *pc = callpc; } -greg_t -dtrace_getfp(void) -{ - return (greg_t)__builtin_frame_address(0); -} - void dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes, uint32_t *intrpc) @@ -171,7 +146,7 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, in aframes++; - sp = dtrace_getfp(); + sp = (uintptr_t)__builtin_frame_address(0); while (depth < pcstack_limit) { if (sp <= osp) @@ -179,7 +154,8 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, in if (!dtrace_sp_inkernel(sp)) break; - callpc = dtrace_get_pc(sp); + osp = sp; + dtrace_next_sp_pc(osp, &sp, &callpc); if (aframes > 0) { aframes--; @@ -190,9 +166,6 @@ dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, in else { pcstack[depth++] = callpc; } - - osp = sp; - sp = dtrace_next_sp(sp); } for (; depth < pcstack_limit; depth++) { @@ -443,7 +416,7 @@ uint64_t dtrace_getarg(int arg, int aframes) { uintptr_t val; - uintptr_t *fp = (uintptr_t *)dtrace_getfp(); + uintptr_t *fp = (uintptr_t *)__builtin_frame_address(0); uintptr_t *stack; int i; @@ -457,8 +430,8 @@ dtrace_getarg(int arg, int aframes) fp = (uintptr_t *)*fp; /* - * On ppc32 AIM, and booke, trapexit() is the immediately following - * label. On ppc64 AIM trapexit() follows a nop. + * On ppc32 trapexit() is the immediately following label. On + * ppc64 AIM trapexit() follows a nop. */ #ifdef __powerpc64__ if ((long)(fp[2]) + 4 == (long)trapexit) { @@ -531,9 +504,7 @@ dtrace_getstackdepth(int aframes) vm_offset_t callpc; osp = PAGE_SIZE; - aframes++; - sp = dtrace_getfp(); - depth++; + sp = (uintptr_t)__builtin_frame_address(0); for(;;) { if (sp <= osp) break; @@ -541,17 +512,14 @@ dtrace_getstackdepth(int aframes) if (!dtrace_sp_inkernel(sp)) break; - if (aframes == 0) - depth++; - else - aframes--; + depth++; osp = sp; - sp = dtrace_next_sp(sp); + dtrace_next_sp_pc(sp, &sp, NULL); } if (depth < aframes) return (0); - return (depth); + return (depth - aframes); } ulong_t