diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -131,10 +131,6 @@ CFLAGS+=-DGDB_LOG .endif -# Disable thread safety analysis since it only finds very simple bugs and -# yields many false positives. -NO_WTHREAD_SAFETY= - NO_WCAST_ALIGN= SUBDIR= kbdlayout diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -729,7 +729,7 @@ * debug server to pause or report an event. vCPU threads wait here * as long as the debug server keeps them suspended. */ -static void +static void __requires_exclusive(&gdb_lock) _gdb_cpu_suspend(int vcpu, bool report_stop) { diff --git a/usr.sbin/bhyve/mem.c b/usr.sbin/bhyve/mem.c --- a/usr.sbin/bhyve/mem.c +++ b/usr.sbin/bhyve/mem.c @@ -172,7 +172,7 @@ void *arg) { struct mmio_rb_range *entry; - int err, perror, immutable; + int err, perror; pthread_rwlock_rdlock(&mmio_rwlock); /* @@ -209,15 +209,12 @@ * deadlock on 'mmio_rwlock'. However by registering the extended * config space window as 'immutable' the deadlock can be avoided. */ - immutable = (entry->mr_param.flags & MEM_F_IMMUTABLE); - if (immutable) { + if ((entry->mr_param.flags & MEM_F_IMMUTABLE) != 0) { perror = pthread_rwlock_unlock(&mmio_rwlock); assert(perror == 0); - } - - err = cb(ctx, vcpu, paddr, &entry->mr_param, arg); - - if (!immutable) { + err = cb(ctx, vcpu, paddr, &entry->mr_param, arg); + } else { + err = cb(ctx, vcpu, paddr, &entry->mr_param, arg); perror = pthread_rwlock_unlock(&mmio_rwlock); assert(perror == 0); } diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -86,13 +86,13 @@ static LIST_HEAD(listhead, mevent) global_head, change_head; -static void +static void __locks_exclusive(&mevent_lmutex) mevent_qlock(void) { pthread_mutex_lock(&mevent_lmutex); } -static void +static void __unlocks(&mevent_lmutex) mevent_qunlock(void) { pthread_mutex_unlock(&mevent_lmutex); diff --git a/usr.sbin/bhyve/pci_e82545.c b/usr.sbin/bhyve/pci_e82545.c --- a/usr.sbin/bhyve/pci_e82545.c +++ b/usr.sbin/bhyve/pci_e82545.c @@ -1461,7 +1461,7 @@ return (desc + 1); } -static void +static void __no_lock_analysis e82545_tx_run(struct e82545_softc *sc) { uint32_t cause; @@ -1539,7 +1539,7 @@ sc->esc_tx_enabled = 1; } -static void +static void __no_lock_analysis e82545_tx_disable(struct e82545_softc *sc) { @@ -1555,7 +1555,7 @@ sc->esc_rx_enabled = 1; } -static void +static void __no_lock_analysis e82545_rx_disable(struct e82545_softc *sc) { diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -740,7 +740,7 @@ } #ifdef BHYVE_SNAPSHOT -static void +static void __no_lock_analysis pci_vtnet_pause(void *vsc) { struct pci_vtnet_softc *sc = vsc; @@ -759,7 +759,7 @@ } } -static void +static void __no_lock_analysis pci_vtnet_resume(void *vsc) { struct pci_vtnet_softc *sc = vsc; diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c --- a/usr.sbin/bhyve/pci_xhci.c +++ b/usr.sbin/bhyve/pci_xhci.c @@ -1873,9 +1873,6 @@ if (err == XHCI_TRB_ERROR_EV_RING_FULL) DPRINTF(("pci_xhci[%d]: event ring full", __LINE__)); - if (!do_retry) - USB_DATA_XFER_UNLOCK(xfer); - if (do_intr) pci_xhci_assert_interrupt(sc); @@ -1885,9 +1882,9 @@ __LINE__)); goto retry; } - if (epid == 1) USB_DATA_XFER_RESET(xfer); + USB_DATA_XFER_UNLOCK(xfer); return (err); } diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h --- a/usr.sbin/bhyve/virtio.h +++ b/usr.sbin/bhyve/virtio.h @@ -247,17 +247,19 @@ uint16_t vs_msix_cfg_idx; /* MSI-X vector for config event */ }; -#define VS_LOCK(vs) \ -do { \ - if (vs->vs_mtx) \ - pthread_mutex_lock(vs->vs_mtx); \ -} while (0) - -#define VS_UNLOCK(vs) \ -do { \ - if (vs->vs_mtx) \ - pthread_mutex_unlock(vs->vs_mtx); \ -} while (0) +static inline void __no_lock_analysis +VS_LOCK(struct virtio_softc *sc) +{ + if (sc->vs_mtx) + pthread_mutex_lock(sc->vs_mtx); +} + +static inline void __no_lock_analysis +VS_UNLOCK(struct virtio_softc *sc) +{ + if (sc->vs_mtx) + pthread_mutex_unlock(sc->vs_mtx); +} struct virtio_consts { const char *vc_name; /* name of driver (for diagnostics) */ diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c --- a/usr.sbin/bhyve/virtio.c +++ b/usr.sbin/bhyve/virtio.c @@ -580,8 +580,7 @@ /* XXX probably should do something better than just assert() */ assert(baridx == 0); - if (vs->vs_mtx) - pthread_mutex_lock(vs->vs_mtx); + VS_LOCK(vs); vc = vs->vs_vc; name = vc->vc_name; @@ -666,8 +665,7 @@ break; } done: - if (vs->vs_mtx) - pthread_mutex_unlock(vs->vs_mtx); + VS_UNLOCK(vs); return (value); } @@ -702,8 +700,7 @@ /* XXX probably should do something better than just assert() */ assert(baridx == 0); - if (vs->vs_mtx) - pthread_mutex_lock(vs->vs_mtx); + VS_LOCK(vs); vc = vs->vs_vc; name = vc->vc_name; @@ -809,8 +806,7 @@ "%s: write config reg %s: curq %d >= max %d", name, cr->cr_name, vs->vs_curq, vc->vc_nvq); done: - if (vs->vs_mtx) - pthread_mutex_unlock(vs->vs_mtx); + VS_UNLOCK(vs); } #ifdef BHYVE_SNAPSHOT