[v2,1/4] net/ice: fix memzone reserve and release in FDIR
diff mbox series

Message ID 20191107022217.41046-2-shougangx.wang@intel.com
State Superseded
Delegated to: xiaolong ye
Headers show
Series
  • net/ice: fix memory release in FDIR
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Wang ShougangX Nov. 7, 2019, 2:22 a.m. UTC
To avoid memzone reserve failure and memory leak, following
resources management should be added.
- Check if the FDIR Memzone already exists before reserving.
- Free FDIR memzone when teardown and other failure scenarios.

Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Cc: stable@dpdk.org

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

Comments

Ye Xiaolong Nov. 11, 2019, 8:09 a.m. UTC | #1
On 11/07, Wang ShougangX wrote:
>To avoid memzone reserve failure and memory leak, following
>resources management should be added.
>- Check if the FDIR Memzone already exists before reserving.

In what scenario it will reserve FDIR memzone twice?

>- Free FDIR memzone when teardown and other failure scenarios.
>
>Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
>Cc: stable@dpdk.org

No need to cc stable since commit  84dc7a95a2d3 is in this release.

>
>Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
>---
> drivers/net/ice/ice_ethdev.h      |  1 +
> drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++++-
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
>index de67e5934..0a39ca6ff 100644
>--- a/drivers/net/ice/ice_ethdev.h
>+++ b/drivers/net/ice/ice_ethdev.h
>@@ -325,6 +325,7 @@ struct ice_fdir_info {
> 	struct ice_rx_queue *rxq;
> 	void *prg_pkt;                 /* memory for fdir program packet */
> 	uint64_t dma_addr;             /* physic address of packet memory*/
>+	const struct rte_memzone *mz;
> 	struct ice_fdir_filter_conf conf;
> 
> 	struct ice_fdir_filter_conf **hash_map;
>diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
>index 736ccd54e..31705c164 100644
>--- a/drivers/net/ice/ice_fdir_filter.c
>+++ b/drivers/net/ice/ice_fdir_filter.c
>@@ -140,6 +140,12 @@ static struct ice_flow_parser ice_fdir_parser_comms;
> static const struct rte_memzone *
> ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
> {
>+	const struct rte_memzone *mz;
>+
>+	mz = rte_memzone_lookup(name);
>+	if (mz)
>+		return mz;
>+
> 	return rte_memzone_reserve_aligned(name, len, socket_id,
> 					   RTE_MEMZONE_IOVA_CONTIG,
> 					   ICE_RING_BASE_ALIGN);
>@@ -493,19 +499,23 @@ ice_fdir_setup(struct ice_pf *pf)
> 	}
> 	pf->fdir.prg_pkt = mz->addr;
> 	pf->fdir.dma_addr = mz->iova;
>+	pf->fdir.mz = mz;
> 
> 	err = ice_fdir_prof_alloc(hw);
> 	if (err) {
> 		PMD_DRV_LOG(ERR, "Cannot allocate memory for "
> 			    "flow director profile.");
> 		err = -ENOMEM;
>-		goto fail_mem;
>+		goto fail_prof;
> 	}
> 
> 	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
> 		    vsi->base_queue);
> 	return ICE_SUCCESS;
> 
>+fail_prof:
>+	rte_memzone_free(pf->fdir.mz);
>+	pf->fdir.mz = NULL;
> fail_mem:
> 	ice_rx_queue_release(pf->fdir.rxq);
> 	pf->fdir.rxq = NULL;
>@@ -619,6 +629,13 @@ ice_fdir_teardown(struct ice_pf *pf)
> 	ice_fdir_prof_free(hw);
> 	ice_release_vsi(vsi);
> 	pf->fdir.fdir_vsi = NULL;
>+
>+	if (pf->fdir.mz) {
>+		err = rte_memzone_free(pf->fdir.mz);
>+		pf->fdir.mz = NULL;
>+		if (err)
>+			PMD_DRV_LOG(ERR, "Failed to free memezone.");

Be more specific about the error, like "Failed to free memzone for flow director."



Thanks,
Xiaolong

>+	}
> }
> 
> static int
>-- 
>2.17.1
>
Wang ShougangX Nov. 11, 2019, 8:39 a.m. UTC | #2
Hi, Xiaolong

> -----Original Message-----
> From: Ye, Xiaolong
> Sent: Monday, November 11, 2019 4:10 PM
> To: Wang, ShougangX <shougangx.wang@intel.com>
> Cc: dev@dpdk.org; Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and
> release in FDIR
> 
> On 11/07, Wang ShougangX wrote:
> >To avoid memzone reserve failure and memory leak, following resources
> >management should be added.
> >- Check if the FDIR Memzone already exists before reserving.
> 
> In what scenario it will reserve FDIR memzone twice?

Currently, there is no scenario.
It is a failsafe method, just like i40e_memzone_reserve().

> 
> >- Free FDIR memzone when teardown and other failure scenarios.
> >
> >Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
> >Cc: stable@dpdk.org
> 
> No need to cc stable since commit  84dc7a95a2d3 is in this release.

Got it.

