From owner-svn-soc-all@freebsd.org Mon Aug 1 11:22:37 2016 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 DE45FBA3149 for ; Mon, 1 Aug 2016 11:22:37 +0000 (UTC) (envelope-from vincenzo@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 D1CF019E5 for ; Mon, 1 Aug 2016 11:22:37 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u71BMbRj063993 for ; Mon, 1 Aug 2016 11:22:37 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u71BMbg2063939 for svn-soc-all@FreeBSD.org; Mon, 1 Aug 2016 11:22:37 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 1 Aug 2016 11:22:37 GMT Message-Id: <201608011122.u71BMbg2063939@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to vincenzo@FreeBSD.org using -f From: vincenzo@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r307057 - soc2016/vincenzo/head/sys/amd64/vmm 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.22 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: Mon, 01 Aug 2016 11:22:38 -0000 Author: vincenzo Date: Mon Aug 1 11:22:36 2016 New Revision: 307057 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=307057 Log: vmm: ioregh: use sx lock in place of spin lock Modified: soc2016/vincenzo/head/sys/amd64/vmm/vmm_ioport.c Modified: soc2016/vincenzo/head/sys/amd64/vmm/vmm_ioport.c ============================================================================== --- soc2016/vincenzo/head/sys/amd64/vmm/vmm_ioport.c Mon Aug 1 11:21:15 2016 (r307056) +++ soc2016/vincenzo/head/sys/amd64/vmm/vmm_ioport.c Mon Aug 1 11:22:36 2016 (r307057) @@ -99,17 +99,15 @@ #ifdef VMM_IOPORT_REG_HANDLER #include +#include #include +#include #include -#include #include static MALLOC_DEFINE(M_IOREGH, "ioregh", "bhyve ioport reg handlers"); -#define IOREGH_LOCK(ioregh) mtx_lock_spin(&((ioregh)->mtx)) -#define IOREGH_UNLOCK(ioregh) mtx_unlock_spin(&((ioregh)->mtx)) - -#define IOPORT_MAX_REG_HANDLER 12 +#define IOPORT_MAX_REG_HANDLER 16 /* * ioport_reg_handler functions allows us to to catch VM write/read @@ -134,8 +132,8 @@ }; struct ioregh { - struct mtx mtx; - /* TODO: use hash table is better */ + struct sx lock; + /* TODO: use hash table */ struct ioport_reg_handler handlers[IOPORT_MAX_REG_HANDLER]; }; @@ -161,7 +159,7 @@ * - VM_IO_REGH_IOCTL: ioctl on fd */ -/* call with ioregh->mtx held */ +/* call with ioregh->lock held */ static struct ioport_reg_handler * vmm_ioport_find_handler(struct ioregh *ioregh, uint16_t port, uint16_t in, uint32_t mask_data, uint32_t data) @@ -184,7 +182,7 @@ return (NULL); } -/* call with ioregh->mtx held */ +/* call with ioregh->lock held */ static struct ioport_reg_handler * vmm_ioport_empty_handler(struct ioregh *ioregh) { @@ -212,7 +210,7 @@ ioregh = vm_ioregh(vm); - IOREGH_LOCK(ioregh); + sx_xlock(&ioregh->lock); regh = vmm_ioport_find_handler(ioregh, port, in, mask_data, data); if (regh != NULL) { @@ -238,7 +236,7 @@ regh->handler_arg = handler_arg; err: - IOREGH_UNLOCK(ioregh); + sx_xunlock(&ioregh->lock); return (ret); } @@ -252,7 +250,7 @@ ioregh = vm_ioregh(vm); - IOREGH_LOCK(ioregh); + sx_xlock(&ioregh->lock); regh = vmm_ioport_find_handler(ioregh, port, in, mask_data, data); @@ -263,7 +261,7 @@ bzero(regh, sizeof(struct ioport_reg_handler)); err: - IOREGH_UNLOCK(ioregh); + sx_xunlock(&ioregh->lock); return (ret); } @@ -298,7 +296,7 @@ */ static int invoke_reg_handler(struct vm *vm, int vcpuid, struct vm_exit *vmexit, - uint32_t *val, int *error) + uint32_t *val, int *error) { struct ioport_reg_handler *regh; struct ioregh *ioregh; @@ -307,16 +305,14 @@ mask_data = vie_size2mask(vmexit->u.inout.bytes); ioregh = vm_ioregh(vm); - IOREGH_LOCK(ioregh); + sx_slock(&ioregh->lock); regh = vmm_ioport_find_handler(ioregh, vmexit->u.inout.port, vmexit->u.inout.in, mask_data, vmexit->u.inout.eax); - if (regh == NULL) { - IOREGH_UNLOCK(ioregh); - return (0); + if (regh != NULL) { + *error = (*(regh->handler))(vm, regh, val); } - *error = (*(regh->handler))(vm, regh, val); - IOREGH_UNLOCK(ioregh); - return (1); + sx_sunlock(&ioregh->lock); + return (regh != NULL); } struct ioregh * @@ -325,8 +321,7 @@ struct ioregh *ioregh; ioregh = malloc(sizeof(struct ioregh), M_IOREGH, M_WAITOK | M_ZERO); - - mtx_init(&ioregh->mtx, "ioregh lock", NULL, MTX_SPIN); + sx_init(&ioregh->lock, "ioregh lock"); return (ioregh); } @@ -334,6 +329,7 @@ void ioregh_cleanup(struct ioregh *ioregh) { + sx_destroy(&ioregh->lock); free(ioregh, M_IOREGH); } #else /* !VMM_IOPORT_REG_HANDLER */