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 82D9CA0597; Wed, 8 Apr 2020 10:29:47 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C9B0C1C069; Wed, 8 Apr 2020 10:29:30 +0200 (CEST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by dpdk.org (Postfix) with ESMTP id 7827F1BFDC for ; Wed, 8 Apr 2020 10:29:27 +0200 (CEST) Received: by mail-lj1-f178.google.com with SMTP id r7so6628823ljg.13 for ; Wed, 08 Apr 2020 01:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wjkQcxrwEVijfs6i/IOTcKsbyTOYyF8v0zZLLJqLqiI=; b=RmTocunwr33CaQJ3VIhheRRRUbmuzHBX6dVDGZ+IhsBoZ3YH4H192flUXfH6LjeJJ8 wbMBYVijsXyu1NjLsv+HeFCk1ghnUta6V9yIlDURPpOFTtgpYxbhH+DFvIi3DH/suwu6 0oTKgNFgR4PzBzWJ/IowBL10chaDdfDlpXqxzEux+FBh3TDTKnMk+yaddy/UBs6akSEc 74+jBghbm8OsCnCU16t3l4qSNm96vUKs76LUR/py/Rlzrrw8R0XiE5Zp3ILV4qBnvEsK 8yGvPzMOoNx3X7FwEcnHCQ2rMbFzsl830XDRaAI7avCFZMyaIqXGMHMF0CzUx4f67xXe HxjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wjkQcxrwEVijfs6i/IOTcKsbyTOYyF8v0zZLLJqLqiI=; b=D8WNPxDI1Bl0wTjQcioyd03mUGkbLphE0LKp7Wwbvi+ddokt8athZVU31QEd4oc/+q qs9N8Tkb/l02rbGUs9RTZrPkNCGrbxFkZ2CTq+dwnhwuVO6dKRisXLZDQxtJFICbyvwU +2Z8qIqzOiBXurOy/samAMYpTLf1Tkyza/FUTDeWwkEIkhYK30u3aztrbYrwp1LrfOmd MfwnqgWKfsBFqy2QCS0bTeF18JxhLIhXYn/RakU/aluUqMqdiY9r3yfRZxlkyo73PFd7 5aS4d4loHWXtFuG+cuAcbpR/6enALQqCY8JDhjDq7pLI3YPYzTndAafhnryqq1lGannu Y3KA== X-Gm-Message-State: AGi0PuYUYNATAWd6oBGHcyIB11BFIRd8/La9Gts4mfb4uQJIyJpd2onn eYYc6fOqoptA797vN5WuW6aBIK1RtiA= X-Google-Smtp-Source: APiQypJZ8OOt9AqEYSEzBSUzBB/Qv3tJ5A+FqrMELGZN4vyuc/nkA0c04MN4X9IAVAvqeEfMHJupTQ== X-Received: by 2002:a2e:3c0b:: with SMTP id j11mr4356316lja.9.1586334566832; Wed, 08 Apr 2020 01:29:26 -0700 (PDT) Received: from mkPC.semihalf.local (193-106-246-138.noc.fibertech.net.pl. [193.106.246.138]) by smtp.gmail.com with ESMTPSA id e8sm765685lja.3.2020.04.08.01.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 01:29:26 -0700 (PDT) From: Michal Krawczyk To: dev@dpdk.org Cc: mw@semihalf.com, mba@semihalf.com, gtzalik@amazon.com, evgenys@amazon.com, igorch@amazon.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, stable@dpdk.org, Michal Krawczyk Date: Wed, 8 Apr 2020 10:28:53 +0200 Message-Id: <20200408082921.31000-3-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200408082921.31000-1-mk@semihalf.com> References: <20200408082921.31000-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 02/30] net/ena/base: make allocation macros thread-safe 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" From: Igor Chauskin Memory allocation region id could possibly be non-unique due to non-atomic increment, causing allocation failure. Fixes: 9ba7981ec992 ("ena: add communication layer for DPDK") Cc: stable@dpdk.org Signed-off-by: Igor Chauskin Reviewed-by: Michal Krawczyk Reviewed-by: Guy Tzalik --- v3: * Update the copyright date in modified files drivers/net/ena/base/ena_plat_dpdk.h | 10 ++++++---- drivers/net/ena/ena_ethdev.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index b611fb204b..70261bdbc6 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates. + * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates. * All rights reserved. */ @@ -180,7 +180,7 @@ do { \ * Each rte_memzone should have unique name. * To satisfy it, count number of allocations and add it to name. */ -extern uint32_t ena_alloc_cnt; +extern rte_atomic32_t ena_alloc_cnt; #define ENA_MEM_ALLOC_COHERENT(dmadev, size, virt, phys, handle) \ do { \ @@ -188,7 +188,8 @@ extern uint32_t ena_alloc_cnt; char z_name[RTE_MEMZONE_NAMESIZE]; \ ENA_TOUCH(dmadev); ENA_TOUCH(handle); \ snprintf(z_name, sizeof(z_name), \ - "ena_alloc_%d", ena_alloc_cnt++); \ + "ena_alloc_%d", \ + rte_atomic32_add_return(&ena_alloc_cnt, 1)); \ mz = rte_memzone_reserve(z_name, size, SOCKET_ID_ANY, \ RTE_MEMZONE_IOVA_CONTIG); \ handle = mz; \ @@ -213,7 +214,8 @@ extern uint32_t ena_alloc_cnt; char z_name[RTE_MEMZONE_NAMESIZE]; \ ENA_TOUCH(dmadev); ENA_TOUCH(dev_node); \ snprintf(z_name, sizeof(z_name), \ - "ena_alloc_%d", ena_alloc_cnt++); \ + "ena_alloc_%d", \ + rte_atomic32_add_return(&ena_alloc_cnt, 1)); \ mz = rte_memzone_reserve(z_name, size, node, \ RTE_MEMZONE_IOVA_CONTIG); \ mem_handle = mz; \ diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index 64aabbbb19..e0ed28419c 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -89,7 +89,7 @@ struct ena_stats { * Each rte_memzone should have unique name. * To satisfy it, count number of allocation and add it to name. */ -uint32_t ena_alloc_cnt; +rte_atomic32_t ena_alloc_cnt; static const struct ena_stats ena_stats_global_strings[] = { ENA_STAT_GLOBAL_ENTRY(wd_expired), -- 2.20.1