> 
> >
> >Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> >---
> > drivers/net/ice/ice_ethdev.h      |  1 +
> > drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++++-
> > 2 files changed, 19 insertions(+), 1 deletion(-)
> >
> >diff --git a/drivers/net/ice/ice_ethdev.h
> >b/drivers/net/ice/ice_ethdev.h index de67e5934..0a39ca6ff 100644
> >--- a/drivers/net/ice/ice_ethdev.h
> >+++ b/drivers/net/ice/ice_ethdev.h
> >@@ -325,6 +325,7 @@ struct ice_fdir_info {
> > 	struct ice_rx_queue *rxq;
> > 	void *prg_pkt;                 /* memory for fdir program packet */
> > 	uint64_t dma_addr;             /* physic address of packet memory*/
> >+	const struct rte_memzone *mz;
> > 	struct ice_fdir_filter_conf conf;
> >
> > 	struct ice_fdir_filter_conf **hash_map; diff --git
> >a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> >index 736ccd54e..31705c164 100644
> >--- a/drivers/net/ice/ice_fdir_filter.c
> >+++ b/drivers/net/ice/ice_fdir_filter.c
> >@@ -140,6 +140,12 @@ static struct ice_flow_parser
> >ice_fdir_parser_comms;  static const struct rte_memzone *
> >ice_memzone_reserve(const char *name, uint32_t len, int socket_id)  {
> >+	const struct rte_memzone *mz;
> >+
> >+	mz = rte_memzone_lookup(name);
> >+	if (mz)
> >+		return mz;
> >+
> > 	return rte_memzone_reserve_aligned(name, len, socket_id,
> > 					   RTE_MEMZONE_IOVA_CONTIG,
> > 					   ICE_RING_BASE_ALIGN);
> >@@ -493,19 +499,23 @@ ice_fdir_setup(struct ice_pf *pf)
> > 	}
> > 	pf->fdir.prg_pkt = mz->addr;
> > 	pf->fdir.dma_addr = mz->iova;
> >+	pf->fdir.mz = mz;
> >
> > 	err = ice_fdir_prof_alloc(hw);
> > 	if (err) {
> > 		PMD_DRV_LOG(ERR, "Cannot allocate memory for "
> > 			    "flow director profile.");
> > 		err = -ENOMEM;
> >-		goto fail_mem;
> >+		goto fail_prof;
> > 	}
> >
> > 	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming
> queue %u.",
> > 		    vsi->base_queue);
> > 	return ICE_SUCCESS;
> >
> >+fail_prof:
> >+	rte_memzone_free(pf->fdir.mz);
> >+	pf->fdir.mz = NULL;
> > fail_mem:
> > 	ice_rx_queue_release(pf->fdir.rxq);
> > 	pf->fdir.rxq = NULL;
> >@@ -619,6 +629,13 @@ ice_fdir_teardown(struct ice_pf *pf)
> > 	ice_fdir_prof_free(hw);
> > 	ice_release_vsi(vsi);
> > 	pf->fdir.fdir_vsi = NULL;
> >+
> >+	if (pf->fdir.mz) {
> >+		err = rte_memzone_free(pf->fdir.mz);
> >+		pf->fdir.mz = NULL;
> >+		if (err)
> >+			PMD_DRV_LOG(ERR, "Failed to free memezone.");
> 
> Be more specific about the error, like "Failed to free memzone for flow
> director."

Got it.

> 
> 
> 
> Thanks,
> Xiaolong
> 
> >+	}
> > }
> >
> > static int
> >--
> >2.17.1
> >

Thanks.
Shougang

Patch
diff mbox series

diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index de67e5934..0a39ca6ff 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -325,6 +325,7 @@  struct ice_fdir_info {
 	struct ice_rx_queue *rxq;
 	void *prg_pkt;                 /* memory for fdir program packet */
 	uint64_t dma_addr;             /* physic address of packet memory*/
+	const struct rte_memzone *mz;
 	struct ice_fdir_filter_conf conf;
 
 	struct ice_fdir_filter_conf **hash_map;
diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 736ccd54e..31705c164 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -140,6 +140,12 @@  static struct ice_flow_parser ice_fdir_parser_comms;
 static const struct rte_memzone *
 ice_memzone_reserve(const char *name, uint32_t len, int socket_id)
 {
+	const struct rte_memzone *mz;
+
+	mz = rte_memzone_lookup(name);
+	if (mz)
+		return mz;
+
 	return rte_memzone_reserve_aligned(name, len, socket_id,
 					   RTE_MEMZONE_IOVA_CONTIG,
 					   ICE_RING_BASE_ALIGN);
@@ -493,19 +499,23 @@  ice_fdir_setup(struct ice_pf *pf)
 	}
 	pf->fdir.prg_pkt = mz->addr;
 	pf->fdir.dma_addr = mz->iova;
+	pf->fdir.mz = mz;
 
 	err = ice_fdir_prof_alloc(hw);
 	if (err) {
 		PMD_DRV_LOG(ERR, "Cannot allocate memory for "
 			    "flow director profile.");
 		err = -ENOMEM;
-		goto fail_mem;
+		goto fail_prof;
 	}
 
 	PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming queue %u.",
 		    vsi->base_queue);
 	return ICE_SUCCESS;
 
+fail_prof:
+	rte_memzone_free(pf->fdir.mz);
+	pf->fdir.mz = NULL;
 fail_mem:
 	ice_rx_queue_release(pf->fdir.rxq);
 	pf->fdir.rxq = NULL;
@@ -619,6 +629,13 @@  ice_fdir_teardown(struct ice_pf *pf)
 	ice_fdir_prof_free(hw);
 	ice_release_vsi(vsi);
 	pf->fdir.fdir_vsi = NULL;
+
+	if (pf->fdir.mz) {
+		err = rte_memzone_free(pf->fdir.mz);
+		pf->fdir.mz = NULL;
+		if (err)
+			PMD_DRV_LOG(ERR, "Failed to free memezone.");
+	}
 }
 
 static int