DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
@ 2017-04-13 14:12 Jianfeng Tan
  2017-04-14  5:32 ` Yuanhan Liu
  2017-04-19  2:30 ` [dpdk-dev] [PATCH v2] " Jianfeng Tan
  0 siblings, 2 replies; 14+ messages in thread
From: Jianfeng Tan @ 2017-04-13 14:12 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, olivier.matz, Jianfeng Tan, stable

virtio-user cannot work on 32-bit system as higher 32-bit of the
addr field (64-bit) in the desc is filled with non-zero value
which should not happen for a 32-bit system.

This is a regression bug. For 32-bit system, the first 4 bytes
is the virtual address, with following 8 bytes pointing to
physical addr. With below wrong definition, both virtual address
and lower 4 bytes of physical addr are obtained.
  #define VIRTIO_MBUF_ADDR(mb, vq) \
	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))

Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
Cc: stable@dpdk.org

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtqueue.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index f9e3736..f43ea70 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -72,7 +72,8 @@ struct rte_mbuf;
  * Return the physical address (or virtual address in case of
  * virtio-user) of mbuf data buffer.
  */
-#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
+#define VIRTIO_MBUF_ADDR(mb, vq) \
+	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))
 #else
 #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
 #endif
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-13 14:12 [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system Jianfeng Tan
@ 2017-04-14  5:32 ` Yuanhan Liu
  2017-04-14  5:53   ` Tan, Jianfeng
  2017-04-19  2:30 ` [dpdk-dev] [PATCH v2] " Jianfeng Tan
  1 sibling, 1 reply; 14+ messages in thread
From: Yuanhan Liu @ 2017-04-14  5:32 UTC (permalink / raw)
  To: Jianfeng Tan; +Cc: dev, olivier.matz, stable

On Thu, Apr 13, 2017 at 02:12:56PM +0000, Jianfeng Tan wrote:
> virtio-user cannot work on 32-bit system as higher 32-bit of the
> addr field (64-bit) in the desc is filled with non-zero value
> which should not happen for a 32-bit system.
> 
> This is a regression bug. For 32-bit system, the first 4 bytes
> is the virtual address, with following 8 bytes pointing to
> physical addr.

It took me a while to understand that you were trying to say "the first
4 bytes __of mbuf__ is ...".

> With below wrong definition, both virtual address
> and lower 4 bytes of physical addr are obtained.

Again, it's not complete. Something like "in the case of virtio-user,
buf_addr will be used for filling the desc addr, ...". will make it much
easier to understand.


>   #define VIRTIO_MBUF_ADDR(mb, vq) \
> 	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
> 
> Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> ---
>  drivers/net/virtio/virtqueue.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> index f9e3736..f43ea70 100644
> --- a/drivers/net/virtio/virtqueue.h
> +++ b/drivers/net/virtio/virtqueue.h
> @@ -72,7 +72,8 @@ struct rte_mbuf;
>   * Return the physical address (or virtual address in case of
>   * virtio-user) of mbuf data buffer.
>   */
> -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
> +#define VIRTIO_MBUF_ADDR(mb, vq) \
> +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))

The "void **" cast makes it a bit complex (thus hard to read). I think
following should work?

    (uint64_t(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))

Besides, it deserves a comment.

	--yliu

>  #else
>  #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
>  #endif
> -- 
> 2.7.4

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-14  5:32 ` Yuanhan Liu
@ 2017-04-14  5:53   ` Tan, Jianfeng
  2017-04-14  6:20     ` Yuanhan Liu
  0 siblings, 1 reply; 14+ messages in thread
From: Tan, Jianfeng @ 2017-04-14  5:53 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, olivier.matz, stable



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Friday, April 14, 2017 1:32 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> Subject: Re: [PATCH] net/virtio-user: fix not working on 32-bit system
> 
> On Thu, Apr 13, 2017 at 02:12:56PM +0000, Jianfeng Tan wrote:
> > virtio-user cannot work on 32-bit system as higher 32-bit of the
> > addr field (64-bit) in the desc is filled with non-zero value
> > which should not happen for a 32-bit system.
> >
> > This is a regression bug. For 32-bit system, the first 4 bytes
> > is the virtual address, with following 8 bytes pointing to
> > physical addr.
> 
> It took me a while to understand that you were trying to say "the first
> 4 bytes __of mbuf__ is ...".

Oops, yes, missed that.

> 
> > With below wrong definition, both virtual address
> > and lower 4 bytes of physical addr are obtained.
> 
> Again, it's not complete. Something like "in the case of virtio-user,
> buf_addr will be used for filling the desc addr, ...". will make it much
> easier to understand.

Yes.

> 
> 
> >   #define VIRTIO_MBUF_ADDR(mb, vq) \
> > 	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
> >
> > Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> > ---
> >  drivers/net/virtio/virtqueue.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> > index f9e3736..f43ea70 100644
> > --- a/drivers/net/virtio/virtqueue.h
> > +++ b/drivers/net/virtio/virtqueue.h
> > @@ -72,7 +72,8 @@ struct rte_mbuf;
> >   * Return the physical address (or virtual address in case of
> >   * virtio-user) of mbuf data buffer.
> >   */
> > -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) +
> (vq)->offset))
> > +#define VIRTIO_MBUF_ADDR(mb, vq) \
> > +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))
> 
> The "void **" cast makes it a bit complex (thus hard to read). I think
> following should work?

