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 <renata.saiakh...@ekinops.com>
---
  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

Reply via email to