DPDK patches and discussions
 help / color / mirror / Atom feed
* Re: [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool
  2018-01-17 10:42 [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool Junjie Chen
@ 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
  1 sibling, 1 reply; 6+ messages in thread
From: Tan, Jianfeng @ 2018-01-17  7:29 UTC (permalink / raw)
  To: Chen, Junjie J, yliu, maxime.coquelin; +Cc: dev, Chen, Junjie J



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Junjie Chen
> Sent: Wednesday, January 17, 2018 6:42 PM
> To: yliu@fridaylinux.org; maxime.coquelin@redhat.com
> Cc: dev@dpdk.org; Chen, Junjie J
> Subject: [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf
> before return to pool
> 
> 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;

I don't think we need to restore priv_size. Refer to its definition in rte_mbuf:
    "Size of the application private data. In case of an indirect mbuf, it stores the direct mbuf private data size."

Thanks,
Jianfeng

> +
> +		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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool
  2018-01-17  7:29 ` Tan, Jianfeng
@ 2018-01-17  8:10   ` Chen, Junjie J
  0 siblings, 0 replies; 6+ messages in thread
From: Chen, Junjie J @ 2018-01-17  8:10 UTC (permalink / raw)
  To: Tan, Jianfeng, yliu, maxime.coquelin; +Cc: dev

> >
> > 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;
> 
> I don't think we need to restore priv_size. Refer to its definition in rte_mbuf:
>     "Size of the application private data. In case of an indirect mbuf, it
> stores the direct mbuf private data size."
> 
> Thanks,
> Jianfeng

You are right, I also remove restore for data_len since it is reset when allocating. Please see v2.
Thanks.

> 
> > +
> > +		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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool
@ 2018-01-17 10:42 Junjie Chen
  2018-01-17  7:29 ` Tan, Jianfeng
  2018-01-17 15:45 ` [dpdk-dev] [PATCH v2] " Junjie Chen
  0 siblings, 2 replies; 6+ messages in thread
From: Junjie Chen @ 2018-01-17 10:42 UTC (permalink / raw)
  To: yliu, maxime.coquelin; +Cc: dev, Junjie Chen

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [dpdk-dev] [PATCH v2] vhost: dequeue zero copy should restore mbuf before return to pool
  2018-01-17 10:42 [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool Junjie Chen
  2018-01-17  7:29 ` Tan, Jianfeng
@ 2018-01-17 15:45 ` Junjie Chen
  2018-01-18  8:44   ` Maxime Coquelin
  1 sibling, 1 reply; 6+ messages in thread
From: Junjie Chen @ 2018-01-17 15:45 UTC (permalink / raw)
  To: jianfen.tan, yliu, maxime.coquelin; +Cc: dev, Junjie Chen

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(+)

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;
-- 
2.0.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v2] vhost: dequeue zero copy should restore mbuf before return to pool
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Maxime Coquelin @ 2018-01-18  8:44 UTC (permalink / raw)
  To: Junjie Chen, jianfen.tan, yliu; +Cc: dev



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH v2] vhost: dequeue zero copy should restore mbuf before return to pool
  2018-01-18  8:44   ` Maxime Coquelin
@ 2018-01-18 13:16     ` Yuanhan Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Yuanhan Liu @ 2018-01-18 13:16 UTC (permalink / raw)
  To: Maxime Coquelin; +Cc: Junjie Chen, jianfen.tan, dev

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-18 13:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-17 10:42 [dpdk-dev] [PATCH] vhost: dequeue zero copy should restore mbuf before return to pool Junjie Chen
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

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).