Yes, uintptr_t can work. I thought void ** is easier to understand, meaning a convert to a pointer which pointing to a pointer. I usually use uintptr_t only for converter from pointer to integer, not the opposite way.

> 
>     (uint64_t(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
> 
> Besides, it deserves a comment.

Will add comment in next version.

Thanks,
Jianfeng

> 
> 	--yliu
> 
> >  #else
> >  #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
> >  #endif
> > --
> > 2.7.4

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-14  5:53   ` Tan, Jianfeng
@ 2017-04-14  6:20     ` Yuanhan Liu
  2017-04-14  6:56       ` Tan, Jianfeng
  0 siblings, 1 reply; 14+ messages in thread
From: Yuanhan Liu @ 2017-04-14  6:20 UTC (permalink / raw)
  To: Tan, Jianfeng; +Cc: dev, olivier.matz, stable

On Fri, Apr 14, 2017 at 05:53:55AM +0000, Tan, Jianfeng wrote:
> > > diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> > > index f9e3736..f43ea70 100644
> > > --- a/drivers/net/virtio/virtqueue.h
> > > +++ b/drivers/net/virtio/virtqueue.h
> > > @@ -72,7 +72,8 @@ struct rte_mbuf;
> > >   * Return the physical address (or virtual address in case of
> > >   * virtio-user) of mbuf data buffer.
> > >   */
> > > -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) +
> > (vq)->offset))
> > > +#define VIRTIO_MBUF_ADDR(mb, vq) \
> > > +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))
> > 
> > The "void **" cast makes it a bit complex (thus hard to read). I think
> > following should work?
> 
> Yes, uintptr_t can work. I thought void ** is easier to understand, meaning a convert to a pointer which pointing to a pointer.

It's twisted, isn't it? :)

> I usually use uintptr_t only for converter from pointer to integer, not the opposite way.

Yes, that's a typical usage. But the fact of the matter is uintptr_t
represents the word size, which is exactly what needed in this case.

	--yliu
> 
> > 
> >     (uint64_t(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
> > 
> > Besides, it deserves a comment.
> 
> Will add comment in next version.
> 
> Thanks,
> Jianfeng
> 
> > 
> > 	--yliu
> > 
> > >  #else
> > >  #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
> > >  #endif
> > > --
> > > 2.7.4

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-14  6:20     ` Yuanhan Liu
@ 2017-04-14  6:56       ` Tan, Jianfeng
  2017-04-14  7:01         ` Yuanhan Liu
  0 siblings, 1 reply; 14+ messages in thread
From: Tan, Jianfeng @ 2017-04-14  6:56 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, olivier.matz, stable



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Friday, April 14, 2017 2:20 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> Subject: Re: [PATCH] net/virtio-user: fix not working on 32-bit system
> 
> On Fri, Apr 14, 2017 at 05:53:55AM +0000, Tan, Jianfeng wrote:
> > > > diff --git a/drivers/net/virtio/virtqueue.h
> b/drivers/net/virtio/virtqueue.h
> > > > index f9e3736..f43ea70 100644
> > > > --- a/drivers/net/virtio/virtqueue.h
> > > > +++ b/drivers/net/virtio/virtqueue.h
> > > > @@ -72,7 +72,8 @@ struct rte_mbuf;
> > > >   * Return the physical address (or virtual address in case of
> > > >   * virtio-user) of mbuf data buffer.
> > > >   */
> > > > -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb)
> +
> > > (vq)->offset))
> > > > +#define VIRTIO_MBUF_ADDR(mb, vq) \
> > > > +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))
> > >
> > > The "void **" cast makes it a bit complex (thus hard to read). I think
> > > following should work?
> >
> > Yes, uintptr_t can work. I thought void ** is easier to understand, meaning
> a convert to a pointer which pointing to a pointer.
> 
> It's twisted, isn't it? :)
> 
> > I usually use uintptr_t only for converter from pointer to integer, not the
> opposite way.
> 
> Yes, that's a typical usage. But the fact of the matter is uintptr_t
> represents the word size, which is exactly what needed in this case.

