From owner-svn-src-stable-9@FreeBSD.ORG Tue Jul 29 20:34:11 2014 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A05E2D75; Tue, 29 Jul 2014 20:34:11 +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 81219219A; Tue, 29 Jul 2014 20:34:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s6TKYBQu039842; Tue, 29 Jul 2014 20:34:11 GMT (envelope-from markj@svn.freebsd.org) Received: (from markj@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s6TKYBPu039840; Tue, 29 Jul 2014 20:34:11 GMT (envelope-from markj@svn.freebsd.org) Message-Id: <201407292034.s6TKYBPu039840@svn.freebsd.org> From: Mark Johnston Date: Tue, 29 Jul 2014 20:34:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r269254 - in stable/9/sys: amd64/amd64 i386/i386 X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jul 2014 20:34:11 -0000 Author: markj Date: Tue Jul 29 20:34:10 2014 New Revision: 269254 URL: http://svnweb.freebsd.org/changeset/base/269254 Log: MFC r263329: Only invoke fasttrap hooks for traps from user mode, and ensure that they're called with interrupts enabled. Calling fasttrap_pid_probe() with interrupts disabled can lead to deadlock if fasttrap writes to the process' address space. Modified: stable/9/sys/amd64/amd64/trap.c stable/9/sys/i386/i386/trap.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/amd64/amd64/trap.c ============================================================================== --- stable/9/sys/amd64/amd64/trap.c Tue Jul 29 20:33:18 2014 (r269253) +++ stable/9/sys/amd64/amd64/trap.c Tue Jul 29 20:34:10 2014 (r269254) @@ -193,6 +193,9 @@ SYSCTL_INT(_machdep, OID_AUTO, uprintf_s void trap(struct trapframe *frame) { +#ifdef KDTRACE_HOOKS + struct reg regs; +#endif struct thread *td = curthread; struct proc *p = td->td_proc; int i = 0, ucode = 0, code; @@ -244,28 +247,10 @@ trap(struct trapframe *frame) /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. - * - * If the DTrace kernel module has registered a trap handler, - * call it and if it returns non-zero, assume that it has - * handled the trap and modified the trap frame so that this - * function can return normally. */ - if (type == T_DTRACE_RET || type == T_BPTFLT) { - struct reg regs; - - fill_frame_regs(frame, ®s); - if (type == T_BPTFLT && - dtrace_pid_probe_ptr != NULL && - dtrace_pid_probe_ptr(®s) == 0) - goto out; - else if (type == T_DTRACE_RET && - dtrace_return_probe_ptr != NULL && - dtrace_return_probe_ptr(®s) == 0) - goto out; - } if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) goto out; #endif @@ -320,6 +305,14 @@ trap(struct trapframe *frame) case T_BPTFLT: /* bpt instruction fault */ case T_TRCTRAP: /* trace trap */ enable_intr(); +#ifdef KDTRACE_HOOKS + if (type == T_BPTFLT) { + fill_frame_regs(frame, ®s); + if (dtrace_pid_probe_ptr != NULL && + dtrace_pid_probe_ptr(®s) == 0) + goto out; + } +#endif frame->tf_rflags &= ~PSL_T; i = SIGTRAP; ucode = (type == T_TRCTRAP ? TRAP_TRACE : TRAP_BRKPT); @@ -449,6 +442,15 @@ trap(struct trapframe *frame) goto userout; i = SIGFPE; break; +#ifdef KDTRACE_HOOKS + case T_DTRACE_RET: + enable_intr(); + fill_frame_regs(frame, ®s); + if (dtrace_return_probe_ptr != NULL && + dtrace_return_probe_ptr(®s) == 0) + goto out; + break; +#endif } } else { /* kernel trap */ Modified: stable/9/sys/i386/i386/trap.c ============================================================================== --- stable/9/sys/i386/i386/trap.c Tue Jul 29 20:33:18 2014 (r269253) +++ stable/9/sys/i386/i386/trap.c Tue Jul 29 20:34:10 2014 (r269254) @@ -207,6 +207,9 @@ SYSCTL_INT(_machdep, OID_AUTO, uprintf_s void trap(struct trapframe *frame) { +#ifdef KDTRACE_HOOKS + struct reg regs; +#endif struct thread *td = curthread; struct proc *p = td->td_proc; int i = 0, ucode = 0, code; @@ -263,28 +266,10 @@ trap(struct trapframe *frame) /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. - * - * If the DTrace kernel module has registered a trap handler, - * call it and if it returns non-zero, assume that it has - * handled the trap and modified the trap frame so that this - * function can return normally. */ - if (type == T_DTRACE_RET || type == T_BPTFLT) { - struct reg regs; - - fill_frame_regs(frame, ®s); - if (type == T_BPTFLT && - dtrace_pid_probe_ptr != NULL && - dtrace_pid_probe_ptr(®s) == 0) - goto out; - if (type == T_DTRACE_RET && - dtrace_return_probe_ptr != NULL && - dtrace_return_probe_ptr(®s) == 0) - goto out; - } if ((type == T_PROTFLT || type == T_PAGEFLT) && dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) goto out; @@ -357,6 +342,14 @@ trap(struct trapframe *frame) case T_BPTFLT: /* bpt instruction fault */ case T_TRCTRAP: /* trace trap */ enable_intr(); +#ifdef KDTRACE_HOOKS + if (type == T_BPTFLT) { + fill_frame_regs(frame, ®s); + if (dtrace_pid_probe_ptr != NULL && + dtrace_pid_probe_ptr(®s) == 0) + goto out; + } +#endif frame->tf_eflags &= ~PSL_T; i = SIGTRAP; ucode = (type == T_TRCTRAP ? TRAP_TRACE : TRAP_BRKPT); @@ -540,6 +533,15 @@ trap(struct trapframe *frame) #endif i = SIGFPE; break; +#ifdef KDTRACE_HOOKS + case T_DTRACE_RET: + enable_intr(); + fill_frame_regs(frame, ®s); + if (dtrace_return_probe_ptr != NULL && + dtrace_return_probe_ptr(®s) == 0) + goto out; + break; +#endif } } else { /* kernel trap */