Skip to content

Commit

Permalink
net/hns3: fix mbuf leakage when RxQ started after reset
Browse files Browse the repository at this point in the history
[ upstream commit f81a18f491522c56ca7ee6ea78be10c784f2ae32 ]

In the reset restore-conf phase, the reset process will allocate for
the Rx ring mbufs unconditionlly.

And the rte_eth_dev_rx_queue_start() will also allocate for the Rx ring
mbufs unconditionlly.

So if the rte_eth_dev_rx_queue_start() is invoked after restore-conf
phase, then the mbufs allocated in restore-conf phase will leak.

So fix it by conditional release Rx ring mbufs in
rte_eth_dev_rx_queue_start(): if the Rx ring mbufs were allocated then
release them first.

This patch also set all sw-ring[]'s mbuf is NULL when release Rx ring
mbufs so that we can determine whether the Rx ring mbufs were allocated
based only on the first sw-ring[0]'s mbuf.

Fixes: fa29fe4 ("net/hns3: support queue start and stop")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
  • Loading branch information
fengchengwen authored and kevintraynor committed Jul 11, 2023
1 parent 3d26d3f commit 51a43c9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/net/hns3/hns3_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ hns3_rx_queue_release_mbufs(struct hns3_rx_queue *rxq)
rxq->sw_ring[i].mbuf = NULL;
}
}
for (i = 0; i < rxq->rx_rearm_nb; i++)
rxq->sw_ring[rxq->rx_rearm_start + i].mbuf = NULL;
}

for (i = 0; i < rxq->bulk_mbuf_num; i++)
Expand Down Expand Up @@ -4503,6 +4505,9 @@ hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
return ret;
}

if (rxq->sw_ring[0].mbuf != NULL)
hns3_rx_queue_release_mbufs(rxq);

ret = hns3_init_rxq(hns, rx_queue_id);
if (ret) {
hns3_err(hw, "fail to init Rx queue %u, ret = %d.",
Expand Down

0 comments on commit 51a43c9

Please sign in to comment.