Another fold, if you refer to the definition of struct rte_mbuf, the first field is defined as void * instead of uintptr_t. I think that why I prefer to use ((void *)*) in the beginning.

Thanks,
Jianfeng

> 
> 	--yliu
> >
> > >
> > >     (uint64_t(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
> > >
> > > Besides, it deserves a comment.
> >
> > Will add comment in next version.
> >
> > Thanks,
> > Jianfeng
> >
> > >
> > > 	--yliu
> > >
> > > >  #else
> > > >  #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
> > > >  #endif
> > > > --
> > > > 2.7.4

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-14  6:56       ` Tan, Jianfeng
@ 2017-04-14  7:01         ` Yuanhan Liu
  2017-04-14  7:14           ` Tan, Jianfeng
  0 siblings, 1 reply; 14+ messages in thread
From: Yuanhan Liu @ 2017-04-14  7:01 UTC (permalink / raw)
  To: Tan, Jianfeng; +Cc: dev, olivier.matz, stable

On Fri, Apr 14, 2017 at 06:56:01AM +0000, Tan, Jianfeng wrote:
> 
> 
> > -----Original Message-----
> > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> > Sent: Friday, April 14, 2017 2:20 PM
> > To: Tan, Jianfeng
> > Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> > Subject: Re: [PATCH] net/virtio-user: fix not working on 32-bit system
> > 
> > On Fri, Apr 14, 2017 at 05:53:55AM +0000, Tan, Jianfeng wrote:
> > > > > diff --git a/drivers/net/virtio/virtqueue.h
> > b/drivers/net/virtio/virtqueue.h
> > > > > index f9e3736..f43ea70 100644
> > > > > --- a/drivers/net/virtio/virtqueue.h
> > > > > +++ b/drivers/net/virtio/virtqueue.h
> > > > > @@ -72,7 +72,8 @@ struct rte_mbuf;
> > > > >   * Return the physical address (or virtual address in case of
> > > > >   * virtio-user) of mbuf data buffer.
> > > > >   */
> > > > > -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb)
> > +
> > > > (vq)->offset))
> > > > > +#define VIRTIO_MBUF_ADDR(mb, vq) \
> > > > > +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)->offset))))
> > > >
> > > > The "void **" cast makes it a bit complex (thus hard to read). I think
> > > > following should work?
> > >
> > > Yes, uintptr_t can work. I thought void ** is easier to understand, meaning
> > a convert to a pointer which pointing to a pointer.
> > 
> > It's twisted, isn't it? :)
> > 
> > > I usually use uintptr_t only for converter from pointer to integer, not the
> > opposite way.
> > 
> > Yes, that's a typical usage. But the fact of the matter is uintptr_t
> > represents the word size, which is exactly what needed in this case.
> 
> Another fold, if you refer to the definition of struct rte_mbuf, the first field is defined as void * instead of uintptr_t. I think that why I prefer to use ((void *)*) in the beginning.

But the type is hidden here: isn't this the purpose you were introducing
the "offset" here? Besides, it could be type "phys_addr_t".

	--yliu

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

* Re: [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system
  2017-04-14  7:01         ` Yuanhan Liu
@ 2017-04-14  7:14           ` Tan, Jianfeng
  0 siblings, 0 replies; 14+ messages in thread
From: Tan, Jianfeng @ 2017-04-14  7:14 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, olivier.matz, stable



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Friday, April 14, 2017 3:01 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> Subject: Re: [PATCH] net/virtio-user: fix not working on 32-bit system
> 
> On Fri, Apr 14, 2017 at 06:56:01AM +0000, Tan, Jianfeng wrote:
> >
> >
> > > -----Original Message-----
> > > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> > > Sent: Friday, April 14, 2017 2:20 PM
> > > To: Tan, Jianfeng
> > > Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> > > Subject: Re: [PATCH] net/virtio-user: fix not working on 32-bit system
> > >
> > > On Fri, Apr 14, 2017 at 05:53:55AM +0000, Tan, Jianfeng wrote:
> > > > > > diff --git a/drivers/net/virtio/virtqueue.h
> > > b/drivers/net/virtio/virtqueue.h
> > > > > > index f9e3736..f43ea70 100644
> > > > > > --- a/drivers/net/virtio/virtqueue.h
> > > > > > +++ b/drivers/net/virtio/virtqueue.h
> > > > > > @@ -72,7 +72,8 @@ struct rte_mbuf;
> > > > > >   * Return the physical address (or virtual address in case of
> > > > > >   * virtio-user) of mbuf data buffer.
> > > > > >   */
> > > > > > -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t
> *)((uintptr_t)(mb)
> > > +
> > > > > (vq)->offset))
> > > > > > +#define VIRTIO_MBUF_ADDR(mb, vq) \
> > > > > > +	((uint64_t)((uintptr_t)(*(void **)((uintptr_t)(mb) + (vq)-
> >offset))))
> > > > >
> > > > > The "void **" cast makes it a bit complex (thus hard to read). I think
> > > > > following should work?
> > > >
> > > > Yes, uintptr_t can work. I thought void ** is easier to understand,
> meaning
> > > a convert to a pointer which pointing to a pointer.
> > >
> > > It's twisted, isn't it? :)
> > >
> > > > I usually use uintptr_t only for converter from pointer to integer, not
> the
> > > opposite way.
> > >
> > > Yes, that's a typical usage. But the fact of the matter is uintptr_t
> > > represents the word size, which is exactly what needed in this case.
> >
> > Another fold, if you refer to the definition of struct rte_mbuf, the first field
> is defined as void * instead of uintptr_t. I think that why I prefer to use ((void
> *)*) in the beginning.
> 
> But the type is hidden here: isn't this the purpose you were introducing
> the "offset" here? Besides, it could be type "phys_addr_t".
> 

Fair enough.

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

* [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-04-13 14:12 [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system Jianfeng Tan
  2017-04-14  5:32 ` Yuanhan Liu
@ 2017-04-19  2:30 ` Jianfeng Tan
  2017-04-19  5:53   ` Yuanhan Liu
  1 sibling, 1 reply; 14+ messages in thread
From: Jianfeng Tan @ 2017-04-19  2:30 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, olivier.matz, Jianfeng Tan, stable

virtio-user cannot work on 32-bit system as higher 32-bit of the
addr field (64-bit) in the desc is filled with non-zero value
which should not happen for a 32-bit system.

In case of virtio-user, we use buf_addr of mbuf to fill the
virtqueue desc addr. This is a regression bug. For 32-bit system,
the first 4 bytes of mbuf is buf_addr, with following 8 bytes for
buf_phyaddr. With below wrong definition, both buf_addr and lower
4 bytes buf_phyaddr are obtained to fill the virtqueue desc.
  #define VIRTIO_MBUF_ADDR(mb, vq) \
	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))

Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
Cc: stable@dpdk.org

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtqueue.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index f9e3736..2e67460 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -69,10 +69,16 @@ struct rte_mbuf;
 
 #ifdef RTE_VIRTIO_USER
 /**
- * Return the physical address (or virtual address in case of
- * virtio-user) of mbuf data buffer.
+ *
+ * Return the physical address of mbuf data buffer for virtio pci:
+ *  on 32-bit system, offset equals 4, return the second four bytes of mbuf;
+ *  on 64-bit system, offset equals 8, return the second eight bytes of mbuf.
+ * Return the virtual address of mbuf data buffer for virtio-user.
+ *  on 32-bit system, offset equals 0, return the first four bytes of mbuf;
+ *  on 64-bit system, offset equals 0, return the first eight bytes of mbuf;
  */
