DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/ice: fix wild pointer
@ 2019-11-05  3:38 Wang ShougangX
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                   ` (3 more replies)
  0 siblings, 4 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-05  3:38 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, yahui.cao, Wang ShougangX, stable

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
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_fdir_filter.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 736ccd54e..d2c754f07 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -403,6 +403,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -525,10 +528,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR
  2019-11-05  3:38 [dpdk-dev] [PATCH] net/ice: fix wild pointer Wang ShougangX
@ 2019-11-07  2:22 ` Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                     ` (7 more replies)
  2019-11-07  3:19 ` [dpdk-dev] [PATCH] " Ye Xiaolong
                   ` (2 subsequent siblings)
  3 siblings, 8 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-07  2:22 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 46 +++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-07  2:22   ` Wang ShougangX
  2019-11-11  8:09     ` Ye Xiaolong
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-07  2:22 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX, stable

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(-)

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
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] net/ice: fix removal of FDIR profile
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-07  2:22   ` Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-07  2:22 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX, stable

The removal of FDIR profile should start from ICE_FLTR_PTYPE_NONF_IPV4_UDP.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
Cc: stable@dpdk.org

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

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 31705c164..87634e4de 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -583,7 +583,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] net/ice: fix FDIR counter resource release
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-07  2:22   ` Wang ShougangX
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 4/4] net/ice: fix wild pointer Wang ShougangX
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-07  2:22 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX, stable

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")
Cc: stable@dpdk.org

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 87634e4de..94a6e96df 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -265,6 +265,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] net/ice: fix wild pointer
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (2 preceding siblings ...)
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-07  2:22   ` Wang ShougangX
  2019-11-12  0:00   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-07  2:22 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX, stable

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")
Cc: stable@dpdk.org

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 94a6e96df..e6e925b4e 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -165,6 +165,10 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
+
+	/* To avoid wild pointer, unused field pointer should be NULL */
+	hw->fdir_prof[ICE_FLTR_PTYPE_NONF_NONE] = NULL;
+
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
@@ -180,9 +184,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 	return -ENOMEM;
 }
 
@@ -262,8 +270,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -412,6 +422,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -538,10 +551,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH] net/ice: fix wild pointer
  2019-11-05  3:38 [dpdk-dev] [PATCH] net/ice: fix wild pointer Wang ShougangX
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-07  3:19 ` Ye Xiaolong
  2019-11-07  3:30   ` Ye Xiaolong
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  3 siblings, 1 reply; 47+ messages in thread
From: Ye Xiaolong @ 2019-11-07  3:19 UTC (permalink / raw)
  To: Wang ShougangX; +Cc: dev, qiming.yang, beilei.xing, yahui.cao, stable

On 11/05, Wang ShougangX wrote:
>To avoid wild pointer, pointers should be set to NULL after free them.
>
>Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
>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_fdir_filter.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
>index 736ccd54e..d2c754f07 100644
>--- a/drivers/net/ice/ice_fdir_filter.c
>+++ b/drivers/net/ice/ice_fdir_filter.c
>@@ -403,6 +403,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
> 		rte_free(fdir_info->hash_map);
> 	if (fdir_info->hash_table)
> 		rte_hash_free(fdir_info->hash_table);
>+
>+	fdir_info->hash_map = NULL;
>+	fdir_info->hash_table = NULL;
> }
> 
> /*
>@@ -525,10 +528,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
> 
> 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> 	     ptype < ICE_FLTR_PTYPE_MAX;
>-	     ptype++)
>+	     ptype++) {
> 		rte_free(hw->fdir_prof[ptype]);
>+		hw->fdir_prof[ptype] = NULL;
>+	}
> 
> 	rte_free(hw->fdir_prof);
>+	hw->fdir_prof = NULL;
> }
> 
> /* Remove a profile for some filter type */
>-- 
>2.17.1
>

Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>

