diff mbox

[dpdk-dev,v2] vhost: dequeue zero copy should restore mbuf before return to pool

Message ID 1516203953-152604-1-git-send-email-junjie.j.chen@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

junjie.j.chen@intel.com Jan. 17, 2018, 3:45 p.m. UTC
dequeue zero copy change buf_addr and buf_iova of mbuf, and return
to mbuf pool without restore them, it breaks vm memory if others allocate
mbuf from same pool since mbuf reset doesn't reset buf_addr and buf_iova.

Signed-off-by: Junjie Chen <junjie.j.chen@intel.com>
---
v2 changes:
Remove useless restore
 lib/librte_vhost/virtio_net.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Maxime Coquelin Jan. 18, 2018, 8:44 a.m. UTC | #1
On 01/17/2018 04:45 PM, Junjie Chen wrote:
> dequeue zero copy change buf_addr and buf_iova of mbuf, and return
> to mbuf pool without restore them, it breaks vm memory if others allocate
> mbuf from same pool since mbuf reset doesn't reset buf_addr and buf_iova.
> 
> Signed-off-by: Junjie Chen <junjie.j.chen@intel.com>
> ---
> v2 changes:
> Remove useless restore
>   lib/librte_vhost/virtio_net.c | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
Yuanhan Liu Jan. 18, 2018, 1:16 p.m. UTC | #2
On Thu, Jan 18, 2018 at 09:44:41AM +0100, Maxime Coquelin wrote:
> 
> 
> On 01/17/2018 04:45 PM, Junjie Chen wrote:
> >dequeue zero copy change buf_addr and buf_iova of mbuf, and return
> >to mbuf pool without restore them, it breaks vm memory if others allocate
> >mbuf from same pool since mbuf reset doesn't reset buf_addr and buf_iova.
> >
> >Signed-off-by: Junjie Chen <junjie.j.chen@intel.com>
> >---
> >v2 changes:
> >Remove useless restore
> >  lib/librte_vhost/virtio_net.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Applied to dpdk-next-virtio, with below addings:

Fixes: b0a985d1f340 ("vhost: add dequeue zero copy")
Cc: stable@dpdk.org

Thanks.

	--yliu
diff mbox

Patch

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 568ad0e..d4f9a3a 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1158,6 +1158,22 @@  mbuf_is_consumed(struct rte_mbuf *m)
 	return true;
 }
 
+static __rte_always_inline void
+restore_mbuf(struct rte_mbuf *m)
+{
+	uint32_t mbuf_size, priv_size;
+
+	while (m) {
+		priv_size = rte_pktmbuf_priv_size(m->pool);
+		mbuf_size = sizeof(struct rte_mbuf) + priv_size;
+		/* start of buffer is after mbuf structure and priv data */
+
+		m->buf_addr = (char *)m + mbuf_size;
+		m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
+		m = m->next;
+	}
+}
+
 uint16_t
 rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
@@ -1209,6 +1225,7 @@  rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 				nr_updated += 1;
 
 				TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
+				restore_mbuf(zmbuf->mbuf);
 				rte_pktmbuf_free(zmbuf->mbuf);
 				put_zmbuf(zmbuf);
 				vq->nr_zmbuf -= 1;