Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/librump/rumpkern Fix a lock order reversal that cau...



details:   https://anonhg.NetBSD.org/src/rev/f6649d3beec8
branches:  trunk
changeset: 933778:f6649d3beec8
user:      ad <ad%NetBSD.org@localhost>
date:      Sat May 30 19:16:53 2020 +0000

description:
Fix a lock order reversal that caused hangs.

diffstat:

 sys/rump/librump/rumpkern/lwproc.c |  38 +++++++++++++++++---------------------
 1 files changed, 17 insertions(+), 21 deletions(-)

diffs (107 lines):

diff -r db436ea72b40 -r f6649d3beec8 sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c        Sat May 30 18:40:28 2020 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c        Sat May 30 19:16:53 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.50 2020/05/23 23:42:44 ad Exp $  */
+/*      $NetBSD: lwproc.c,v 1.51 2020/05/30 19:16:53 ad Exp $  */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #define RUMP__CURLWP_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.50 2020/05/23 23:42:44 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.51 2020/05/30 19:16:53 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -343,12 +343,10 @@
 
 extern kmutex_t unruntime_lock;
 
-/*
- * called with p_lock held, releases lock before return
- */
-static void
-lwproc_makelwp(struct proc *p, struct lwp *l, bool doswitch, bool procmake)
+static struct lwp *
+lwproc_makelwp(struct proc *p, bool doswitch, bool procmake)
 {
+       struct lwp *l = kmem_zalloc(sizeof(*l), KM_SLEEP);
 
        /*
         * Account the new lwp to the owner of the process.
@@ -365,6 +363,9 @@
        l->l_mutex = &unruntime_lock;
 
        proc_alloc_lwpid(p, l);
+
+       mutex_enter(p->p_lock);
+       KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
        LIST_INSERT_HEAD(&p->p_lwps, l, l_sibling);
 
        l->l_fd = p->p_fd;
@@ -392,12 +393,13 @@
        mutex_enter(&proc_lock);
        LIST_INSERT_HEAD(&alllwp, l, l_list);
        mutex_exit(&proc_lock);
+
+       return l;
 }
 
 struct lwp *
 rump__lwproc_alloclwp(struct proc *p)
 {
-       struct lwp *l;
        bool newproc = false;
 
        if (p == NULL) {
@@ -405,13 +407,7 @@
                newproc = true;
        }
 
-       l = kmem_zalloc(sizeof(*l), KM_SLEEP);
-
-       mutex_enter(p->p_lock);
-       KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
-       lwproc_makelwp(p, l, false, newproc);
-
-       return l;
+       return lwproc_makelwp(p, false, newproc);
 }
 
 int
@@ -435,8 +431,12 @@
                kmem_free(l, sizeof(*l));
                return EBUSY;
        }
+       mutex_exit(p->p_lock);
        mutex_exit(&proc_lock);
-       lwproc_makelwp(p, l, true, false);
+
+       /* XXX what holds proc? */
+
+       lwproc_makelwp(p, true, false);
 
        return 0;
 }
@@ -445,17 +445,13 @@
 rump_lwproc_rfork_vmspace(struct vmspace *vm, int flags)
 {
        struct proc *p;
-       struct lwp *l;
 
        if (flags & ~(RUMP_RFFDG|RUMP_RFCFDG) ||
            (~flags & (RUMP_RFFDG|RUMP_RFCFDG)) == 0)
                return EINVAL;
 
        p = lwproc_newproc(curproc, vm, flags);
-       l = kmem_zalloc(sizeof(*l), KM_SLEEP);
-       mutex_enter(p->p_lock);
-       KASSERT((p->p_sflag & PS_RUMP_LWPEXIT) == 0);
-       lwproc_makelwp(p, l, true, true);
+       lwproc_makelwp(p, true, true);
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index