diff options
author | jhb <jhb@FreeBSD.org> | 2014-07-21 19:08:02 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2014-07-21 19:08:02 +0000 |
commit | e6b48465b7c368666e10a2bd8f4f500483497b24 (patch) | |
tree | 7e529f938e1d777df1f54045191fa3003056dbda /usr.sbin | |
parent | b164bf591711a4c455ca47e1f58b0bb91e5e904c (diff) | |
download | FreeBSD-src-e6b48465b7c368666e10a2bd8f4f500483497b24.zip FreeBSD-src-e6b48465b7c368666e10a2bd8f4f500483497b24.tar.gz |
MFC 264353,264509,264768,264770,264825,264846,264988,265114,265165,265365,
265941,265951,266390,266550,266910:
Various bhyve fixes:
- Don't save host's return address in 'struct vmxctx'.
- Permit non-32-bit accesses to local APIC registers.
- Factor out common ioport handler code.
- Use calloc() in favor of malloc + memset.
- Change the vlapic timer frequency to be in the ballpark of contemporary
hardware.
- Allow the guest to read the TSC via MSR 0x10.
- A VMCS is always inactive when it exits the vmx_run() loop. Remove
redundant code and the misleading comment that suggest otherwise.
- Ignore writes to microcode update MSR. This MSR is accessed by RHEL7
guest.
Add KTR tracepoints to annotate wrmsr and rdmsr VM exits.
- Provide an alias for the userboot console and name it 'comconsole'.
- Use EV_ADD to create an mevent and EV_ENABLE to enable it.
- abort(3) the process in response to a VMEXIT_ABORT.
- Don't include the guest memory segments in the bhyve(8) process core dump.
- Make the vmx asm code dtrace-fbt-friendly.
- Allow vmx_getdesc() and vmx_setdesc() to be called for a vcpu that is in
the VCPU_RUNNING state.
- Enable VMX in the IA32_FEATURE_CONTROL MSR if it not enabled and the MSR
isn't locked.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bhyve/bhyve.8 | 4 | ||||
-rw-r--r-- | usr.sbin/bhyve/bhyverun.c | 22 | ||||
-rw-r--r-- | usr.sbin/bhyve/block_if.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/inout.c | 34 | ||||
-rw-r--r-- | usr.sbin/bhyve/mevent.c | 22 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_ahci.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_emul.c | 9 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_passthru.c | 6 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_virtio_block.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_virtio_net.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_virtio_rnd.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/uart_emul.c | 3 | ||||
-rw-r--r-- | usr.sbin/bhyve/xmsr.c | 2 |
13 files changed, 53 insertions, 64 deletions
diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index 2d2d396..aad1aef 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -32,7 +32,7 @@ .Nd "run a guest operating system inside a virtual machine" .Sh SYNOPSIS .Nm -.Op Fl aehwxAHPW +.Op Fl aehwxACHPW .Op Fl c Ar numcpus .Op Fl g Ar gdbport .Op Fl p Ar vcpu:hostcpu @@ -69,6 +69,8 @@ guests. .It Fl c Ar numcpus Number of guest virtual CPUs. The default is 1 and the maximum is 16. +.It Fl C +Include guest memory in core file. .It Fl H Yield the virtual CPU thread when a HLT instruction is detected. If this option is not specified, virtual CPUs will use 100% of a host CPU. diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index e662ca3..b2354c9 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -68,7 +68,6 @@ __FBSDID("$FreeBSD$"); #define GUEST_NIO_PORT 0x488 /* guest upcalls via i/o port */ -#define VMEXIT_SWITCH 0 /* force vcpu switch in mux mode */ #define VMEXIT_CONTINUE 1 /* continue from next instruction */ #define VMEXIT_RESTART 2 /* restart current instruction */ #define VMEXIT_ABORT 3 /* abort the vm run loop */ @@ -135,6 +134,7 @@ usage(int code) " -A: create an ACPI table\n" " -g: gdb port\n" " -c: # cpus (default 1)\n" + " -C: include guest memory in core file\n" " -p: pin 'vcpu' to 'hostcpu'\n" " -H: vmexit from the guest on hlt\n" " -P: vmexit from the guest on pause\n" @@ -272,12 +272,6 @@ fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) } static int -vmexit_catch_inout(void) -{ - return (VMEXIT_ABORT); -} - -static int vmexit_handle_notify(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu, uint32_t eax) { @@ -330,7 +324,7 @@ vmexit_inout(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) fprintf(stderr, "Unhandled %s%c 0x%04x\n", in ? "in" : "out", bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'), port); - return (vmexit_catch_inout()); + return (VMEXIT_ABORT); } } @@ -575,6 +569,8 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) assert(error == 0 || errno == EALREADY); rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length; break; + case VMEXIT_ABORT: + abort(); default: exit(1); } @@ -647,19 +643,20 @@ int main(int argc, char *argv[]) { int c, error, gdb_port, err, bvmcons; - int max_vcpus, mptgen; + int dump_guest_memory, max_vcpus, mptgen; struct vmctx *ctx; uint64_t rip; size_t memsize; bvmcons = 0; + dump_guest_memory = 0; progname = basename(argv[0]); gdb_port = 0; guest_ncpus = 1; memsize = 256 * MB; mptgen = 1; - while ((c = getopt(argc, argv, "abehwxAHIPWYp:g:c:s:m:l:U:")) != -1) { + while ((c = getopt(argc, argv, "abehwxACHIPWYp:g:c:s:m:l:U:")) != -1) { switch (c) { case 'a': x2apic_mode = 0; @@ -679,6 +676,9 @@ main(int argc, char *argv[]) case 'c': guest_ncpus = atoi(optarg); break; + case 'C': + dump_guest_memory = 1; + break; case 'g': gdb_port = atoi(optarg); break; @@ -760,6 +760,8 @@ main(int argc, char *argv[]) fbsdrun_set_capabilities(ctx, BSP); + if (dump_guest_memory) + vm_set_memflags(ctx, VM_MEM_F_INCORE); err = vm_setup_memory(ctx, memsize, VM_MMAP_ALL); if (err) { fprintf(stderr, "Unable to setup memory (%d)\n", err); diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c index ffa343c..b29bc78 100644 --- a/usr.sbin/bhyve/block_if.c +++ b/usr.sbin/bhyve/block_if.c @@ -270,13 +270,12 @@ blockif_open(const char *optstr, const char *ident) assert(sectsz != 0); } - bc = malloc(sizeof(struct blockif_ctxt)); + bc = calloc(1, sizeof(struct blockif_ctxt)); if (bc == NULL) { close(fd); return (NULL); } - memset(bc, 0, sizeof(*bc)); bc->bc_magic = BLOCKIF_SIG; bc->bc_fd = fd; bc->bc_size = size; diff --git a/usr.sbin/bhyve/inout.c b/usr.sbin/bhyve/inout.c index 9fec70a..5fbe99b 100644 --- a/usr.sbin/bhyve/inout.c +++ b/usr.sbin/bhyve/inout.c @@ -107,18 +107,19 @@ emulate_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes, if (strict && handler == default_inout) return (-1); + switch (bytes) { + case 1: + mask = 0xff; + break; + case 2: + mask = 0xffff; + break; + default: + mask = 0xffffffff; + break; + } + if (!in) { - switch (bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } val = *eax & mask; } @@ -131,17 +132,6 @@ emulate_inout(struct vmctx *ctx, int vcpu, int in, int port, int bytes, error = -1; if (!error && in) { - switch (bytes) { - case 1: - mask = 0xff; - break; - case 2: - mask = 0xffff; - break; - default: - mask = 0xffffffff; - break; - } *eax &= ~mask; *eax |= val & mask; } diff --git a/usr.sbin/bhyve/mevent.c b/usr.sbin/bhyve/mevent.c index 82faab2..07d3baf 100644 --- a/usr.sbin/bhyve/mevent.c +++ b/usr.sbin/bhyve/mevent.c @@ -52,9 +52,10 @@ __FBSDID("$FreeBSD$"); #define MEVENT_MAX 64 -#define MEV_ENABLE 1 -#define MEV_DISABLE 2 -#define MEV_DEL_PENDING 3 +#define MEV_ADD 1 +#define MEV_ENABLE 2 +#define MEV_DISABLE 3 +#define MEV_DEL_PENDING 4 extern char *vmname; @@ -147,10 +148,11 @@ mevent_kq_flags(struct mevent *mevp) int ret; switch (mevp->me_state) { + case MEV_ADD: + ret = EV_ADD; /* implicitly enabled */ + break; case MEV_ENABLE: - ret = EV_ADD; - if (mevp->me_type == EVF_TIMER) - ret |= EV_ENABLE; + ret = EV_ENABLE; break; case MEV_DISABLE: ret = EV_DISABLE; @@ -158,6 +160,9 @@ mevent_kq_flags(struct mevent *mevp) case MEV_DEL_PENDING: ret = EV_DELETE; break; + default: + assert(0); + break; } return (ret); @@ -268,12 +273,11 @@ mevent_add(int tfd, enum ev_type type, /* * Allocate an entry, populate it, and add it to the change list. */ - mevp = malloc(sizeof(struct mevent)); + mevp = calloc(1, sizeof(struct mevent)); if (mevp == NULL) { goto exit; } - memset(mevp, 0, sizeof(struct mevent)); if (type == EVF_TIMER) { mevp->me_msecs = tfd; mevp->me_timid = mevent_timid++; @@ -285,7 +289,7 @@ mevent_add(int tfd, enum ev_type type, LIST_INSERT_HEAD(&change_head, mevp, me_list); mevp->me_cq = 1; - mevp->me_state = MEV_ENABLE; + mevp->me_state = MEV_ADD; mevent_notify(); exit: diff --git a/usr.sbin/bhyve/pci_ahci.c b/usr.sbin/bhyve/pci_ahci.c index dd9bfb9..9f61107 100644 --- a/usr.sbin/bhyve/pci_ahci.c +++ b/usr.sbin/bhyve/pci_ahci.c @@ -1786,8 +1786,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts, int atapi) dbg = fopen("/tmp/log", "w+"); #endif - sc = malloc(sizeof(struct pci_ahci_softc)); - memset(sc, 0, sizeof(struct pci_ahci_softc)); + sc = calloc(1, sizeof(struct pci_ahci_softc)); pi->pi_arg = sc; sc->asc_pi = pi; sc->ports = MAX_PORTS; diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index 8fd19ac..5455f40 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -705,8 +705,7 @@ pci_emul_init(struct vmctx *ctx, struct pci_devemu *pde, int bus, int slot, struct pci_devinst *pdi; int err; - pdi = malloc(sizeof(struct pci_devinst)); - bzero(pdi, sizeof(*pdi)); + pdi = calloc(1, sizeof(struct pci_devinst)); pdi->pi_vmctx = ctx; pdi->pi_bus = bus; @@ -798,8 +797,7 @@ pci_msix_table_init(struct pci_devinst *pi, int table_entries) assert(table_entries <= MAX_MSIX_TABLE_ENTRIES); table_size = table_entries * MSIX_TABLE_ENTRY_SIZE; - pi->pi_msix.table = malloc(table_size); - bzero(pi->pi_msix.table, table_size); + pi->pi_msix.table = calloc(1, table_size); /* set mask bit of vector control register */ for (i = 0; i < table_entries; i++) @@ -1809,8 +1807,7 @@ pci_emul_dinit(struct vmctx *ctx, struct pci_devinst *pi, char *opts) int error; struct pci_emul_dsoftc *sc; - sc = malloc(sizeof(struct pci_emul_dsoftc)); - memset(sc, 0, sizeof(struct pci_emul_dsoftc)); + sc = calloc(1, sizeof(struct pci_emul_dsoftc)); pi->pi_arg = sc; diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 562d532..04d68c4 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -232,8 +232,7 @@ cfginitmsi(struct passthru_softc *sc) /* Allocate the emulated MSI-X table array */ table_size = pi->pi_msix.table_count * MSIX_TABLE_ENTRY_SIZE; - pi->pi_msix.table = malloc(table_size); - bzero(pi->pi_msix.table, table_size); + pi->pi_msix.table = calloc(1, table_size); /* Mask all table entries */ for (i = 0; i < pi->pi_msix.table_count; i++) { @@ -574,8 +573,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) if (vm_assign_pptdev(ctx, bus, slot, func) != 0) goto done; - sc = malloc(sizeof(struct passthru_softc)); - memset(sc, 0, sizeof(struct passthru_softc)); + sc = calloc(1, sizeof(struct passthru_softc)); pi->pi_arg = sc; sc->psc_pi = pi; diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 2f37804..3474fd7 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -299,8 +299,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) assert(sectsz != 0); } - sc = malloc(sizeof(struct pci_vtblk_softc)); - memset(sc, 0, sizeof(struct pci_vtblk_softc)); + sc = calloc(1, sizeof(struct pci_vtblk_softc)); /* record fd of storage device/file */ sc->vbsc_fd = fd; diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c index e7b54bc..c3b8690 100644 --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -513,8 +513,7 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) char *vtopts; int mac_provided; - sc = malloc(sizeof(struct pci_vtnet_softc)); - memset(sc, 0, sizeof(struct pci_vtnet_softc)); + sc = calloc(1, sizeof(struct pci_vtnet_softc)); pthread_mutex_init(&sc->vsc_mtx, NULL); diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c index 38459d2..4d53183 100644 --- a/usr.sbin/bhyve/pci_virtio_rnd.c +++ b/usr.sbin/bhyve/pci_virtio_rnd.c @@ -155,8 +155,7 @@ pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) return (1); } - sc = malloc(sizeof(struct pci_vtrnd_softc)); - memset(sc, 0, sizeof(struct pci_vtrnd_softc)); + sc = calloc(1, sizeof(struct pci_vtrnd_softc)); vi_softc_linkup(&sc->vrsc_vs, &vtrnd_vi_consts, sc, pi, &sc->vrsc_vq); sc->vrsc_vs.vs_mtx = &sc->vrsc_mtx; diff --git a/usr.sbin/bhyve/uart_emul.c b/usr.sbin/bhyve/uart_emul.c index ae4cab3..4242e5c 100644 --- a/usr.sbin/bhyve/uart_emul.c +++ b/usr.sbin/bhyve/uart_emul.c @@ -594,8 +594,7 @@ uart_init(uart_intr_func_t intr_assert, uart_intr_func_t intr_deassert, { struct uart_softc *sc; - sc = malloc(sizeof(struct uart_softc)); - bzero(sc, sizeof(struct uart_softc)); + sc = calloc(1, sizeof(struct uart_softc)); sc->arg = arg; sc->intr_assert = intr_assert; diff --git a/usr.sbin/bhyve/xmsr.c b/usr.sbin/bhyve/xmsr.c index ba94125..63522bf 100644 --- a/usr.sbin/bhyve/xmsr.c +++ b/usr.sbin/bhyve/xmsr.c @@ -47,6 +47,8 @@ emulate_wrmsr(struct vmctx *ctx, int vcpu, uint32_t code, uint64_t val) case 0xd04: /* Sandy Bridge uncore PMC MSRs */ case 0xc24: return (0); + case 0x79: + return (0); /* IA32_BIOS_UPDT_TRIG MSR */ default: break; } |