From owner-svn-src-stable-8@FreeBSD.ORG Tue Dec 1 23:06:18 2009 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DFEAA106566C; Tue, 1 Dec 2009 23:06:17 +0000 (UTC) (envelope-from fabient@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CE5CB8FC18; Tue, 1 Dec 2009 23:06:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nB1N6HJv079472; Tue, 1 Dec 2009 23:06:17 GMT (envelope-from fabient@svn.freebsd.org) Received: (from fabient@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB1N6HEh079470; Tue, 1 Dec 2009 23:06:17 GMT (envelope-from fabient@svn.freebsd.org) Message-Id: <200912012306.nB1N6HEh079470@svn.freebsd.org> From: Fabien Thomas Date: Tue, 1 Dec 2009 23:06:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200010 - stable/8/sys/dev/hwpmc X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Dec 2009 23:06:18 -0000 Author: fabient Date: Tue Dec 1 23:06:17 2009 New Revision: 200010 URL: http://svn.freebsd.org/changeset/base/200010 Log: MFC 199763: - fix a LOR between process lock and pmc thread mutex - fix a system deadlock on process exit when the sample buffer is full (pmclog_loop blocked in fo_write) and pmcstat exit. Modified: stable/8/sys/dev/hwpmc/hwpmc_logging.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/dev/hwpmc/hwpmc_logging.c ============================================================================== --- stable/8/sys/dev/hwpmc/hwpmc_logging.c Tue Dec 1 23:01:59 2009 (r200009) +++ stable/8/sys/dev/hwpmc/hwpmc_logging.c Tue Dec 1 23:06:17 2009 (r200010) @@ -240,6 +240,7 @@ pmclog_loop(void *arg) int error; struct pmc_owner *po; struct pmclog_buffer *lb; + struct proc *p; struct ucred *ownercred; struct ucred *mycred; struct thread *td; @@ -248,12 +249,13 @@ pmclog_loop(void *arg) size_t nbytes; po = (struct pmc_owner *) arg; + p = po->po_owner; td = curthread; mycred = td->td_ucred; - PROC_LOCK(po->po_owner); - ownercred = crhold(po->po_owner->p_ucred); - PROC_UNLOCK(po->po_owner); + PROC_LOCK(p); + ownercred = crhold(p->p_ucred); + PROC_UNLOCK(p); PMCDBG(LOG,INI,1, "po=%p kt=%p", po, po->po_kthread); KASSERT(po->po_kthread == curthread->td_proc, @@ -324,16 +326,16 @@ pmclog_loop(void *arg) error = fo_write(po->po_file, &auio, ownercred, 0, td); td->td_ucred = mycred; - mtx_lock(&pmc_kthread_mtx); - if (error) { /* XXX some errors are recoverable */ /* XXX also check for SIGPIPE if a socket */ /* send a SIGIO to the owner and exit */ - PROC_LOCK(po->po_owner); - psignal(po->po_owner, SIGIO); - PROC_UNLOCK(po->po_owner); + PROC_LOCK(p); + psignal(p, SIGIO); + PROC_UNLOCK(p); + + mtx_lock(&pmc_kthread_mtx); po->po_error = error; /* save for flush log */ @@ -342,6 +344,8 @@ pmclog_loop(void *arg) break; } + mtx_lock(&pmc_kthread_mtx); + /* put the used buffer back into the global pool */ PMCLOG_INIT_BUFFER_DESCRIPTOR(lb); @@ -525,15 +529,20 @@ static void pmclog_stop_kthread(struct pmc_owner *po) { /* - * Unset flag, wakeup the helper thread, + * Close the file to force the thread out of fo_write, + * unset flag, wakeup the helper thread, * wait for it to exit */ - mtx_assert(&pmc_kthread_mtx, MA_OWNED); + if (po->po_file != NULL) + fo_close(po->po_file, curthread); + + mtx_lock(&pmc_kthread_mtx); po->po_flags &= ~PMC_PO_OWNS_LOGFILE; wakeup_one(po); if (po->po_kthread) msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmckstp", 0); + mtx_unlock(&pmc_kthread_mtx); } /* @@ -602,10 +611,8 @@ pmclog_configure_log(struct pmc_mdep *md error: /* shutdown the thread */ - mtx_lock(&pmc_kthread_mtx); if (po->po_kthread) pmclog_stop_kthread(po); - mtx_unlock(&pmc_kthread_mtx); KASSERT(po->po_kthread == NULL, ("[pmclog,%d] po=%p kthread not " "stopped", __LINE__, po)); @@ -641,10 +648,8 @@ pmclog_deconfigure_log(struct pmc_owner ("[pmclog,%d] po=%p no log file", __LINE__, po)); /* stop the kthread, this will reset the 'OWNS_LOGFILE' flag */ - mtx_lock(&pmc_kthread_mtx); if (po->po_kthread) pmclog_stop_kthread(po); - mtx_unlock(&pmc_kthread_mtx); KASSERT(po->po_kthread == NULL, ("[pmclog,%d] po=%p kthread not stopped", __LINE__, po));