net/ice: fix memzone reserve and release in flow director
authorShougang Wang <shougangx.wang@intel.com>
Wed, 13 Nov 2019 01:37:55 +0000 (01:37 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 20 Nov 2019 16:36:05 +0000 (17:36 +0100)
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: Shougang Wang <shougangx.wang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Xiaolong Ye <xiaolong.ye@intel.com>
drivers/net/ice/ice_ethdev.h
drivers/net/ice/ice_fdir_filter.c

index e2a0f6b..4a0d37b 100644 (file)
@@ -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;
index afab5af..a89c506 100644 (file)
@@ -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