From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CFFA5A04A2 for ; Tue, 5 Nov 2019 06:09:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9C322374C; Tue, 5 Nov 2019 06:09:28 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id EAA382BC7; Tue, 5 Nov 2019 06:09:24 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Nov 2019 21:09:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,270,1569308400"; d="scan'208";a="232337050" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 04 Nov 2019 21:09:23 -0800 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 4 Nov 2019 21:09:23 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 4 Nov 2019 21:09:23 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.213]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.127]) with mapi id 14.03.0439.000; Tue, 5 Nov 2019 13:09:21 +0800 From: "Xing, Beilei" To: "Wang, ShougangX" , "dev@dpdk.org" CC: "Yang, Qiming" , "Cao, Yahui" , "stable@dpdk.org" Thread-Topic: [PATCH] net/ice: fix memory release in FDIR Thread-Index: AQHVk4WFlAAUtQp6vU6W+2l7Wjy896d8BtEw Date: Tue, 5 Nov 2019 05:09:20 +0000 Message-ID: <94479800C636CB44BD422CB454846E013CE80E82@SHSMSX101.ccr.corp.intel.com> References: <20191104204347.62267-1-shougangx.wang@intel.com> In-Reply-To: <20191104204347.62267-1-shougangx.wang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-stable] [PATCH] net/ice: fix memory release in FDIR X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" > -----Original Message----- > From: Wang, ShougangX > Sent: Tuesday, November 5, 2019 4:44 AM > To: dev@dpdk.org > Cc: Yang, Qiming ; Xing, Beilei > ; Cao, Yahui ; Wang, Shougang= X > ; stable@dpdk.org > Subject: [PATCH] net/ice: fix memory release in FDIR >=20 > 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 >=20 > Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine") > Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/re= lease") > Cc: stable@dpdk.org >=20 > Signed-off-by: Wang ShougangX > --- > drivers/net/ice/ice_ethdev.h | 1 + > drivers/net/ice/ice_fdir_filter.c | 41 ++++++++++++++++++++++++++++--- > 2 files changed, 38 insertions(+), 4 deletions(-) >=20 > 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; >=20 > 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 =3D 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] =3D NULL; > + > for (ptype =3D 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 =3D NULL; > return -ENOMEM; > } >=20 > @@ -256,8 +267,13 @@ ice_fdir_counter_release(struct ice_pf *pf) > &fdir_info->counter; > uint8_t i; >=20 > - for (i =3D 0; i < container->index_free; i++) > + for (i =3D 0; i < container->index_free; i++) { > rte_free(container->pools[i]); > + container->pools[i] =3D NULL; > + } > + > + TAILQ_INIT(&container->pool_list); > + container->index_free =3D 0; >=20 > 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 =3D NULL; > + fdir_info->hash_table =3D NULL; > } >=20 > /* > @@ -493,19 +512,23 @@ ice_fdir_setup(struct ice_pf *pf) > } > pf->fdir.prg_pkt =3D mz->addr; > pf->fdir.dma_addr =3D mz->iova; > + pf->fdir.mz =3D mz; >=20 > err =3D ice_fdir_prof_alloc(hw); > if (err) { > PMD_DRV_LOG(ERR, "Cannot allocate memory for " > "flow director profile."); > err =3D -ENOMEM; > - goto fail_mem; > + goto fail_prof; > } >=20 > PMD_DRV_LOG(INFO, "FDIR setup successfully, with programming > queue %u.", > vsi->base_queue); > return ICE_SUCCESS; >=20 > +fail_prof: > + rte_memzone_free(pf->fdir.mz); > + pf->fdir.mz =3D NULL; > fail_mem: > ice_rx_queue_release(pf->fdir.rxq); > pf->fdir.rxq =3D NULL; > @@ -525,10 +548,13 @@ ice_fdir_prof_free(struct ice_hw *hw) >=20 > for (ptype =3D ICE_FLTR_PTYPE_NONF_IPV4_UDP; > ptype < ICE_FLTR_PTYPE_MAX; > - ptype++) > + ptype++) { > rte_free(hw->fdir_prof[ptype]); > + hw->fdir_prof[ptype] =3D NULL; > + } >=20 > rte_free(hw->fdir_prof); > + hw->fdir_prof =3D NULL; > } >=20 > /* 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; >=20 > - for (ptype =3D ICE_FLTR_PTYPE_NONF_NONE; > + for (ptype =3D 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 =3D NULL; > + > + if (pf->fdir.mz) { > + err =3D rte_memzone_free(pf->fdir.mz); > + pf->fdir.mz =3D NULL; > + if (err) > + PMD_DRV_LOG(ERR, "Failed to free memezone."); > + } > } >=20 > static int > -- > 2.17.1