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 1808AA04B8; Tue, 5 May 2020 12:46:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2E4401D563; Tue, 5 May 2020 12:45:54 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 1BBA51D14F for ; Tue, 5 May 2020 12:45:51 +0200 (CEST) IronPort-SDR: b/IRLJx0k9p8tPCfNgzubWQE9rYTTUQZRru0JgD3mD8y1mwXZoJvRlmk8acxUHtaGYGM+q1r7E fmJwOb1jD1rQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2020 03:45:49 -0700 IronPort-SDR: A+rWnBCHVH196Vhe7w8EqtfSzI+GXGXLcfJ2Vp0RCaUHB26oQS/ogG1ECyKOwHd9TQXrsss8pr LHjKccGJ0Z/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,354,1583222400"; d="scan'208";a="304438594" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.197.31]) ([10.213.197.31]) by FMSMGA003.fm.intel.com with ESMTP; 05 May 2020 03:45:48 -0700 From: "Burakov, Anatoly" To: Renata Saiakhova , dev@dpdk.org References: <20200503162636.5233-1-Renata.Saiakhova@ekinops.com> <20200503162636.5233-2-Renata.Saiakhova@ekinops.com> Message-ID: Date: Tue, 5 May 2020 11:45:47 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH 1/2] librte_ethdev: Introduce a function to release HW rings X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 05-May-20 11:25 AM, Burakov, Anatoly wrote: > On 03-May-20 5:26 PM, Renata Saiakhova wrote: >> Free previously allocated memzone for HW rings >> >> Signed-off-by: Renata Saiakhova >> --- >>   lib/librte_ethdev/rte_ethdev.c           | 23 +++++++++++++++++++++++ >>   lib/librte_ethdev/rte_ethdev_driver.h    | 14 ++++++++++++++ >>   lib/librte_ethdev/rte_ethdev_version.map |  1 + >>   3 files changed, 38 insertions(+) >> >> diff --git a/lib/librte_ethdev/rte_ethdev.c >> b/lib/librte_ethdev/rte_ethdev.c >> index 72aed59a5..c6d27e1aa 100644 >> --- a/lib/librte_ethdev/rte_ethdev.c >> +++ b/lib/librte_ethdev/rte_ethdev.c >> @@ -4206,6 +4206,29 @@ rte_eth_dma_zone_reserve(const struct >> rte_eth_dev *dev, const char *ring_name, >>               RTE_MEMZONE_IOVA_CONTIG, align); >>   } >> +int >> +rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char >> *ring_name, >> +        uint16_t queue_id) >> +{ >> +    char z_name[RTE_MEMZONE_NAMESIZE]; >> +    const struct rte_memzone *mz; >> +    int rc = 0; >> + >> +    snprintf(z_name, sizeof(z_name), "eth_p%d_q%d_%s", >> +            dev->data->port_id, queue_id, ring_name); >> +    if (rc >= RTE_MEMZONE_NAMESIZE) { >> +        RTE_ETHDEV_LOG(ERR, "ring name too long\n"); >> +        rte_errno = ENAMETOOLONG; >> +        return NULL; >> +    } >> + >> +    mz = rte_memzone_lookup(z_name); >> +    if (mz) >> +        rc = rte_memzone_free(mz); > > This is racy. Please just use rte_memzone_free() unconditionally. It'll > return 0 if memzone existed, or will set rte_errno to EINVAL if it > didn't. (this is suboptimal, it should be ENOENT, but changing this > would be an API break... I'll submit a patch for future release to fix > this) > My apologies, just using rte_memzone_free will not solve the problem because you don't have memzone pointer. Now that i think of it, the rte_eth_dma_zone_reserve() suffers from this issue too, and the problem is lack of atomic "find or create" memzone API. This patch is OK for now, as it follows similar code in rte_eth_dma_zone_reserve(), but ideally, this should be fixed at the memzone API level. I'll see if i can cobble together a quick patchset adding atomic "find or reserve" and "find and free" operations. -- Thanks, Anatoly