From: Jun Yang <[email protected]> Add qman_find_fq_by_cgid() to find frame queues associated with a given CGID. This allows the driver to verify that all FQs using a CGR are shut down before releasing the CGR ID, preventing use-after-free of CGR resources.
Signed-off-by: Jun Yang <[email protected]> Signed-off-by: Hemant Agrawal <[email protected]> --- drivers/bus/dpaa/dpaa_bus_base_symbols.c | 1 + drivers/bus/dpaa/include/fsl_qman.h | 3 +++ drivers/net/dpaa/dpaa_ethdev.c | 29 ++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/bus/dpaa/dpaa_bus_base_symbols.c b/drivers/bus/dpaa/dpaa_bus_base_symbols.c index 52abec2b4c..514ab7b1f1 100644 --- a/drivers/bus/dpaa/dpaa_bus_base_symbols.c +++ b/drivers/bus/dpaa/dpaa_bus_base_symbols.c @@ -56,6 +56,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(qman_reserve_fqid_range) RTE_EXPORT_INTERNAL_SYMBOL(qman_alloc_pool_range) RTE_EXPORT_INTERNAL_SYMBOL(qman_alloc_cgrid_range) RTE_EXPORT_INTERNAL_SYMBOL(qman_release_cgrid_range) +RTE_EXPORT_INTERNAL_SYMBOL(qman_find_fq_by_cgrid) RTE_EXPORT_INTERNAL_SYMBOL(dpaa_intr_enable) RTE_EXPORT_INTERNAL_SYMBOL(dpaa_intr_disable) RTE_EXPORT_INTERNAL_SYMBOL(dpaa_get_ioctl_version_number) diff --git a/drivers/bus/dpaa/include/fsl_qman.h b/drivers/bus/dpaa/include/fsl_qman.h index bd46207232..20321ed355 100644 --- a/drivers/bus/dpaa/include/fsl_qman.h +++ b/drivers/bus/dpaa/include/fsl_qman.h @@ -1907,6 +1907,9 @@ static inline int qman_shutdown_fq_by_fqid(u32 fqid) return qman_shutdown_fq(&fq); } +__rte_internal +int qman_find_fq_by_cgrid(u32 cgrid, u32 *fqid); + /** * qman_reserve_fqid_range - Reserve the specified range of frame queue IDs * @fqid: the base FQID of the range to deallocate diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c index 1615cf3892..e1856580b9 100644 --- a/drivers/net/dpaa/dpaa_ethdev.c +++ b/drivers/net/dpaa/dpaa_ethdev.c @@ -511,7 +511,7 @@ static int dpaa_eth_dev_close(struct rte_eth_dev *dev) struct rte_eth_link *link = &dev->data->dev_link; struct dpaa_if *dpaa_intf = dev->data->dev_private; struct qman_fq *fq; - int loop; + uint32_t fqid, loop; int ret; PMD_INIT_FUNC_TRACE(); @@ -574,28 +574,53 @@ static int dpaa_eth_dev_close(struct rte_eth_dev *dev) /* release configuration memory */ rte_free(dpaa_intf->fc_conf); + /** Release congestion Groups after releasing FQIDs*/ /* Release RX congestion Groups */ if (dpaa_intf->cgr_rx) { for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++) { + ret = qman_find_fq_by_cgrid(dpaa_intf->cgr_rx[loop].cgrid, &fqid); + if (!ret) { + /** Should be FQ not cleaned in previous program.*/ + DPAA_PMD_DEBUG("FQ(fqid=0x%x) with rx cgid=%d is still alive?", + fqid, dpaa_intf->cgr_rx[loop].cgrid); + ret = qman_shutdown_fq_by_fqid(fqid); + if (ret) { + DPAA_PMD_WARN("Failed(%d) to shutdown fq(fqid=0x%x)", + ret, fqid); + } + } ret = qman_delete_cgr(&dpaa_intf->cgr_rx[loop]); if (ret) { DPAA_PMD_WARN("%s: delete rxq%d's cgr err(%d)", dev->data->name, loop, ret); } } + qman_release_cgrid_range(dpaa_intf->cgr_rx[0].cgrid, dpaa_intf->nb_rx_queues); rte_free(dpaa_intf->cgr_rx); dpaa_intf->cgr_rx = NULL; } /* Release TX congestion Groups */ if (dpaa_intf->cgr_tx) { - for (loop = 0; loop < MAX_DPAA_CORES; loop++) { + for (loop = 0; loop < dpaa_intf->nb_tx_queues; loop++) { + ret = qman_find_fq_by_cgrid(dpaa_intf->cgr_tx[loop].cgrid, &fqid); + if (!ret) { + /** Should be FQ not cleaned in previous program.*/ + DPAA_PMD_DEBUG("FQ(fqid=0x%x) with tx cgid=%d is still alive?", + fqid, dpaa_intf->cgr_tx[loop].cgrid); + ret = qman_shutdown_fq_by_fqid(fqid); + if (ret) { + DPAA_PMD_WARN("Failed(%d) to shutdown fq(fqid=0x%x)", + ret, fqid); + } + } ret = qman_delete_cgr(&dpaa_intf->cgr_tx[loop]); if (ret) { DPAA_PMD_WARN("%s: delete txq%d's cgr err(%d)", dev->data->name, loop, ret); } } + qman_release_cgrid_range(dpaa_intf->cgr_tx[0].cgrid, dpaa_intf->nb_tx_queues); rte_free(dpaa_intf->cgr_tx); dpaa_intf->cgr_tx = NULL; } -- 2.25.1