-#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
+#define VIRTIO_MBUF_ADDR(mb, vq) \
+	((uint64_t)(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
 #else
 #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
 #endif
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-04-19  2:30 ` [dpdk-dev] [PATCH v2] " Jianfeng Tan
@ 2017-04-19  5:53   ` Yuanhan Liu
  2017-04-19  6:21     ` Tan, Jianfeng
  0 siblings, 1 reply; 14+ messages in thread
From: Yuanhan Liu @ 2017-04-19  5:53 UTC (permalink / raw)
  To: Jianfeng Tan; +Cc: dev, olivier.matz, stable

On Wed, Apr 19, 2017 at 02:30:33AM +0000, Jianfeng Tan wrote:
> virtio-user cannot work on 32-bit system as higher 32-bit of the
> addr field (64-bit) in the desc is filled with non-zero value
> which should not happen for a 32-bit system.
> 
> In case of virtio-user, we use buf_addr of mbuf to fill the
> virtqueue desc addr. This is a regression bug. For 32-bit system,
> the first 4 bytes of mbuf is buf_addr, with following 8 bytes for
> buf_phyaddr. With below wrong definition, both buf_addr and lower
> 4 bytes buf_phyaddr are obtained to fill the virtqueue desc.
>   #define VIRTIO_MBUF_ADDR(mb, vq) \
> 	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
> 
> Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> ---
>  drivers/net/virtio/virtqueue.h | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> index f9e3736..2e67460 100644
> --- a/drivers/net/virtio/virtqueue.h
> +++ b/drivers/net/virtio/virtqueue.h
> @@ -69,10 +69,16 @@ struct rte_mbuf;
>  
>  #ifdef RTE_VIRTIO_USER
>  /**
> - * Return the physical address (or virtual address in case of
> - * virtio-user) of mbuf data buffer.
> + *
> + * Return the physical address of mbuf data buffer for virtio pci:
> + *  on 32-bit system, offset equals 4, return the second four bytes of mbuf;
> + *  on 64-bit system, offset equals 8, return the second eight bytes of mbuf.
> + * Return the virtual address of mbuf data buffer for virtio-user.
> + *  on 32-bit system, offset equals 0, return the first four bytes of mbuf;
> + *  on 64-bit system, offset equals 0, return the first eight bytes of mbuf;


I've expected it to be plain english, something like following:

    /*
     * Return the physical address (or virtual address in case of
     * virtio-user) of mbuf data buffer.
     *
     * The address is firstly casted to the word size (sizeof(uintptr_t))
     * before casting it to uint64_t. This is to make it work with different
     * combination of word size (64 bit and 32 bit) and virtio device
     * (virtio-pci and virtio-user).
     */

Okay to you?

	--yliu

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

* Re: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-04-19  5:53   ` Yuanhan Liu
@ 2017-04-19  6:21     ` Tan, Jianfeng
  2017-04-19  6:24       ` Yuanhan Liu
  0 siblings, 1 reply; 14+ messages in thread
From: Tan, Jianfeng @ 2017-04-19  6:21 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, olivier.matz, stable



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Wednesday, April 19, 2017 1:54 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; olivier.matz@6wind.com; stable@dpdk.org
> Subject: Re: [PATCH v2] net/virtio-user: fix not working on 32-bit system
> 
> On Wed, Apr 19, 2017 at 02:30:33AM +0000, Jianfeng Tan wrote:
> > virtio-user cannot work on 32-bit system as higher 32-bit of the
> > addr field (64-bit) in the desc is filled with non-zero value
> > which should not happen for a 32-bit system.
> >
> > In case of virtio-user, we use buf_addr of mbuf to fill the
> > virtqueue desc addr. This is a regression bug. For 32-bit system,
> > the first 4 bytes of mbuf is buf_addr, with following 8 bytes for
> > buf_phyaddr. With below wrong definition, both buf_addr and lower
> > 4 bytes buf_phyaddr are obtained to fill the virtqueue desc.
> >   #define VIRTIO_MBUF_ADDR(mb, vq) \
> > 	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))
> >
> > Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> > ---
> >  drivers/net/virtio/virtqueue.h | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
> > index f9e3736..2e67460 100644
> > --- a/drivers/net/virtio/virtqueue.h
> > +++ b/drivers/net/virtio/virtqueue.h
> > @@ -69,10 +69,16 @@ struct rte_mbuf;
> >
> >  #ifdef RTE_VIRTIO_USER
> >  /**
> > - * Return the physical address (or virtual address in case of
> > - * virtio-user) of mbuf data buffer.
> > + *
> > + * Return the physical address of mbuf data buffer for virtio pci:
> > + *  on 32-bit system, offset equals 4, return the second four bytes of mbuf;
> > + *  on 64-bit system, offset equals 8, return the second eight bytes of
> mbuf.
> > + * Return the virtual address of mbuf data buffer for virtio-user.
> > + *  on 32-bit system, offset equals 0, return the first four bytes of mbuf;
> > + *  on 64-bit system, offset equals 0, return the first eight bytes of mbuf;
> 
> 
> I've expected it to be plain english, something like following:
> 
>     /*
>      * Return the physical address (or virtual address in case of
>      * virtio-user) of mbuf data buffer.
>      *
>      * The address is firstly casted to the word size (sizeof(uintptr_t))
>      * before casting it to uint64_t. This is to make it work with different
>      * combination of word size (64 bit and 32 bit) and virtio device
>      * (virtio-pci and virtio-user).
>      */
> 
> Okay to you?

