summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorgrehan <grehan@FreeBSD.org>2013-10-25 18:39:01 +0000
committergrehan <grehan@FreeBSD.org>2013-10-25 18:39:01 +0000
commitc26ecf05552e3861de3293801d85fe44f236b115 (patch)
treef61d0d83e28cb48d2f2c466e962659a04c5f5620 /usr.sbin
parent47b928f216400825cad00e3435e0c50fcb7ebb58 (diff)
downloadFreeBSD-src-c26ecf05552e3861de3293801d85fe44f236b115.zip
FreeBSD-src-c26ecf05552e3861de3293801d85fe44f236b115.tar.gz
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)
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bhyve/pci_ahci.c7
-rw-r--r--usr.sbin/bhyve/pci_virtio_block.c9
2 files changed, 10 insertions, 6 deletions
diff --git a/usr.sbin/bhyve/pci_ahci.c b/usr.sbin/bhyve/pci_ahci.c
index 76f263b..68d9bc1 100644
--- a/usr.sbin/bhyve/pci_ahci.c
+++ b/usr.sbin/bhyve/pci_ahci.c
@@ -663,8 +663,7 @@ atapi_read_capacity(struct ahci_port *p, int slot, uint8_t *cfis)
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, uint8_t *cfis,
/*
* 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++;
diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c
index a7556d7..a642b11 100644
--- a/usr.sbin/bhyve/pci_virtio_block.c
+++ b/usr.sbin/bhyve/pci_virtio_block.c
@@ -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 pci_devinst *pi, char *opts)
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 */
OpenPOWER on IntegriCloud