DPDK patches and discussions
 help / color / mirror / Atom feed
From: Junjie Chen <junjie.j.chen@intel.com>
To: yliu@fridaylinux.org, maxime.coquelin@redhat.com
Cc: dev@dpdk.org, Junjie Chen <junjie.j.chen@intel.com>
Subject: [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool
Date: Wed, 17 Jan 2018 05:42:06 -0500	[thread overview]
Message-ID: <1516185726-31797-1-git-send-email-junjie.j.chen@intel.com> (raw)

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>
---
 lib/librte_vhost/virtio_net.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 568ad0e..e9aaf6d 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1158,6 +1158,26 @@ 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->priv_size = priv_size;
+
+		m->buf_addr = (char *)m + mbuf_size;
+		m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
+		m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM,
+			(uint16_t)m->buf_len);
+		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 +1229,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;
-- 
2.0.1

             reply	other threads:[~2018-01-17  3:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 10:42 Junjie Chen [this message]
2018-01-17  7:29 ` Tan, Jianfeng
2018-01-17  8:10   ` Chen, Junjie J
2018-01-17 15:45 ` [dpdk-dev] [PATCH v2] " Junjie Chen
2018-01-18  8:44   ` Maxime Coquelin
2018-01-18 13:16     ` Yuanhan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516185726-31797-1-git-send-email-junjie.j.chen@intel.com \
    --to=junjie.j.chen@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=yliu@fridaylinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).