From 5dab6f9ed3816204ff73fd075abfaba1ed5c7673 Mon Sep 17 00:00:00 2001 From: neel Date: Thu, 19 Dec 2013 22:27:28 +0000 Subject: [PATCH] Add an option to ignore accesses by the guest to unimplemented MSRs. Also, ignore a couple of SandyBridge uncore PMC MSRs that Centos 6.4 writes to during boot. Reviewed by: grehan --- usr.sbin/bhyve/bhyve.8 | 4 +++- usr.sbin/bhyve/bhyverun.c | 50 ++++++++++++++++++++++++++++++--------- usr.sbin/bhyve/xmsr.c | 17 +++++++++++-- usr.sbin/bhyve/xmsr.h | 1 + 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index b83211a67f27..8e817cfcab36 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 aehAHPW +.Op Fl aehwAHPW .Op Fl c Ar numcpus .Op Fl g Ar gdbport .Op Fl p Ar pinnedcpu @@ -229,6 +229,8 @@ Force .Nm to exit when a guest issues an access to an I/O port that is not emulated. This is intended for debug purposes. +.It Fl w +Ignore accesses to unimplemented Model Specific Registers (MSRs). This is intended for debug purposes. .It Fl h Print help message and exit. .It Ar vmname diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 0ea2904b6f3c..7afac4938ef6 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -87,6 +87,7 @@ static int guest_vmexit_on_hlt, guest_vmexit_on_pause, disable_x2apic; static int virtio_msix = 1; static int strictio; +static int strictmsr = 1; static int acpi; @@ -122,7 +123,7 @@ usage(int code) { fprintf(stderr, - "Usage: %s [-aehAHIPW] [-g ] [-s ] [-S ]\n" + "Usage: %s [-aehwAHIPW] [-g ] [-s ] [-S ]\n" " %*s [-c vcpus] [-p pincpu] [-m mem] [-l ] \n" " -a: local apic is in XAPIC mode (default is X2APIC)\n" " -A: create an ACPI table\n" @@ -137,7 +138,8 @@ usage(int code) " -s: PCI slot config\n" " -S: legacy PCI slot config\n" " -l: LPC device configuration\n" - " -m: memory size in MB\n", + " -m: memory size in MB\n" + " -w: ignore unimplemented MSRs\n", progname, (int)strlen(progname), ""); exit(code); @@ -310,20 +312,43 @@ vmexit_inout(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) static int vmexit_rdmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) { - fprintf(stderr, "vm exit rdmsr 0x%x, cpu %d\n", vme->u.msr.code, - *pvcpu); - return (VMEXIT_ABORT); + uint64_t val; + uint32_t eax, edx; + int error; + + val = 0; + error = emulate_rdmsr(ctx, *pvcpu, vme->u.msr.code, &val); + if (error != 0) { + fprintf(stderr, "rdmsr to register %#x on vcpu %d\n", + vme->u.msr.code, *pvcpu); + if (strictmsr) + return (VMEXIT_ABORT); + } + + eax = val; + error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RAX, eax); + assert(error == 0); + + edx = val >> 32; + error = vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RDX, edx); + assert(error == 0); + + return (VMEXIT_CONTINUE); } static int vmexit_wrmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) { - int newcpu; - int retval = VMEXIT_CONTINUE; + int error; - newcpu = emulate_wrmsr(ctx, *pvcpu, vme->u.msr.code,vme->u.msr.wval); - - return (retval); + error = emulate_wrmsr(ctx, *pvcpu, vme->u.msr.code, vme->u.msr.wval); + if (error != 0) { + fprintf(stderr, "wrmsr to register %#x(%#lx) on vcpu %d\n", + vme->u.msr.code, vme->u.msr.wval, *pvcpu); + if (strictmsr) + return (VMEXIT_ABORT); + } + return (VMEXIT_CONTINUE); } static int @@ -577,7 +602,7 @@ main(int argc, char *argv[]) guest_ncpus = 1; memsize = 256 * MB; - while ((c = getopt(argc, argv, "abehAHIPWp:g:c:s:S:m:l:")) != -1) { + while ((c = getopt(argc, argv, "abehwAHIPWp:g:c:s:S:m:l:")) != -1) { switch (c) { case 'a': disable_x2apic = 1; @@ -636,6 +661,9 @@ main(int argc, char *argv[]) case 'e': strictio = 1; break; + case 'w': + strictmsr = 0; + break; case 'W': virtio_msix = 0; break; diff --git a/usr.sbin/bhyve/xmsr.c b/usr.sbin/bhyve/xmsr.c index 9c05f0230c9b..ba94125a0900 100644 --- a/usr.sbin/bhyve/xmsr.c +++ b/usr.sbin/bhyve/xmsr.c @@ -43,6 +43,19 @@ int emulate_wrmsr(struct vmctx *ctx, int vcpu, uint32_t code, uint64_t val) { - printf("Unknown WRMSR code %x, val %lx, cpu %d\n", code, val, vcpu); - exit(1); + switch (code) { + case 0xd04: /* Sandy Bridge uncore PMC MSRs */ + case 0xc24: + return (0); + default: + break; + } + return (-1); +} + +int +emulate_rdmsr(struct vmctx *ctx, int vcpu, uint32_t code, uint64_t *val) +{ + + return (-1); } diff --git a/usr.sbin/bhyve/xmsr.h b/usr.sbin/bhyve/xmsr.h index 8cebcea0cd55..b097cf885357 100644 --- a/usr.sbin/bhyve/xmsr.h +++ b/usr.sbin/bhyve/xmsr.h @@ -30,5 +30,6 @@ #define _XMSR_H_ int emulate_wrmsr(struct vmctx *ctx, int vcpu, uint32_t code, uint64_t val); +int emulate_rdmsr(struct vmctx *ctx, int vcpu, uint32_t code, uint64_t *val); #endif