Applied to dpdk-next-net-intel. Thanks.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH] net/ice: fix wild pointer
  2019-11-07  3:19 ` [dpdk-dev] [PATCH] " Ye Xiaolong
@ 2019-11-07  3:30   ` Ye Xiaolong
  2019-11-07  5:44     ` Wang, ShougangX
  0 siblings, 1 reply; 47+ messages in thread
From: Ye Xiaolong @ 2019-11-07  3:30 UTC (permalink / raw)
  To: Wang ShougangX; +Cc: dev, qiming.yang, beilei.xing, yahui.cao, stable

On 11/07, Ye Xiaolong wrote:
>On 11/05, Wang ShougangX wrote:
>>To avoid wild pointer, pointers should be set to NULL after free them.
>>
>>Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
>>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_fdir_filter.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>>diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
>>index 736ccd54e..d2c754f07 100644
>>--- a/drivers/net/ice/ice_fdir_filter.c
>>+++ b/drivers/net/ice/ice_fdir_filter.c
>>@@ -403,6 +403,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
>> 		rte_free(fdir_info->hash_map);
>> 	if (fdir_info->hash_table)
>> 		rte_hash_free(fdir_info->hash_table);
>>+
>>+	fdir_info->hash_map = NULL;
>>+	fdir_info->hash_table = NULL;
>> }
>> 
>> /*
>>@@ -525,10 +528,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
>> 
>> 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
>> 	     ptype < ICE_FLTR_PTYPE_MAX;
>>-	     ptype++)
>>+	     ptype++) {
>> 		rte_free(hw->fdir_prof[ptype]);
>>+		hw->fdir_prof[ptype] = NULL;
>>+	}
>> 
>> 	rte_free(hw->fdir_prof);
>>+	hw->fdir_prof = NULL;
>> }
>> 
>> /* Remove a profile for some filter type */
>>-- 
>>2.17.1
>>
>
>Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
>
>Applied to dpdk-next-net-intel. Thanks.

Please ignore this mail, I'm still waiting for your new patchset.

Thanks,
Xiaolong

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH] net/ice: fix wild pointer
  2019-11-07  3:30   ` Ye Xiaolong
@ 2019-11-07  5:44     ` Wang, ShougangX
  0 siblings, 0 replies; 47+ messages in thread
From: Wang, ShougangX @ 2019-11-07  5:44 UTC (permalink / raw)
  To: Ye, Xiaolong; +Cc: dev, Yang, Qiming, Xing, Beilei, Cao, Yahui, stable


> -----Original Message-----
> From: Ye, Xiaolong
> Sent: Thursday, November 7, 2019 11:30 AM
> To: Wang, ShougangX <shougangx.wang@intel.com>
> Cc: dev@dpdk.org; Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; Cao, Yahui <yahui.cao@intel.com>; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/ice: fix wild pointer
> 
> On 11/07, Ye Xiaolong wrote:
> >On 11/05, Wang ShougangX wrote:
> >>To avoid wild pointer, pointers should be set to NULL after free them.
> >>
> >>Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
> >>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_fdir_filter.c | 8 +++++++-
> >> 1 file changed, 7 insertions(+), 1 deletion(-)
> >>
> >>diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> >>index 736ccd54e..d2c754f07 100644
> >>--- a/drivers/net/ice/ice_fdir_filter.c
> >>+++ b/drivers/net/ice/ice_fdir_filter.c
> >>@@ -403,6 +403,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
> >> 		rte_free(fdir_info->hash_map);
> >> 	if (fdir_info->hash_table)
> >> 		rte_hash_free(fdir_info->hash_table);
> >>+
> >>+	fdir_info->hash_map = NULL;
> >>+	fdir_info->hash_table = NULL;
> >> }
> >>
> >> /*
> >>@@ -525,10 +528,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
> >>
> >> 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> >> 	     ptype < ICE_FLTR_PTYPE_MAX;
> >>-	     ptype++)
> >>+	     ptype++) {
> >> 		rte_free(hw->fdir_prof[ptype]);
> >>+		hw->fdir_prof[ptype] = NULL;
> >>+	}
> >>
> >> 	rte_free(hw->fdir_prof);
> >>+	hw->fdir_prof = NULL;
> >> }
> >>
> >> /* Remove a profile for some filter type */
> >>--
> >>2.17.1
> >>
> >
> >Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
> >
> >Applied to dpdk-next-net-intel. Thanks.
> 
> Please ignore this mail, I'm still waiting for your new patchset.
> 
OK, I will make a patchset.

> Thanks,
> Xiaolong

Thanks.
Shougang

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-11  8:09     ` Ye Xiaolong
  2019-11-11  8:39       ` Wang, ShougangX
  0 siblings, 1 reply; 47+ messages in thread
From: Ye Xiaolong @ 2019-11-11  8:09 UTC (permalink / raw)
  To: Wang ShougangX; +Cc: dev, qiming.yang, beilei.xing, stable

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
>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-11  8:09     ` Ye Xiaolong
@ 2019-11-11  8:39       ` Wang, ShougangX
  0 siblings, 0 replies; 47+ messages in thread
From: Wang, ShougangX @ 2019-11-11  8:39 UTC (permalink / raw)
  To: Ye, Xiaolong; +Cc: dev, Yang, Qiming, Xing, Beilei, stable

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

^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (3 preceding siblings ...)
  2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 4/4] net/ice: fix wild pointer Wang ShougangX
@ 2019-11-12  0:00   ` Wang ShougangX
  2019-11-12  0:10   ` Wang ShougangX
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:00 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 46 +++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (4 preceding siblings ...)
  2019-11-12  0:00   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-12  0:10   ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                       ` (3 more replies)
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  7 siblings, 4 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:10 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 46 +++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-12  0:10   ` Wang ShougangX
@ 2019-11-12  0:10     ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:10 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

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")

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 c55713cc1..d4ab18436 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -334,6 +334,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 afab5af7f..a89c506c0 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -127,6 +127,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);
@@ -481,19 +487,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;
@@ -607,6 +617,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 FDIR memezone.");
+	}
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  0:10   ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-12  0:10     ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:10 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

The removal of FDIR profile should start from ICE_FLTR_PTYPE_NONF_IPV4_UDP.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")

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

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index a89c506c0..f728b9062 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release
  2019-11-12  0:10   ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12  0:10     ` Wang ShougangX
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:10 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index f728b9062..361969f71 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -252,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer
  2019-11-12  0:10   ` Wang ShougangX
                       ` (2 preceding siblings ...)
  2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-12  0:10     ` Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:10 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 361969f71..78754f365 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -152,6 +152,10 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
+
+	/* To avoid wild pointer, unused field pointer should be NULL */
+	hw->fdir_prof[ICE_FLTR_PTYPE_NONF_NONE] = NULL;
+
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
@@ -167,9 +171,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 	return -ENOMEM;
 }
 
@@ -249,8 +257,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +410,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +539,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (5 preceding siblings ...)
  2019-11-12  0:10   ` Wang ShougangX
