vhost: fix packed ring dequeue offloading
authorMarvin Liu <yong.liu@intel.com>
Fri, 5 Feb 2021 07:47:58 +0000 (15:47 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 10 Feb 2021 21:17:47 +0000 (22:17 +0100)
When vhost is doing dequeue offloading, it parses ethernet and L3/L4
headers of the packet. Then vhost will set corresponding value in mbuf
attributes. It means offloading action should be after packet data copy.

Fixes: 75ed51697820 ("vhost: add packed ring batch dequeue")
Cc: stable@dpdk.org
Signed-off-by: Marvin Liu <yong.liu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
lib/librte_vhost/virtio_net.c

index 6580983..583bf37 100644 (file)
@@ -2263,7 +2263,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);
@@ -2320,13 +2319,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:
@@ -2344,6 +2336,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;
@@ -2360,6 +2353,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]);