Source-Changes-HG archive

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

[src/trunk]: src/sys/kern IPL_VM is the highest interrupt priority where alld...



details:   https://anonhg.NetBSD.org/src/rev/78a444ea9f1c
branches:  trunk
changeset: 754457:78a444ea9f1c
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Fri Apr 30 21:17:22 2010 +0000

description:
IPL_VM is the highest interrupt priority where alldevs is read/written,
and acquiring alldevs_mtx already blocks those interrupts, so delete the
splhigh()/splx() in config_alldevs_lock()/_unlock().

Release alldevs_mtx while freeing memory with kmem_free(9); according to
new documentation, kmem_free(9) can sleep! :-) Thanks to rmind@ for the
tip.

Next step: use finer-grained locking, probably by adding a mutex to
    cfdriver_t.

And after that: make sure that all threads of execution are out of the
    device_t and/or softc before releasing their memory.

diffstat:

 sys/kern/subr_autoconf.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (67 lines):

diff -r 7daa6b84c4d1 -r 78a444ea9f1c sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Fri Apr 30 21:17:19 2010 +0000
+++ b/sys/kern/subr_autoconf.c  Fri Apr 30 21:17:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.205 2010/04/19 11:20:56 jruoho Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.206 2010/04/30 21:17:22 dyoung Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.205 2010/04/19 11:20:56 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.206 2010/04/30 21:17:22 dyoung Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1118,7 +1118,9 @@
                 * not hold alldevs_mtx, try again.
                 */
                if (cd->cd_devs != osp) {
+                       mutex_exit(&alldevs_mtx);
                        kmem_free(nsp, sizeof(device_t[new]));
+                       mutex_enter(&alldevs_mtx);
                        continue;
                }
 
@@ -1128,8 +1130,11 @@
 
                cd->cd_ndevs = new;
                cd->cd_devs = nsp;
-               if (old != 0)
+               if (old != 0) {
+                       mutex_exit(&alldevs_mtx);
                        kmem_free(osp, sizeof(device_t[old]));
+                       mutex_enter(&alldevs_mtx);
+               }
        }
        alldevs_nwrite--;
 }
@@ -2005,11 +2010,8 @@
 static int
 config_alldevs_lock(void)
 {
-       int s;
-
-       s = splhigh();
        mutex_enter(&alldevs_mtx);
-       return s;
+       return 0;
 }
 
 static void
@@ -2027,11 +2029,11 @@
        config_dump_garbage(&af->af_garbage);
 }
 
+/*ARGSUSED*/
 static void
 config_alldevs_unlock(int s)
 {
        mutex_exit(&alldevs_mtx);
-       splx(s);
 }
 
 /*



Home | Main Index | Thread Index | Old Index