Fix packed ring header len
cover Fix packed ring header len
First patch is fixing packed ring header len. Issue was reported by Marvin.
Second patch is a (very) light optimization, to make used directly of the static hdr len value in packed-ring only functions.
Maxime Coquelin (2):
vhost: fix Virtio-net header len with packed ring
vhost: use fixed Virtio-net header len packed ring
lib/librte_vhost/vhost_user.c | 4 +++- lib/librte_vhost/virtio_net.c | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/2 vhost: fix Virtio-net header len with packed ring
In case packed ring layout has been negotiated, but neither Version 1 nor mergeable buffers, the Virtio-net header len is assigned to the legacy devices value, which is wrong.
This patch fixes this with using the proper len as devices using packed ring are not legacy devices.
--- lib/librte_vhost/vhost_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_vhost/vhost_user.c +3 -1
@@ -341,7 +341,9 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, dev->features = features;if (dev->features & - ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) { + ((1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | + (1ULL <<VIRTIO_F_VERSION_1 ) | + (1ULL <<VIRTIO_F_RING_PACKED ))) { dev->vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); }else { dev->vhost_hlen =sizeof (struct virtio_net_hdr );
Signature · 1 line
2.26.2
Re: [dpdk-dev] [PATCH 1/2] vhost: fix Virtio-net header len with packed ring
Quoted 43 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, October 1, 2020 6:12 PM
To: [email protected]; Xia, Chenbo <[email protected]>; Liu, Yong <[email protected]>
Cc: Maxime Coquelin <[email protected]>; [email protected]
Subject: [PATCH 1/2] vhost: fix Virtio-net header len with packed ringIn case packed ring layout has been negotiated, but neither Version 1 nor mergeable buffers, the Virtio-net header len is assigned to the legacy devices value, which is wrong.
This patch fixes this with using the proper len as devices using packed ring are not legacy devices.
Fixes a922401f35cc ("vhost: add Rx support for packed ring")Fixes ae999ce49dcb ("vhost: add Tx support for packed ring")Reported-by Marvin Liu <[email protected]>Signed-off-by Maxime Coquelin <[email protected]>--- lib/librte_vhost/vhost_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/librte_vhost/vhost_user.c +3
-1@@ -341,7 +341,9 @@ vhost_user_set_features(struct virtio_net **pdev,struct VhostUserMsg *msg, dev->features = features;if (dev->features & - ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) { + ((1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | + (1ULL <<VIRTIO_F_VERSION_1 ) | + (1ULL <<VIRTIO_F_RING_PACKED ))) { dev->vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf );lib/librte_vhost/vhost_user.c +0
-1}else { dev->vhost_hlen =sizeof (struct virtio_net_hdr ); --
Quoted 1 line
2.26.2
PATCH 2/2 vhost: use fixed Virtio-net header len packed ring
In reply to Maxime CoquelinThis small optimization uses static the Virtio-net header len in packed datapath, since Virtio-net header cannot be the legacy one in case of packed ring.
--- lib/librte_vhost/virtio_net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
lib/librte_vhost/virtio_net.c +6 -5
@@ -1147,7 +1147,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev,uint16_t buf_id =0 ;uint32_t len =0 ;uint16_t desc_count; -uint32_t size = pkt->pkt_len + dev->vhost_hlen; +uint32_t size = pkt->pkt_len +sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t num_buffers =0 ;uint32_t buffer_len[vq->size];uint16_t buffer_buf_id[vq->size];
@@ -1262,7 +1262,7 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,uint16_t avail_idx = vq->last_avail_idx;uint64_t desc_addrs[PACKED_BATCH_SIZE ];struct virtio_net_hdr_mrg_rxbuf *hdrs[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint64_t lens[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i;
@@ -1308,7 +1308,8 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,rte_prefetch0 ((void *)(uintptr_t )desc_addrs[i]); hdrs[i] = (struct virtio_net_hdr_mrg_rxbuf *) (uintptr_t )desc_addrs[i]; - lens[i] = pkts[i]->pkt_len + dev->vhost_hlen; + lens[i] = pkts[i]->pkt_len + +sizeof (struct virtio_net_hdr_mrg_rxbuf ); }vhost_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE )
@@ -2277,7 +2278,7 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,struct virtio_net_hdr *hdr;uint64_t lens[PACKED_BATCH_SIZE ];uint64_t buf_lens[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t flags, i;if (unlikely (avail_idx &PACKED_BATCH_MASK ))
@@ -2354,7 +2355,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev, struct rte_mbuf **pkts) {uint16_t avail_idx = vq->last_avail_idx; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uintptr_t desc_addrs[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i;
Signature · 1 line
2.26.2
Re: [dpdk-dev] [PATCH 2/2] vhost: use fixed Virtio-net header len packed ring
Hi Maxime,
Quoted 9 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, October 1, 2020 6:12 PM
To: [email protected]; Xia, Chenbo <[email protected]>; Liu, Yong <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH 2/2] vhost: use fixed Virtio-net header len packed ringThis small optimization uses static the Virtio-net header len
Better use 'the static Virtio-net header length' here when you apply the patch 😊. With this fix:
Quoted 62 lines
in packed datapath, since Virtio-net header cannot be the legacy one in case of packed ring.
Signed-off-by Maxime Coquelin <[email protected]>--- lib/librte_vhost/virtio_net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)lib/librte_vhost/virtio_net.c +1
-1@@ -1147,7 +1147,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev,uint16_t buf_id =0 ;uint32_t len =0 ;uint16_t desc_count; -uint32_t size = pkt->pkt_len + dev->vhost_hlen; +uint32_t size = pkt->pkt_len +sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t num_buffers =0 ;uint32_t buffer_len[vq->size];lib/librte_vhost/virtio_net.c +4
-3uint16_t buffer_buf_id[vq->size];@@ -1262,7 +1262,7 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,uint16_t avail_idx = vq->last_avail_idx;uint64_t desc_addrs[PACKED_BATCH_SIZE ];struct virtio_net_hdr_mrg_rxbuf *hdrs[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint64_t lens[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i;@@ -1308,7 +1308,8 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,rte_prefetch0 ((void *)(uintptr_t )desc_addrs[i]); hdrs[i] = (struct virtio_net_hdr_mrg_rxbuf *) (uintptr_t )desc_addrs[i]; - lens[i] = pkts[i]->pkt_len + dev->vhost_hlen; + lens[i] = pkts[i]->pkt_len + +sizeof (struct virtio_net_hdr_mrg_rxbuf ); }vhost_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE )@@ -2277,7 +2278,7 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev, struct virtio_net_hdr *hdr;uint64_t lens[PACKED_BATCH_SIZE ];uint64_t buf_lens[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t flags, i;lib/librte_vhost/virtio_net.c +1
-2if (unlikely (avail_idx &PACKED_BATCH_MASK ))@@ -2354,7 +2355,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev, struct rte_mbuf **pkts) {uint16_t avail_idx = vq->last_avail_idx; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uintptr_t desc_addrs[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i; --2.26.2
Re: [dpdk-dev] [PATCH 2/2] vhost: use fixed Virtio-net header len packed ring
Welcome back Chenbo,
Quoted 10 lines · Chenbo
Hi Maxime,
Quoted 8 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, October 1, 2020 6:12 PM
To: [email protected]; Xia, Chenbo <[email protected]>; Liu, Yong <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH 2/2] vhost: use fixed Virtio-net header len packed ring
Quoted 4 lines
Quoted 1 line
This small optimization uses static the Virtio-net header len
Better use 'the static Virtio-net header length' here when you apply the patch 😊. With this fix:
I did the change when applying, thanks!
Maxime
Quoted 65 lines
Reviewed-by Chenbo Xia <[email protected]>Quoted 62 lines
in packed datapath, since Virtio-net header cannot be the legacy one in case of packed ring.
Signed-off-by Maxime Coquelin <[email protected]>--- lib/librte_vhost/virtio_net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)lib/librte_vhost/virtio_net.c +1
-1@@ -1147,7 +1147,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev,uint16_t buf_id =0 ;uint32_t len =0 ;uint16_t desc_count; -uint32_t size = pkt->pkt_len + dev->vhost_hlen; +uint32_t size = pkt->pkt_len +sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t num_buffers =0 ;uint32_t buffer_len[vq->size];lib/librte_vhost/virtio_net.c +4
-3uint16_t buffer_buf_id[vq->size];@@ -1262,7 +1262,7 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,uint16_t avail_idx = vq->last_avail_idx;uint64_t desc_addrs[PACKED_BATCH_SIZE ];struct virtio_net_hdr_mrg_rxbuf *hdrs[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint64_t lens[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i;@@ -1308,7 +1308,8 @@ virtio_dev_rx_batch_packed(struct virtio_net *dev,rte_prefetch0 ((void *)(uintptr_t )desc_addrs[i]); hdrs[i] = (struct virtio_net_hdr_mrg_rxbuf *) (uintptr_t )desc_addrs[i]; - lens[i] = pkts[i]->pkt_len + dev->vhost_hlen; + lens[i] = pkts[i]->pkt_len + +sizeof (struct virtio_net_hdr_mrg_rxbuf ); }vhost_for_each_try_unroll (i,0 ,PACKED_BATCH_SIZE )@@ -2277,7 +2278,7 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev, struct virtio_net_hdr *hdr;uint64_t lens[PACKED_BATCH_SIZE ];uint64_t buf_lens[PACKED_BATCH_SIZE ]; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uint16_t flags, i;lib/librte_vhost/virtio_net.c +1
-2if (unlikely (avail_idx &PACKED_BATCH_MASK ))@@ -2354,7 +2355,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev, struct rte_mbuf **pkts) {uint16_t avail_idx = vq->last_avail_idx; -uint32_t buf_offset = dev->vhost_hlen; +uint32_t buf_offset =sizeof (struct virtio_net_hdr_mrg_rxbuf );uintptr_t desc_addrs[PACKED_BATCH_SIZE ];uint16_t ids[PACKED_BATCH_SIZE ];uint16_t i; --2.26.2
Maxime Coquelin
AppliedQuoted 7 lines · Maxime Coquelin
First patch is fixing packed ring header len. Issue was reported by Marvin.
Second patch is a (very) light optimization, to make used directly of the static hdr len value in packed-ring only functions.
Quoted 8 lines
Maxime Coquelin (2):
vhost: fix Virtio-net header len with packed ring
vhost: use fixed Virtio-net header len packed ringlib/librte_vhost/vhost_user.c | 4 +++- lib/librte_vhost/virtio_net.c | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-)
Applied to dpdk-next-virtio/main.
Thanks,
Maxime