From b3080da236407f37102bde7b1e2cd292b78aa8ab Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 13 Sep 2013 06:39:10 +0000 Subject: Reduce the scope of the proctree_lock. If several processes cause continuous calls to the uprintf(9), the proctree_lock could be shared-locked for indefinite amount of time, starving exclusive requests. Since proctree_lock is needed for fork() and exit(), this effectively stops the machine. While there, do the similar reduction for tprintf(9). Reported and tested by: pho Reviewed by: ed Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (glebius) --- sys/kern/subr_prf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 042afa3..93d8ed3 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -151,26 +151,25 @@ uprintf(const char *fmt, ...) PROC_LOCK(p); if ((p->p_flag & P_CONTROLT) == 0) { PROC_UNLOCK(p); - retval = 0; - goto out; + sx_sunlock(&proctree_lock); + return (0); } SESS_LOCK(p->p_session); pca.tty = p->p_session->s_ttyp; SESS_UNLOCK(p->p_session); PROC_UNLOCK(p); if (pca.tty == NULL) { - retval = 0; - goto out; + sx_sunlock(&proctree_lock); + return (0); } pca.flags = TOTTY; pca.p_bufr = NULL; va_start(ap, fmt); tty_lock(pca.tty); + sx_sunlock(&proctree_lock); retval = kvprintf(fmt, putchar, &pca, 10, ap); tty_unlock(pca.tty); va_end(ap); -out: - sx_sunlock(&proctree_lock); return (retval); } @@ -219,13 +218,13 @@ vtprintf(struct proc *p, int pri, const char *fmt, va_list ap) pca.p_bufr = NULL; if (pca.tty != NULL) tty_lock(pca.tty); + sx_sunlock(&proctree_lock); kvprintf(fmt, putchar, &pca, 10, ap); if (pca.tty != NULL) tty_unlock(pca.tty); if (sess != NULL) sess_release(sess); msgbuftrigger = 1; - sx_sunlock(&proctree_lock); } /* -- cgit v1.1