From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5438DA0C47; Tue, 6 Jul 2021 10:58:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3FAEF4120E; Tue, 6 Jul 2021 10:58:09 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1A1474120E for ; Tue, 6 Jul 2021 10:58:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625561887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5iiYwb3H0EqmUXUYnm7s5y1x/T4f9CCaPV2paQ+F2PA=; b=jEnxs3Bry4icxXZoEF/IxftnlIzCzrv2Zu00r9f7BRR1Uez6atxjh6VhdNVVuEb3NLfQVm x/kztIrgR+ngcxGS2xAP9JKDx7+PzdXLGMs2lP6FGGZVRi6B3rKMXtMZ70K0jwwoBIdjBS jhU/lUcW6VAyWsvZNIabWUHR2qfmSNk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-Ef7dlJO5PlG7Ylh6uc72yw-1; Tue, 06 Jul 2021 04:58:04 -0400 X-MC-Unique: Ef7dlJO5PlG7Ylh6uc72yw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 37BFA100C660; Tue, 6 Jul 2021 08:58:02 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BF41369A; Tue, 6 Jul 2021 08:57:56 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: stable@dpdk.org, Jingjing Wu , Beilei Xing , "Min Hu (Connor)" , Yisen Zhuang , Lijun Ou , Qiming Yang , Qi Zhang , Helin Zhang , Ferruh Yigit , Wenzhuo Lu , Huisong Li , Chunsong Feng , "Wei Hu (Xavier)" , Hao Chen Date: Tue, 6 Jul 2021 10:57:50 +0200 Message-Id: <20210706085750.5453-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Caught by code review. Using a random name for memzone allocations can result in init failures in the unlikely case that a name collision occurs. Use a simple sequential generator on 64 bits. Fixes: 3f50f072ff06 ("i40e: fix memzone freeing") Fixes: 22b123a36d07 ("net/avf: initialize PMD") Fixes: 5f0978e96220 ("net/ice/base: add OS specific implementation") Fixes: 737f30e1c3ab ("net/hns3: support command interface with firmware") Cc: stable@dpdk.org Signed-off-by: David Marchand --- drivers/common/iavf/iavf_impl.c | 5 +++-- drivers/net/hns3/hns3_cmd.c | 4 +++- drivers/net/i40e/i40e_ethdev.c | 4 +++- drivers/net/ice/base/ice_osdep.h | 5 +++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/common/iavf/iavf_impl.c b/drivers/common/iavf/iavf_impl.c index 0c7d5c0dae..8919b0e7c3 100644 --- a/drivers/common/iavf/iavf_impl.c +++ b/drivers/common/iavf/iavf_impl.c @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -19,13 +18,15 @@ iavf_allocate_dma_mem_d(__rte_unused struct iavf_hw *hw, u64 size, u32 alignment) { + static uint64_t iavf_dma_memzone_id; const struct rte_memzone *mz = NULL; char z_name[RTE_MEMZONE_NAMESIZE]; if (!mem) return IAVF_ERR_PARAM; - snprintf(z_name, sizeof(z_name), "iavf_dma_%"PRIu64, rte_rand()); + snprintf(z_name, sizeof(z_name), "iavf_dma_%" PRIu64, + __atomic_fetch_add(&iavf_dma_memzone_id, 1, __ATOMIC_RELAXED)); mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M); diff --git a/drivers/net/hns3/hns3_cmd.c b/drivers/net/hns3/hns3_cmd.c index 44a4e2860d..175d48d14b 100644 --- a/drivers/net/hns3/hns3_cmd.c +++ b/drivers/net/hns3/hns3_cmd.c @@ -44,10 +44,12 @@ static int hns3_allocate_dma_mem(struct hns3_hw *hw, struct hns3_cmq_ring *ring, uint64_t size, uint32_t alignment) { + static uint64_t hns3_dma_memzone_id; const struct rte_memzone *mz = NULL; char z_name[RTE_MEMZONE_NAMESIZE]; - snprintf(z_name, sizeof(z_name), "hns3_dma_%" PRIu64, rte_rand()); + snprintf(z_name, sizeof(z_name), "hns3_dma_%" PRIu64, + __atomic_fetch_add(&hns3_dma_memzone_id, 1, __ATOMIC_RELAXED)); mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M); diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index dd61258739..87d5053a24 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -4548,13 +4548,15 @@ i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw, u64 size, u32 alignment) { + static uint64_t i40e_dma_memzone_id; const struct rte_memzone *mz = NULL; char z_name[RTE_MEMZONE_NAMESIZE]; if (!mem) return I40E_ERR_PARAM; - snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand()); + snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64, + __atomic_fetch_add(&i40e_dma_memzone_id, 1, __ATOMIC_RELAXED)); mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M); if (!mz) diff --git a/drivers/net/ice/base/ice_osdep.h b/drivers/net/ice/base/ice_osdep.h index 878c5597d4..154fe96e93 100644 --- a/drivers/net/ice/base/ice_osdep.h +++ b/drivers/net/ice/base/ice_osdep.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "ice_alloc.h" @@ -260,13 +259,15 @@ static inline void * ice_alloc_dma_mem(__rte_unused struct ice_hw *hw, struct ice_dma_mem *mem, u64 size) { + static uint64_t ice_dma_memzone_id; const struct rte_memzone *mz = NULL; char z_name[RTE_MEMZONE_NAMESIZE]; if (!mem) return NULL; - snprintf(z_name, sizeof(z_name), "ice_dma_%"PRIu64, rte_rand()); + snprintf(z_name, sizeof(z_name), "ice_dma_%" PRIu64, + __atomic_fetch_add(&ice_dma_memzone_id, 1, __ATOMIC_RELAXED)); mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0, 0, RTE_PGSIZE_2M); if (!mz) -- 2.23.0