@ 2019-11-12  0:26   ` Wang ShougangX
  2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                       ` (3 more replies)
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  7 siblings, 4 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:26 UTC (permalink / raw)
  To: dev; +Cc: Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 46 +++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-12  0:26     ` Wang ShougangX
  2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:26 UTC (permalink / raw)
  To: dev; +Cc: Wang ShougangX

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")

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 c55713cc1..d4ab18436 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -334,6 +334,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 afab5af7f..a89c506c0 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -127,6 +127,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);
@@ -481,19 +487,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;
@@ -607,6 +617,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 FDIR memezone.");
+	}
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-12  0:26     ` Wang ShougangX
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:26 UTC (permalink / raw)
  To: dev; +Cc: Wang ShougangX

The removal of FDIR profile should start from ICE_FLTR_PTYPE_NONF_IPV4_UDP.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")

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

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index a89c506c0..f728b9062 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12  0:27     ` Wang ShougangX
  2019-11-12  7:42       ` Zhang, Qi Z
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:27 UTC (permalink / raw)
  To: dev; +Cc: Wang ShougangX

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index f728b9062..361969f71 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -252,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                       ` (2 preceding siblings ...)
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-12  0:27     ` Wang ShougangX
  2019-11-12  7:39       ` Zhang, Qi Z
  3 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:27 UTC (permalink / raw)
  To: dev; +Cc: Wang ShougangX

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 361969f71..78754f365 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -152,6 +152,10 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
+
+	/* To avoid wild pointer, unused field pointer should be NULL */
+	hw->fdir_prof[ICE_FLTR_PTYPE_NONF_NONE] = NULL;
+
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
@@ -167,9 +171,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 	return -ENOMEM;
 }
 
@@ -249,8 +257,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +410,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +539,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (6 preceding siblings ...)
  2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-12  0:50   ` Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                       ` (3 more replies)
  7 siblings, 4 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 46 +++++++++++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-12  0:50     ` Wang ShougangX
  2019-11-12  7:45       ` Zhang, Qi Z
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                       ` (2 subsequent siblings)
  3 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

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")

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 c55713cc1..d4ab18436 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -334,6 +334,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 afab5af7f..a89c506c0 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -127,6 +127,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);
@@ -481,19 +487,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;
@@ -607,6 +617,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 FDIR memezone.");
+	}
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-12  0:50     ` Wang ShougangX
  2019-11-12  7:50       ` Zhang, Qi Z
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

The removal of FDIR profile should start from ICE_FLTR_PTYPE_NONF_IPV4_UDP.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")

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

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index a89c506c0..f728b9062 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12  0:50     ` Wang ShougangX
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index f728b9062..361969f71 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -252,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer
  2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                       ` (2 preceding siblings ...)
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-12  0:50     ` Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  0:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, beilei.xing, Wang ShougangX

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 361969f71..78754f365 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -152,6 +152,10 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
+
+	/* To avoid wild pointer, unused field pointer should be NULL */
+	hw->fdir_prof[ICE_FLTR_PTYPE_NONF_NONE] = NULL;
+
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
@@ -167,9 +171,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 	return -ENOMEM;
 }
 
@@ -249,8 +257,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +410,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +539,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR
  2019-11-05  3:38 [dpdk-dev] [PATCH] net/ice: fix wild pointer Wang ShougangX
  2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-07  3:19 ` [dpdk-dev] [PATCH] " Ye Xiaolong
