Source-Changes-HG archive

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

[src/trunk]: src/sys/kern autoconf(9): Take kernel lock in config_detach.



details:   https://anonhg.NetBSD.org/src/rev/0ac032ab6c9f
branches:  trunk
changeset: 983891:0ac032ab6c9f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Jun 13 09:30:48 2021 +0000

description:
autoconf(9): Take kernel lock in config_detach.

config_detach is used in too many places to audit for now -- so
although I'm quite sure it is racy (e.g., with cloning devices and
drvctl: drvctl -d a newly opened fss0 before sc_state has
transitioned from FSS_IDLE), this will mitigate the immediate fallout
until we can properly fix autoconf's notions of device pointers.

diffstat:

 sys/kern/subr_autoconf.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (56 lines):

diff -r b921e92b1da2 -r 0ac032ab6c9f sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Sun Jun 13 09:29:38 2021 +0000
+++ b/sys/kern/subr_autoconf.c  Sun Jun 13 09:30:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.286 2021/06/13 00:11:46 riastradh Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.287 2021/06/13 09:30:48 riastradh Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -79,7 +79,7 @@
 #define        __SUBR_AUTOCONF_PRIVATE /* see <sys/device.h> */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.286 2021/06/13 00:11:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.287 2021/06/13 09:30:48 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1969,7 +1969,7 @@
        device_t d __diagused;
        int rv = 0;
 
-       KASSERT(KERNEL_LOCKED_P());
+       KERNEL_LOCK(1, NULL);
 
        cf = dev->dv_cfdata;
        KASSERTMSG((cf == NULL || cf->cf_fstate == FSTATE_FOUND ||
@@ -1988,8 +1988,10 @@
         * attached.
         */
        rv = config_detach_enter(dev);
-       if (rv)
+       if (rv) {
+               KERNEL_UNLOCK_ONE(NULL);
                return rv;
+       }
 
        mutex_enter(&alldevs_lock);
        if (dev->dv_del_gen != 0) {
@@ -1999,6 +2001,7 @@
                    device_xname(dev));
 #endif /* DIAGNOSTIC */
                config_detach_exit(dev);
+               KERNEL_UNLOCK_ONE(NULL);
                return ENOENT;
        }
        alldevs_nwrite++;
@@ -2095,6 +2098,8 @@
        }
        config_alldevs_exit(&af);
 
+       KERNEL_UNLOCK_ONE(NULL);
+
        return rv;
 }
 



Home | Main Index | Thread Index | Old Index