Skip to contentSkip to conversation

vhost: fix packed ring dequeue offloading

PATCH In review Marvin Liu 3 participants 3 messages Feb 5, 2021 – Feb 10, 2021

lore
Share & tools
lore

Marvin Liu

author
#0 lore raw

PATCH 1/1 vhost: fix packed ring dequeue offloading

When vhost doing dequeue offloading, will parse ethernet and l3/l4 header of the packet. Then vhost will set corresponded value in mbuf attributes. Thus mean offloading action should after packet data copy.

Fixes 75ed51697820 ("vhost: add packed ring batch dequeue")
lib/librte_vhost/virtio_net.c +8 -8
index 730b92e478..0a7d008a91 100644
@@ -2267,7 +2267,6 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,
 {
 	bool wrap = vq->avail_wrap_counter;
 	struct vring_packed_desc *descs = vq->desc_packed;
-	struct virtio_net_hdr *hdr;
 	uint64_t lens[PACKED_BATCH_SIZE];
 	uint64_t buf_lens[PACKED_BATCH_SIZE];
 	uint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);
@@ -2324,13 +2323,6 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,
 		ids[i] = descs[avail_idx + i].id;
 	}
 
-	if (virtio_net_with_host_offload(dev)) {
-		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
-			hdr = (struct virtio_net_hdr *)(desc_addrs[i]);
-			vhost_dequeue_offload(hdr, pkts[i]);
-		}
-	}
-
 	return 0;
 
 free_buf:
@@ -2348,6 +2340,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev,
 {
 	uint16_t avail_idx = vq->last_avail_idx;
 	uint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);
+	struct virtio_net_hdr *hdr;
 	uintptr_t desc_addrs[PACKED_BATCH_SIZE];
 	uint16_t ids[PACKED_BATCH_SIZE];
 	uint16_t i;
@@ -2364,6 +2357,13 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev,
 			   (void *)(uintptr_t)(desc_addrs[i] + buf_offset),
 			   pkts[i]->pkt_len);
 
+	if (virtio_net_with_host_offload(dev)) {
+		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
+			hdr = (struct virtio_net_hdr *)(desc_addrs[i]);
+			vhost_dequeue_offload(hdr, pkts[i]);
+		}
+	}
+
 	if (virtio_net_is_inorder(dev))
 		vhost_shadow_dequeue_batch_packed_inorder(vq,
 			ids[PACKED_BATCH_SIZE - 1]);
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Marvin Liu

When vhost doing dequeue offloading, will parse ethernet and l3/l4 header of the packet. Then vhost will set corresponded value in mbuf

corresponding*

Quoted 1 line

attributes. Thus mean offloading action should after packet data copy.

It means*

Quoted 6 lines
Fixes 75ed51697820 ("vhost: add packed ring batch dequeue")

Please check your git patch formatting config, diff stats are missing.

Quoted 39 lines
lib/librte_vhost/virtio_net.c +1 -8
index 730b92e478..0a7d008a91 100644
@@ -2267,7 +2267,6 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,
 {
 	bool wrap = vq->avail_wrap_counter;
 	struct vring_packed_desc *descs = vq->desc_packed;
-	struct virtio_net_hdr *hdr;
 	uint64_t lens[PACKED_BATCH_SIZE];
 	uint64_t buf_lens[PACKED_BATCH_SIZE];
 	uint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);
@@ -2324,13 +2323,6 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,
 		ids[i] = descs[avail_idx + i].id;
 	}
 
-	if (virtio_net_with_host_offload(dev)) {
-		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
-			hdr = (struct virtio_net_hdr *)(desc_addrs[i]);
-			vhost_dequeue_offload(hdr, pkts[i]);
-		}
-	}
-
 	return 0;
 
 free_buf:
@@ -2348,6 +2340,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev,
 {
 	uint16_t avail_idx = vq->last_avail_idx;
 	uint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);
+	struct virtio_net_hdr *hdr;
 	uintptr_t desc_addrs[PACKED_BATCH_SIZE];
 	uint16_t ids[PACKED_BATCH_SIZE];
 	uint16_t i;
@@ -2364,6 +2357,13 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev,
 			   (void *)(uintptr_t)(desc_addrs[i] + buf_offset),
 			   pkts[i]->pkt_len);
 

lib/librte_vhost/virtio_net.c virtio_dev_tx_batch_packed(struct virtio_net *dev, · line 2369

Quoted 10 lines
lib/librte_vhost/virtio_net.c +7 -0
+	if (virtio_net_with_host_offload(dev)) {
+		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
+			hdr = (struct virtio_net_hdr *)(desc_addrs[i]);
+			vhost_dequeue_offload(hdr, pkts[i]);
+		}
+	}
+
 	if (virtio_net_is_inorder(dev))
 		vhost_shadow_dequeue_batch_packed_inorder(vq,
 			ids[PACKED_BATCH_SIZE - 1]);

I'll fixup the commit message while applying.

Thanks,
Maxime

#2 lore raw

09/02/2021 15:52, Maxime Coquelin:

Quoted 12 lines · Marvin Liu
Quoted 2 lines

When vhost doing dequeue offloading, will parse ethernet and l3/l4 header of the packet. Then vhost will set corresponded value in mbuf

corresponding*

Quoted 1 line

attributes. Thus mean offloading action should after packet data copy.

It means*

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Fixes 75ed51697820 ("vhost: add packed ring batch dequeue")

I'll fixup the commit message while applying.

Fixed english wording and applied, thanks.