summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bhyve
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2014-12-30 22:22:46 +0000
committerneel <neel@FreeBSD.org>2014-12-30 22:22:46 +0000
commit10c6be06b424f54357c7ab09aee6e5ea3a110720 (patch)
tree0070ed7d3e7a4cd528fae2ab795fedf9c463711d /usr.sbin/bhyve
parentb7c609250bb56ecd416c82894f0f4018f1d6af24 (diff)
downloadFreeBSD-src-10c6be06b424f54357c7ab09aee6e5ea3a110720.zip
FreeBSD-src-10c6be06b424f54357c7ab09aee6e5ea3a110720.tar.gz
MFC r273683
Move the ACPI PM timer emulation into vmm.ko. MFC r273706 Change the type of the first argument to the I/O emulation handlers to 'struct vm *'. MFC r273710 Add a comment explaining the intent behind the I/O reservation [0x72-0x77]. MFC r273744 Add foo_genassym.c files to DPSRCS so dependencies for them are generated. This ensures these objects are rebuilt to generate an updated header of assembly constants if needed. MFC r274045 If the start bit, PxCMD.ST, is cleared and nothing is in-flight then PxCI, PxSACT, PxCMD.CCS and PxCMD.CR should be 0. MFC r274076 Improve the ability to cancel an in-flight request by using an interrupt, via SIGCONT, to force the read or write system call to return prematurely. MFC r274330 To allow a request to be submitted from within the callback routine of a completing one increase the total by 1 but don't advertise it. MFC r274931 Change the lower bound for guest vmspace allocation to 0 instead of using the VM_MIN_ADDRESS constant. MFC r275817 For level triggered interrupts clear the PIC IRR bit when the interrupt pin is deasserted. MFC r275850 Fix 8259 IRQ priority resolver. MFC r275952 Various 8259 device model improvements. MFC r275965 Emulate writes to the IA32_MISC_ENABLE MSR.
Diffstat (limited to 'usr.sbin/bhyve')
-rw-r--r--usr.sbin/bhyve/Makefile1
-rw-r--r--usr.sbin/bhyve/block_if.c174
-rw-r--r--usr.sbin/bhyve/pci_ahci.c8
-rw-r--r--usr.sbin/bhyve/pmtmr.c173
-rw-r--r--usr.sbin/bhyve/rtc.c4
5 files changed, 158 insertions, 202 deletions
diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile
index 1c95f77..377a2e6 100644
--- a/usr.sbin/bhyve/Makefile
+++ b/usr.sbin/bhyve/Makefile
@@ -31,7 +31,6 @@ SRCS= \
pci_virtio_rnd.c \
pci_uart.c \
pm.c \
- pmtmr.c \
post.c \
rtc.c \
smbiostbl.c \
diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c
index cbe5ac3..8687e9a 100644
--- a/usr.sbin/bhyve/block_if.c
+++ b/usr.sbin/bhyve/block_if.c
@@ -43,14 +43,18 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <pthread.h>
#include <pthread_np.h>
+#include <signal.h>
#include <unistd.h>
+#include <machine/atomic.h>
+
#include "bhyverun.h"
+#include "mevent.h"
#include "block_if.h"
#define BLOCKIF_SIG 0xb109b109
-#define BLOCKIF_MAXREQ 32
+#define BLOCKIF_MAXREQ 33
enum blockop {
BOP_READ,
@@ -60,7 +64,9 @@ enum blockop {
enum blockstat {
BST_FREE,
- BST_INUSE
+ BST_PEND,
+ BST_BUSY,
+ BST_DONE
};
struct blockif_elem {
@@ -68,6 +74,7 @@ struct blockif_elem {
struct blockif_req *be_req;
enum blockop be_op;
enum blockstat be_status;
+ pthread_t be_tid;
};
struct blockif_ctxt {
@@ -81,13 +88,25 @@ struct blockif_ctxt {
pthread_cond_t bc_cond;
int bc_closing;
- /* Request elements and free/inuse queues */
+ /* Request elements and free/pending/busy queues */
TAILQ_HEAD(, blockif_elem) bc_freeq;
- TAILQ_HEAD(, blockif_elem) bc_inuseq;
+ TAILQ_HEAD(, blockif_elem) bc_pendq;
+ TAILQ_HEAD(, blockif_elem) bc_busyq;
u_int bc_req_count;
struct blockif_elem bc_reqs[BLOCKIF_MAXREQ];
};
+static pthread_once_t blockif_once = PTHREAD_ONCE_INIT;
+
+struct blockif_sig_elem {
+ pthread_mutex_t bse_mtx;
+ pthread_cond_t bse_cond;
+ int bse_pending;
+ struct blockif_sig_elem *bse_next;
+};
+
+static struct blockif_sig_elem *blockif_bse_head;
+
static int
blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
enum blockop op)
@@ -101,10 +120,10 @@ blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
assert(be->be_status == BST_FREE);
TAILQ_REMOVE(&bc->bc_freeq, be, be_link);
- be->be_status = BST_INUSE;
+ be->be_status = BST_PEND;
be->be_req = breq;
be->be_op = op;
- TAILQ_INSERT_TAIL(&bc->bc_inuseq, be, be_link);
+ TAILQ_INSERT_TAIL(&bc->bc_pendq, be, be_link);
bc->bc_req_count++;
@@ -112,26 +131,38 @@ blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
}
static int
-blockif_dequeue(struct blockif_ctxt *bc, struct blockif_elem *el)
+blockif_dequeue(struct blockif_ctxt *bc, struct blockif_elem **bep)
{
struct blockif_elem *be;
if (bc->bc_req_count == 0)
return (ENOENT);
- be = TAILQ_FIRST(&bc->bc_inuseq);
+ be = TAILQ_FIRST(&bc->bc_pendq);
assert(be != NULL);
- assert(be->be_status == BST_INUSE);
- *el = *be;
+ assert(be->be_status == BST_PEND);
+ TAILQ_REMOVE(&bc->bc_pendq, be, be_link);
+ be->be_status = BST_BUSY;
+ be->be_tid = bc->bc_btid;
+ TAILQ_INSERT_TAIL(&bc->bc_busyq, be, be_link);
+
+ *bep = be;
+
+ return (0);
+}
+
+static void
+blockif_complete(struct blockif_ctxt *bc, struct blockif_elem *be)
+{
+ assert(be->be_status == BST_DONE);
- TAILQ_REMOVE(&bc->bc_inuseq, be, be_link);
+ TAILQ_REMOVE(&bc->bc_busyq, be, be_link);
+ be->be_tid = 0;
be->be_status = BST_FREE;
be->be_req = NULL;
TAILQ_INSERT_TAIL(&bc->bc_freeq, be, be_link);
-
- bc->bc_req_count--;
- return (0);
+ bc->bc_req_count--;
}
static void
@@ -163,6 +194,8 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be)
break;
}
+ be->be_status = BST_DONE;
+
(*br->br_callback)(br, err);
}
@@ -170,16 +203,17 @@ static void *
blockif_thr(void *arg)
{
struct blockif_ctxt *bc;
- struct blockif_elem req;
+ struct blockif_elem *be;
bc = arg;
for (;;) {
pthread_mutex_lock(&bc->bc_mtx);
- while (!blockif_dequeue(bc, &req)) {
+ while (!blockif_dequeue(bc, &be)) {
pthread_mutex_unlock(&bc->bc_mtx);
- blockif_proc(bc, &req);
+ blockif_proc(bc, be);
pthread_mutex_lock(&bc->bc_mtx);
+ blockif_complete(bc, be);
}
pthread_cond_wait(&bc->bc_cond, &bc->bc_mtx);
pthread_mutex_unlock(&bc->bc_mtx);
@@ -195,6 +229,38 @@ blockif_thr(void *arg)
return (NULL);
}
+static void
+blockif_sigcont_handler(int signal, enum ev_type type, void *arg)
+{
+ struct blockif_sig_elem *bse;
+
+ for (;;) {
+ /*
+ * Process the entire list even if not intended for
+ * this thread.
+ */
+ do {
+ bse = blockif_bse_head;
+ if (bse == NULL)
+ return;
+ } while (!atomic_cmpset_ptr((uintptr_t *)&blockif_bse_head,
+ (uintptr_t)bse,
+ (uintptr_t)bse->bse_next));
+
+ pthread_mutex_lock(&bse->bse_mtx);
+ bse->bse_pending = 0;
+ pthread_cond_signal(&bse->bse_cond);
+ pthread_mutex_unlock(&bse->bse_mtx);
+ }
+}
+
+static void
+blockif_init(void)
+{
+ mevent_add(SIGCONT, EVF_SIGNAL, blockif_sigcont_handler, NULL);
+ (void) signal(SIGCONT, SIG_IGN);
+}
+
struct blockif_ctxt *
blockif_open(const char *optstr, const char *ident)
{
@@ -206,6 +272,8 @@ blockif_open(const char *optstr, const char *ident)
int extra, fd, i, sectsz;
int nocache, sync, ro;
+ pthread_once(&blockif_once, blockif_init);
+
nocache = 0;
sync = 0;
ro = 0;
@@ -280,7 +348,8 @@ blockif_open(const char *optstr, const char *ident)
pthread_mutex_init(&bc->bc_mtx, NULL);
pthread_cond_init(&bc->bc_cond, NULL);
TAILQ_INIT(&bc->bc_freeq);
- TAILQ_INIT(&bc->bc_inuseq);
+ TAILQ_INIT(&bc->bc_pendq);
+ TAILQ_INIT(&bc->bc_busyq);
bc->bc_req_count = 0;
for (i = 0; i < BLOCKIF_MAXREQ; i++) {
bc->bc_reqs[i].be_status = BST_FREE;
@@ -357,23 +426,76 @@ blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
assert(bc->bc_magic == BLOCKIF_SIG);
pthread_mutex_lock(&bc->bc_mtx);
- TAILQ_FOREACH(be, &bc->bc_inuseq, be_link) {
+ /*
+ * Check pending requests.
+ */
+ TAILQ_FOREACH(be, &bc->bc_pendq, be_link) {
+ if (be->be_req == breq)
+ break;
+ }
+ if (be != NULL) {
+ /*
+ * Found it.
+ */
+ TAILQ_REMOVE(&bc->bc_pendq, be, be_link);
+ be->be_status = BST_FREE;
+ be->be_req = NULL;
+ TAILQ_INSERT_TAIL(&bc->bc_freeq, be, be_link);
+ bc->bc_req_count--;
+ pthread_mutex_unlock(&bc->bc_mtx);
+
+ return (0);
+ }
+
+ /*
+ * Check in-flight requests.
+ */
+ TAILQ_FOREACH(be, &bc->bc_busyq, be_link) {
if (be->be_req == breq)
break;
}
if (be == NULL) {
+ /*
+ * Didn't find it.
+ */
pthread_mutex_unlock(&bc->bc_mtx);
return (EINVAL);
}
- TAILQ_REMOVE(&bc->bc_inuseq, be, be_link);
- be->be_status = BST_FREE;
- be->be_req = NULL;
- TAILQ_INSERT_TAIL(&bc->bc_freeq, be, be_link);
- bc->bc_req_count--;
+ /*
+ * Interrupt the processing thread to force it return
+ * prematurely via it's normal callback path.
+ */
+ while (be->be_status == BST_BUSY) {
+ struct blockif_sig_elem bse, *old_head;
+
+ pthread_mutex_init(&bse.bse_mtx, NULL);
+ pthread_cond_init(&bse.bse_cond, NULL);
+
+ bse.bse_pending = 1;
+
+ do {
+ old_head = blockif_bse_head;
+ bse.bse_next = old_head;
+ } while (!atomic_cmpset_ptr((uintptr_t *)&blockif_bse_head,
+ (uintptr_t)old_head,
+ (uintptr_t)&bse));
+
+ pthread_kill(be->be_tid, SIGCONT);
+
+ pthread_mutex_lock(&bse.bse_mtx);
+ while (bse.bse_pending)
+ pthread_cond_wait(&bse.bse_cond, &bse.bse_mtx);
+ pthread_mutex_unlock(&bse.bse_mtx);
+ }
+
pthread_mutex_unlock(&bc->bc_mtx);
- return (0);
+ /*
+ * The processing thread has been interrupted. Since it's not
+ * clear if the callback has been invoked yet, return EBUSY.
+ */
+ return (EBUSY);
}
int
@@ -478,7 +600,7 @@ blockif_queuesz(struct blockif_ctxt *bc)
{
assert(bc->bc_magic == BLOCKIF_SIG);
- return (BLOCKIF_MAXREQ);
+ return (BLOCKIF_MAXREQ - 1);
}
int
diff --git a/usr.sbin/bhyve/pci_ahci.c b/usr.sbin/bhyve/pci_ahci.c
index 42aa0b3..ab40854 100644
--- a/usr.sbin/bhyve/pci_ahci.c
+++ b/usr.sbin/bhyve/pci_ahci.c
@@ -367,11 +367,15 @@ ahci_check_stopped(struct ahci_port *p)
{
/*
* If we are no longer processing the command list and nothing
- * is in-flight, clear the running bit.
+ * is in-flight, clear the running bit, the current command
+ * slot, the command issue and active bits.
*/
if (!(p->cmd & AHCI_P_CMD_ST)) {
- if (p->pending == 0)
+ if (p->pending == 0) {
p->cmd &= ~(AHCI_P_CMD_CR | AHCI_P_CMD_CCS_MASK);
+ p->ci = 0;
+ p->sact = 0;
+ }
}
}
diff --git a/usr.sbin/bhyve/pmtmr.c b/usr.sbin/bhyve/pmtmr.c
deleted file mode 100644
index 3a46f9b..0000000
--- a/usr.sbin/bhyve/pmtmr.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*-
- * Copyright (c) 2012 NetApp, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#include <sys/time.h>
-#include <machine/cpufunc.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <assert.h>
-#include <pthread.h>
-
-#include "acpi.h"
-#include "inout.h"
-
-/*
- * The ACPI Power Management timer is a free-running 24- or 32-bit
- * timer with a frequency of 3.579545MHz
- *
- * This implementation will be 32-bits
- */
-
-#define PMTMR_FREQ 3579545 /* 3.579545MHz */
-
-static pthread_mutex_t pmtmr_mtx;
-static pthread_once_t pmtmr_once = PTHREAD_ONCE_INIT;
-
-static uint64_t pmtmr_old;
-
-static uint64_t pmtmr_tscf;
-static uint64_t pmtmr_tsc_old;
-
-static clockid_t clockid = CLOCK_UPTIME_FAST;
-static struct timespec pmtmr_uptime_old;
-
-#define timespecsub(vvp, uvp) \
- do { \
- (vvp)->tv_sec -= (uvp)->tv_sec; \
- (vvp)->tv_nsec -= (uvp)->tv_nsec; \
- if ((vvp)->tv_nsec < 0) { \
- (vvp)->tv_sec--; \
- (vvp)->tv_nsec += 1000000000; \
- } \
- } while (0)
-
-static uint64_t
-timespec_to_pmtmr(const struct timespec *tsnew, const struct timespec *tsold)
-{
- struct timespec tsdiff;
- int64_t nsecs;
-
- tsdiff = *tsnew;
- timespecsub(&tsdiff, tsold);
- nsecs = tsdiff.tv_sec * 1000000000 + tsdiff.tv_nsec;
- assert(nsecs >= 0);
-
- return (nsecs * PMTMR_FREQ / 1000000000 + pmtmr_old);
-}
-
-static uint64_t
-tsc_to_pmtmr(uint64_t tsc_new, uint64_t tsc_old)
-{
-
- return ((tsc_new - tsc_old) * PMTMR_FREQ / pmtmr_tscf + pmtmr_old);
-}
-
-static void
-pmtmr_init(void)
-{
- size_t len;
- int smp_tsc, err;
- struct timespec tsnew, tsold = { 0 };
-
- len = sizeof(smp_tsc);
- err = sysctlbyname("kern.timecounter.smp_tsc", &smp_tsc, &len, NULL, 0);
- assert(err == 0);
-
- if (smp_tsc) {
- len = sizeof(pmtmr_tscf);
- err = sysctlbyname("machdep.tsc_freq", &pmtmr_tscf, &len,
- NULL, 0);
- assert(err == 0);
-
- pmtmr_tsc_old = rdtsc();
- pmtmr_old = tsc_to_pmtmr(pmtmr_tsc_old, 0);
- } else {
- if (getenv("BHYVE_PMTMR_PRECISE") != NULL)
- clockid = CLOCK_UPTIME;
-
- err = clock_gettime(clockid, &tsnew);
- assert(err == 0);
-
- pmtmr_uptime_old = tsnew;
- pmtmr_old = timespec_to_pmtmr(&tsnew, &tsold);
- }
- pthread_mutex_init(&pmtmr_mtx, NULL);
-}
-
-static uint32_t
-pmtmr_val(void)
-{
- struct timespec tsnew;
- uint64_t pmtmr_tsc_new;
- uint64_t pmtmr_new;
- int error;
-
- pthread_once(&pmtmr_once, pmtmr_init);
-
- pthread_mutex_lock(&pmtmr_mtx);
-
- if (pmtmr_tscf) {
- pmtmr_tsc_new = rdtsc();
- pmtmr_new = tsc_to_pmtmr(pmtmr_tsc_new, pmtmr_tsc_old);
- pmtmr_tsc_old = pmtmr_tsc_new;
- } else {
- error = clock_gettime(clockid, &tsnew);
- assert(error == 0);
-
- pmtmr_new = timespec_to_pmtmr(&tsnew, &pmtmr_uptime_old);
- pmtmr_uptime_old = tsnew;
- }
- pmtmr_old = pmtmr_new;
-
- pthread_mutex_unlock(&pmtmr_mtx);
-
- return (pmtmr_new);
-}
-
-static int
-pmtmr_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
- uint32_t *eax, void *arg)
-{
- assert(in == 1);
-
- if (bytes != 4)
- return (-1);
-
- *eax = pmtmr_val();
-
- return (0);
-}
-
-INOUT_PORT(pmtmr, IO_PMTMR, IOPORT_F_IN, pmtmr_handler);
diff --git a/usr.sbin/bhyve/rtc.c b/usr.sbin/bhyve/rtc.c
index b3631fc..459c900 100644
--- a/usr.sbin/bhyve/rtc.c
+++ b/usr.sbin/bhyve/rtc.c
@@ -375,4 +375,8 @@ rtc_dsdt(void)
}
LPC_DSDT(rtc_dsdt);
+/*
+ * Reserve the extended RTC I/O ports although they are not emulated at this
+ * time.
+ */
SYSRES_IO(0x72, 6);
OpenPOWER on IntegriCloud