@ 2019-11-12  3:50 ` Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                     ` (3 more replies)
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  3 siblings, 4 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  3:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v4 changes:
  Removed unnecessary pointer initialization operations.
  Changed for loop start index in ice_fdir_prof_alloc().
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 43 +++++++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 5 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v4 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-12  3:50   ` Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  3:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

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")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@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 c55713cc1..d4ab18436 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -334,6 +334,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 afab5af7f..a89c506c0 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -127,6 +127,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);
@@ -481,19 +487,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;
@@ -607,6 +617,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 FDIR memezone.");
+	}
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-12  3:50   ` Wang ShougangX
  2019-11-12 10:36     ` Yang, Qiming
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  3:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

The removal of FDIR profile should start from the next
of ICE_FLTR_PTYPE_NONF_NONE.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")

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

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index a89c506c0..039e00a28 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v4 3/4] net/ice: fix FDIR counter resource release
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12  3:50   ` Wang ShougangX
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 4/4] net/ice: fix wild pointer Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  3:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 039e00a28..82dd283f7 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -252,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v4 4/4] net/ice: fix wild pointer
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (2 preceding siblings ...)
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-12  3:50   ` Wang ShougangX
  3 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-12  3:50 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 82dd283f7..ac03819ed 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -152,6 +152,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
+
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
@@ -167,9 +168,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 	return -ENOMEM;
 }
 
@@ -249,8 +254,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +407,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +536,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
@ 2019-11-12  7:39       ` Zhang, Qi Z
  0 siblings, 0 replies; 47+ messages in thread
From: Zhang, Qi Z @ 2019-11-12  7:39 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Wang, ShougangX



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Wang ShougangX
> Sent: Tuesday, November 12, 2019 8:27 AM
> To: dev@dpdk.org
> Cc: Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer
> 
> To avoid wild pointer, pointers should be set to NULL after free them.
> 
> Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
> Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
> Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index 361969f71..78754f365 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -152,6 +152,10 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  		if (!hw->fdir_prof)
>  			return -ENOMEM;
>  	}
> +
> +	/* To avoid wild pointer, unused field pointer should be NULL */
> +	hw->fdir_prof[ICE_FLTR_PTYPE_NONF_NONE] = NULL;

This is not necessary, since ice_malloc already guarantee all the allocated memory is init to 0

> +
>  	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++) {
> @@ -167,9 +171,13 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  fail_mem:
>  	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
>  	     fltr_ptype < ptype;
> -	     fltr_ptype++)
> +	     fltr_ptype++) {
>  		rte_free(hw->fdir_prof[fltr_ptype]);
> +		hw->fdir_prof[fltr_ptype] = NULL;
> +	}
> +
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
>  	return -ENOMEM;
>  }
> 
> @@ -249,8 +257,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
>  				&fdir_info->counter;
>  	uint8_t i;
> 
> -	for (i = 0; i < container->index_free; i++)
> +	for (i = 0; i < container->index_free; i++) {
>  		rte_free(container->pools[i]);
> +		container->pools[i] = NULL;
> +	}
> 
>  	TAILQ_INIT(&container->pool_list);
>  	container->index_free = 0;
> @@ -400,6 +410,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
>  		rte_free(fdir_info->hash_map);
>  	if (fdir_info->hash_table)
>  		rte_hash_free(fdir_info->hash_table);
> +
> +	fdir_info->hash_map = NULL;
> +	fdir_info->hash_table = NULL;
>  }
> 
>  /*
> @@ -526,10 +539,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
> 
>  	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
> -	     ptype++)
> +	     ptype++) {
>  		rte_free(hw->fdir_prof[ptype]);
> +		hw->fdir_prof[ptype] = NULL;
> +	}
> 
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
>  }
> 
>  /* Remove a profile for some filter type */
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release
  2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-12  7:42       ` Zhang, Qi Z
  0 siblings, 0 replies; 47+ messages in thread
From: Zhang, Qi Z @ 2019-11-12  7:42 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Wang, ShougangX



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Wang ShougangX
> Sent: Tuesday, November 12, 2019 8:27 AM
> To: dev@dpdk.org
> Cc: Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release
> 
> All the counter resources should be cleaned up when teardown.
> 
> Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-12  7:45       ` Zhang, Qi Z
  0 siblings, 0 replies; 47+ messages in thread
