Pull up following revision(s) (requested by ozaki-r in ticket #279):

sys/kern/kern_ktrace.c: revision 1.166
	sys/dev/isa/aps.c: revision 1.16
	sys/dev/sysmon/sysmonvar.h: revision 1.45
	sys/dev/ir/irframe_tty.c: revision 1.60
	sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111
	sys/dev/sysmon/sysmon_envsys_events.c: revision 1.112
	sys/dev/pci/pccbb.c: revision 1.207
	sys/dev/wscons/wskbd.c: revision 1.135
	sys/dev/usb/ohci.c: revision 1.254
	sys/net/if_ecosubr.c: revision 1.41
	sys/dev/pcmcia/btbc.c: revision 1.17
	sys/arch/x86/x86/via_padlock.c: revision 1.23
	sys/dev/sdmmc/sdmmc.c: revision 1.23
	sys/dev/bluetooth/btkbd.c: revision 1.17
	sys/dev/bluetooth/bcsp.c: revision 1.25
	sys/arch/x86/pci/fwhrng.c: revision 1.8
	sys/dev/ic/nslm7x.c: revision 1.61
	share/man/man9/callout.9: revision 1.28
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
Discussed with martin@ and riastradh@.
Make it clear that we should use not callout_stop but callout_halt
before callout_destroy
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete.
Reviewed by riastradh@.
Kill sme_callout_mtx and use sme_mtx instead
We can use sme_mtx for the callout as well. Actually we should do so
because sme_events_list and some other data that are touched in the
callout should be protected by sme_mtx, not sme_callout_mtx.
Discussed with riastradh@ in
http://mail-index.netbsd.org/tech-kern/2014/11/11/msg017956.html
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED
is unset before calling callout_halt to prevent the callout from calling
callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61.
Reviewed by riastradh@.
This commit is contained in:
martin 2014-12-01 11:38:42 +00:00
parent f7d1111887
commit 850f05a73b
17 changed files with 66 additions and 59 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: callout.9,v 1.27 2014/07/27 21:35:07 riastradh Exp $
.\" $NetBSD: callout.9,v 1.27.2.1 2014/12/01 11:38:43 martin Exp $
.\"
.\" Copyright (c) 2000, 2003, 2009 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 2, 2013
.Dd November 21, 2014
.Dt CALLOUT 9
.Os
.Sh NAME
@ -116,7 +116,11 @@ should always be called when the callout is no longer required (for instance,
when a device is being detached).
The callout should be stopped before
.Fn callout_destroy
is called.
is called by calling
.Fn callout_halt .
Note that
.Fn callout_stop
shouldn't be used for this purpose.
.Pp
The
.Fn callout_reset

View File

@ -1,4 +1,4 @@
/* $NetBSD: fwhrng.c,v 1.7 2014/08/10 16:44:34 tls Exp $ */
/* $NetBSD: fwhrng.c,v 1.7.2.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 2000 Michael Shalayeff
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fwhrng.c,v 1.7 2014/08/10 16:44:34 tls Exp $");
__KERNEL_RCSID(0, "$NetBSD: fwhrng.c,v 1.7.2.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -211,7 +211,7 @@ fwhrng_detach(device_t self, int flags)
rnd_detach_source(&sc->sc_rnd_source);
callout_stop(&sc->sc_rnd_ch);
callout_halt(&sc->sc_rnd_ch, NULL);
callout_destroy(&sc->sc_rnd_ch);
/* Disable the RNG. */

View File

@ -1,5 +1,5 @@
/* $OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $ */
/* $NetBSD: via_padlock.c,v 1.22 2014/08/10 16:44:34 tls Exp $ */
/* $NetBSD: via_padlock.c,v 1.22.2.1 2014/12/01 11:38:43 martin Exp $ */
/*-
* Copyright (c) 2003 Jason Wright
@ -20,7 +20,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.22 2014/08/10 16:44:34 tls Exp $");
__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.22.2.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -626,7 +626,7 @@ via_padlock_detach(device_t self, int flags)
struct via_padlock_softc *sc = device_private(self);
if (sc->sc_rnd_attached) {
callout_stop(&sc->sc_rnd_co);
callout_halt(&sc->sc_rnd_co, NULL);
callout_destroy(&sc->sc_rnd_co);
rnd_detach_source(&sc->sc_rnd_source);
sc->sc_rnd_attached = false;

View File

@ -1,4 +1,4 @@
/* $NetBSD: bcsp.c,v 1.24 2014/05/20 18:25:54 rmind Exp $ */
/* $NetBSD: bcsp.c,v 1.24.2.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 2007 KIYOHARA Takashi
* All rights reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bcsp.c,v 1.24 2014/05/20 18:25:54 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: bcsp.c,v 1.24.2.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -349,10 +349,10 @@ bcsp_detach(device_t self, int flags __unused)
sc->sc_unit = NULL;
}
callout_stop(&sc->sc_seq_timer);
callout_halt(&sc->sc_seq_timer, NULL);
callout_destroy(&sc->sc_seq_timer);
callout_stop(&sc->sc_le_timer);
callout_halt(&sc->sc_le_timer, NULL);
callout_destroy(&sc->sc_le_timer);
return 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: btkbd.c,v 1.16 2013/09/12 12:20:01 martin Exp $ */
/* $NetBSD: btkbd.c,v 1.16.4.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: btkbd.c,v 1.16 2013/09/12 12:20:01 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: btkbd.c,v 1.16.4.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/callout.h>
@ -251,8 +251,7 @@ btkbd_detach(device_t self, int flags)
#ifdef WSDISPLAY_COMPAT_RAWKBD
#ifdef BTKBD_REPEAT
callout_stop(&sc->sc_repeat);
KASSERT(!callout_invoking(&sc->sc_repeat));
callout_halt(&sc->sc_repeat, NULL);
callout_destroy(&sc->sc_repeat);
#endif
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: nslm7x.c,v 1.60 2013/10/20 21:13:15 christos Exp $ */
/* $NetBSD: nslm7x.c,v 1.60.4.1 2014/12/01 11:38:43 martin Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.60 2013/10/20 21:13:15 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.60.4.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1703,7 +1703,7 @@ lm_attach(struct lm_softc *lmsc)
void
lm_detach(struct lm_softc *lmsc)
{
callout_stop(&lmsc->sc_callout);
callout_halt(&lmsc->sc_callout, NULL);
callout_destroy(&lmsc->sc_callout);
sysmon_envsys_unregister(lmsc->sc_sme);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: irframe_tty.c,v 1.59 2013/12/16 15:49:40 mrg Exp $ */
/* $NetBSD: irframe_tty.c,v 1.59.4.1 2014/12/01 11:38:42 martin Exp $ */
/*
* TODO
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.59 2013/12/16 15:49:40 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: irframe_tty.c,v 1.59.4.1 2014/12/01 11:38:42 martin Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -245,7 +245,7 @@ irframet_detach(device_t dev, int flags)
struct irframet_softc *sc = device_private(dev);
int rc;
callout_stop(&sc->sc_timeout);
callout_halt(&sc->sc_timeout, NULL);
rc = irframe_detach(dev, flags);

View File

@ -1,4 +1,4 @@
/* $NetBSD: aps.c,v 1.15 2012/08/14 14:36:43 jruoho Exp $ */
/* $NetBSD: aps.c,v 1.15.14.1 2014/12/01 11:38:42 martin Exp $ */
/* $OpenBSD: aps.c,v 1.15 2007/05/19 19:14:11 tedu Exp $ */
/* $OpenBSD: aps.c,v 1.17 2008/06/27 06:08:43 canacar Exp $ */
/*
@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: aps.c,v 1.15 2012/08/14 14:36:43 jruoho Exp $");
__KERNEL_RCSID(0, "$NetBSD: aps.c,v 1.15.14.1 2014/12/01 11:38:42 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -429,7 +429,7 @@ aps_detach(device_t self, int flags)
{
struct aps_softc *sc = device_private(self);
callout_stop(&sc->sc_callout);
callout_halt(&sc->sc_callout, NULL);
callout_destroy(&sc->sc_callout);
if (sc->sc_sme)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pccbb.c,v 1.206 2014/03/29 19:28:25 christos Exp $ */
/* $NetBSD: pccbb.c,v 1.206.4.1 2014/12/01 11:38:42 martin Exp $ */
/*
* Copyright (c) 1998, 1999 and 2000
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.206 2014/03/29 19:28:25 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.206.4.1 2014/12/01 11:38:42 martin Exp $");
/*
#define CBB_DEBUG
@ -560,7 +560,7 @@ pccbbdetach(device_t self, int flags)
if (!TAILQ_EMPTY(&sc->sc_memwindow))
aprint_error_dev(self, "memory windows not empty");
callout_stop(&sc->sc_insert_ch);
callout_halt(&sc->sc_insert_ch, NULL);
callout_destroy(&sc->sc_insert_ch);
mutex_destroy(&sc->sc_pwr_mtx);

View File

@ -1,4 +1,4 @@
/* $NetBSD: btbc.c,v 1.16 2014/05/20 18:25:54 rmind Exp $ */
/* $NetBSD: btbc.c,v 1.16.2.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 2007 KIYOHARA Takashi
* All rights reserved.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: btbc.c,v 1.16 2014/05/20 18:25:54 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: btbc.c,v 1.16.2.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/callout.h>
@ -210,7 +210,7 @@ btbc_detach(device_t self, int flags)
pmf_device_deregister(self);
btbc_disable(sc->sc_dev);
callout_stop(&sc->sc_ledch);
callout_halt(&sc->sc_ledch, NULL);
callout_destroy(&sc->sc_ledch);
if (sc->sc_unit) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: sdmmc.c,v 1.22 2014/03/19 15:26:42 nonaka Exp $ */
/* $NetBSD: sdmmc.c,v 1.22.4.1 2014/12/01 11:38:43 martin Exp $ */
/* $OpenBSD: sdmmc.c,v 1.18 2009/01/09 10:58:38 jsg Exp $ */
/*
@ -49,7 +49,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.22 2014/03/19 15:26:42 nonaka Exp $");
__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.22.4.1 2014/12/01 11:38:43 martin Exp $");
#ifdef _KERNEL_OPT
#include "opt_sdmmc.h"
@ -199,7 +199,7 @@ sdmmc_detach(device_t self, int flags)
}
if (ISSET(sc->sc_caps, SMC_CAPS_POLL_CARD_DET)) {
callout_stop(&sc->sc_card_detect_ch);
callout_halt(&sc->sc_card_detect_ch, NULL);
callout_destroy(&sc->sc_card_detect_ch);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmon_envsys_events.c,v 1.110 2013/09/15 14:40:56 martin Exp $ */
/* $NetBSD: sysmon_envsys_events.c,v 1.110.4.1 2014/12/01 11:38:42 martin Exp $ */
/*-
* Copyright (c) 2007, 2008 Juan Romero Pardines.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.110 2013/09/15 14:40:56 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.110.4.1 2014/12/01 11:38:42 martin Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -566,7 +566,6 @@ sme_events_init(struct sysmon_envsys *sme)
if (error)
return error;
mutex_init(&sme->sme_callout_mtx, MUTEX_DEFAULT, IPL_SOFTCLOCK);
callout_init(&sme->sme_callout, CALLOUT_MPSAFE);
callout_setfunc(&sme->sme_callout, sme_events_check, sme);
sme->sme_flags |= SME_CALLOUT_INITIALIZED;
@ -612,11 +611,16 @@ sme_events_destroy(struct sysmon_envsys *sme)
{
KASSERT(mutex_owned(&sme->sme_mtx));
callout_stop(&sme->sme_callout);
workqueue_destroy(sme->sme_wq);
mutex_destroy(&sme->sme_callout_mtx);
callout_destroy(&sme->sme_callout);
/*
* Unset before callout_halt to ensure callout is not scheduled again
* during callout_halt.
*/
sme->sme_flags &= ~SME_CALLOUT_INITIALIZED;
callout_halt(&sme->sme_callout, &sme->sme_mtx);
callout_destroy(&sme->sme_callout);
workqueue_destroy(sme->sme_wq);
DPRINTF(("%s: events framework destroyed for '%s'\n",
__func__, sme->sme_name));
}
@ -708,14 +712,14 @@ sme_events_check(void *arg)
KASSERT(sme != NULL);
mutex_enter(&sme->sme_callout_mtx);
mutex_enter(&sme->sme_mtx);
LIST_FOREACH(see, &sme->sme_events_list, see_list) {
workqueue_enqueue(sme->sme_wq, &see->see_wk, NULL);
see->see_edata->flags |= ENVSYS_FNEED_REFRESH;
}
if (!sysmon_low_power)
sme_schedule_callout(sme);
mutex_exit(&sme->sme_callout_mtx);
mutex_exit(&sme->sme_mtx);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysmonvar.h,v 1.44 2012/12/11 15:39:06 pgoyette Exp $ */
/* $NetBSD: sysmonvar.h,v 1.44.12.1 2014/12/01 11:38:42 martin Exp $ */
/*-
* Copyright (c) 2000 Zembu Labs, Inc.
@ -208,7 +208,6 @@ struct sysmon_envsys {
* Locking/synchronization.
*/
kmutex_t sme_mtx;
kmutex_t sme_callout_mtx;
kcondvar_t sme_condvar;
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ohci.c,v 1.253 2014/08/05 10:33:46 skrll Exp $ */
/* $NetBSD: ohci.c,v 1.253.2.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.253 2014/08/05 10:33:46 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.253.2.1 2014/12/01 11:38:43 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -350,7 +350,7 @@ ohci_detach(struct ohci_softc *sc, int flags)
if (rv != 0)
return (rv);
callout_stop(&sc->sc_tmo_rhsc);
callout_halt(&sc->sc_tmo_rhsc, &sc->sc_lock);
usb_delay_ms(&sc->sc_bus, 300); /* XXX let stray task complete */
callout_destroy(&sc->sc_tmo_rhsc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: wskbd.c,v 1.134 2014/07/25 08:10:39 dholland Exp $ */
/* $NetBSD: wskbd.c,v 1.134.2.1 2014/12/01 11:38:43 martin Exp $ */
/*
* Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved.
@ -105,7 +105,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.134 2014/07/25 08:10:39 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.134.2.1 2014/12/01 11:38:43 martin Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -634,7 +634,7 @@ wskbd_detach(device_t self, int flags)
wsmux_detach_sc(&sc->sc_base);
#endif
callout_stop(&sc->sc_repeat_ch);
callout_halt(&sc->sc_repeat_ch, NULL);
callout_destroy(&sc->sc_repeat_ch);
if (sc->sc_isconsole) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_ktrace.c,v 1.164 2013/12/09 16:45:23 pooka Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.164.4.1 2014/12/01 11:38:42 martin Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.164 2013/12/09 16:45:23 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.164.4.1 2014/12/01 11:38:42 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1402,6 +1402,9 @@ ktrace_thread(void *arg)
}
TAILQ_REMOVE(&ktdq, ktd, ktd_list);
callout_halt(&ktd->ktd_wakch, &ktrace_lock);
callout_destroy(&ktd->ktd_wakch);
mutex_exit(&ktrace_lock);
/*
@ -1415,8 +1418,6 @@ ktrace_thread(void *arg)
cv_destroy(&ktd->ktd_sync_cv);
cv_destroy(&ktd->ktd_cv);
callout_stop(&ktd->ktd_wakch);
callout_destroy(&ktd->ktd_wakch);
kmem_free(ktd, sizeof(*ktd));
kthread_exit(0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ecosubr.c,v 1.40 2014/06/05 23:48:16 rmind Exp $ */
/* $NetBSD: if_ecosubr.c,v 1.40.2.1 2014/12/01 11:38:43 martin Exp $ */
/*-
* Copyright (c) 2001 Ben Harris
@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.40 2014/06/05 23:48:16 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.40.2.1 2014/12/01 11:38:43 martin Exp $");
#include "opt_inet.h"
@ -860,7 +860,7 @@ eco_retry_free(struct eco_retry *er)
{
int s;
callout_stop(&er->er_callout);
callout_halt(&er->er_callout, NULL);
m_freem(er->er_packet);
s = splnet();
LIST_REMOVE(er, er_link);