Yep, sounds better. Thanks!

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

* Re: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-04-19  6:21     ` Tan, Jianfeng
@ 2017-04-19  6:24       ` Yuanhan Liu
  0 siblings, 0 replies; 14+ messages in thread
From: Yuanhan Liu @ 2017-04-19  6:24 UTC (permalink / raw)
  To: Tan, Jianfeng; +Cc: dev, olivier.matz, stable

On Wed, Apr 19, 2017 at 06:21:59AM +0000, Tan, Jianfeng wrote:
> 
> 
> > I've expected it to be plain english, something like following:
> > 
> >     /*
> >      * Return the physical address (or virtual address in case of
> >      * virtio-user) of mbuf data buffer.
> >      *
> >      * The address is firstly casted to the word size (sizeof(uintptr_t))
> >      * before casting it to uint64_t. This is to make it work with different
> >      * combination of word size (64 bit and 32 bit) and virtio device
> >      * (virtio-pci and virtio-user).
> >      */
> > 
> > Okay to you?
> 
> Yep, sounds better. Thanks!

Good. Applied to dpdk-next-virtio, with above change.

Thanks.

	--yliu

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

* Re: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-09-20  2:17 ` Tan, Jianfeng
@ 2017-09-20  2:55   ` Jim Murphy
  0 siblings, 0 replies; 14+ messages in thread