From: Zhang, Qi Z @ 2019-11-12  7:45 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Yang, Qiming, Xing, Beilei, Wang, ShougangX



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Wang ShougangX
> Sent: Tuesday, November 12, 2019 8:51 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and release
> in FDIR
> 
> 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")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12  7:50       ` Zhang, Qi Z
  2019-11-12  8:03         ` Wang, ShougangX
  0 siblings, 1 reply; 47+ messages in thread
From: Zhang, Qi Z @ 2019-11-12  7:50 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Yang, Qiming, Xing, Beilei, Wang, ShougangX



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Wang ShougangX
> Sent: Tuesday, November 12, 2019 8:51 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
> 
> The removal of FDIR profile should start from
> ICE_FLTR_PTYPE_NONF_IPV4_UDP.
> 
> Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index a89c506c0..f728b9062 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)  {
>  	enum ice_fltr_ptype ptype;
> 
> -	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
> +	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;

Is "ptype = ICE_FLTR_PTYPE_NONF_NONE + 1" better?, so we don't need to worry profile be re-ordered or new one be inserted in future.


>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++) {
>  		ice_fdir_prof_rm(pf, ptype, false);
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  7:50       ` Zhang, Qi Z
@ 2019-11-12  8:03         ` Wang, ShougangX
  0 siblings, 0 replies; 47+ messages in thread
From: Wang, ShougangX @ 2019-11-12  8:03 UTC (permalink / raw)
  To: Zhang, Qi Z, dev; +Cc: Yang, Qiming, Xing, Beilei

Hi, Qi

> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Tuesday, November 12, 2019 3:51 PM
> To: Wang, ShougangX <shougangx.wang@intel.com>; dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: RE: [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile
> 
> 
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of Wang ShougangX
> > Sent: Tuesday, November 12, 2019 8:51 AM
> > To: dev@dpdk.org
> > Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> > <beilei.xing@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> > Subject: [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR
> > profile
> >
> > The removal of FDIR profile should start from
> > ICE_FLTR_PTYPE_NONF_IPV4_UDP.
> >
> > Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
> >
> > Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> > ---
> >  drivers/net/ice/ice_fdir_filter.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ice/ice_fdir_filter.c
> > b/drivers/net/ice/ice_fdir_filter.c
> > index a89c506c0..f728b9062 100644
> > --- a/drivers/net/ice/ice_fdir_filter.c
> > +++ b/drivers/net/ice/ice_fdir_filter.c
> > @@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)  {
> >  	enum ice_fltr_ptype ptype;
> >
> > -	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
> > +	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> 
> Is "ptype = ICE_FLTR_PTYPE_NONF_NONE + 1" better?, so we don't need to
> worry profile be re-ordered or new one be inserted in future.
yes, it is better. I will change it in next version. Thank you very much.

> 
> 
> >  	     ptype < ICE_FLTR_PTYPE_MAX;
> >  	     ptype++) {
> >  		ice_fdir_prof_rm(pf, ptype, false);
> > --
> > 2.17.1

Thanks.
Shougang

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile
  2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-12 10:36     ` Yang, Qiming
  2019-11-13  6:21       ` Wang, ShougangX
  0 siblings, 1 reply; 47+ messages in thread
From: Yang, Qiming @ 2019-11-12 10:36 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Zhang, Qi Z

Hi,

> -----Original Message-----
> From: Wang, ShougangX
> Sent: Tuesday, November 12, 2019 11:50 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [PATCH v4 2/4] net/ice: fix removal of FDIR profile
> 
> The removal of FDIR profile should start from the next of
> ICE_FLTR_PTYPE_NONF_NONE.
> 
> Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index a89c506c0..039e00a28 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)  {
>  	enum ice_fltr_ptype ptype;
> 
> -	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
> +	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;

I think we should also use ICE_FLTR_PTYPE_NONF_NONE + 1 instead of ICE_FLTR_PTYPE_TCP_IPV4 in prof_add,
To make sure it is symmetric. And it should be contained in this patch.

>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++) {
>  		ice_fdir_prof_rm(pf, ptype, false);
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR
  2019-11-05  3:38 [dpdk-dev] [PATCH] net/ice: fix wild pointer Wang ShougangX
                   ` (2 preceding siblings ...)
  2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-13  1:37 ` Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 1/4] net/ice: fix memzone reserve and " Wang ShougangX
                     ` (4 more replies)
  3 siblings, 5 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-13  1:37 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

These patches include FDIR memory resource fixes related to ICE driver.
Patch 1: fix memzone reserve and release in FDIR
Patch 2: fix removal of FDIR profile
Patch 3: fix FDIR counter resource release
Patch 4: fix wild pointer

