DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cheng Jiang <cheng1.jiang@intel.com>
To: maxime.coquelin@redhat.com, chenbo.xia@intel.com
Cc: dev@dpdk.org, jiayu.hu@intel.com, xuan.ding@intel.com,
	wenwux.ma@intel.com, yuanx.wang@intel.com,
	yvonnex.yang@intel.com, xingguang.he@intel.com,
	Cheng Jiang <cheng1.jiang@intel.com>
Subject: [PATH 2/2] vhost: fix slot index calculation in async vhost
Date: Mon, 22 Aug 2022 04:31:26 +0000	[thread overview]
Message-ID: <20220822043126.19340-3-cheng1.jiang@intel.com> (raw)
In-Reply-To: <20220822043126.19340-1-cheng1.jiang@intel.com>

When the packet receiving failure and the DMA ring full occur
simultaneously in the asynchronous vhost, the slot_idx needs to be
reduced by 1. For packed virtqueue, the slot index should be
ring_size - 1, if the slot_idx is currently 0, since the ring size is
not necessarily the power of 2.

Signed-off-by: Cheng Jiang <cheng1.jiang@intel.com>
---
 lib/vhost/virtio_net.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index bfc6d65b7c..f804bce0bd 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -3462,6 +3462,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 				allocerr_warned = true;
 			}
 			dropped = true;
+			slot_idx--;
 			break;
 		}
 
@@ -3652,6 +3653,12 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(virtio_dev_tx_async_single_packed(dev, vq, mbuf_pool, pkt,
 				slot_idx, legacy_ol_flags))) {
 			rte_pktmbuf_free_bulk(&pkts_prealloc[pkt_idx], count - pkt_idx);
+
+			if (slot_idx == 0)
+				slot_idx = vq->size - 1;
+			else
+				slot_idx--;
+
 			break;
 		}
 
@@ -3679,8 +3686,13 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 			async->buffer_idx_packed += vq->size - pkt_err;
 
 		while (pkt_err-- > 0) {
-			rte_pktmbuf_free(pkts_info[slot_idx % vq->size].mbuf);
-			slot_idx--;
+			rte_pktmbuf_free(pkts_info[slot_idx].mbuf);
+			descs_err += pkts_info[slot_idx].descs;
+
+			if (slot_idx == 0)
+				slot_idx = vq->size - 1;
+			else
+				slot_idx--;
 		}
 
 		/* recover available ring */
-- 
2.35.1


  parent reply	other threads:[~2022-08-22  5:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22  4:31 [PATH 0/2] vhost: fix some async vhost index calculation issues Cheng Jiang
2022-08-22  4:31 ` [PATH 1/2] vhost: fix descs count in async vhost packed ring Cheng Jiang
2022-10-03 10:07   ` Maxime Coquelin
2022-08-22  4:31 ` Cheng Jiang [this message]
2022-10-03 10:10   ` [PATH 2/2] vhost: fix slot index calculation in async vhost Maxime Coquelin
2022-10-11  2:31     ` Jiang, Cheng1
2022-10-11  3:08 ` [PATCH v2 0/2] vhost: fix some async vhost index calculation issues Cheng Jiang
2022-10-11  3:08   ` [PATCH v2 1/2] vhost: fix descs count in async vhost packed ring Cheng Jiang
2022-10-21  8:16     ` Maxime Coquelin
2022-10-24  1:41       ` Jiang, Cheng1
2022-10-24  8:42         ` Xia, Chenbo
2022-10-11  3:08   ` [PATCH v2 2/2] vhost: fix slot index calculation in async vhost Cheng Jiang
2022-10-13  9:40     ` Ling, WeiX
2022-10-21  8:17     ` Maxime Coquelin
2022-10-24  8:43     ` Xia, Chenbo
2022-10-26  9:27   ` [PATCH v2 0/2] vhost: fix some async vhost index calculation issues Xia, Chenbo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220822043126.19340-3-cheng1.jiang@intel.com \
    --to=cheng1.jiang@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=wenwux.ma@intel.com \
    --cc=xingguang.he@intel.com \
    --cc=xuan.ding@intel.com \
    --cc=yuanx.wang@intel.com \
    --cc=yvonnex.yang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).