From: Tiwei Bie <tiwei.bie@intel.com>
To: yskoh@mellanox.com, stable@dpdk.org
Cc: maxime.coquelin@redhat.com, zhihong.wang@intel.com
Subject: [dpdk-stable] [PATCH 17.11 1/3] vhost: restore mbuf first when freeing zmbuf
Date: Fri, 9 Aug 2019 19:11:04 +0800 [thread overview]
Message-ID: <20190809111106.32223-2-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190809111106.32223-1-tiwei.bie@intel.com>
[ backported from upstream commit 041d37b2ef25faeb1c00ed70a5fc2ea6e93c4828 ]
The mbufs should also be restored in free_zmbufs().
Fixes: b0a985d1f340 ("vhost: add dequeue zero copy")
Fixes: 3ebd930588b7 ("vhost: fix mbuf free")
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/librte_vhost/vhost.h | 16 ++++++++++++++++
lib/librte_vhost/vhost_user.c | 1 +
lib/librte_vhost/virtio_net.c | 16 ----------------
3 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 11ce27118..c9e86a2c9 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -513,4 +513,20 @@ vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
return __vhost_iova_to_vva(dev, vq, iova, len, perm);
}
+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;
+ }
+}
+
#endif /* _VHOST_NET_CDEV_H_ */
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 84c18f965..7c0d8c6e4 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -888,6 +888,7 @@ free_zmbufs(struct vhost_virtqueue *vq)
zmbuf != NULL; zmbuf = next) {
next = TAILQ_NEXT(zmbuf, next);
+ restore_mbuf(zmbuf->mbuf);
rte_pktmbuf_free(zmbuf->mbuf);
TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
}
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 07d4609ee..e3d50c96b 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1466,22 +1466,6 @@ 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)
--
2.17.1
next prev parent reply other threads:[~2019-08-09 11:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-09 11:11 [dpdk-stable] [PATCH 17.11 0/3] Vhost zero-copy backports for 17.11 Tiwei Bie
2019-08-09 11:11 ` Tiwei Bie [this message]
2019-08-09 11:11 ` [dpdk-stable] [PATCH 17.11 2/3] vhost: fix potential use-after-free for zero copy mbuf Tiwei Bie
2019-08-09 11:11 ` [dpdk-stable] [PATCH 17.11 3/3] vhost: fix potential use-after-free for memory region Tiwei Bie
2019-08-12 18:52 ` [dpdk-stable] [PATCH 17.11 0/3] Vhost zero-copy backports for 17.11 Yongseok Koh
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=20190809111106.32223-2-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=stable@dpdk.org \
--cc=yskoh@mellanox.com \
--cc=zhihong.wang@intel.com \
/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).