From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 417BA5A4B for ; Fri, 7 Aug 2015 17:27:40 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 07 Aug 2015 08:27:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,630,1432623600"; d="scan'208";a="779757633" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 07 Aug 2015 08:27:34 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t77FRXuB002603 for ; Fri, 7 Aug 2015 16:27:33 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id t77FRX1i004061 for ; Fri, 7 Aug 2015 16:27:33 +0100 Received: (from smonroy@localhost) by sivswdev02.ir.intel.com with id t77FRXu1004057 for dev@dpdk.org; Fri, 7 Aug 2015 16:27:33 +0100 From: Sergio Gonzalez Monroy To: dev@dpdk.org Date: Fri, 7 Aug 2015 16:27:33 +0100 Message-Id: <1438961253-4011-2-git-send-email-sergio.gonzalez.monroy@intel.com> X-Mailer: git-send-email 1.8.5.4 In-Reply-To: <1438961253-4011-1-git-send-email-sergio.gonzalez.monroy@intel.com> References: <1438961253-4011-1-git-send-email-sergio.gonzalez.monroy@intel.com> Subject: [dpdk-dev] [PATCH 2/2] mem: fix freeing an IVSHMEM memzone X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Aug 2015 15:27:40 -0000 There is no sync between host and guest to allow removal of memzones, and freeing them result in undefined behavior. In the guest, we identify IVSHMEM memsegs/memzones by having ioremap_addr != 0. In the host, nothing is done to the memzone, meaning ioremap_addr == 0. As a solution, mark memzones being added to IVSHMEM in the host, by setting ioremap_addr, then return an error whenever we try to free an IVSHMEM memzone. Fixes: ff909fe21f0 ("mem: introduce memzone freeing") Signed-off-by: Sergio Gonzalez Monroy --- lib/librte_eal/common/eal_common_memzone.c | 8 ++++++++ lib/librte_eal/common/include/rte_memzone.h | 4 +++- lib/librte_ivshmem/rte_ivshmem.c | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 7b1d77e..febc56b 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -322,6 +322,14 @@ rte_memzone_free(const struct rte_memzone *mz) idx = idx / sizeof(struct rte_memzone); addr = mcfg->memzone[idx].addr; +#ifdef RTE_LIBRTE_IVSHMEM + /* + * If ioremap_addr is set, it's an IVSHMEM memzone and we cannot + * free it. + */ + if (mcfg->memzone[idx].ioremap_addr != 0) + ret = -EINVAL; +#endif if (addr == NULL) ret = -EINVAL; else if (mcfg->memzone_cnt == 0) { diff --git a/lib/librte_eal/common/include/rte_memzone.h b/lib/librte_eal/common/include/rte_memzone.h index 38e5f5b..6a92222 100644 --- a/lib/librte_eal/common/include/rte_memzone.h +++ b/lib/librte_eal/common/include/rte_memzone.h @@ -258,10 +258,12 @@ const struct rte_memzone *rte_memzone_reserve_bounded(const char *name, /** * Free a memzone. * + * Note: an IVSHMEM zone cannot be freed. + * * @param mz * A pointer to the memzone * @return - * -EINVAL - invalid parameter + * -EINVAL - invalid parameter, IVSHMEM memzone. * 0 - success */ int rte_memzone_free(const struct rte_memzone *mz); diff --git a/lib/librte_ivshmem/rte_ivshmem.c b/lib/librte_ivshmem/rte_ivshmem.c index 9621906..8fc4b57 100644 --- a/lib/librte_ivshmem/rte_ivshmem.c +++ b/lib/librte_ivshmem/rte_ivshmem.c @@ -504,7 +504,22 @@ add_memzone_to_metadata(const struct rte_memzone * mz, config->metadata->name); goto fail; } +#ifdef RTE_LIBRTE_IVSHMEM + struct rte_mem_config *mcfg; + unsigned int idx; + mcfg = rte_eal_get_configuration()->mem_config; + + rte_rwlock_write_lock(&mcfg->mlock); + + idx = ((uintptr_t)mz - (uintptr_t)mcfg->memzone); + idx = idx / sizeof(struct rte_memzone); + + /* mark the memzone not freeable */ + mcfg->memzone[idx].ioremap_addr = mz->phys_addr; + + rte_rwlock_write_unlock(&mcfg->mlock); +#endif rte_spinlock_unlock(&config->sl); return 0; fail: -- 1.9.3