[v2,2/2] vhost: fix slot index calculation in async vhost
Checks
Commit Message
When the packet receiving failure and the DMA ring full occur
simultaneously in the asynchronous vhost, the slot_idx needs to be
decreased 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.
Fixes: 84d5204310d7 ("vhost: support async dequeue for split ring")
Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue")
Cc: stable@dpdk.org
Signed-off-by: Cheng Jiang <cheng1.jiang@intel.com>
---
lib/vhost/virtio_net.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
Comments
> -----Original Message-----
> From: Cheng Jiang <cheng1.jiang@intel.com>
> Sent: Tuesday, October 11, 2022 11:08 AM
> To: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; Hu, Jiayu <jiayu.hu@intel.com>; Ding, Xuan
> <xuan.ding@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>; Wang,
> YuanX <yuanx.wang@intel.com>; Yang, YvonneX
> <yvonnex.yang@intel.com>; He, Xingguang <xingguang.he@intel.com>;
> Jiang, Cheng1 <cheng1.jiang@intel.com>; stable@dpdk.org
> Subject: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost
>
> When the packet receiving failure and the DMA ring full occur simultaneously
> in the asynchronous vhost, the slot_idx needs to be decreased 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.
>
> Fixes: 84d5204310d7 ("vhost: support async dequeue for split ring")
> Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue")
> Cc: stable@dpdk.org
>
> Signed-off-by: Cheng Jiang <cheng1.jiang@intel.com>
> ---
Tested-by: Wei Ling <weix.ling@intel.com>
On 10/11/22 05:08, Cheng Jiang wrote:
> When the packet receiving failure and the DMA ring full occur
> simultaneously in the asynchronous vhost, the slot_idx needs to be
> decreased 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.
>
> Fixes: 84d5204310d7 ("vhost: support async dequeue for split ring")
> Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue")
> Cc: stable@dpdk.org
>
> 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 457ac2e92a..efebd063d7 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -3457,6 +3457,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
> allocerr_warned = true;
> }
> dropped = true;
> + slot_idx--;
> break;
> }
>
> @@ -3647,6 +3648,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;
> }
>
> @@ -3674,8 +3681,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 */
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Thanks,
Maxime
> -----Original Message-----
> From: Jiang, Cheng1 <cheng1.jiang@intel.com>
> Sent: Tuesday, October 11, 2022 11:08 AM
> To: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; Hu, Jiayu <jiayu.hu@intel.com>; Ding, Xuan
> <xuan.ding@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>; Wang, YuanX
> <yuanx.wang@intel.com>; Yang, YvonneX <yvonnex.yang@intel.com>; He,
> Xingguang <xingguang.he@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>;
> stable@dpdk.org
> Subject: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost
>
> When the packet receiving failure and the DMA ring full occur
> simultaneously in the asynchronous vhost, the slot_idx needs to be
> decreased 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.
>
> Fixes: 84d5204310d7 ("vhost: support async dequeue for split ring")
> Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue")
> Cc: stable@dpdk.org
>
> 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 457ac2e92a..efebd063d7 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -3457,6 +3457,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev,
> struct vhost_virtqueue *vq,
> allocerr_warned = true;
> }
> dropped = true;
> + slot_idx--;
> break;
> }
>
> @@ -3647,6 +3648,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;
> }
>
> @@ -3674,8 +3681,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
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
@@ -3457,6 +3457,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
allocerr_warned = true;
}
dropped = true;
+ slot_idx--;
break;
}
@@ -3647,6 +3648,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;
}
@@ -3674,8 +3681,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 */