From 16598eeedf115523000b9a9b458333e59ef6538d Mon Sep 17 00:00:00 2001 From: ad Date: Mon, 8 Oct 2007 18:09:37 +0000 Subject: [PATCH] Merge from vmlocking: don't hold scheduler locks across copyout(). --- sys/kern/init_sysctl.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/sys/kern/init_sysctl.c b/sys/kern/init_sysctl.c index c7410323bd77..6993619a8bd7 100644 --- a/sys/kern/init_sysctl.c +++ b/sys/kern/init_sysctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.106 2007/09/28 21:25:21 joerg Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.107 2007/10/08 18:09:37 ad Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.106 2007/09/28 21:25:21 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.107 2007/10/08 18:09:37 ad Exp $"); #include "opt_sysv.h" #include "opt_multiprocessor.h" @@ -1659,9 +1659,6 @@ sysctl_kern_lwp(SYSCTLFN_ARGS) /* * Copy out elem_size, but not larger than * the size of a struct kinfo_proc2. - * - * XXX We should not be holding p_smutex, but - * for now, the buffer is wired. Fix later. */ error = dcopyout(l, &klwp, dp, min(sizeof(klwp), elem_size)); @@ -1682,21 +1679,31 @@ sysctl_kern_lwp(SYSCTLFN_ARGS) mutex_enter(&p->p_smutex); LIST_FOREACH(l2, &p->p_lwps, l_sibling) { if (buflen >= elem_size && elem_count > 0) { + struct lwp *l3; + lwp_lock(l2); fill_lwp(l2, &klwp); lwp_unlock(l2); - + mutex_exit(&p->p_smutex); /* * Copy out elem_size, but not larger than * the size of a struct kinfo_proc2. - * - * XXX We should not be holding p_smutex, but - * for now, the buffer is wired. Fix later. */ error = dcopyout(l, &klwp, dp, min(sizeof(klwp), elem_size)); - if (error) + if (error) { goto cleanup; + } + mutex_enter(&p->p_smutex); + LIST_FOREACH(l3, &p->p_lwps, l_sibling) { + if (l2 == l3) + break; + } + if (l2 == NULL) { + mutex_exit(&p->p_smutex); + error = EAGAIN; + goto cleanup; + } dp += elem_size; buflen -= elem_size; elem_count--; @@ -1717,6 +1724,7 @@ sysctl_kern_lwp(SYSCTLFN_ARGS) } return (0); cleanup: + mutex_exit(&proclist_lock); return (error); }