vhost: fix packed ring index wrapping
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Wed, 7 Jul 2021 10:30:04 +0000 (12:30 +0200)
committerChenbo Xia <chenbo.xia@intel.com>
Wed, 21 Jul 2021 05:56:13 +0000 (07:56 +0200)
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 <maxime.coquelin@redhat.com>
Acked-by: Cheng Jiang <cheng1.jiang@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
lib/vhost/virtio_net.c

index f0b78f5..6e5d82c 100644 (file)
@@ -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;
                }