Module Name: src Committed By: msaitoh Date: Thu Dec 28 03:39:48 UTC 2017
Modified Files: src/sys/kern: kern_softint.c subr_pserialize.c subr_psref.c Log Message: Prevent panic or hangup in softint_disestablish(), pserialize_perform() or psref_target_destroy() while mp_online == false. See http://mail-index.netbsd.org/tech-kern/2017/12/25/msg022829.html To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/kern/kern_softint.c cvs rdiff -u -r1.9 -r1.10 src/sys/kern/subr_pserialize.c \ src/sys/kern/subr_psref.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_softint.c diff -u src/sys/kern/kern_softint.c:1.44 src/sys/kern/kern_softint.c:1.45 --- src/sys/kern/kern_softint.c:1.44 Wed Nov 22 02:20:21 2017 +++ src/sys/kern/kern_softint.c Thu Dec 28 03:39:48 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_softint.c,v 1.44 2017/11/22 02:20:21 msaitoh Exp $ */ +/* $NetBSD: kern_softint.c,v 1.45 2017/12/28 03:39:48 msaitoh Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -170,13 +170,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.44 2017/11/22 02:20:21 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.45 2017/12/28 03:39:48 msaitoh Exp $"); #include <sys/param.h> #include <sys/proc.h> #include <sys/intr.h> #include <sys/ipi.h> #include <sys/mutex.h> +#include <sys/kernel.h> #include <sys/kthread.h> #include <sys/evcnt.h> #include <sys/cpu.h> @@ -430,8 +431,10 @@ softint_disestablish(void *arg) * it again. So, we are only looking for handler records with * SOFTINT_ACTIVE already set. */ - where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL); - xc_wait(where); + if (__predict_true(mp_online)) { + where = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL); + xc_wait(where); + } for (;;) { /* Collect flag values from each CPU. */ Index: src/sys/kern/subr_pserialize.c diff -u src/sys/kern/subr_pserialize.c:1.9 src/sys/kern/subr_pserialize.c:1.10 --- src/sys/kern/subr_pserialize.c:1.9 Tue Nov 21 08:49:14 2017 +++ src/sys/kern/subr_pserialize.c Thu Dec 28 03:39:48 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_pserialize.c,v 1.9 2017/11/21 08:49:14 ozaki-r Exp $ */ +/* $NetBSD: subr_pserialize.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $ */ /*- * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.9 2017/11/21 08:49:14 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $"); #include <sys/param.h> @@ -157,6 +157,11 @@ pserialize_perform(pserialize_t psz) KASSERT(psz->psz_owner == NULL); KASSERT(ncpu > 0); + if (__predict_false(mp_online == false)) { + psz_ev_excl.ev_count++; + return; + } + /* * Set up the object and put it onto the queue. The lock * activity here provides the necessary memory barrier to Index: src/sys/kern/subr_psref.c diff -u src/sys/kern/subr_psref.c:1.9 src/sys/kern/subr_psref.c:1.10 --- src/sys/kern/subr_psref.c:1.9 Thu Dec 14 05:45:55 2017 +++ src/sys/kern/subr_psref.c Thu Dec 28 03:39:48 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_psref.c,v 1.9 2017/12/14 05:45:55 ozaki-r Exp $ */ +/* $NetBSD: subr_psref.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.9 2017/12/14 05:45:55 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.10 2017/12/28 03:39:48 msaitoh Exp $"); #include <sys/types.h> #include <sys/condvar.h> @@ -429,8 +429,14 @@ psreffed_p(struct psref_target *target, .ret = false, }; - /* Ask all CPUs to say whether they hold a psref to the target. */ - xc_wait(xc_broadcast(0, &psreffed_p_xc, &P, NULL)); + if (__predict_true(mp_online)) { + /* + * Ask all CPUs to say whether they hold a psref to the + * target. + */ + xc_wait(xc_broadcast(0, &psreffed_p_xc, &P, NULL)); + } else + psreffed_p_xc(&P, NULL); return P.ret; }