[dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system

Jim Murphy jmurphy at arista.com
Wed Sep 20 00:24:13 CEST 2017


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


More information about the dev mailing list