summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McDonald <danmcd@joyent.com>2022-04-15 10:13:21 -0400
committerDan McDonald <danmcd@joyent.com>2022-04-15 10:13:21 -0400
commit70d78bcfe99bc1c8ee66f47e1354512df641c20f (patch)
tree15d5d8d68917cec788ab7bae51da31b7f6eeb8ae
parente288b3334358bc9608454ec63e63334d92f39f80 (diff)
parentfb29dee06f421b37b3394b542f15f91d4dbc7046 (diff)
downloadillumos-joyent-70d78bcfe99bc1c8ee66f47e1354512df641c20f.tar.gz
[illumos-gate merge]
commit fb29dee06f421b37b3394b542f15f91d4dbc7046 14636 discard mutex shim for bhyve
-rw-r--r--usr/src/compat/bhyve/sys/lock.h23
-rw-r--r--usr/src/compat/bhyve/sys/mutex.h78
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vatpic.c14
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vatpit.c11
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vhpet.c10
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vioapic.c13
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vlapic.c15
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vlapic_priv.h2
-rw-r--r--usr/src/uts/i86pc/io/vmm/io/vrtc.c31
-rw-r--r--usr/src/uts/i86pc/io/vmm/vmm.c27
-rw-r--r--usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c20
11 files changed, 61 insertions, 183 deletions
diff --git a/usr/src/compat/bhyve/sys/lock.h b/usr/src/compat/bhyve/sys/lock.h
deleted file mode 100644
index fd6021a87e..0000000000
--- a/usr/src/compat/bhyve/sys/lock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2017 Joyent, Inc.
- */
-
-#ifndef _COMPAT_FREEBSD_SYS_LOCK_H_
-#define _COMPAT_FREEBSD_SYS_LOCK_H_
-
-#include_next <sys/lock.h>
-
-#define WITNESS_WARN(...)
-
-#endif /* _COMPAT_FREEBSD_SYS_LOCK_H_ */
diff --git a/usr/src/compat/bhyve/sys/mutex.h b/usr/src/compat/bhyve/sys/mutex.h
deleted file mode 100644
index 9e588cb98a..0000000000
--- a/usr/src/compat/bhyve/sys/mutex.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source. A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2014 Pluribus Networks Inc.
- * Copyright 2018 Joyent, Inc.
- */
-
-#ifndef _COMPAT_FREEBSD_SYS_MUTEX_H_
-#define _COMPAT_FREEBSD_SYS_MUTEX_H_
-
-#ifdef _KERNEL
-
-#include <sys/debug.h>
-
-#define MTX_DEF 0x00000000
-#define MTX_SPIN 0x00000001
-
-struct mtx;
-
-void mtx_init(struct mtx *, char *name, const char *type_name, int opts);
-void mtx_destroy(struct mtx *);
-
-#endif /* KERNEL */
-#include_next <sys/mutex.h>
-#ifdef _KERNEL
-
-struct mtx {
- kmutex_t m;
-};
-
-static __inline void mtx_lock(struct mtx *mtx)
-{
- mutex_enter(&mtx->m);
-}
-
-static __inline void mtx_unlock(struct mtx *mtx)
-{
- mutex_exit(&mtx->m);
-}
-
-static __inline void mtx_lock_spin(struct mtx *mtx)
-{
- mutex_enter(&mtx->m);
-}
-
-static __inline void mtx_unlock_spin(struct mtx *mtx)
-{
- mutex_exit(&mtx->m);
-}
-
-static __inline int mtx_owned(struct mtx *mtx)
-{
- return (mutex_owned(&mtx->m));
-}
-
-#define MA_OWNED 0
-
-static __inline void mtx_assert(struct mtx *mtx, int what)
-{
- switch (what) {
- case MA_OWNED:
- ASSERT(mutex_owned(&mtx->m));
- break;
- }
-}
-
-#endif /* _KERNEL */
-
-#endif /* _COMPAT_FREEBSD_SYS_MUTEX_H_ */
diff --git a/usr/src/uts/i86pc/io/vmm/io/vatpic.c b/usr/src/uts/i86pc/io/vmm/io/vatpic.c
index 63306de731..aa3ae4186d 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vatpic.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vatpic.c
@@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/kernel.h>
-#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/systm.h>
@@ -62,9 +61,9 @@ __FBSDID("$FreeBSD$");
static MALLOC_DEFINE(M_VATPIC, "atpic", "bhyve virtual atpic (8259)");
-#define VATPIC_LOCK(vatpic) mtx_lock_spin(&((vatpic)->mtx))
-#define VATPIC_UNLOCK(vatpic) mtx_unlock_spin(&((vatpic)->mtx))
-#define VATPIC_LOCKED(vatpic) mtx_owned(&((vatpic)->mtx))
+#define VATPIC_LOCK(vatpic) mutex_enter(&((vatpic)->lock))
+#define VATPIC_UNLOCK(vatpic) mutex_exit(&((vatpic)->lock))
+#define VATPIC_LOCKED(vatpic) MUTEX_HELD(&((vatpic)->lock))
#define IRQ_BASE_MASK 0xf8
@@ -111,7 +110,7 @@ struct atpic_stats {
struct vatpic {
struct vm *vm;
- struct mtx mtx;
+ kmutex_t lock;
struct atpic atpic[2];
struct atpic_stats stats;
};
@@ -228,7 +227,7 @@ vatpic_notify_intr(struct vatpic *vatpic)
struct atpic *atpic;
int pin;
- KASSERT(VATPIC_LOCKED(vatpic), ("vatpic_notify_intr not locked"));
+ ASSERT(VATPIC_LOCKED(vatpic));
/*
* First check the slave.
@@ -813,7 +812,7 @@ vatpic_init(struct vm *vm)
vatpic = malloc(sizeof (struct vatpic), M_VATPIC, M_WAITOK | M_ZERO);
vatpic->vm = vm;
- mtx_init(&vatpic->mtx, "vatpic lock", NULL, MTX_SPIN);
+ mutex_init(&vatpic->lock, NULL, MUTEX_ADAPTIVE, NULL);
return (vatpic);
}
@@ -821,5 +820,6 @@ vatpic_init(struct vm *vm)
void
vatpic_cleanup(struct vatpic *vatpic)
{
+ mutex_destroy(&vatpic->lock);
free(vatpic, M_VATPIC);
}
diff --git a/usr/src/uts/i86pc/io/vmm/io/vatpit.c b/usr/src/uts/i86pc/io/vmm/io/vatpit.c
index 3f137e1b4d..9616444d25 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vatpit.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vatpit.c
@@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/kernel.h>
-#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/systm.h>
@@ -48,9 +47,8 @@ __FBSDID("$FreeBSD$");
static MALLOC_DEFINE(M_VATPIT, "atpit", "bhyve virtual atpit (8254)");
-#define VATPIT_LOCK(vatpit) mtx_lock_spin(&((vatpit)->mtx))
-#define VATPIT_UNLOCK(vatpit) mtx_unlock_spin(&((vatpit)->mtx))
-#define VATPIT_LOCKED(vatpit) mtx_owned(&((vatpit)->mtx))
+#define VATPIT_LOCK(vatpit) mutex_enter(&((vatpit)->lock))
+#define VATPIT_UNLOCK(vatpit) mutex_exit(&((vatpit)->lock))
#define TIMER_SEL_MASK 0xc0
#define TIMER_RW_MASK 0x30
@@ -100,7 +98,7 @@ struct channel {
struct vatpit {
struct vm *vm;
- struct mtx mtx;
+ kmutex_t lock;
struct channel channel[3];
};
@@ -455,7 +453,7 @@ vatpit_init(struct vm *vm)
vatpit = malloc(sizeof (struct vatpit), M_VATPIT, M_WAITOK | M_ZERO);
vatpit->vm = vm;
- mtx_init(&vatpit->mtx, "vatpit lock", NULL, MTX_SPIN);
+ mutex_init(&vatpit->lock, NULL, MUTEX_ADAPTIVE, NULL);
for (i = 0; i < 3; i++) {
callout_init(&vatpit->channel[i].callout, 1);
@@ -475,6 +473,7 @@ vatpit_cleanup(struct vatpit *vatpit)
for (i = 0; i < 3; i++)
callout_drain(&vatpit->channel[i].callout);
+ mutex_destroy(&vatpit->lock);
free(vatpit, M_VATPIT);
}
diff --git a/usr/src/uts/i86pc/io/vmm/io/vhpet.c b/usr/src/uts/i86pc/io/vmm/io/vhpet.c
index deb1417b71..d9515d0cc3 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vhpet.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vhpet.c
@@ -37,7 +37,6 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
@@ -88,7 +87,7 @@ struct vhpet_timer {
struct vhpet {
struct vm *vm;
- struct mtx mtx;
+ kmutex_t lock;
uint64_t config; /* Configuration */
uint64_t isr; /* Interrupt Status */
@@ -98,8 +97,8 @@ struct vhpet {
struct vhpet_timer timer[VHPET_NUM_TIMERS];
};
-#define VHPET_LOCK(vhp) mtx_lock(&((vhp)->mtx))
-#define VHPET_UNLOCK(vhp) mtx_unlock(&((vhp)->mtx))
+#define VHPET_LOCK(vhp) mutex_enter(&((vhp)->lock))
+#define VHPET_UNLOCK(vhp) mutex_exit(&((vhp)->lock))
static void vhpet_start_timer(struct vhpet *vhpet, int n, uint32_t counter,
hrtime_t now);
@@ -708,7 +707,7 @@ vhpet_init(struct vm *vm)
vhpet = malloc(sizeof (struct vhpet), M_VHPET, M_WAITOK | M_ZERO);
vhpet->vm = vm;
- mtx_init(&vhpet->mtx, "vhpet lock", NULL, MTX_DEF);
+ mutex_init(&vhpet->lock, NULL, MUTEX_ADAPTIVE, NULL);
pincount = vioapic_pincount(vm);
if (pincount >= 32)
@@ -745,6 +744,7 @@ vhpet_cleanup(struct vhpet *vhpet)
for (i = 0; i < VHPET_NUM_TIMERS; i++)
callout_drain(&vhpet->timer[i].callout);
+ mutex_destroy(&vhpet->lock);
free(vhpet, M_VHPET);
}
diff --git a/usr/src/uts/i86pc/io/vmm/io/vioapic.c b/usr/src/uts/i86pc/io/vmm/io/vioapic.c
index e5c95a944b..90dedb9ac1 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vioapic.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vioapic.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/queue.h>
-#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -77,7 +76,7 @@ struct ioapic_stats {
struct vioapic {
struct vm *vm;
- struct mtx mtx;
+ kmutex_t lock;
uint32_t id;
uint32_t ioregsel;
struct {
@@ -93,9 +92,9 @@ struct vioapic {
struct ioapic_stats stats;
};
-#define VIOAPIC_LOCK(vioapic) mtx_lock_spin(&((vioapic)->mtx))
-#define VIOAPIC_UNLOCK(vioapic) mtx_unlock_spin(&((vioapic)->mtx))
-#define VIOAPIC_LOCKED(vioapic) mtx_owned(&((vioapic)->mtx))
+#define VIOAPIC_LOCK(vioapic) mutex_enter(&((vioapic)->lock))
+#define VIOAPIC_UNLOCK(vioapic) mutex_exit(&((vioapic)->lock))
+#define VIOAPIC_LOCKED(vioapic) MUTEX_HELD(&((vioapic)->lock))
static MALLOC_DEFINE(M_VIOAPIC, "vioapic", "bhyve virtual ioapic");
@@ -452,7 +451,7 @@ vioapic_init(struct vm *vm)
vioapic = malloc(sizeof (struct vioapic), M_VIOAPIC, M_WAITOK | M_ZERO);
vioapic->vm = vm;
- mtx_init(&vioapic->mtx, "vioapic lock", NULL, MTX_SPIN);
+ mutex_init(&vioapic->lock, NULL, MUTEX_ADAPTIVE, NULL);
/* Initialize all redirection entries to mask all interrupts */
for (i = 0; i < REDIR_ENTRIES; i++)
@@ -464,7 +463,7 @@ vioapic_init(struct vm *vm)
void
vioapic_cleanup(struct vioapic *vioapic)
{
-
+ mutex_destroy(&vioapic->lock);
free(vioapic, M_VIOAPIC);
}
diff --git a/usr/src/uts/i86pc/io/vmm/io/vlapic.c b/usr/src/uts/i86pc/io/vmm/io/vlapic.c
index 12a20257a9..1cd6c72aaf 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vlapic.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vlapic.c
@@ -47,7 +47,6 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/lock.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
@@ -81,14 +80,14 @@ __FBSDID("$FreeBSD$");
#define VLAPIC_VERSION (16)
/*
- * The 'vlapic->timer_mtx' is used to provide mutual exclusion between the
+ * The 'vlapic->timer_lock' is used to provide mutual exclusion between the
* vlapic_callout_handler() and vcpu accesses to:
* - timer_freq_bt, timer_period_bt, timer_fire_bt
* - timer LVT register
*/
-#define VLAPIC_TIMER_LOCK(vlapic) mtx_lock_spin(&((vlapic)->timer_mtx))
-#define VLAPIC_TIMER_UNLOCK(vlapic) mtx_unlock_spin(&((vlapic)->timer_mtx))
-#define VLAPIC_TIMER_LOCKED(vlapic) mtx_owned(&((vlapic)->timer_mtx))
+#define VLAPIC_TIMER_LOCK(vlapic) mutex_enter(&((vlapic)->timer_lock))
+#define VLAPIC_TIMER_UNLOCK(vlapic) mutex_exit(&((vlapic)->timer_lock))
+#define VLAPIC_TIMER_LOCKED(vlapic) MUTEX_HELD(&((vlapic)->timer_lock))
/*
* APIC timer frequency:
@@ -688,8 +687,7 @@ static VMM_STAT(VLAPIC_INTR_TIMER, "timer interrupts generated by vlapic");
static void
vlapic_fire_timer(struct vlapic *vlapic)
{
-
- KASSERT(VLAPIC_TIMER_LOCKED(vlapic), ("vlapic_fire_timer not locked"));
+ ASSERT(VLAPIC_TIMER_LOCKED(vlapic));
if (vlapic_fire_lvt(vlapic, APIC_LVT_TIMER)) {
VLAPIC_CTR0(vlapic, "vlapic timer fired");
@@ -1445,7 +1443,7 @@ vlapic_init(struct vlapic *vlapic)
* Therefore the timer mutex must be a spinlock because blockable
* mutexes cannot be acquired in a critical section.
*/
- mtx_init(&vlapic->timer_mtx, "vlapic timer mtx", NULL, MTX_SPIN);
+ mutex_init(&vlapic->timer_lock, NULL, MUTEX_ADAPTIVE, NULL);
callout_init(&vlapic->callout, 1);
vlapic_reset(vlapic);
@@ -1455,6 +1453,7 @@ void
vlapic_cleanup(struct vlapic *vlapic)
{
callout_drain(&vlapic->callout);
+ mutex_destroy(&vlapic->timer_lock);
}
int
diff --git a/usr/src/uts/i86pc/io/vmm/io/vlapic_priv.h b/usr/src/uts/i86pc/io/vmm/io/vlapic_priv.h
index 7f07665874..7b12b60f51 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vlapic_priv.h
+++ b/usr/src/uts/i86pc/io/vmm/io/vlapic_priv.h
@@ -174,7 +174,7 @@ struct vlapic {
hrtime_t timer_period;
uint32_t timer_cur_freq;
- struct mtx timer_mtx;
+ kmutex_t timer_lock;
uint64_t msr_apicbase;
diff --git a/usr/src/uts/i86pc/io/vmm/io/vrtc.c b/usr/src/uts/i86pc/io/vmm/io/vrtc.c
index 2b3a5b5432..185cbc100a 100644
--- a/usr/src/uts/i86pc/io/vmm/io/vrtc.c
+++ b/usr/src/uts/i86pc/io/vmm/io/vrtc.c
@@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$");
#include <sys/queue.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
-#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/clock.h>
#include <sys/sysctl.h>
@@ -77,7 +76,7 @@ CTASSERT(offsetof(struct rtcdev, century) == RTC_CENTURY);
struct vrtc {
struct vm *vm;
- struct mtx mtx;
+ kmutex_t lock;
struct callout callout;
uint_t addr; /* RTC register to read or write */
hrtime_t base_uptime;
@@ -85,9 +84,9 @@ struct vrtc {
struct rtcdev rtcdev;
};
-#define VRTC_LOCK(vrtc) mtx_lock(&((vrtc)->mtx))
-#define VRTC_UNLOCK(vrtc) mtx_unlock(&((vrtc)->mtx))
-#define VRTC_LOCKED(vrtc) mtx_owned(&((vrtc)->mtx))
+#define VRTC_LOCK(vrtc) mutex_enter(&((vrtc)->lock))
+#define VRTC_UNLOCK(vrtc) mutex_exit(&((vrtc)->lock))
+#define VRTC_LOCKED(vrtc) MUTEX_HELD(&((vrtc)->lock))
/*
* RTC time is considered "broken" if:
@@ -152,7 +151,7 @@ vrtc_curtime(struct vrtc *vrtc, hrtime_t *basetime)
time_t t = vrtc->base_rtctime;
hrtime_t base = vrtc->base_uptime;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
if (update_enabled(vrtc)) {
const hrtime_t delta = gethrtime() - vrtc->base_uptime;
@@ -187,7 +186,7 @@ secs_to_rtc(time_t rtctime, struct vrtc *vrtc, int force_update)
struct rtcdev *rtc;
int hour;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
if (rtctime < 0) {
KASSERT(rtctime == VRTC_BROKEN_TIME,
@@ -288,7 +287,7 @@ rtc_to_secs(struct vrtc *vrtc)
struct rtcdev *rtc;
int century, error, hour, pm, year;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
rtc = &vrtc->rtcdev;
@@ -396,7 +395,7 @@ vrtc_time_update(struct vrtc *vrtc, time_t newtime, hrtime_t newbase)
time_t oldtime;
uint8_t alarm_sec, alarm_min, alarm_hour;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
rtc = &vrtc->rtcdev;
alarm_sec = rtc->alarm_sec;
@@ -486,7 +485,7 @@ vrtc_freq(struct vrtc *vrtc)
NANOSEC / 2,
};
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
/*
* If both periodic and alarm interrupts are enabled then use the
@@ -511,7 +510,7 @@ static void
vrtc_callout_reset(struct vrtc *vrtc, hrtime_t freqhrt)
{
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
if (freqhrt == 0) {
if (callout_active(&vrtc->callout)) {
@@ -583,7 +582,7 @@ vrtc_set_reg_c(struct vrtc *vrtc, uint8_t newval)
int oldirqf, newirqf;
uint8_t oldval, changed;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
rtc = &vrtc->rtcdev;
newval &= RTCIR_ALARM | RTCIR_PERIOD | RTCIR_UPDATE;
@@ -623,7 +622,7 @@ vrtc_set_reg_b(struct vrtc *vrtc, uint8_t newval)
int error;
uint8_t oldval, changed;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
rtc = &vrtc->rtcdev;
oldval = rtc->reg_b;
@@ -698,7 +697,7 @@ vrtc_set_reg_a(struct vrtc *vrtc, uint8_t newval)
hrtime_t oldfreq, newfreq;
uint8_t oldval, changed;
- KASSERT(VRTC_LOCKED(vrtc), ("%s: vrtc not locked", __func__));
+ ASSERT(VRTC_LOCKED(vrtc));
newval &= ~RTCSA_TUP;
oldval = vrtc->rtcdev.reg_a;
@@ -970,7 +969,7 @@ vrtc_init(struct vm *vm)
vrtc = malloc(sizeof (struct vrtc), M_VRTC, M_WAITOK | M_ZERO);
vrtc->vm = vm;
- mtx_init(&vrtc->mtx, "vrtc lock", NULL, MTX_DEF);
+ mutex_init(&vrtc->lock, NULL, MUTEX_ADAPTIVE, NULL);
callout_init(&vrtc->callout, 1);
/* Allow dividers to keep time but disable everything else */
@@ -1000,8 +999,8 @@ vrtc_init(struct vm *vm)
void
vrtc_cleanup(struct vrtc *vrtc)
{
-
callout_drain(&vrtc->callout);
+ mutex_destroy(&vrtc->lock);
free(vrtc, M_VRTC);
}
diff --git a/usr/src/uts/i86pc/io/vmm/vmm.c b/usr/src/uts/i86pc/io/vmm/vmm.c
index ae80146a12..be181781de 100644
--- a/usr/src/uts/i86pc/io/vmm/vmm.c
+++ b/usr/src/uts/i86pc/io/vmm/vmm.c
@@ -53,7 +53,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/pcpu.h>
-#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/rwlock.h>
@@ -113,7 +112,7 @@ typedef struct vm_thread_ctx {
*/
struct vcpu {
/* (o) protects state, run_state, hostcpu, sipi_vector */
- struct mtx mtx;
+ kmutex_t lock;
enum vcpu_state state; /* (o) vcpu state */
enum vcpu_run_state run_state; /* (i) vcpu init/sipi/run state */
@@ -148,11 +147,9 @@ struct vcpu {
struct ctxop *ctxop; /* (o) ctxop storage for vcpu */
};
-#define vcpu_lock_initialized(v) mtx_initialized(&((v)->mtx))
-#define vcpu_lock_init(v) mtx_init(&((v)->mtx), "vcpu lock", 0, MTX_SPIN)
-#define vcpu_lock(v) mtx_lock_spin(&((v)->mtx))
-#define vcpu_unlock(v) mtx_unlock_spin(&((v)->mtx))
-#define vcpu_assert_locked(v) mtx_assert(&((v)->mtx), MA_OWNED)
+#define vcpu_lock(v) mutex_enter(&((v)->lock))
+#define vcpu_unlock(v) mutex_exit(&((v)->lock))
+#define vcpu_assert_locked(v) ASSERT(MUTEX_HELD(&((v)->lock)))
struct mem_seg {
size_t len;
@@ -318,13 +315,18 @@ vcpu_cleanup(struct vm *vm, int i, bool destroy)
VLAPIC_CLEANUP(vm->cookie, vcpu->vlapic);
if (destroy) {
vmm_stat_free(vcpu->stats);
+
hma_fpu_free(vcpu->guestfpu);
vcpu->guestfpu = NULL;
+
vie_free(vcpu->vie_ctx);
vcpu->vie_ctx = NULL;
+
vmc_destroy(vcpu->vmclient);
vcpu->vmclient = NULL;
+
ctxop_free(vcpu->ctxop);
+ mutex_destroy(&vcpu->lock);
}
}
@@ -339,7 +341,8 @@ vcpu_init(struct vm *vm, int vcpu_id, bool create)
vcpu = &vm->vcpu[vcpu_id];
if (create) {
- vcpu_lock_init(vcpu);
+ mutex_init(&vcpu->lock, NULL, MUTEX_ADAPTIVE, NULL);
+
vcpu->state = VCPU_IDLE;
vcpu->hostcpu = NOCPU;
vcpu->lastloccpu = NOCPU;
@@ -1323,7 +1326,7 @@ vcpu_set_state_locked(struct vm *vm, int vcpuid, enum vcpu_state newstate,
vcpu_notify_event_locked(vcpu, VCPU_NOTIFY_EXIT);
VCPU_CTR1(vm, vcpuid, "vcpu state change from %s to "
"idle requested", vcpu_state2str(vcpu->state));
- cv_wait(&vcpu->state_cv, &vcpu->mtx.m);
+ cv_wait(&vcpu->state_cv, &vcpu->lock);
}
} else {
KASSERT(vcpu->state != VCPU_IDLE, ("invalid transition from "
@@ -1457,7 +1460,7 @@ vm_handle_hlt(struct vm *vm, int vcpuid, bool intr_disabled)
vcpu_ustate_change(vm, vcpuid, VU_IDLE);
vcpu_require_state_locked(vm, vcpuid, VCPU_SLEEPING);
- (void) cv_wait_sig(&vcpu->vcpu_cv, &vcpu->mtx.m);
+ (void) cv_wait_sig(&vcpu->vcpu_cv, &vcpu->lock);
vcpu_require_state_locked(vm, vcpuid, VCPU_FROZEN);
vcpu_ustate_change(vm, vcpuid, VU_EMU_KERN);
}
@@ -1750,7 +1753,7 @@ vm_handle_suspend(struct vm *vm, int vcpuid)
}
vcpu_require_state_locked(vm, vcpuid, VCPU_SLEEPING);
- rc = cv_reltimedwait_sig(&vcpu->vcpu_cv, &vcpu->mtx.m, hz,
+ rc = cv_reltimedwait_sig(&vcpu->vcpu_cv, &vcpu->lock, hz,
TR_CLOCK_TICK);
vcpu_require_state_locked(vm, vcpuid, VCPU_FROZEN);
@@ -1845,7 +1848,7 @@ vm_handle_run_state(struct vm *vm, int vcpuid)
vcpu_ustate_change(vm, vcpuid, VU_IDLE);
vcpu_require_state_locked(vm, vcpuid, VCPU_SLEEPING);
- (void) cv_wait_sig(&vcpu->vcpu_cv, &vcpu->mtx.m);
+ (void) cv_wait_sig(&vcpu->vcpu_cv, &vcpu->lock);
vcpu_require_state_locked(vm, vcpuid, VCPU_FROZEN);
vcpu_ustate_change(vm, vcpuid, VU_EMU_KERN);
}
diff --git a/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c b/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c
index 04bdb6a3d6..132d5dc87f 100644
--- a/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c
+++ b/usr/src/uts/i86pc/io/vmm/vmm_sol_glue.c
@@ -283,26 +283,6 @@ contigfree(void *addr, unsigned long size, struct malloc_type *type)
}
void
-mtx_init(struct mtx *mtx, char *name, const char *type_name, int opts)
-{
- /*
- * Requests that a mutex be initialized to the MTX_SPIN type are
- * ignored. The limitations which may have required spinlocks on
- * FreeBSD do not apply to how bhyve has been structured here.
- *
- * Adaptive mutexes are required to avoid deadlocks when certain
- * cyclics behavior interacts with interrupts and contended locks.
- */
- mutex_init(&mtx->m, name, MUTEX_ADAPTIVE, NULL);
-}
-
-void
-mtx_destroy(struct mtx *mtx)
-{
- mutex_destroy(&mtx->m);
-}
-
-void
critical_enter(void)
{
kpreempt_disable();