Skip to contentSkip to conversation

Some fixes for mergeable Rx

PATCH Applied Tiwei Bie 2 participants 6 messages Jun 20, 2019 Network drivers

lore
Share & tools
lore

Tiwei Bie

author
#0 lore raw

v2 cover Some fixes for mergeable Rx

v2:
- Fix commit log (Maxime);

Tiwei Bie (4):
net/virtio: fix memory leak in in-order Rx net/virtio: fix memory leak in mergeable Rx net/virtio: fix memory leak in mergeable packed Rx net/virtio: fix packets check in mergeable packed Rx

 drivers/net/virtio/virtio_rxtx.c | 56 +++++++++++++++-----------------
 1 file changed, 26 insertions(+), 30 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/4 net/virtio: fix memory leak in in-order Rx

When there is no enough segments for a packet in in-order mergeable Rx path, we should free the whole mbuf chain instead of just recycling the last segment.

Fixes e5f456a98d3c ("net/virtio: support in-order Rx and Tx")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 1f1178467..bdb3a2f18 100644
@@ -1555,7 +1555,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf_inorder(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/4 net/virtio: fix memory leak in mergeable Rx

In reply to Tiwei Bie

When there is no enough segments for a packet in mergeable Rx path, we should free the whole mbuf chain instead of just recycling the last segment.

Fixes bcac5aa207f8 ("net/virtio: improve batching in mergeable path")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index bdb3a2f18..9cf422ffe 100644
@@ -1737,7 +1737,7 @@ virtio_recv_mergeable_pkts(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 3/4 net/virtio: fix memory leak in mergeable packed Rx

In reply to Tiwei Bie

When there is no enough segments for a packet in mergeable packed Rx path, we should free the whole mbuf chain instead of just recycling the last segment.

Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
 drivers/net/virtio/virtio_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_rxtx.c +1 -1
index 9cf422ffe..8b75291f5 100644
@@ -1910,7 +1910,7 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue,
 		} else {
 			PMD_RX_LOG(ERR,
 					"No enough segments for packet.");
-			virtio_discard_rxbuf(vq, prev);
+			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH v2 4/4 net/virtio: fix packets check in mergeable packed Rx

In reply to Tiwei Bie

We should check the descriptor state instead of vq's internal free count (i.e. the number of descriptors that we haven't made available) for the remaining mergeable packets.

Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
---
 drivers/net/virtio/virtio_rxtx.c | 50 +++++++++++++++-----------------
 1 file changed, 23 insertions(+), 27 deletions(-)
drivers/net/virtio/virtio_rxtx.c +23 -27
index 8b75291f5..b5062ff84 100644
@@ -1882,38 +1882,34 @@ virtio_recv_mergeable_pkts_packed(void *rx_queue,
 	while (seg_res != 0) {
 		uint16_t rcv_cnt = RTE_MIN((uint16_t)seg_res,
 					VIRTIO_MBUF_BURST_SZ);
-		if (likely(vq->vq_free_cnt >= rcv_cnt)) {
-			num = virtqueue_dequeue_burst_rx_packed(vq, rcv_pkts,
-					len, rcv_cnt);
-			uint16_t extra_idx = 0;
+		uint16_t extra_idx = 0;
 
-			rcv_cnt = num;
-
-			while (extra_idx < rcv_cnt) {
-				rxm = rcv_pkts[extra_idx];
-
-				rxm->data_off =
-					RTE_PKTMBUF_HEADROOM - hdr_size;
-				rxm->pkt_len = (uint32_t)(len[extra_idx]);
-				rxm->data_len = (uint16_t)(len[extra_idx]);
-
-				prev->next = rxm;
-				prev = rxm;
-				rx_pkts[nb_rx]->pkt_len += len[extra_idx];
-				extra_idx += 1;
-			}
-			seg_res -= rcv_cnt;
-			if (!seg_res) {
-				virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]);
-				nb_rx++;
-			}
-		} else {
-			PMD_RX_LOG(ERR,
-					"No enough segments for packet.");
+		rcv_cnt = virtqueue_dequeue_burst_rx_packed(vq, rcv_pkts,
+				len, rcv_cnt);
+		if (unlikely(rcv_cnt == 0)) {
+			PMD_RX_LOG(ERR, "No enough segments for packet.");
 			rte_pktmbuf_free(rx_pkts[nb_rx]);
 			rxvq->stats.errors++;
 			break;
 		}
+
+		while (extra_idx < rcv_cnt) {
+			rxm = rcv_pkts[extra_idx];
+
+			rxm->data_off = RTE_PKTMBUF_HEADROOM - hdr_size;
+			rxm->pkt_len = (uint32_t)(len[extra_idx]);
+			rxm->data_len = (uint16_t)(len[extra_idx]);
+
+			prev->next = rxm;
+			prev = rxm;
+			rx_pkts[nb_rx]->pkt_len += len[extra_idx];
+			extra_idx += 1;
+		}
+		seg_res -= rcv_cnt;
+		if (!seg_res) {
+			virtio_rx_stats_updated(rxvq, rx_pkts[nb_rx]);
+			nb_rx++;
+		}
 	}
 
 	rxvq->stats.packets += nb_rx;
Signature · 1 line
2.17.1
#5 lore raw
In reply to Tiwei Bie
Quoted 12 lines · Tiwei Bie

v2:
- Fix commit log (Maxime);

Tiwei Bie (4):
net/virtio: fix memory leak in in-order Rx net/virtio: fix memory leak in mergeable Rx net/virtio: fix memory leak in mergeable packed Rx net/virtio: fix packets check in mergeable packed Rx

  drivers/net/virtio/virtio_rxtx.c | 56 +++++++++++++++-----------------
  1 file changed, 26 insertions(+), 30 deletions(-)

Applied to dpdk-next-virtio/master.

Thanks,
Maxime