* [dpdk-dev] [PATCH] net/ice: fix memory release in FDIR
@ 2019-11-04 20:43 Wang ShougangX
2019-11-05 5:09 ` Xing, Beilei
0 siblings, 1 reply; 3+ messages in thread
From: Wang ShougangX @ 2019-11-04 20:43 UTC (permalink / raw)
To: dev; +Cc: qiming.yang, beilei.xing, yahui.cao, Wang ShougangX, stable
To avoid wild pointer 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.
- Set pointers to NULL after free them.
- Release all counter resources when teardown.
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_ethdev.h | 1 +
drivers/net/ice/ice_fdir_filter.c | 41 ++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 4 deletions(-)
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..059a579dc 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);
@@ -159,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++) {
@@ -177,6 +187,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
fltr_ptype++)
rte_free(hw->fdir_prof[fltr_ptype]);
rte_free(hw->fdir_prof);
+ hw->fdir_prof = NULL;
return -ENOMEM;
}
@@ -256,8 +267,13 @@ 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;
return 0;
}
@@ -403,6 +419,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;
}
/*
@@ -493,19 +512,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;
@@ -525,10 +548,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 */
@@ -573,7 +599,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);
@@ -619,6 +645,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] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] net/ice: fix memory release in FDIR
2019-11-04 20:43 [dpdk-dev] [PATCH] net/ice: fix memory release in FDIR Wang ShougangX
@ 2019-11-05 5:09 ` Xing, Beilei
2019-11-05 6:10 ` Wang, ShougangX
0 siblings, 1 reply; 3+ messages in thread
From: Xing, Beilei @ 2019-11-05 5:09 UTC (permalink / raw)
To: Wang, ShougangX, dev; +Cc: Yang, Qiming, Cao, Yahui, stable
> -----Original Message-----
> From: Wang, ShougangX
> Sent: Tuesday, November 5, 2019 4:44 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> <beilei.xing@intel.com>; Cao, Yahui <yahui.cao@intel.com>; Wang, ShougangX
> <shougangx.wang@intel.com>; stable@dpdk.org
> Subject: [PATCH] net/ice: fix memory release in FDIR
>
> To avoid wild pointer 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.
> - Set pointers to NULL after free them.
> - Release all counter resources when teardown.
Thanks for the patch, but could you split the patch according to different issues?
Beilei
>
> 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_ethdev.h | 1 +
> drivers/net/ice/ice_fdir_filter.c | 41 ++++++++++++++++++++++++++++---
> 2 files changed, 38 insertions(+), 4 deletions(-)
>
> 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..059a579dc 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);
> @@ -159,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++) {
> @@ -177,6 +187,7 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
> fltr_ptype++)
> rte_free(hw->fdir_prof[fltr_ptype]);
> rte_free(hw->fdir_prof);
> + hw->fdir_prof = NULL;
> return -ENOMEM;
> }
>
> @@ -256,8 +267,13 @@ 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;
>
> return 0;
> }
> @@ -403,6 +419,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;
> }
>
> /*
> @@ -493,19 +512,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;
> @@ -525,10 +548,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 */ @@ -573,7 +599,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);
> @@ -619,6 +645,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] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] net/ice: fix memory release in FDIR
2019-11-05 5:09 ` Xing, Beilei
@ 2019-11-05 6:10 ` Wang, ShougangX
0 siblings, 0 replies; 3+ messages in thread
From: Wang, ShougangX @ 2019-11-05 6:10 UTC (permalink / raw)
To: Xing, Beilei, dev; +Cc: Yang, Qiming, Cao, Yahui, stable
Hi, Beilei
> -----Original Message-----
> From: Xing, Beilei
> Sent: Tuesday, November 5, 2019 1:09 PM
> To: Wang, ShougangX <shougangx.wang@intel.com>; dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Cao, Yahui
> <yahui.cao@intel.com>; stable@dpdk.org
> Subject: RE: [PATCH] net/ice: fix memory release in FDIR
>
>
>
> > -----Original Message-----
> > From: Wang, ShougangX
> > Sent: Tuesday, November 5, 2019 4:44 AM
> > To: dev@dpdk.org
> > Cc: Yang, Qiming <qiming.yang@intel.com>; Xing, Beilei
> > <beilei.xing@intel.com>; Cao, Yahui <yahui.cao@intel.com>; Wang,
> > ShougangX <shougangx.wang@intel.com>; stable@dpdk.org
> > Subject: [PATCH] net/ice: fix memory release in FDIR
> >
> > To avoid wild pointer 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.
> > - Set pointers to NULL after free them.
> > - Release all counter resources when teardown.
>
> Thanks for the patch, but could you split the patch according to different issues?
>
> Beilei
OK, I will split them in next version.
Thanks.
Shougang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-05 6:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 20:43 [dpdk-dev] [PATCH] net/ice: fix memory release in FDIR Wang ShougangX
2019-11-05 5:09 ` Xing, Beilei
2019-11-05 6:10 ` Wang, ShougangX
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).