From: Maxime Coquelin Date: Wed, 7 Jul 2021 10:30:04 +0000 (+0200) Subject: vhost: fix packed ring index wrapping X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=92ed77dce68d45e7a343163cdc41ac9bdd099eec;p=dpdk.git vhost: fix packed ring index wrapping Unlike split ring, packed ring does not mandate the ring size to be a power of 2. So we have to use a modulo operation when wrapping ring index. Fixes: 873e8dad6f49 ("vhost: support packed ring in async datapath") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin Acked-by: Cheng Jiang Reviewed-by: Chenbo Xia --- diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index f0b78f5374..6e5d82c1a8 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1586,7 +1586,7 @@ virtio_dev_rx_async_get_info_idx(uint16_t pkts_idx, uint16_t vq_size, uint16_t n_inflight) { return pkts_idx > n_inflight ? (pkts_idx - n_inflight) : - (vq_size - n_inflight + pkts_idx) & (vq_size - 1); + (vq_size - n_inflight + pkts_idx) % vq_size; } static __rte_always_inline void @@ -2228,7 +2228,7 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, if (vq_is_packed(dev)) { for (i = 0; i < n_pkts_put; i++) { - from = (start_idx + i) & (vq_size - 1); + from = (start_idx + i) % vq_size; n_buffers += pkts_info[from].nr_buffers; pkts[i] = pkts_info[from].mbuf; }