From: Jim Murphy @ 2017-09-20  2:55 UTC (permalink / raw)
  To: Tan, Jianfeng; +Cc: dev

On Tue, Sep 19, 2017 at 7:17 PM, Tan, Jianfeng <jianfeng.tan@intel.com>
wrote:

> Hi Jim,
>
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jim Murphy
> > Sent: Wednesday, September 20, 2017 6:24 AM
> > To: dev@dpdk.org
> > Subject: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit
> > system
> >
> > Hi,
> >
> > The fix contained in this patch breaks under the following scenario:
> >
> > 1. A 64 bit host and virtual machine. Therefore all physical addresses
> are
> > 64 bits.
>
> Host, VM and application are 64bit, then I suppose there's no problem?
>

Right, no problem. I was just describing this as my setup.


>
> > 2. A 32 bit user mode DPDK process running on a 64 bit virtual machine
> (64
> > bit kernel).
>
> Ah, this is a case we fail to cover.
>

Yes.


> >
> > In this case, the physical address is 64bits but the virtual address of
> the
> > user process is 32 bits so uintptr_t is only 32 bits. As a result when:
> >
> >  (uintptr_t)(mb) + (vq)->offset)
> >
> > is referenced, only 32 bits are copied into the descriptor but 64 bits
> are
> > required because in this scenario that is the size of a physical address.
> >
> > So it seems like we need a way to determine the size of the physical
> > address and then VIRTIO_MBUF_ADDR should be written to copy that many
> > bytes
> > into the uint64_t. Does anyone know how to determine the size of the
> > physical address?
>
> It's easy to find a way to decide the length (similar to _offset_), but
> copying variable length of bytes seems not an efficient way.
>
>
I agree regarding the efficiency issue. To get something at compile time
does RTE_MACHINE or something derived from it help us?