---
v5 changes:
  Changed loop start index in ice_fdir_prof_alloc().
  Changed loop start index in ice_fdir_prof_free().
v4 changes:
  Removed unnecessary pointer initialization operations.
  Changed loop start index in ice_fdir_prof_rm_all().
v3 changes:
  Changed error log.
v2 changes:
  Merged patches related to CVL memory resources management into patchset.

Wang ShougangX (4):
  net/ice: fix memzone reserve and release in FDIR
  net/ice: fix removal of FDIR profile
  net/ice: fix FDIR counter resource release
  net/ice: fix wild pointer

 drivers/net/ice/ice_ethdev.h      |  1 +
 drivers/net/ice/ice_fdir_filter.c | 49 ++++++++++++++++++++++++++-----
 2 files changed, 42 insertions(+), 8 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v5 1/4] net/ice: fix memzone reserve and release in FDIR
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-13  1:37   ` Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-13  1:37 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

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")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@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 c55713cc1..d4ab18436 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -334,6 +334,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 afab5af7f..a89c506c0 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -127,6 +127,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);
@@ -481,19 +487,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;
@@ -607,6 +617,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 FDIR memezone.");
+	}
 }
 
 static int
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 1/4] net/ice: fix memzone reserve and " Wang ShougangX
@ 2019-11-13  1:37   ` Wang ShougangX
  2019-11-13  8:44     ` Yang, Qiming
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-13  1:37 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

The removal of FDIR profile should start from the next
of ICE_FLTR_PTYPE_NONF_NONE.

Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index a89c506c0..39c0efbdc 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -152,7 +152,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 		if (!hw->fdir_prof)
 			return -ENOMEM;
 	}
-	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		if (!hw->fdir_prof[ptype]) {
@@ -165,7 +165,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 	return 0;
 
 fail_mem:
-	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     fltr_ptype < ptype;
 	     fltr_ptype++)
 		rte_free(hw->fdir_prof[fltr_ptype]);
@@ -521,7 +521,7 @@ ice_fdir_prof_free(struct ice_hw *hw)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
+	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++)
 		rte_free(hw->fdir_prof[ptype]);
@@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)
 {
 	enum ice_fltr_ptype ptype;
 
-	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
+	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
 	     ptype++) {
 		ice_fdir_prof_rm(pf, ptype, false);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v5 3/4] net/ice: fix FDIR counter resource release
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 1/4] net/ice: fix memzone reserve and " Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-13  1:37   ` Wang ShougangX
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer Wang ShougangX
  2019-11-13  8:54   ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Ye Xiaolong
  4 siblings, 0 replies; 47+ messages in thread
From: Wang ShougangX @ 2019-11-13  1:37 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

All the counter resources should be cleaned up when teardown.

Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index 39c0efbdc..e3b633e23 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -252,6 +252,9 @@ ice_fdir_counter_release(struct ice_pf *pf)
 	for (i = 0; i < container->index_free; i++)
 		rte_free(container->pools[i]);
 
+	TAILQ_INIT(&container->pool_list);
+	container->index_free = 0;
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (2 preceding siblings ...)
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
@ 2019-11-13  1:37   ` Wang ShougangX
  2019-11-13  8:44     ` Yang, Qiming
  2019-11-13  8:54   ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Ye Xiaolong
  4 siblings, 1 reply; 47+ messages in thread
From: Wang ShougangX @ 2019-11-13  1:37 UTC (permalink / raw)
  To: dev; +Cc: qiming.yang, qi.z.zhang, Wang ShougangX

To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index e3b633e23..dd0e1b0c9 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -167,9 +167,14 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
+
 	return -ENOMEM;
 }
 
@@ -249,8 +254,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +407,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +536,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile
  2019-11-12 10:36     ` Yang, Qiming
@ 2019-11-13  6:21       ` Wang, ShougangX
  0 siblings, 0 replies; 47+ messages in thread
From: Wang, ShougangX @ 2019-11-13  6:21 UTC (permalink / raw)
  To: Yang, Qiming, dev; +Cc: Zhang, Qi Z

Hi, Qiming

