Source-Changes-HG archive

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

[src/trunk]: src/sys/kern When doing an unlock/relock dance to avoid lock inv...



details:   https://anonhg.NetBSD.org/src/rev/8cfba36639ea
branches:  trunk
changeset: 342797:8cfba36639ea
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sat Jan 09 07:52:38 2016 +0000

description:
When doing an unlock/relock dance to avoid lock inversion, it's important
to relock the lock you unlocked. Otherwise the lock you unlocked won't
walk the walk, not by a long chalk, and you'll end up getting mocked.

>From Mateusz Guzik of FreeBSD via freenode.

XXX: pullup-6 and -7

diffstat:

 sys/kern/kern_fork.c   |  5 +++--
 sys/kern/sys_process.c |  5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diffs (52 lines):

diff -r 1c305726fb7b -r 8cfba36639ea sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c      Sat Jan 09 07:27:31 2016 +0000
+++ b/sys/kern/kern_fork.c      Sat Jan 09 07:52:38 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_fork.c,v 1.194 2015/10/02 16:54:15 christos Exp $ */
+/*     $NetBSD: kern_fork.c,v 1.195 2016/01/09 07:52:38 dholland Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.194 2015/10/02 16:54:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.195 2016/01/09 07:52:38 dholland Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -486,6 +486,7 @@
                                if (!mutex_tryenter(parent1->p_lock)) {
                                        mutex_exit(p2->p_lock);
                                        mutex_enter(parent1->p_lock);
+                                       mutex_enter(p2->p_lock);
                                }
                        } else if (parent1->p_lock > p2->p_lock) {
                                mutex_enter(parent1->p_lock);
diff -r 1c305726fb7b -r 8cfba36639ea sys/kern/sys_process.c
--- a/sys/kern/sys_process.c    Sat Jan 09 07:27:31 2016 +0000
+++ b/sys/kern/sys_process.c    Sat Jan 09 07:52:38 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_process.c,v 1.166 2015/07/02 03:47:54 christos Exp $       */
+/*     $NetBSD: sys_process.c,v 1.167 2016/01/09 07:52:38 dholland Exp $       */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.166 2015/07/02 03:47:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.167 2016/01/09 07:52:38 dholland Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_ktrace.h"
@@ -782,6 +782,7 @@
                                if (!mutex_tryenter(parent->p_lock)) {
                                        mutex_exit(t->p_lock);
                                        mutex_enter(parent->p_lock);
+                                       mutex_enter(t->p_lock);
                                }
                        } else if (parent->p_lock > t->p_lock) {
                                mutex_enter(parent->p_lock);



Home | Main Index | Thread Index | Old Index