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 C9877A057B; Wed, 1 Apr 2020 16:21:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8D9AD1BEB0; Wed, 1 Apr 2020 16:21:42 +0200 (CEST) Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by dpdk.org (Postfix) with ESMTP id 79D461BE91 for ; Wed, 1 Apr 2020 16:21:40 +0200 (CEST) Received: by mail-lj1-f194.google.com with SMTP id t17so25991312ljc.12 for ; Wed, 01 Apr 2020 07:21:40 -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=ml9WG5T39h/X9RwlD+wafkPNAZJw+p0Y2bxqSiZewx8=; b=rJzYfHfQAw8gi7JT/ConxqsmYJBNqgJdwT3EYu/CaJRjW1ENqcTGN7fsJZRY/ZK+29 FpKs7YdBnjrxh4dZJCymBdd9EDOokuG0K0IhrLp/+sRW20C7A/eUR+GmwO8kHBCHW5mC i+EPr6wJf9Dw2SMz20HUppVF8wIamlhMPtMxw37RLzDKFBxjVUA+To4jUeUBApE62Vgu GJzsCHU2RJJpq3kpLVDwQ+FvmS+MsO/xY6X/G+qr6U1z+4k0e35QYUFcIuFVaWMEfNbl FEGatdxheU8PL0OQPJeHgWcSBOHinz0UW/Zo3oeGP16lg3osOP965rvAQq4w4/RMZt3S 6+Xg== 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=ml9WG5T39h/X9RwlD+wafkPNAZJw+p0Y2bxqSiZewx8=; b=is53xvfp03doKsT1ViL5dfbugnrQm93VT0wqCA2MtmminG0BP0j9NGUcKRaa2gM1TA ykfIN8DAgKRm0O3weVJm6kAndRGtwjsZXQsO7VWl0h/IChPOh0IClS7v1IyuafRL0MIb n5iFLUmSTyajhkXqa0KSZ90XfXXu1jheClsbuWuvehNsVjIstO4JhzxXxaU+jEtvP8av rHpNtnsPR9TYwdZtNMYgm4nmKk+kx8PqKIeZtZTC8YCUjnB8MFG4Brups/ZSy0TYsel8 yxkH0wG8JyPjlgMGFTNvsOF0Z21xOoqGfoKfxBa8BEoo0R+a6vndhl9QsVEhoKdAU8nS l3Jg== X-Gm-Message-State: AGi0PubPoHK9kFNuNjNM+tLttLK2ah0ELXzgZxubQ9+0+/7vADd7oZLa 7ZtAwC1A7LHPtJvwKRFj6aMG5iEqXfM= X-Google-Smtp-Source: APiQypI8ZbHUms4IxV2Z13RujQPaVRl2HEX3/DHZdsRNwlC+22DZ7SduEI8DVbfS1gXhYobY6+7/RQ== X-Received: by 2002:a2e:8e2a:: with SMTP id r10mr13123189ljk.276.1585750899786; Wed, 01 Apr 2020 07:21:39 -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 r21sm1435961ljp.29.2020.04.01.07.21.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 07:21:39 -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, stable@dpdk.org, Michal Krawczyk Date: Wed, 1 Apr 2020 16:21:00 +0200 Message-Id: <20200401142127.13715-3-mk@semihalf.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401142127.13715-1-mk@semihalf.com> References: <20200401142127.13715-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 02/29] 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 --- drivers/net/ena/base/ena_plat_dpdk.h | 8 +++++--- drivers/net/ena/ena_ethdev.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index b611fb204b..192bbaefcf 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -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 292526466c..854c724e32 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