Index: usr.sbin/bhyve/pci_nvme.c =================================================================== --- usr.sbin/bhyve/pci_nvme.c +++ usr.sbin/bhyve/pci_nvme.c @@ -2168,9 +2168,10 @@ static int pci_nvme_append_iov_req(struct pci_nvme_softc *sc, struct pci_nvme_ioreq *req, - uint64_t gpaddr, size_t size, int do_write, uint64_t lba) + uint64_t gpaddr, size_t size, int do_write, uint64_t offset) { int iovidx; + bool range_is_contiguous; if (req == NULL) return (-1); @@ -2179,8 +2180,16 @@ return (-1); } - /* concatenate contig block-iovs to minimize number of iovs */ - if ((req->prev_gpaddr + req->prev_size) == gpaddr) { + /* + * Minimize the number of IOVs by concatenating contiguous address + * ranges. Skip if there is no previous range. + */ + if (req->io_req.br_iovcnt == 0) + range_is_contiguous = false; + else + range_is_contiguous = (req->prev_gpaddr + req->prev_size) == gpaddr; + + if (range_is_contiguous) { iovidx = req->io_req.br_iovcnt - 1; req->io_req.br_iov[iovidx].iov_base = @@ -2194,7 +2203,7 @@ } else { iovidx = req->io_req.br_iovcnt; if (iovidx == 0) { - req->io_req.br_offset = lba; + req->io_req.br_offset = offset; req->io_req.br_resid = 0; req->io_req.br_param = req; }