> -----Original Message-----
> From: Yang, Qiming
> Sent: Tuesday, November 12, 2019 6:37 PM
> To: Wang, ShougangX <shougangx.wang@intel.com>; dev@dpdk.org
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: RE: [PATCH v4 2/4] net/ice: fix removal of FDIR profile
> 
> Hi,
> 
> > -----Original Message-----
> > From: Wang, ShougangX
> > Sent: Tuesday, November 12, 2019 11:50 AM
> > To: dev@dpdk.org
> > Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> > <qi.z.zhang@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> > Subject: [PATCH v4 2/4] net/ice: fix removal of FDIR profile
> >
> > The removal of FDIR profile should start from the next of
> > ICE_FLTR_PTYPE_NONF_NONE.
> >
> > Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
> >
> > Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> > ---
> >  drivers/net/ice/ice_fdir_filter.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ice/ice_fdir_filter.c
> > b/drivers/net/ice/ice_fdir_filter.c
> > index a89c506c0..039e00a28 100644
> > --- a/drivers/net/ice/ice_fdir_filter.c
> > +++ b/drivers/net/ice/ice_fdir_filter.c
> > @@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)  {
> >  	enum ice_fltr_ptype ptype;
> >
> > -	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
> > +	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
> 
> I think we should also use ICE_FLTR_PTYPE_NONF_NONE + 1 instead of
> ICE_FLTR_PTYPE_TCP_IPV4 in prof_add, To make sure it is symmetric. And it
> should be contained in this patch.
OK, I will replace them.

> 
> >  	     ptype < ICE_FLTR_PTYPE_MAX;
> >  	     ptype++) {
> >  		ice_fdir_prof_rm(pf, ptype, false);
> > --
> > 2.17.1


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
@ 2019-11-13  8:44     ` Yang, Qiming
  0 siblings, 0 replies; 47+ messages in thread
From: Yang, Qiming @ 2019-11-13  8:44 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Zhang, Qi Z

Hi,

> -----Original Message-----
> From: Wang, ShougangX
> Sent: Wednesday, November 13, 2019 9:38 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [PATCH v5 2/4] net/ice: fix removal of FDIR profile
> 
> The removal of FDIR profile should start from the next of
> ICE_FLTR_PTYPE_NONF_NONE.
> 
> Fixes: 109e8e06249e ("net/ice: configure HW flow director rule")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index a89c506c0..39c0efbdc 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -152,7 +152,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  		if (!hw->fdir_prof)
>  			return -ENOMEM;
>  	}
> -	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> +	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++) {
>  		if (!hw->fdir_prof[ptype]) {
> @@ -165,7 +165,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  	return 0;
> 
>  fail_mem:
> -	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> +	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     fltr_ptype < ptype;
>  	     fltr_ptype++)
>  		rte_free(hw->fdir_prof[fltr_ptype]);
> @@ -521,7 +521,7 @@ ice_fdir_prof_free(struct ice_hw *hw)  {
>  	enum ice_fltr_ptype ptype;
> 
> -	for (ptype = ICE_FLTR_PTYPE_NONF_IPV4_UDP;
> +	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++)
>  		rte_free(hw->fdir_prof[ptype]);
> @@ -571,7 +571,7 @@ ice_fdir_prof_rm_all(struct ice_pf *pf)  {
>  	enum ice_fltr_ptype ptype;
> 
> -	for (ptype = ICE_FLTR_PTYPE_NONF_NONE;
> +	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
>  	     ptype++) {
>  		ice_fdir_prof_rm(pf, ptype, false);
> --
> 2.17.1

Acked-by: Qiming Yang <Qiming.yang@intel.com>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer Wang ShougangX
@ 2019-11-13  8:44     ` Yang, Qiming
  0 siblings, 0 replies; 47+ messages in thread
From: Yang, Qiming @ 2019-11-13  8:44 UTC (permalink / raw)
  To: Wang, ShougangX, dev; +Cc: Zhang, Qi Z

Hi,

> -----Original Message-----
> From: Wang, ShougangX
> Sent: Wednesday, November 13, 2019 9:38 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [PATCH v5 4/4] net/ice: fix wild pointer
> 
> To avoid wild pointer, pointers should be set to NULL after free them.
> 
> Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
> Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
> Fixes: 0f880c3df192 ("net/ice: add flow director counter resource
> init/release")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index e3b633e23..dd0e1b0c9 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -167,9 +167,14 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  fail_mem:
>  	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     fltr_ptype < ptype;
> -	     fltr_ptype++)
> +	     fltr_ptype++) {
>  		rte_free(hw->fdir_prof[fltr_ptype]);
> +		hw->fdir_prof[fltr_ptype] = NULL;
> +	}
> +
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
> +
>  	return -ENOMEM;
>  }
> 
> @@ -249,8 +254,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
>  				&fdir_info->counter;
>  	uint8_t i;
> 
> -	for (i = 0; i < container->index_free; i++)
> +	for (i = 0; i < container->index_free; i++) {
>  		rte_free(container->pools[i]);
> +		container->pools[i] = NULL;
> +	}
> 
>  	TAILQ_INIT(&container->pool_list);
>  	container->index_free = 0;
> @@ -400,6 +407,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
>  		rte_free(fdir_info->hash_map);
>  	if (fdir_info->hash_table)
>  		rte_hash_free(fdir_info->hash_table);
> +
> +	fdir_info->hash_map = NULL;
> +	fdir_info->hash_table = NULL;
>  }
> 
>  /*
> @@ -526,10 +536,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
> 
>  	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
> -	     ptype++)
> +	     ptype++) {
>  		rte_free(hw->fdir_prof[ptype]);
> +		hw->fdir_prof[ptype] = NULL;
> +	}
> 
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
>  }
> 
>  /* Remove a profile for some filter type */
> --
> 2.17.1

