summaryrefslogtreecommitdiff
path: root/lib/librte_vhost
diff options
context:
space:
mode:
authorTiwei Bie <tiwei.bie@intel.com>2018-07-17 21:10:35 +0800
committerFerruh Yigit <ferruh.yigit@intel.com>2018-07-23 23:55:26 +0200
commit04651f72d1d2724de2823505b4d30fac780ad5fe (patch)
tree5d0e1fec1ed77154dde9a30541ed66a7587a67a2 /lib/librte_vhost
parent4a61f16444541c2fa13e345af0a3c3532434a93a (diff)
downloaddpdk-04651f72d1d2724de2823505b4d30fac780ad5fe.zip
dpdk-04651f72d1d2724de2823505b4d30fac780ad5fe.tar.gz
dpdk-04651f72d1d2724de2823505b4d30fac780ad5fe.tar.xz
vhost: fix buffer length calculation
Fixes: fd68b4739d2c ("vhost: use buffer vectors in dequeue path") Reported-by: Yinan Wang <yinan.wang@intel.com> Signed-off-by: Tiwei Bie <tiwei.bie@intel.com> Acked-by: Zhihong Wang <zhihong.wang@intel.com> Tested-by: Yinan Wang <yinan.wang@intel.com>
Diffstat (limited to 'lib/librte_vhost')
-rw-r--r--lib/librte_vhost/virtio_net.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 2b7ffcf..07cc0c8 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -720,7 +720,8 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
uint16_t hdr_vec_idx = 0;
while (remain) {
- len = remain;
+ len = RTE_MIN(remain,
+ buf_vec[hdr_vec_idx].buf_len);
dst = buf_vec[hdr_vec_idx].buf_addr;
rte_memcpy((void *)(uintptr_t)dst,
(void *)(uintptr_t)src,
@@ -747,7 +748,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
hdr_addr = 0;
}
- cpy_len = RTE_MIN(buf_len, mbuf_avail);
+ cpy_len = RTE_MIN(buf_avail, mbuf_avail);
if (likely(cpy_len > MAX_BATCH_LEN ||
vq->batch_copy_nb_elems >= vq->size)) {
@@ -1112,7 +1113,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
* in a contiguous virtual area.
*/
while (remain) {
- len = remain;
+ len = RTE_MIN(remain,
+ buf_vec[hdr_vec_idx].buf_len);
src = buf_vec[hdr_vec_idx].buf_addr;
rte_memcpy((void *)(uintptr_t)dst,
(void *)(uintptr_t)src, len);