Thanks,

Jim

Thanks,
> Jianfeng
>
>

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

* Re: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
  2017-09-19 22:24 Jim Murphy
@ 2017-09-20  2:17 ` Tan, Jianfeng
  2017-09-20  2:55   ` Jim Murphy
  0 siblings, 1 reply; 14+ messages in thread
From: Tan, Jianfeng @ 2017-09-20  2:17 UTC (permalink / raw)
  To: Jim Murphy, dev

Hi Jim,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jim Murphy
> Sent: Wednesday, September 20, 2017 6:24 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit
> system
> 
> Hi,
> 
> The fix contained in this patch breaks under the following scenario:
> 
> 1. A 64 bit host and virtual machine. Therefore all physical addresses are
> 64 bits.

Host, VM and application are 64bit, then I suppose there's no problem?

> 2. A 32 bit user mode DPDK process running on a 64 bit virtual machine (64
> bit kernel).

Ah, this is a case we fail to cover.

> 
> In this case, the physical address is 64bits but the virtual address of the
> user process is 32 bits so uintptr_t is only 32 bits. As a result when:
> 
>  (uintptr_t)(mb) + (vq)->offset)
> 
> is referenced, only 32 bits are copied into the descriptor but 64 bits are
> required because in this scenario that is the size of a physical address.
> 
> So it seems like we need a way to determine the size of the physical
> address and then VIRTIO_MBUF_ADDR should be written to copy that many
> bytes
> into the uint64_t. Does anyone know how to determine the size of the
> physical address?

It's easy to find a way to decide the length (similar to _offset_), but copying variable length of bytes seems not an efficient way.

Thanks,
Jianfeng


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