Acked-by: Qiming Yang <qiming.yang@intel.com>

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR
  2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
                     ` (3 preceding siblings ...)
  2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer Wang ShougangX
@ 2019-11-13  8:54   ` Ye Xiaolong
  4 siblings, 0 replies; 47+ messages in thread
From: Ye Xiaolong @ 2019-11-13  8:54 UTC (permalink / raw)
  To: Wang ShougangX; +Cc: dev, qiming.yang, qi.z.zhang

On 11/13, Wang ShougangX wrote:
>These patches include FDIR memory resource fixes related to ICE driver.
>Patch 1: fix memzone reserve and release in FDIR
>Patch 2: fix removal of FDIR profile
>Patch 3: fix FDIR counter resource release
>Patch 4: fix wild pointer
>
>---
>v5 changes:
>  Changed loop start index in ice_fdir_prof_alloc().
>  Changed loop start index in ice_fdir_prof_free().
>v4 changes:
>  Removed unnecessary pointer initialization operations.
>  Changed loop start index in ice_fdir_prof_rm_all().
>v3 changes:
>  Changed error log.
>v2 changes:
>  Merged patches related to CVL memory resources management into patchset.
>
>Wang ShougangX (4):
>  net/ice: fix memzone reserve and release in FDIR
>  net/ice: fix removal of FDIR profile
>  net/ice: fix FDIR counter resource release
>  net/ice: fix wild pointer
>
> drivers/net/ice/ice_ethdev.h      |  1 +
> drivers/net/ice/ice_fdir_filter.c | 49 ++++++++++++++++++++++++++-----
> 2 files changed, 42 insertions(+), 8 deletions(-)
>
>-- 
>2.17.1
>

Acked-by: Xiaolong Ye <xiaolong.ye@intel.com>

Series applied to dpdk-next-net-intel, Thanks.

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2019-11-13  8:57 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05  3:38 [dpdk-dev] [PATCH] net/ice: fix wild pointer Wang ShougangX
2019-11-07  2:22 ` [dpdk-dev] [PATCH v2 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-11  8:09     ` Ye Xiaolong
2019-11-11  8:39       ` Wang, ShougangX
2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-07  2:22   ` [dpdk-dev] [PATCH v2 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-12  0:00   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-12  0:10   ` Wang ShougangX
2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-12  0:10     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-12  0:26   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-12  0:26     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-12  7:42       ` Zhang, Qi Z
2019-11-12  0:27     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-12  7:39       ` Zhang, Qi Z
2019-11-12  0:50   ` [dpdk-dev] [PATCH v3 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-12  7:45       ` Zhang, Qi Z
2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-12  7:50       ` Zhang, Qi Z
2019-11-12  8:03         ` Wang, ShougangX
2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-12  0:50     ` [dpdk-dev] [PATCH v3 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-07  3:19 ` [dpdk-dev] [PATCH] " Ye Xiaolong
2019-11-07  3:30   ` Ye Xiaolong
2019-11-07  5:44     ` Wang, ShougangX
2019-11-12  3:50 ` [dpdk-dev] [PATCH v4 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-12 10:36     ` Yang, Qiming
2019-11-13  6:21       ` Wang, ShougangX
2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-12  3:50   ` [dpdk-dev] [PATCH v4 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-13  1:37 ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 1/4] net/ice: fix memzone reserve and " Wang ShougangX
2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 2/4] net/ice: fix removal of FDIR profile Wang ShougangX
2019-11-13  8:44     ` Yang, Qiming
2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 3/4] net/ice: fix FDIR counter resource release Wang ShougangX
2019-11-13  1:37   ` [dpdk-dev] [PATCH v5 4/4] net/ice: fix wild pointer Wang ShougangX
2019-11-13  8:44     ` Yang, Qiming
2019-11-13  8:54   ` [dpdk-dev] [PATCH v5 0/4] net/ice: fix memory release in FDIR Ye Xiaolong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).