From owner-svn-src-all@FreeBSD.ORG Thu Jul 3 06:52:27 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3D1DA3CE; Thu, 3 Jul 2014 06:52:27 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 10A5922C9; Thu, 3 Jul 2014 06:52:27 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s636qQT4073494; Thu, 3 Jul 2014 06:52:26 GMT (envelope-from jhibbits@svn.freebsd.org) Received: (from jhibbits@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s636qQ1I073493; Thu, 3 Jul 2014 06:52:26 GMT (envelope-from jhibbits@svn.freebsd.org) Message-Id: <201407030652.s636qQ1I073493@svn.freebsd.org> From: Justin Hibbits Date: Thu, 3 Jul 2014 06:52:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268207 - head/sys/dev/hwpmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 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: Thu, 03 Jul 2014 06:52:27 -0000 Author: jhibbits Date: Thu Jul 3 06:52:26 2014 New Revision: 268207 URL: http://svnweb.freebsd.org/changeset/base/268207 Log: Fix a bug in hwpmc(4) callchain retrieval, for both user and kernel. The array index for the callchain is getting double-incremented -- both in the loop and the storing. It should only be incremented in one location. Also, constrain the stack pointer range check. MFC after: 2 weeks Modified: head/sys/dev/hwpmc/hwpmc_powerpc.c Modified: head/sys/dev/hwpmc/hwpmc_powerpc.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_powerpc.c Thu Jul 3 06:44:55 2014 (r268206) +++ head/sys/dev/hwpmc/hwpmc_powerpc.c Thu Jul 3 06:52:26 2014 (r268207) @@ -55,20 +55,22 @@ int pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, struct trapframe *tf) { + uintptr_t *osp, *sp; int frames = 0; - uintptr_t *sp; cc[frames++] = PMC_TRAPFRAME_TO_PC(tf); sp = (uintptr_t *)PMC_TRAPFRAME_TO_FP(tf); + osp = NULL; for (; frames < maxsamples; frames++) { - if (!INKERNEL(sp)) + if (!INKERNEL(sp) || sp <= osp) break; #ifdef __powerpc64__ - cc[frames++] = sp[2]; + cc[frames] = sp[2]; #else - cc[frames++] = sp[1]; + cc[frames] = sp[1]; #endif + osp = sp; sp = (uintptr_t *)*sp; } return (frames); @@ -184,26 +186,28 @@ int pmc_save_user_callchain(uintptr_t *cc, int maxsamples, struct trapframe *tf) { - uintptr_t *sp; + uintptr_t *osp, *sp; int frames = 0; cc[frames++] = PMC_TRAPFRAME_TO_PC(tf); sp = (uintptr_t *)PMC_TRAPFRAME_TO_FP(tf); + osp = NULL; for (; frames < maxsamples; frames++) { - if (!INUSER(sp)) + if (!INUSER(sp) || sp <= osp) break; + osp = sp; #ifdef __powerpc64__ /* Check if 32-bit mode. */ if (!(tf->srr1 & PSL_SF)) { - cc[frames++] = fuword32((uint32_t *)sp + 1); + cc[frames] = fuword32((uint32_t *)sp + 1); sp = (uintptr_t *)(uintptr_t)fuword32(sp); } else { - cc[frames++] = fuword(sp + 2); + cc[frames] = fuword(sp + 2); sp = (uintptr_t *)fuword(sp); } #else - cc[frames++] = fuword32((uint32_t *)sp + 1); + cc[frames] = fuword32((uint32_t *)sp + 1); sp = (uintptr_t *)fuword32(sp); #endif }