From owner-svn-soc-all@freebsd.org Thu Jul 23 17:57:54 2015 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CFD959A9E39 for ; Thu, 23 Jul 2015 17:57:54 +0000 (UTC) (envelope-from mihai@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B24CB1924 for ; Thu, 23 Jul 2015 17:57:54 +0000 (UTC) (envelope-from mihai@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id t6NHvsfG037056 for ; Thu, 23 Jul 2015 17:57:54 GMT (envelope-from mihai@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id t6NHvrZc037041 for svn-soc-all@FreeBSD.org; Thu, 23 Jul 2015 17:57:53 GMT (envelope-from mihai@FreeBSD.org) Date: Thu, 23 Jul 2015 17:57:53 GMT Message-Id: <201507231757.t6NHvrZc037041@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mihai@FreeBSD.org using -f From: mihai@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r288700 - soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2015 17:57:55 -0000 Author: mihai Date: Thu Jul 23 17:57:53 2015 New Revision: 288700 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=288700 Log: soc2015: mihai: bhyve: usr.sbin: bhyvearm: bhyverun.c : added support for instruction emulation Modified: soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/Makefile soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/bhyverun.c Modified: soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/Makefile ============================================================================== --- soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/Makefile Thu Jul 23 17:56:52 2015 (r288699) +++ soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/Makefile Thu Jul 23 17:57:53 2015 (r288700) @@ -6,12 +6,15 @@ DEBUG_FLAGS= -g -O0 -SRCS= bhyverun.c block_if.c mem.c mevent.c +SRCS= bhyverun.c block_if.c mem.c mevent.c consport.c .PATH: ${.CURDIR}/../../sys/arm/vmm NO_MAN= +.PATH: ${.CURDIR}/../../sys/arm/vmm +SRCS+= vmm_instruction_emul.c + DPADD= ${LIBVMMAPIARM} ${LIBMD} ${LIBPTHREAD} LDADD= -lvmmapiarm -lmd -lpthread Modified: soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/bhyverun.c ============================================================================== --- soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/bhyverun.c Thu Jul 23 17:56:52 2015 (r288699) +++ soc2015/mihai/bhyve-on-arm-head/usr.sbin/bhyvearm/bhyverun.c Thu Jul 23 17:57:53 2015 (r288700) @@ -82,14 +82,7 @@ struct bhyvestats { uint64_t vmexit_bogus; - uint64_t vmexit_bogus_switch; - uint64_t vmexit_hlt; - uint64_t vmexit_pause; - uint64_t vmexit_mtrap; - uint64_t vmexit_paging; - uint64_t cpu_switch_rotate; - uint64_t cpu_switch_direct; - int io_reset; + uint64_t vmexit_inst_emul; } stats; struct mt_vmm_info { @@ -103,13 +96,11 @@ { fprintf(stderr, - "Usage: %s [-aehAHIP][-g ][-s ][-S ]" - "[-c vcpus][-p pincpu]" + "Usage: %s [-b] [-c vcpus][-p pincpu]" " \n" + " -b: use bvmconsole" " -c: # cpus (default 1)\n" " -p: pin vcpu 'n' to host cpu 'pincpu + n'\n" - " -H: vmexit from the guest on hlt\n" - " -P: vmexit from the guest on pause\n" " -h: help\n", progname); @@ -203,25 +194,6 @@ } static int -vmexit_catch_reset(void) -{ - stats.io_reset++; - return (VMEXIT_RESET); -} - -static int -vmexit_handle_notify(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu, - uint32_t eax) -{ -#if BHYVE_DEBUG - /* - * put guest-driven debug here - */ -#endif - return (VMEXIT_CONTINUE); -} - -static int vmexit_hyp(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) { @@ -243,67 +215,33 @@ } static int -vmexit_hlt(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) -{ - - stats.vmexit_hlt++; - - /* - * Just continue execution with the next instruction. We use - * the HLT VM exit as a way to be friendly with the host - * scheduler. - */ - return (VMEXIT_CONTINUE); -} - -static int -vmexit_pause(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) -{ - - stats.vmexit_pause++; - - return (VMEXIT_CONTINUE); -} - -static int -vmexit_mtrap(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) -{ - - stats.vmexit_mtrap++; - - return (VMEXIT_RESTART); -} - -static int -vmexit_paging(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) { int err; - stats.vmexit_paging++; + struct vie *vie; + + stats.vmexit_inst_emul++; - err = emulate_mem(ctx, *pvcpu, vmexit->u.paging.gpa, NULL); -// &vmexit->u.paging.vie); + vie = &vmexit->u.inst_emul.vie; + err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa, vie); if (err) { - if (err == EINVAL) { - fprintf(stderr, - "Failed to emulate instruction at 0x%llx\n", - vmexit->pc); - } else if (err == ESRCH) { + if (err == ESRCH) { fprintf(stderr, "Unhandled memory access to 0x%llx\n", - vmexit->u.paging.gpa); + vmexit->u.inst_emul.gpa); } + fprintf(stderr, "Failed to emulate instruction at 0x%llx\n", vmexit->pc); return (VMEXIT_ABORT); } - return (VMEXIT_CONTINUE); } + static vmexit_handler_t handler[VM_EXITCODE_MAX] = { [VM_EXITCODE_HYP] = vmexit_hyp, [VM_EXITCODE_BOGUS] = vmexit_bogus, - [VM_EXITCODE_MTRAP] = vmexit_mtrap, - [VM_EXITCODE_PAGING] = vmexit_paging, + [VM_EXITCODE_INST_EMUL] = vmexit_inst_emul, }; static void @@ -378,18 +316,22 @@ int main(int argc, char *argv[]) { - int c, error, tmp, err; + int c, error, bvmcons; int max_vcpus; struct vmctx *ctx; uint64_t pc; size_t memsize; + bvmcons = 0; progname = basename(argv[0]); guest_ncpus = 1; memsize = 256 * MB; while ((c = getopt(argc, argv, "abehAHIPp:g:c:s:S:m:")) != -1) { switch (c) { + case 'b': + bvmcons = 1; + break; case 'p': pincpu = atoi(optarg); break; @@ -429,33 +371,11 @@ exit(1); } - if (fbsdrun_vmexit_on_hlt()) { - err = vm_get_capability(ctx, BSP, VM_CAP_HALT_EXIT, &tmp); - if (err < 0) { - fprintf(stderr, "VM exit on HLT not supported\n"); - exit(1); - } - vm_set_capability(ctx, BSP, VM_CAP_HALT_EXIT, 1); - handler[VM_EXITCODE_HLT] = vmexit_hlt; - } - - if (fbsdrun_vmexit_on_pause()) { - /* - * pause exit support required for this mode - */ - err = vm_get_capability(ctx, BSP, VM_CAP_PAUSE_EXIT, &tmp); - if (err < 0) { - fprintf(stderr, - "SMP mux requested, no pause support\n"); - exit(1); - } - vm_set_capability(ctx, BSP, VM_CAP_PAUSE_EXIT, 1); - handler[VM_EXITCODE_PAUSE] = vmexit_pause; - } - - init_mem(); + if (bvmcons) + init_bvmcons(); + error = vm_get_register(ctx, BSP, VM_REG_GUEST_PC, &pc); assert(error == 0); printf("%s pc: %llx\n",__func__, pc);