From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from compass.polito.it (compass.polito.it [130.192.55.110]) by dpdk.org (Postfix) with ESMTP id 3CCAA2B97 for ; Fri, 1 Apr 2016 10:16:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 0175F1001D0; Fri, 1 Apr 2016 10:16:54 +0200 (CEST) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=x-mailer:message-id:date:date:subject :subject:cc:to:from:from:received:received; s=y2k10; t= 1459498613; bh=69QAgo5rBd4EgTTg+grEV/JLARUz1Gc7Ar07ezfG2ZA=; b=g 1fW1mn+QNHGRvTebsVOHsin0M4m6PKc/hVZqhWogPRMjB2uOYN/qES70QMBr1ISb i9D4F6o/ImdO8lJ7SxP70n6Z8+cKmZzN0msS9uhUKlUeXtoYumuIbCY/5jTJ4684 3y/DKXbdDQArk/JcDxPM2Wb4DZ0P5VJJ58fYpB17Vk= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -5.825 X-Spam-Level: X-Spam-Status: No, score=-5.825 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, AWL=0.675, BAYES_00=-1.5] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pvTyJVZZJiuD; Fri, 1 Apr 2016 10:16:53 +0200 (CEST) Received: from localhost.localdomain (unknown [130.192.225.153]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id 1E8CE1001CF; Fri, 1 Apr 2016 10:16:53 +0200 (CEST) From: Mauricio Vasquez B To: Anatoly Burakov Cc: dev@dpdk.org Date: Fri, 1 Apr 2016 10:16:48 +0200 Message-Id: <1459498608-10789-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] ivshmem: fix race condition 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, 01 Apr 2016 08:16:54 -0000 The memory zone could be freed just after adding it to the metadata file and just before marking it as not freeable. This patch changes the locking logic in order to prevent it. Fixes: cd10c42eb5bc ("mem: fix ivshmem freeing") Signed-off-by: Mauricio Vasquez B --- lib/librte_ivshmem/rte_ivshmem.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/librte_ivshmem/rte_ivshmem.c b/lib/librte_ivshmem/rte_ivshmem.c index 8fc4b57..ed2c276 100644 --- a/lib/librte_ivshmem/rte_ivshmem.c +++ b/lib/librte_ivshmem/rte_ivshmem.c @@ -471,10 +471,16 @@ add_memzone_to_metadata(const struct rte_memzone * mz, struct ivshmem_config * config) { struct rte_ivshmem_metadata_entry * entry; - unsigned i; + unsigned i, idx; + struct rte_mem_config *mcfg; rte_spinlock_lock(&config->sl); + mcfg = rte_eal_get_configuration()->mem_config; + + /* it prevents the memzone being freed while we add it to the metadata */ + rte_rwlock_write_lock(&mcfg->mlock); + /* find free slot in this config */ for (i = 0; i < RTE_DIM(config->metadata->entry); i++) { entry = &config->metadata->entry[i]; @@ -504,13 +510,6 @@ 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); @@ -519,10 +518,10 @@ add_memzone_to_metadata(const struct rte_memzone * mz, mcfg->memzone[idx].ioremap_addr = mz->phys_addr; rte_rwlock_write_unlock(&mcfg->mlock); -#endif rte_spinlock_unlock(&config->sl); return 0; fail: + rte_rwlock_write_unlock(&mcfg->mlock); rte_spinlock_unlock(&config->sl); return -1; } -- 1.9.1