From owner-svn-src-all@FreeBSD.ORG Sun Jun 1 02:13:08 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 18E1C90A; Sun, 1 Jun 2014 02:13:08 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (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 DEA65227E; Sun, 1 Jun 2014 02:13:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s512D7tb064312; Sun, 1 Jun 2014 02:13:07 GMT (envelope-from neel@svn.freebsd.org) Received: (from neel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s512D7Z6064311; Sun, 1 Jun 2014 02:13:07 GMT (envelope-from neel@svn.freebsd.org) Message-Id: <201406010213.s512D7Z6064311@svn.freebsd.org> From: Neel Natu Date: Sun, 1 Jun 2014 02:13:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r266934 - head/usr.sbin/bhyve X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jun 2014 02:13:08 -0000 Author: neel Date: Sun Jun 1 02:13:07 2014 New Revision: 266934 URL: http://svnweb.freebsd.org/changeset/base/266934 Log: Limit the maximum number of back-to-back iterations of a "rep; ins/outs" to 16. This is arbitrary and is used to ensure that a vcpu goes back into the vm_run() loop to process interrupts or rendezvous events in a timely fashion. Found with: Coverity Scan CID: 1216436 Modified: head/usr.sbin/bhyve/inout.c Modified: head/usr.sbin/bhyve/inout.c ============================================================================== --- head/usr.sbin/bhyve/inout.c Sat May 31 23:37:34 2014 (r266933) +++ head/usr.sbin/bhyve/inout.c Sun Jun 1 02:13:07 2014 (r266934) @@ -55,6 +55,10 @@ SET_DECLARE(inout_port_set, struct inout #define VERIFY_IOPORT(port, size) \ assert((port) >= 0 && (size) > 0 && ((port) + (size)) <= MAX_IOPORTS) +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif + static struct { const char *name; int flags; @@ -109,7 +113,7 @@ emulate_inout(struct vmctx *ctx, int vcp void *arg; int error, retval; enum vm_reg_name idxreg; - uint64_t gla, index, count; + uint64_t gla, index, iterations, count; struct vm_inout_str *vis; struct iovec iov[2]; @@ -151,14 +155,17 @@ emulate_inout(struct vmctx *ctx, int vcp /* Count register */ count = vis->count & vie_size2mask(addrsize); - while (count) { + /* Limit number of back-to-back in/out emulations to 16 */ + iterations = min(count, 16); + while (iterations > 0) { if (vie_calculate_gla(vis->paging.cpu_mode, vis->seg_name, &vis->seg_desc, index, bytes, addrsize, prot, &gla)) { error = vm_inject_exception2(ctx, vcpu, IDT_GP, 0); assert(error == 0); - return (INOUT_RESTART); + retval = INOUT_RESTART; + break; } error = vm_gla2gpa(ctx, vcpu, &vis->paging, gla, bytes, @@ -196,6 +203,7 @@ emulate_inout(struct vmctx *ctx, int vcp index += bytes; count--; + iterations--; } /* Update index register */