From owner-svn-src-all@FreeBSD.ORG Fri Oct 25 18:39:02 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id DE68DD59; Fri, 25 Oct 2013 18:39:01 +0000 (UTC) (envelope-from grehan@FreeBSD.org) 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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BC4552957; Fri, 25 Oct 2013 18:39:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9PId1vX081252; Fri, 25 Oct 2013 18:39:01 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9PId10v081250; Fri, 25 Oct 2013 18:39:01 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201310251839.r9PId10v081250@svn.freebsd.org> From: Peter Grehan Date: Fri, 25 Oct 2013 18:39:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r257128 - stable/10/usr.sbin/bhyve X-SVN-Group: stable-10 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.14 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: Fri, 25 Oct 2013 18:39:02 -0000 Author: grehan Date: Fri Oct 25 18:39:01 2013 New Revision: 257128 URL: http://svnweb.freebsd.org/changeset/base/257128 Log: MFC r256926, r257005 r256926 Fix AHCI ATAPI emulation when backed with /dev/cd0 - remove assumption that the backing file/device had 512-byte sectors - fix incorrect iovec size variable that would result in a buffer overrun when an o/s issued an i/o request with more s/g elements than the blockif api r257005 Export the block size capability to guests. - Use #defines for capability bits - Export the VTBLK_F_BLK_SIZE capability - Fix bug in calculating capacity: it is in 512-byte units, not the underlying sector size This allows virtio-blk to have backing devices with non 512-byte sector sizes e.g. /dev/cd0, and 4K-block harddrives. Approved by: re (glebius) Modified: stable/10/usr.sbin/bhyve/pci_ahci.c stable/10/usr.sbin/bhyve/pci_virtio_block.c Directory Properties: stable/10/usr.sbin/bhyve/ (props changed) Modified: stable/10/usr.sbin/bhyve/pci_ahci.c ============================================================================== --- stable/10/usr.sbin/bhyve/pci_ahci.c Fri Oct 25 18:38:44 2013 (r257127) +++ stable/10/usr.sbin/bhyve/pci_ahci.c Fri Oct 25 18:39:01 2013 (r257128) @@ -663,8 +663,7 @@ atapi_read_capacity(struct ahci_port *p, uint8_t buf[8]; uint64_t sectors; - sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx); - sectors >>= 2; + sectors = blockif_size(p->bctx) / 2048; be32enc(buf, sectors - 1); be32enc(buf + 4, 2048); cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN; @@ -908,9 +907,9 @@ atapi_read(struct ahci_port *p, int slot /* * Build up the iovec based on the prdt */ - for (i = 0; i < hdr->prdtl; i++) { + for (i = 0; i < iovcnt; i++) { breq->br_iov[i].iov_base = paddr_guest2host(ahci_ctx(sc), - prdt->dba, prdt->dbc + 1); + prdt->dba, prdt->dbc + 1); breq->br_iov[i].iov_len = prdt->dbc + 1; aior->done += (prdt->dbc + 1); prdt++; Modified: stable/10/usr.sbin/bhyve/pci_virtio_block.c ============================================================================== --- stable/10/usr.sbin/bhyve/pci_virtio_block.c Fri Oct 25 18:38:44 2013 (r257127) +++ stable/10/usr.sbin/bhyve/pci_virtio_block.c Fri Oct 25 18:39:01 2013 (r257128) @@ -66,11 +66,16 @@ __FBSDID("$FreeBSD$"); #define VTBLK_BLK_ID_BYTES 20 +/* Capability bits */ +#define VTBLK_F_SEG_MAX (1 << 2) /* Maximum request segments */ +#define VTBLK_F_BLK_SIZE (1 << 6) /* cfg block size valid */ + /* * Host capabilities */ #define VTBLK_S_HOSTCAPS \ - ( 0x00000004 | /* host maximum request segments */ \ + ( VTBLK_F_SEG_MAX | \ + VTBLK_F_BLK_SIZE | \ VIRTIO_RING_F_INDIRECT_DESC ) /* indirect descriptors */ /* @@ -315,7 +320,7 @@ pci_vtblk_init(struct vmctx *ctx, struct digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]); /* setup virtio block config space */ - sc->vbsc_cfg.vbc_capacity = size / sectsz; + sc->vbsc_cfg.vbc_capacity = size / DEV_BSIZE; /* 512-byte units */ sc->vbsc_cfg.vbc_seg_max = VTBLK_MAXSEGS; sc->vbsc_cfg.vbc_blk_size = sectsz; sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */