From owner-svn-src-all@FreeBSD.ORG Tue Mar 18 00:29:34 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 1BC68F15; Tue, 18 Mar 2014 00:29:34 +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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 06F35E48; Tue, 18 Mar 2014 00:29:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2I0TXl4037281; Tue, 18 Mar 2014 00:29:33 GMT (envelope-from markj@svn.freebsd.org) Received: (from markj@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2I0TXJc037279; Tue, 18 Mar 2014 00:29:33 GMT (envelope-from markj@svn.freebsd.org) Message-Id: <201403180029.s2I0TXJc037279@svn.freebsd.org> From: Mark Johnston Date: Tue, 18 Mar 2014 00:29:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r263281 - in stable/10/sys: cddl/contrib/opensolaris/uts/intel/dtrace kern X-SVN-Group: stable-10 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.17 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: Tue, 18 Mar 2014 00:29:34 -0000 Author: markj Date: Tue Mar 18 00:29:33 2014 New Revision: 263281 URL: http://svnweb.freebsd.org/changeset/base/263281 Log: MFC r259535: The fasttrap fork handler is responsible for removing tracepoints in the child process that were inherited from its parent. However, this should not be done in the case of a vfork, since the fork handler ends up removing the tracepoints from the shared vm space, and userland DTrace probes in the parent will no longer fire as a result. Now the child of a vfork may trigger userland DTrace probes enabled in its parent, so modify the fasttrap probe handler to handle this case and handle the child process in the same way that it would handle the traced process. In particular, if once traces function foo() in a process that vforks, and the child calls foo(), fasttrap will treat this call as having come from the parent. This is the behaviour of the upstream code. While here, add #ifdef guards to some code that isn't present upstream. Modified: stable/10/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c stable/10/sys/kern/kern_fork.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c ============================================================================== --- stable/10/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c Mon Mar 17 23:30:38 2014 (r263280) +++ stable/10/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c Tue Mar 18 00:29:33 2014 (r263281) @@ -988,6 +988,9 @@ int fasttrap_pid_probe(struct reg *rp) { proc_t *p = curproc; +#if !defined(sun) + proc_t *pp; +#endif uintptr_t pc = rp->r_rip - 1; uintptr_t new_pc = 0; fasttrap_bucket_t *bucket; @@ -1023,24 +1026,32 @@ fasttrap_pid_probe(struct reg *rp) curthread->t_dtrace_regv = 0; #endif -#if defined(sun) /* * Treat a child created by a call to vfork(2) as if it were its * parent. We know that there's only one thread of control in such a * process: this one. */ +#if defined(sun) while (p->p_flag & SVFORK) { p = p->p_parent; } -#endif - PROC_LOCK(p); - _PHOLD(p); pid = p->p_pid; -#if defined(sun) pid_mtx = &cpu_core[CPU->cpu_id].cpuc_pid_lock; mutex_enter(pid_mtx); +#else + pp = p; + sx_slock(&proctree_lock); + while (pp->p_vmspace == pp->p_pptr->p_vmspace) + pp = pp->p_pptr; + pid = pp->p_pid; + sx_sunlock(&proctree_lock); + pp = NULL; + + PROC_LOCK(p); + _PHOLD(p); #endif + bucket = &fasttrap_tpoints.fth_table[FASTTRAP_TPOINTS_INDEX(pid, pc)]; /* @@ -1060,9 +1071,10 @@ fasttrap_pid_probe(struct reg *rp) if (tp == NULL) { #if defined(sun) mutex_exit(pid_mtx); -#endif +#else _PRELE(p); PROC_UNLOCK(p); +#endif return (-1); } @@ -1184,9 +1196,10 @@ fasttrap_pid_probe(struct reg *rp) * tracepoint again later if we need to light up any return probes. */ tp_local = *tp; - PROC_UNLOCK(p); #if defined(sun) mutex_exit(pid_mtx); +#else + PROC_UNLOCK(p); #endif tp = &tp_local; @@ -1736,7 +1749,7 @@ fasttrap_pid_probe(struct reg *rp) #if defined(sun) if (fasttrap_copyout(scratch, (char *)addr, i)) { #else - if (uwrite(curproc, scratch, i, addr)) { + if (uwrite(p, scratch, i, addr)) { #endif fasttrap_sigtrap(p, curthread, pc); new_pc = pc; @@ -1795,10 +1808,12 @@ done: rp->r_rip = new_pc; +#if !defined(sun) PROC_LOCK(p); proc_write_regs(curthread, rp); _PRELE(p); PROC_UNLOCK(p); +#endif return (0); } Modified: stable/10/sys/kern/kern_fork.c ============================================================================== --- stable/10/sys/kern/kern_fork.c Mon Mar 17 23:30:38 2014 (r263280) +++ stable/10/sys/kern/kern_fork.c Tue Mar 18 00:29:33 2014 (r263281) @@ -684,12 +684,12 @@ do_fork(struct thread *td, int flags, st #ifdef KDTRACE_HOOKS /* - * Tell the DTrace fasttrap provider about the new process - * if it has registered an interest. We have to do this only after - * p_state is PRS_NORMAL since the fasttrap module will use pfind() - * later on. + * Tell the DTrace fasttrap provider about the new process so that any + * tracepoints inherited from the parent can be removed. We have to do + * this only after p_state is PRS_NORMAL since the fasttrap module will + * use pfind() later on. */ - if (dtrace_fasttrap_fork) + if ((flags & RFMEM) == 0 && dtrace_fasttrap_fork) dtrace_fasttrap_fork(p1, p2); #endif if ((p1->p_flag & (P_TRACED | P_FOLLOWFORK)) == (P_TRACED |