vhost: fix some async vhost index calculation issues
cover vhost: fix some async vhost index calculation issues
Fix some async vhost index calculation issues.
Cheng Jiang (2):
vhost: fix descs count in async vhost packed ring
vhost: fix slot index calculation in async vhost
lib/vhost/virtio_net.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
--
2.35.1
PATCH 1/2 vhost: fix descs count in async vhost packed ring
When vhost receive packets from the front-end using packed virtqueue, it might use multiple descriptors for one packet, so we need calculate and record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
lib/vhost/virtio_net.c +15 -9
@@ -3553,14 +3553,15 @@ virtio_dev_tx_async_split_compliant(struct virtio_net *dev, } static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq,uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq, +uint16_t buf_id,uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed; async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (async->buffer_idx_packed >= vq->size)
@@ -3581,6 +3582,8 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,uint16_t nr_vec =0 ;uint32_t buf_len;struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx, &desc_count,
@@ -3609,8 +3612,12 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,return -1 ; } + pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); +vhost_async_shadow_dequeue_single_packed (vq, buf_id, desc_count); + +vq_inc_last_avail_packed (vq, desc_count);return err; }
@@ -3649,9 +3656,6 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, } pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - } n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id, async->pkts_idx,
@@ -3662,6 +3666,8 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, pkt_err = pkt_idx - n_xfer;if (unlikely (pkt_err)) { +uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/**
@@ -3678,10 +3684,10 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, }/* recover available ring */ -if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }
Signature · 1 line
2.35.1
Re: [PATH 1/2] vhost: fix descs count in async vhost packed ring
Quoted 1 line · Cheng Jiang
When vhost receive packets from the front-end using packed virtqueue, it
receives*
Quoted 1 line
might use multiple descriptors for one packet, so we need calculate and
so we need to*
Quoted 3 lines
record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
This is a fix, so the Fixes tag should be present, and [email protected] cc'ed.
Quoted 73 lines
Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)lib/vhost/virtio_net.c +12
-6@@ -3553,14 +3553,15 @@ virtio_dev_tx_async_split_compliant(struct virtio_net *dev, } static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq,uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq, +uint16_t buf_id,uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed; async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (async->buffer_idx_packed >= vq->size)@@ -3581,6 +3582,8 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,uint16_t nr_vec =0 ;uint32_t buf_len;struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx, &desc_count,@@ -3609,8 +3612,12 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,return -1 ; } + pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); +vhost_async_shadow_dequeue_single_packed (vq, buf_id, desc_count); + +vq_inc_last_avail_packed (vq, desc_count);return err; }@@ -3649,9 +3656,6 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, } pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - } n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id, async->pkts_idx,@@ -3662,6 +3666,8 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, pkt_err = pkt_idx - n_xfer;if (unlikely (pkt_err)) { +uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/** @@ -3678,10 +3684,10 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, }/* recover available ring */
lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 3693
Quoted 10 lines
lib/vhost/virtio_net.c +3
-3-if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }
I'm not sure to understand, isn't descs_err always 0 here?
Maxime
PATCH 2/2 vhost: fix slot index calculation in async vhost
In reply to Cheng JiangWhen 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.
--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
lib/vhost/virtio_net.c +14 -2
@@ -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 */
Signature · 1 line
2.35.1
Re: [PATH 2/2] vhost: fix slot index calculation in async vhost
Quoted 3 lines · Cheng Jiang
When the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the
slot_idxneeds to be reduced by 1. For packed virtqueue, the slot index should be
s/reduced/decreased/
Quoted 2 lines
ring_size- 1, if theslot_idxis currently 0, since the ring size is not necessarily the power of 2.
This is a fix, so fixes tag and [email protected] is required.
Quoted 46 lines
Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)lib/vhost/virtio_net.c +14
-2@@ -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 */
RE: [PATH 2/2] vhost: fix slot index calculation in async vhost
Hi,
Quoted 13 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Monday, October 3, 2022 6:10 PM
To: Jiang, Cheng1 <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>
Subject: Re: [PATH 2/2] vhost: fix slot index calculation in async vhost
Quoted 6 lines
Quoted 3 lines · Cheng Jiang
When the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the
slot_idxneeds to be reduced by 1. For packed virtqueue, the slot index should bes/reduced/decreased/
Sure, thanks.
Quoted 5 lines
Quoted 3 lines
ring_size- 1, if theslot_idxis currently 0, since the ring size is not necessarily the power of 2.This is a fix, so fixes tag and [email protected] is required.
Sorry for the miss. It will be fixed in the next version.
Thanks,
Cheng
Quoted 53 lines
lib/vhost/virtio_net.c virtio_dev_tx_async_split(struct virtio_net *dev,
Quoted 11 lines
Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0
-0
bfc6d65b7c..f804bce0bd100644lib/vhost/virtio_net.c +0
-0@@ -3462,6 +3462,7 @@ virtio_dev_tx_async_split(struct virtio_net *dev,struct
vhost_virtqueue*vq,lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 8 lines
lib/vhost/virtio_net.c +1
-0allocerr_warned = true; } dropped = true; + slot_idx--;break ; }@@ -3652,6 +3653,12 @@ virtio_dev_tx_async_packed(struct virtio_net*dev, struct
vhost_virtqueue*vq,lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net · line 3653
Quoted 1 line
lib/vhost/virtio_net.c +0
-0if (unlikely(virtio_dev_tx_async_single_packed(dev, vq,
mbuf_pool, pkt,lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net · line 3655
Quoted 2 lines
lib/vhost/virtio_net.c +0
-0slot_idx, legacy_ol_flags))) { rte_pktmbuf_free_bulk(&pkts_prealloc[pkt_idx],count -
pkt_idx);lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 10 lines
lib/vhost/virtio_net.c +6
-0+ +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,Quoted 16 lines
lib/vhost/virtio_net.c +7
-2async->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 */
v2 cover vhost: fix some async vhost index calculation issues
In reply to Cheng JiangFix some async vhost index calculation issues.
v2: fixed fixes tag and replaced some words in commit message.
Cheng Jiang (2):
vhost: fix descs count in async vhost packed ring
vhost: fix slot index calculation in async vhost
lib/vhost/virtio_net.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
--
2.35.1
PATCH v2 1/2 vhost: fix descs count in async vhost packed ring
When vhost receive packets from the front-end using packed virtqueue, it might use multiple descriptors for one packet, so we need calculate and record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
lib/vhost/virtio_net.c +15 -9
@@ -3548,14 +3548,15 @@ virtio_dev_tx_async_split_compliant(struct virtio_net *dev, } static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq,uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq, +uint16_t buf_id,uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed; async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (async->buffer_idx_packed >= vq->size)
@@ -3576,6 +3577,8 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,uint16_t nr_vec =0 ;uint32_t buf_len;struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx, &desc_count,
@@ -3604,8 +3607,12 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,return -1 ; } + pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); +vhost_async_shadow_dequeue_single_packed (vq, buf_id, desc_count); + +vq_inc_last_avail_packed (vq, desc_count);return err; }
@@ -3644,9 +3651,6 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, } pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - } n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id, async->pkts_idx,
@@ -3657,6 +3661,8 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, pkt_err = pkt_idx - n_xfer;if (unlikely (pkt_err)) { +uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/**
@@ -3673,10 +3679,10 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, }/* recover available ring */ -if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }
Signature · 1 line
2.35.1
Re: [PATCH v2 1/2] vhost: fix descs count in async vhost packed ring
Quoted 1 line · Cheng Jiang
When vhost receive packets from the front-end using packed virtqueue, it
receives
Quoted 1 line
might use multiple descriptors for one packet, so we need calculate and
to calculate
Quoted 80 lines
record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
Fixes fe8477ebbd94 ("vhost: support async packed ring dequeue")Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)lib/vhost/virtio_net.c +12
-6@@ -3548,14 +3548,15 @@ virtio_dev_tx_async_split_compliant(struct virtio_net *dev, } static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq,uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed (struct vhost_virtqueue *vq, +uint16_t buf_id,uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed; async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (async->buffer_idx_packed >= vq->size)@@ -3576,6 +3577,8 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,uint16_t nr_vec =0 ;uint32_t buf_len;struct buf_vector buf_vec[BUF_VECTOR_MAX ]; +struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx, &desc_count,@@ -3604,8 +3607,12 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,return -1 ; } + pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); +vhost_async_shadow_dequeue_single_packed (vq, buf_id, desc_count); + +vq_inc_last_avail_packed (vq, desc_count);return err; }@@ -3644,9 +3651,6 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, } pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - } n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id, async->pkts_idx,@@ -3657,6 +3661,8 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, pkt_err = pkt_idx - n_xfer;if (unlikely (pkt_err)) { +uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/** @@ -3673,10 +3679,10 @@ virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, }/* recover available ring */
lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 3688
Quoted 10 lines
lib/vhost/virtio_net.c +3
-3-if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }
If only the commit message typos need to be fixed, maybe no need to send a new version.
Thanks,
Maxime
RE: [PATCH v2 1/2] vhost: fix descs count in async vhost packed ring
Hi Maxime,
Quoted 114 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, October 21, 2022 4:16 PM
To: Jiang, Cheng1 <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/2] vhost: fix descs count in async vhost packed ringQuoted 2 lines · Cheng Jiang
When vhost receive packets from the front-end using packed virtqueue, it
receives
Quoted 2 lines
might use multiple descriptors for one packet, so we need calculate and
to calculate
lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct
Quoted 17 lines
record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
Fixes fe8477ebbd94 ("vhost: support async packed ring dequeue")Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0
-0
8f4d0f0502..457ac2e92a100644lib/vhost/virtio_net.c +0
-0@@ -3548,14 +3548,15 @@ virtio_dev_tx_async_split_compliant(struct
virtio_net*dev,lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct virtio_net *dev,
Quoted 4 lines
lib/vhost/virtio_net.c +0
-1}static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed(struct vhost_virtqueue*vq,
lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct · line 3552
Quoted 2 lines
lib/vhost/virtio_net.c +1
-0uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed(struct vhost_virtqueue*vq,
Quoted 21 lines
lib/vhost/virtio_net.c +2
-1+ uint16_t buf_id, uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed; async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (
async->buffer_idx_packed>=vq->size) @@ -3576,6 +3577,8 @@
virtio_dev_tx_async_single_packed(structvirtio_net*dev,
uint16_tnr_vec= 0;
uint32_tbuf_len;
structbuf_vectorbuf_vec[BUF_VECTOR_MAX];lib/vhost/virtio_net.c +2
-0+struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx,Quoted 1 line
&desc_count, @@ -3604,8 +3607,12 @@virtio_dev_tx_async_single_packed(struct
virtio_net*dev,lib/vhost/virtio_net.c virtio_dev_tx_async_single_packed(struct virtio_net *dev,
Quoted 8 lines
return -1; }lib/vhost/virtio_net.c +3
-1+ pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); + vhost_async_shadow_dequeue_single_packed(vq, buf_id,
desc_count);lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 6 lines
lib/vhost/virtio_net.c +2
-0+ +vq_inc_last_avail_packed (vq, desc_count);return err; }@@ -3644,9 +3651,6 @@ virtio_dev_tx_async_packed(struct virtio_net*dev, struct
vhost_virtqueue*vq,Quoted 10 lines
lib/vhost/virtio_net.c +0
-3} pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - } n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id,
async->pkts_idx, @@ -3657,6 +3661,8 @@virtio_dev_tx_async_packed(struct
virtio_net*dev, structvhost_virtqueue*vq,lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 9 lines
pkt_err = pkt_idx - n_xfer; if (unlikely(pkt_err)) {lib/vhost/virtio_net.c +2
-0+uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/** @@ -3673,10 +3679,10 @@ virtio_dev_tx_async_packed(struct virtio_net*dev, struct
vhost_virtqueue*vq,Quoted 2 lines
lib/vhost/virtio_net.c +0
-0}
Quoted 14 lines
lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 3688
Quoted 11 lines
lib/vhost/virtio_net.c +3
-3/* recover available ring */ -if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }If only the commit message typos need to be fixed, maybe no need to send a new version.
Sure, thanks a lot!
Cheng
Quoted 5 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
Xia, Chenbo
Reviewed-byRE: [PATCH v2 1/2] vhost: fix descs count in async vhost packed ring
Quoted 114 lines
-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Monday, October 24, 2022 9:42 AM
To: Maxime Coquelin <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; [email protected]
Subject: RE: [PATCH v2 1/2] vhost: fix descs count in async vhost packed ringHi Maxime,
Quoted 11 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, October 21, 2022 4:16 PM
To: Jiang, Cheng1 <[email protected]>; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; [email protected]
Subject: Re: [PATCH v2 1/2] vhost: fix descs count in async vhost packedring
Quoted 45 lines · Cheng Jiang
Quoted 2 lines
When vhost receive packets from the front-end using packed virtqueue, it
receives
Quoted 2 lines
might use multiple descriptors for one packet, so we need calculate and
to calculate
lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct
Quoted 17 lines
record the descriptor number for each packet to update available descriptor counter and used descriptor counter, and rollback when DMA ring is full.
Fixes fe8477ebbd94 ("vhost: support async packed ring dequeue")Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0
-0
8f4d0f0502..457ac2e92a100644lib/vhost/virtio_net.c +0
-0@@ -3548,14 +3548,15 @@ virtio_dev_tx_async_split_compliant(struct
virtio_net*dev,lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct virtio_net *dev,
Quoted 4 lines
lib/vhost/virtio_net.c +0
-1}static __rte_always_inline void -vhost_async_shadow_dequeue_single_packed(struct vhost_virtqueue*vq,
lib/vhost/virtio_net.c virtio_dev_tx_async_split_compliant(struct · line 3552
Quoted 2 lines
lib/vhost/virtio_net.c +1
-0uint16_t buf_id) +vhost_async_shadow_dequeue_single_packed(struct vhost_virtqueue*vq,
Quoted 5 lines
lib/vhost/virtio_net.c +1
-0+ uint16_t buf_id, uint16_t count) {struct vhost_async *async = vq->async;uint16_t idx = async->buffer_idx_packed;Quoted 7 lines
Quoted 7 lines
lib/vhost/virtio_net.c +1
-1async->buffers_packed[idx].id = buf_id; async->buffers_packed[idx].len =0 ; - async->buffers_packed[idx].count =1 ; + async->buffers_packed[idx].count = count; async->buffer_idx_packed++;if (
async->buffer_idx_packed>=vq->size) @@ -3576,6 +3577,8@@
Quoted 35 lines
Quoted 10 lines
virtio_dev_tx_async_single_packed(struct
virtio_net*dev,
uint16_tnr_vec= 0;
uint32_tbuf_len;
structbuf_vectorbuf_vec[BUF_VECTOR_MAX];lib/vhost/virtio_net.c +2
-0+struct vhost_async *async = vq->async; +struct async_inflight_info *pkts_info = async->pkts_info;static bool allocerr_warned; if (unlikely(fill_vec_buf_packed(dev, vq, vq->last_avail_idx,
&desc_count, @@ -3604,8 +3607,12 @@virtio_dev_tx_async_single_packed(struct
virtio_net*dev,lib/vhost/virtio_net.c virtio_dev_tx_async_single_packed(struct virtio_net *dev,
Quoted 8 lines
return -1; }lib/vhost/virtio_net.c +3
-1+ pkts_info[slot_idx].descs = desc_count; +/* update async shadow packed ring */ -vhost_async_shadow_dequeue_single_packed (vq, buf_id); + vhost_async_shadow_dequeue_single_packed(vq, buf_id,
desc_count);lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 6 lines
lib/vhost/virtio_net.c +2
-0+ +vq_inc_last_avail_packed (vq, desc_count);return err; }@@ -3644,9 +3651,6 @@ virtio_dev_tx_async_packed(struct virtio_net*dev, struct
vhost_virtqueue*vq,Quoted 8 lines
lib/vhost/virtio_net.c +0
-3} pkts_info[slot_idx].mbuf = pkt; - -vq_inc_last_avail_packed (vq,1 ); - }
Quoted 31 lines
Quoted 3 lines
Quoted 2 lines
lib/vhost/virtio_net.c +0
-0n_xfer = vhost_async_dma_transfer(dev, vq, dma_id, vchan_id,
async->pkts_idx, @@ -3657,6 +3661,8 @@virtio_dev_tx_async_packed(struct
virtio_net*dev, struct
vhost_virtqueueQuoted 27 lines
*vq,
lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net
Quoted 9 lines
pkt_err = pkt_idx - n_xfer; if (unlikely(pkt_err)) {lib/vhost/virtio_net.c +2
-0+uint16_t descs_err =0 ; + pkt_idx -= pkt_err;/** @@ -3673,10 +3679,10 @@ virtio_dev_tx_async_packed(struct virtio_net*dev, struct
vhost_virtqueue*vq,lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 3688
Quoted 13 lines
lib/vhost/virtio_net.c +3
-3}/* recover available ring */ -if (vq->last_avail_idx >= pkt_err) { - vq->last_avail_idx -= pkt_err; +if (vq->last_avail_idx >= descs_err) { + vq->last_avail_idx -= descs_err; }else { - vq->last_avail_idx += vq->size - pkt_err; + vq->last_avail_idx += vq->size - descs_err; vq->avail_wrap_counter ^=1 ; } }If only the commit message typos need to be fixed, maybe no need to send a new version.
Will fix above typos when applying
Thanks,
Chenbo
Quoted 9 lines
Sure, thanks a lot!
ChengQuoted 5 lines
Reviewed-by Maxime Coquelin <[email protected]>Thanks,
Maxime
PATCH v2 2/2 vhost: fix slot index calculation in async vhost
In reply to Cheng JiangWhen 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.
--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
lib/vhost/virtio_net.c +14 -2
@@ -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 */
Signature · 1 line
2.35.1
RE: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost
Quoted 16 lines
-----Original Message-----
From: Cheng Jiang <[email protected]>
Sent: Tuesday, October 11, 2022 11:08 AM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] vhost: fix slot index calculation in async vhostWhen the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the
slot_idxneeds to be decreased by 1. For packed virtqueue, the slot index should bering_size- 1, if theslot_idxis currently 0, since the ring size is not necessarily the power of 2.
Quoted 6 lines
Fixes 84d5204310d7 ("vhost: support async dequeue for split ring")Fixes fe8477ebbd94 ("vhost: support async packed ring dequeue")Signed-off-by Cheng Jiang <[email protected]>---
Re: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost
In reply to Cheng JiangQuoted 46 lines · Cheng Jiang
When the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the
slot_idxneeds to be decreased by 1. For packed virtqueue, the slot index should bering_size- 1, if theslot_idxis 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")Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)lib/vhost/virtio_net.c +7
-2@@ -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--;
lib/vhost/virtio_net.c virtio_dev_tx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, · line 3693
Quoted 10 lines
lib/vhost/virtio_net.c +7
-0+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 */
Thanks,
Maxime
RE: [PATCH v2 2/2] vhost: fix slot index calculation in async vhost
In reply to Cheng JiangQuoted 71 lines
-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Tuesday, October 11, 2022 11:08 AM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] vhost: fix slot index calculation in async vhostWhen the packet receiving failure and the DMA ring full occur simultaneously in the asynchronous vhost, the
slot_idxneeds to be decreased by 1. For packed virtqueue, the slot index should bering_size- 1, if theslot_idxis 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")Signed-off-by Cheng Jiang <[email protected]>--- lib/vhost/virtio_net.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)lib/vhost/virtio_net.c +7
-0@@ -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--; +lib/vhost/virtio_net.c +7
-2break ; }@@ -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--; }
Quoted 3 lines
/* recover available ring */
--
2.35.1
Quoted 19 lines
-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Tuesday, October 11, 2022 11:08 AM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Ma, WenwuX <[email protected]>; Wang, YuanX <[email protected]>; Yang, YvonneX <[email protected]>; He, Xingguang <[email protected]>; Jiang, Cheng1 <[email protected]>
Subject: [PATCH v2 0/2] vhost: fix some async vhost index calculation issuesFix some async vhost index calculation issues.
v2: fixed fixes tag and replaced some words in commit message.
Cheng Jiang (2):
vhost: fix descs count in async vhost packed ring
vhost: fix slot index calculation in async vhost
Quoted 5 lines
lib/vhost/virtio_net.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)--
2.35.1
Series applied to next-virtio/main, thanks