* [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system
@ 2017-09-19 22:24 Jim Murphy
  2017-09-20  2:17 ` Tan, Jianfeng
  0 siblings, 1 reply; 14+ messages in thread
From: Jim Murphy @ 2017-09-19 22:24 UTC (permalink / raw)
  To: dev

Hi,

The fix contained in this patch breaks under the following scenario:

1. A 64 bit host and virtual machine. Therefore all physical addresses are
64 bits.
2. A 32 bit user mode DPDK process running on a 64 bit virtual machine (64
bit kernel).

In this case, the physical address is 64bits but the virtual address of the
user process is 32 bits so uintptr_t is only 32 bits. As a result when:

 (uintptr_t)(mb) + (vq)->offset)

is referenced, only 32 bits are copied into the descriptor but 64 bits are
required because in this scenario that is the size of a physical address.

So it seems like we need a way to determine the size of the physical
address and then VIRTIO_MBUF_ADDR should be written to copy that many bytes
into the uint64_t. Does anyone know how to determine the size of the
physical address?

Thanks,

Jim

Original Post:

virtio-user cannot work on 32-bit system as higher 32-bit of the
addr field (64-bit) in the desc is filled with non-zero value
which should not happen for a 32-bit system.

In case of virtio-user, we use buf_addr of mbuf to fill the
virtqueue desc addr. This is a regression bug. For 32-bit system,
the first 4 bytes of mbuf is buf_addr, with following 8 bytes for
buf_phyaddr. With below wrong definition, both buf_addr and lower
4 bytes buf_phyaddr are obtained to fill the virtqueue desc.
  #define VIRTIO_MBUF_ADDR(mb, vq) \
	(*(uint64_t *)((uintptr_t)(mb) + (vq)->offset))

Fixes: 25f80d108780 ("net/virtio: fix packet corruption")
Cc: stable at dpdk.org <http://dpdk.org/ml/listinfo/dev>

Signed-off-by: Jianfeng Tan <jianfeng.tan at intel.com
<http://dpdk.org/ml/listinfo/dev>>
---
 drivers/net/virtio/virtqueue.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index f9e3736..2e67460 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -69,10 +69,16 @@ struct rte_mbuf;

 #ifdef RTE_VIRTIO_USER
 /**
- * Return the physical address (or virtual address in case of
- * virtio-user) of mbuf data buffer.
+ *
+ * Return the physical address of mbuf data buffer for virtio pci:
+ *  on 32-bit system, offset equals 4, return the second four bytes of mbuf;
+ *  on 64-bit system, offset equals 8, return the second eight bytes of mbuf.
+ * Return the virtual address of mbuf data buffer for virtio-user.
+ *  on 32-bit system, offset equals 0, return the first four bytes of mbuf;
+ *  on 64-bit system, offset equals 0, return the first eight bytes of mbuf;
  */
-#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) +
(vq)->offset))
+#define VIRTIO_MBUF_ADDR(mb, vq) \
+	((uint64_t)(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
 #else
 #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)
 #endif
-- 
2.7.4

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

end of thread, other threads:[~2017-09-20  2:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-13 14:12 [dpdk-dev] [PATCH] net/virtio-user: fix not working on 32-bit system Jianfeng Tan
2017-04-14  5:32 ` Yuanhan Liu
2017-04-14  5:53   ` Tan, Jianfeng
2017-04-14  6:20     ` Yuanhan Liu
2017-04-14  6:56       ` Tan, Jianfeng
2017-04-14  7:01         ` Yuanhan Liu
2017-04-14  7:14           ` Tan, Jianfeng
2017-04-19  2:30 ` [dpdk-dev] [PATCH v2] " Jianfeng Tan
2017-04-19  5:53   ` Yuanhan Liu
2017-04-19  6:21     ` Tan, Jianfeng
2017-04-19  6:24       ` Yuanhan Liu
2017-09-19 22:24 Jim Murphy
2017-09-20  2:17 ` Tan, Jianfeng
2017-09-20  2:55   ` Jim Murphy

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