Mechanically replace simplelock with kmutex_t.

This commit is contained in:
skrll 2014-03-20 06:48:54 +00:00
parent 43b8706dc0
commit 8f2cde0556
13 changed files with 104 additions and 125 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ixp12x0_intr.c,v 1.27 2014/03/02 13:23:32 joerg Exp $ */
/* $NetBSD: ixp12x0_intr.c,v 1.28 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ixp12x0_intr.c,v 1.27 2014/03/02 13:23:32 joerg Exp $");
__KERNEL_RCSID(0, "$NetBSD: ixp12x0_intr.c,v 1.28 2014/03/20 06:48:54 skrll Exp $");
/*
* Interrupt support for the Intel ixp12x0
@ -39,7 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: ixp12x0_intr.c,v 1.27 2014/03/02 13:23:32 joerg Exp
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/simplelock.h>
#include <sys/termios.h>
#include <sys/bus.h>
#include <sys/intr.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: ixp425_if_npe.c,v 1.24 2014/02/24 10:47:46 martin Exp $ */
/* $NetBSD: ixp425_if_npe.c,v 1.25 2014/03/20 06:48:54 skrll Exp $ */
/*-
* Copyright (c) 2006 Sam Leffler. All rights reserved.
@ -28,7 +28,7 @@
#if 0
__FBSDID("$FreeBSD: src/sys/arm/xscale/ixp425/if_npe.c,v 1.1 2006/11/19 23:55:23 sam Exp $");
#endif
__KERNEL_RCSID(0, "$NetBSD: ixp425_if_npe.c,v 1.24 2014/02/24 10:47:46 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: ixp425_if_npe.c,v 1.25 2014/03/20 06:48:54 skrll Exp $");
/*
* Intel XScale NPE Ethernet driver.
@ -57,7 +57,6 @@ __KERNEL_RCSID(0, "$NetBSD: ixp425_if_npe.c,v 1.24 2014/02/24 10:47:46 martin Ex
#include <sys/socket.h>
#include <sys/endian.h>
#include <sys/ioctl.h>
#include <sys/simplelock.h>
#include <sys/syslog.h>
#include <sys/bus.h>

View File

@ -1,4 +1,4 @@
/* $NetBSD: ixp425_npe.c,v 1.9 2012/10/14 14:20:58 msaitoh Exp $ */
/* $NetBSD: ixp425_npe.c,v 1.10 2014/03/20 06:48:54 skrll Exp $ */
/*-
* Copyright (c) 2006 Sam Leffler, Errno Consulting
@ -62,7 +62,7 @@
#if 0
__FBSDID("$FreeBSD: src/sys/arm/xscale/ixp425/ixp425_npe.c,v 1.1 2006/11/19 23:55:23 sam Exp $");
#endif
__KERNEL_RCSID(0, "$NetBSD: ixp425_npe.c,v 1.9 2012/10/14 14:20:58 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: ixp425_npe.c,v 1.10 2014/03/20 06:48:54 skrll Exp $");
/*
* Intel XScale Network Processing Engine (NPE) support.
@ -86,7 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: ixp425_npe.c,v 1.9 2012/10/14 14:20:58 msaitoh Exp $
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/simplelock.h>
#include <sys/mutex.h>
#include <sys/time.h>
#include <sys/proc.h>
@ -274,7 +274,7 @@ ixpnpe_attach(device_t parent, device_t self, void *arg)
sc->sc_dt = ixa->ixa_dt;
sc->sc_unit = ixa->ixa_npe;
simple_lock_init(&sc->sc_lock);
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
/* XXX: Check features to ensure this NPE is enabled */
@ -353,13 +353,13 @@ ixpnpe_stopandreset(struct ixpnpe_softc *sc)
{
int error;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
error = npe_cpu_stop(sc); /* stop NPE */
if (error == 0)
error = npe_cpu_reset(sc); /* reset it */
if (error == 0)
sc->started = 0; /* mark stopped */
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
DPRINTF(sc->sc_dev, "%s: error %d\n", __func__, error);
return error;
@ -386,9 +386,9 @@ ixpnpe_start(struct ixpnpe_softc *sc)
{
int ret;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
ret = ixpnpe_start_locked(sc);
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
return (ret);
}
@ -397,11 +397,11 @@ ixpnpe_stop(struct ixpnpe_softc *sc)
{
int error;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
error = npe_cpu_stop(sc);
if (error == 0)
sc->started = 0;
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
DPRINTF(sc->sc_dev, "%s: error %d\n", __func__, error);
return error;
@ -489,7 +489,7 @@ ixpnpe_init(struct ixpnpe_softc *sc, const char *imageName, uint32_t imageId)
* currently loaded images. If a critical error occured
* during download, record that the NPE has an invalid image
*/
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
error = npe_load_image(sc, imageCodePtr, 1 /*VERIFY*/);
if (error == 0) {
sc->validImage = 1;
@ -498,7 +498,7 @@ ixpnpe_init(struct ixpnpe_softc *sc, const char *imageName, uint32_t imageId)
sc->validImage = 0;
}
sc->functionalityId = IX_NPEDL_FUNCTIONID_FROM_IMAGEID_GET(imageId);
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
done:
DPRINTF(sc->sc_dev, "%s: error %d\n", __func__, error);
return error;
@ -1405,11 +1405,11 @@ ixpnpe_sendandrecvmsg(struct ixpnpe_softc *sc,
{
int error;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
error = ixpnpe_sendmsg_locked(sc, send);
if (error == 0)
error = ixpnpe_recvmsg_locked(sc, recv);
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
return error;
}
@ -1421,9 +1421,9 @@ ixpnpe_sendmsg(struct ixpnpe_softc *sc, const uint32_t msg[2])
{
int error;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
error = ixpnpe_sendmsg_locked(sc, msg);
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
return error;
}
@ -1433,12 +1433,12 @@ ixpnpe_recvmsg(struct ixpnpe_softc *sc, uint32_t msg[2])
{
int error;
simple_lock(&sc->sc_lock);
mutex_enter(&sc->sc_lock);
if (sc->sc_msgwaiting)
memcpy(msg, sc->sc_msg, sizeof(sc->sc_msg));
/* NB: sc_msgwaiting != 1 means the ack fetch failed */
error = sc->sc_msgwaiting != 1 ? EIO : 0;
simple_unlock(&sc->sc_lock);
mutex_exit(&sc->sc_lock);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ixp425_npevar.h,v 1.4 2012/10/14 14:20:58 msaitoh Exp $ */
/* $NetBSD: ixp425_npevar.h,v 1.5 2014/03/20 06:48:54 skrll Exp $ */
/*-
* Copyright (c) 2006 Sam Leffler. All rights reserved.
@ -89,7 +89,7 @@ struct ixpnpe_softc {
bus_size_t sc_size; /* size of mapped register window */
int sc_unit;
void *sc_ih; /* interrupt handler */
struct simplelock sc_lock; /* mailbox lock */
kmutex_t sc_lock; /* mailbox lock */
uint32_t sc_msg[2]; /* reply msg collected in ixpnpe_intr */
int sc_msgwaiting; /* sc_msg holds valid data */

View File

@ -1,4 +1,4 @@
/* $NetBSD: xbdvar.h,v 1.14 2012/02/02 19:43:01 tls Exp $ */
/* $NetBSD: xbdvar.h,v 1.15 2014/03/20 06:48:54 skrll Exp $ */
/*
*
@ -30,14 +30,11 @@
#ifndef _XEN_XBDVAR_H_
#define _XEN_XBDVAR_H_
#include <sys/simplelock.h>
struct xbd_softc {
device_t sc_dev; /* base device glue */
struct dk_softc sc_dksc; /* generic disk interface */
unsigned long sc_xd_device; /* cookie identifying device */
struct dk_intf *sc_di; /* pseudo-disk interface */
struct simplelock sc_slock; /* our lock */
int sc_shutdown; /* about to be removed */
krndsource_t sc_rnd_source;
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: coda_vnops.c,v 1.95 2014/02/27 16:51:37 hannken Exp $ */
/* $NetBSD: coda_vnops.c,v 1.96 2014/03/20 06:48:54 skrll Exp $ */
/*
*
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.95 2014/02/27 16:51:37 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.96 2014/03/20 06:48:54 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1936,7 +1936,7 @@ coda_getpages(void *v)
* XXX Perhaps we should not fully open the file, but
* simply obtain a container file.
*/
/* XXX Is it ok to do this while holding the simplelock? */
/* XXX Is it ok to do this while holding the mutex? */
cerror = VOP_OPEN(vp, FREAD, cred);
if (cerror) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ed_mca.c,v 1.54 2014/03/16 05:20:28 dholland Exp $ */
/* $NetBSD: ed_mca.c,v 1.55 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.54 2014/03/16 05:20:28 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.55 2014/03/20 06:48:54 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -158,7 +158,7 @@ ed_mca_attach(device_t parent, device_t self, void *aux)
edc_add_disk(sc, ed);
bufq_alloc(&ed->sc_q, "disksort", BUFQ_SORT_RAWBLOCK);
simple_lock_init(&ed->sc_q_lock);
mutex_init(&ed->sc_q_lock, MUTEX_DEFAULT, IPL_VM);
if (ed_get_params(ed, &drv_flags)) {
printf(": IDENTIFY failed, no disk found\n");
@ -257,9 +257,9 @@ edmcastrategy(struct buf *bp)
bp->b_rawblkno = blkno;
/* Queue transfer on drive, activate drive and controller if idle. */
simple_lock(&ed->sc_q_lock);
mutex_enter(&ed->sc_q_lock);
bufq_put(ed->sc_q, bp);
simple_unlock(&ed->sc_q_lock);
mutex_exit(&ed->sc_q_lock);
/* Ring the worker thread */
wakeup(ed->edc_softc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: edc_mca.c,v 1.48 2013/10/12 21:11:42 christos Exp $ */
/* $NetBSD: edc_mca.c,v 1.49 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: edc_mca.c,v 1.48 2013/10/12 21:11:42 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: edc_mca.c,v 1.49 2014/03/20 06:48:54 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -815,13 +815,13 @@ edcworker(void *arg)
}
/* Is there a buf for us ? */
simple_lock(&ed->sc_q_lock);
mutex_enter(&ed->sc_q_lock);
if ((bp = bufq_get(ed->sc_q)) == NULL) {
simple_unlock(&ed->sc_q_lock);
mutex_exit(&ed->sc_q_lock);
i++;
continue;
}
simple_unlock(&ed->sc_q_lock);
mutex_exit(&ed->sc_q_lock);
/* Instrumentation. */
disk_busy(&ed->sc_dk);

View File

@ -1,4 +1,4 @@
/* $NetBSD: edvar.h,v 1.16 2012/10/27 17:18:26 chs Exp $ */
/* $NetBSD: edvar.h,v 1.17 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/simplelock.h>
#include <sys/mutex.h>
struct edc_mca_softc;
@ -39,7 +39,7 @@ struct ed_softc {
/* General disk infos */
struct disk sc_dk;
struct bufq_state *sc_q;
struct simplelock sc_q_lock;
kmutex_t sc_q_lock;
struct edc_mca_softc *edc_softc; /* pointer to our controller */

View File

@ -47,8 +47,6 @@ typedef char *caddr_t;
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/simplelock.h>
#include <sys/kthread.h>
#include <sys/workqueue.h>
@ -69,12 +67,12 @@ void cxgb_make_task(void *);
void m_cljset(struct mbuf *m, void *cl, int type);
#define mtx simplelock
#define mtx_init(a, b, c, d) { (a)->lock_data = __SIMPLELOCK_UNLOCKED; }
#define mtx kmutex_t
#define mtx_init(a, b, c, d) { mutex_init(a, MUTEX_DEFAULT, IPL_HIGH) }
#define mtx_destroy(a)
#define mtx_lock(a) simple_lock(a)
#define mtx_unlock(a) simple_unlock(a)
#define mtx_trylock(a) simple_lock_try(a)
#define mtx_lock(a) mutex_spin_enter(a)
#define mtx_unlock(a) mutex_spin_exit(a)
#define mtx_trylock(a) mutex_tryenter(a)
#define MA_OWNED 1
#define MA_NOTOWNED 0
#define mtx_assert(a, w)

View File

@ -1,4 +1,4 @@
/* $NetBSD: cy82c693.c,v 1.8 2010/04/19 18:24:27 dyoung Exp $ */
/* $NetBSD: cy82c693.c,v 1.9 2014/03/20 06:48:54 skrll Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -35,16 +35,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cy82c693.c,v 1.8 2010/04/19 18:24:27 dyoung Exp $");
#include "opt_multiprocessor.h"
#include "opt_lockdebug.h"
__KERNEL_RCSID(0, "$NetBSD: cy82c693.c,v 1.9 2014/03/20 06:48:54 skrll Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/simplelock.h>
#include <sys/once.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
@ -52,40 +49,43 @@ __KERNEL_RCSID(0, "$NetBSD: cy82c693.c,v 1.8 2010/04/19 18:24:27 dyoung Exp $");
#include <dev/pci/cy82c693reg.h>
#include <dev/pci/cy82c693var.h>
ONCE_DECL(cyhc_once);
static struct cy82c693_handle cyhc_handle;
static int cyhc_initialized;
static struct simplelock cyhc_slock = SIMPLELOCK_INITIALIZER;
static kmutex_t cyhc_slock;
#define CYHC_LOCK(s) \
do { \
s = splhigh(); \
simple_lock(&cyhc_slock); \
} while (0)
static int
cy82c693_onceinit(void)
{
#define CYHC_UNLOCK(s) \
do { \
simple_unlock(&cyhc_slock); \
splx(s); \
} while (0)
mutex_init(&cyhc_slock, MUTEX_DEFAULT, IPL_HIGH);
return 0;
}
const struct cy82c693_handle *
cy82c693_init(bus_space_tag_t iot)
{
bus_space_handle_t ioh;
int s;
int err;
CYHC_LOCK(s);
err = RUN_ONCE(&cyhc_once, cy82c693_onceinit);
if (err)
return NULL;
mutex_spin_enter(&cyhc_slock);
if (cyhc_initialized) {
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
KASSERT(bus_space_is_equal(iot, cyhc_handle.cyhc_iot));
return (&cyhc_handle);
return &cyhc_handle;
}
if (bus_space_map(iot, CYHC_CONFIG_ADDR, 2, 0, &ioh) != 0) {
CYHC_UNLOCK(s);
return (NULL);
mutex_spin_exit(&cyhc_slock);;
return NULL;
}
cyhc_handle.cyhc_iot = iot;
@ -93,46 +93,44 @@ cy82c693_init(bus_space_tag_t iot)
cyhc_initialized = 1;
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
return (&cyhc_handle);
return &cyhc_handle;
}
u_int8_t
cy82c693_read(const struct cy82c693_handle *cyhc, int reg)
{
int s;
u_int8_t rv;
uint8_t rv;
CYHC_LOCK(s);
mutex_spin_enter(&cyhc_slock);
if (cyhc_initialized == 0) {
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
panic("cy82c693_read");
}
bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 0, reg);
rv = bus_space_read_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 1);
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
return (rv);
return rv;
}
void
cy82c693_write(const struct cy82c693_handle *cyhc, int reg, u_int8_t val)
{
int s;
CYHC_LOCK(s);
mutex_spin_enter(&cyhc_slock);
if (cyhc_initialized == 0) {
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
panic("cy82c693_write");
}
bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 0, reg);
bus_space_write_1(cyhc->cyhc_iot, cyhc->cyhc_ioh, 1, val);
CYHC_UNLOCK(s);
mutex_spin_exit(&cyhc_slock);;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_tap.c,v 1.73 2014/03/16 05:20:30 dholland Exp $ */
/* $NetBSD: if_tap.c,v 1.74 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.73 2014/03/16 05:20:30 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.74 2014/03/20 06:48:54 skrll Exp $");
#if defined(_KERNEL_OPT)
@ -60,7 +60,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.73 2014/03/16 05:20:30 dholland Exp $")
#endif
#include <sys/kauth.h>
#include <sys/mutex.h>
#include <sys/simplelock.h>
#include <sys/intr.h>
#include <sys/stat.h>
@ -112,7 +111,7 @@ struct tap_softc {
struct selinfo sc_rsel;
pid_t sc_pgid; /* For async. IO */
kmutex_t sc_rdlock;
struct simplelock sc_kqlock;
kmutex_t sc_kqlock;
void *sc_sih;
struct timespec sc_atime;
struct timespec sc_mtime;
@ -367,11 +366,10 @@ tap_attach(device_t parent, device_t self, void *aux)
* the same moment and both try and dequeue a single packet.
*
* The queue for event listeners (used by kqueue(9), see below) has
* to be protected, too, but we don't need the same level of
* complexity for that lock, so a simple spinning lock is fine.
* to be protected too, so use a spin lock.
*/
mutex_init(&sc->sc_rdlock, MUTEX_DEFAULT, IPL_NONE);
simple_lock_init(&sc->sc_kqlock);
mutex_init(&sc->sc_kqlock, MUTEX_DEFAULT, IPL_VM);
selinit(&sc->sc_rsel);
}
@ -1188,9 +1186,9 @@ tap_dev_poll(int unit, int events, struct lwp *l)
if (m != NULL)
revents |= events & (POLLIN|POLLRDNORM);
else {
simple_lock(&sc->sc_kqlock);
mutex_spin_enter(&sc->sc_kqlock);
selrecord(l, &sc->sc_rsel);
simple_unlock(&sc->sc_kqlock);
mutex_spin_exit(&sc->sc_kqlock);
}
}
revents |= events & (POLLOUT|POLLWRNORM);
@ -1238,9 +1236,9 @@ tap_dev_kqfilter(int unit, struct knote *kn)
}
kn->kn_hook = sc;
simple_lock(&sc->sc_kqlock);
mutex_spin_enter(&sc->sc_kqlock);
SLIST_INSERT_HEAD(&sc->sc_rsel.sel_klist, kn, kn_selnext);
simple_unlock(&sc->sc_kqlock);
mutex_spin_exit(&sc->sc_kqlock);
KERNEL_UNLOCK_ONE(NULL);
return (0);
}
@ -1251,9 +1249,9 @@ tap_kqdetach(struct knote *kn)
struct tap_softc *sc = (struct tap_softc *)kn->kn_hook;
KERNEL_LOCK(1, NULL);
simple_lock(&sc->sc_kqlock);
mutex_spin_enter(&sc->sc_kqlock);
SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
simple_unlock(&sc->sc_kqlock);
mutex_spin_exit(&sc->sc_kqlock);
KERNEL_UNLOCK_ONE(NULL);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_tun.c,v 1.116 2014/03/16 05:20:30 dholland Exp $ */
/* $NetBSD: if_tun.c,v 1.117 2014/03/20 06:48:54 skrll Exp $ */
/*
* Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
@ -15,7 +15,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.116 2014/03/16 05:20:30 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.117 2014/03/20 06:48:54 skrll Exp $");
#include "opt_inet.h"
@ -35,7 +35,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.116 2014/03/16 05:20:30 dholland Exp $"
#include <sys/signalvar.h>
#include <sys/conf.h>
#include <sys/kauth.h>
#include <sys/simplelock.h>
#include <sys/mutex.h>
#include <sys/cpu.h>
@ -67,7 +66,7 @@ void tunattach(int);
static LIST_HEAD(, tun_softc) tun_softc_list;
static LIST_HEAD(, tun_softc) tunz_softc_list;
static struct simplelock tun_softc_lock;
static kmutex_t tun_softc_lock;
static int tun_ioctl(struct ifnet *, u_long, void *);
static int tun_output(struct ifnet *, struct mbuf *,
@ -114,7 +113,7 @@ void
tunattach(int unused)
{
simple_lock_init(&tun_softc_lock);
mutex_init(&tun_softc_lock, MUTEX_DEFAULT, IPL_NET);
LIST_INIT(&tun_softc_list);
LIST_INIT(&tunz_softc_list);
if_clone_attach(&tun_cloner);
@ -122,7 +121,6 @@ tunattach(int unused)
/*
* Find driver instance from dev_t.
* Call at splnet().
* Returns with tp locked (if found).
*/
static struct tun_softc *
@ -131,20 +129,19 @@ tun_find_unit(dev_t dev)
struct tun_softc *tp;
int unit = minor(dev);
simple_lock(&tun_softc_lock);
mutex_enter(&tun_softc_lock);
LIST_FOREACH(tp, &tun_softc_list, tun_list)
if (unit == tp->tun_unit)
break;
if (tp)
mutex_enter(&tp->tun_lock);
simple_unlock(&tun_softc_lock);
mutex_exit(&tun_softc_lock);
return (tp);
}
/*
* Find zombie driver instance by unit number.
* Call at splnet().
* Remove tp from list and return it unlocked (if found).
*/
static struct tun_softc *
@ -152,13 +149,13 @@ tun_find_zunit(int unit)
{
struct tun_softc *tp;
simple_lock(&tun_softc_lock);
mutex_enter(&tun_softc_lock);
LIST_FOREACH(tp, &tunz_softc_list, tun_list)
if (unit == tp->tun_unit)
break;
if (tp)
LIST_REMOVE(tp, tun_list);
simple_unlock(&tun_softc_lock);
mutex_exit(&tun_softc_lock);
#ifdef DIAGNOSTIC
if (tp != NULL && (tp->tun_flags & (TUN_INITED|TUN_OPEN)) != TUN_OPEN)
printf("tun%d: inconsistent flags: %x\n", unit, tp->tun_flags);
@ -191,9 +188,9 @@ tun_clone_create(struct if_clone *ifc, int unit)
tp->tun_osih = softint_establish(SOFTINT_CLOCK, tun_o_softintr, tp);
tp->tun_isih = softint_establish(SOFTINT_CLOCK, tun_i_softintr, tp);
simple_lock(&tun_softc_lock);
mutex_enter(&tun_softc_lock);
LIST_INSERT_HEAD(&tun_softc_list, tp, tun_list);
simple_unlock(&tun_softc_lock);
mutex_exit(&tun_softc_lock);
return (0);
}
@ -232,13 +229,12 @@ static int
tun_clone_destroy(struct ifnet *ifp)
{
struct tun_softc *tp = (void *)ifp;
int s, zombie = 0;
int zombie = 0;
IF_PURGE(&ifp->if_snd);
ifp->if_flags &= ~IFF_RUNNING;
s = splnet();
simple_lock(&tun_softc_lock);
mutex_enter(&tun_softc_lock);
mutex_enter(&tp->tun_lock);
LIST_REMOVE(tp, tun_list);
if (tp->tun_flags & TUN_OPEN) {
@ -247,7 +243,7 @@ tun_clone_destroy(struct ifnet *ifp)
tp->tun_flags &= ~TUN_INITED;
LIST_INSERT_HEAD(&tunz_softc_list, tp, tun_list);
}
simple_unlock(&tun_softc_lock);
mutex_exit(&tun_softc_lock);
if (tp->tun_flags & TUN_RWAIT) {
tp->tun_flags &= ~TUN_RWAIT;
@ -256,7 +252,6 @@ tun_clone_destroy(struct ifnet *ifp)
selnotify(&tp->tun_rsel, 0, 0);
mutex_exit(&tp->tun_lock);
splx(s);
if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
fownsignal(tp->tun_pgid, SIGIO, POLL_HUP, 0, NULL);
@ -285,14 +280,13 @@ tunopen(dev_t dev, int flag, int mode, struct lwp *l)
{
struct ifnet *ifp;
struct tun_softc *tp;
int s, error;
int error;
error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_INTERFACE_TUN,
KAUTH_REQ_NETWORK_INTERFACE_TUN_ADD, NULL, NULL, NULL);
if (error)
return (error);
s = splnet();
tp = tun_find_unit(dev);
if (tp == NULL) {
@ -315,7 +309,6 @@ tunopen(dev_t dev, int flag, int mode, struct lwp *l)
out:
mutex_exit(&tp->tun_lock);
out_nolock:
splx(s);
return (error);
}
@ -327,11 +320,9 @@ int
tunclose(dev_t dev, int flag, int mode,
struct lwp *l)
{
int s;
struct tun_softc *tp;
struct ifnet *ifp;
s = splnet();
if ((tp = tun_find_zunit(minor(dev))) != NULL) {
/* interface was "destroyed" before the close */
seldestroy(&tp->tun_rsel);
@ -380,7 +371,6 @@ tunclose(dev_t dev, int flag, int mode,
}
}
out_nolock:
splx(s);
return (0);
}