forked from amzn/amzn-drivers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0023-net-ena-base-make-allocation-macros-thread-safe.patch
80 lines (72 loc) · 2.93 KB
/
0023-net-ena-base-make-allocation-macros-thread-safe.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From fdcc0fb63b9014b820a045134799fe87cda9f368 Mon Sep 17 00:00:00 2001
From: Igor Chauskin <[email protected]>
Date: Wed, 8 Apr 2020 10:28:53 +0200
Subject: [PATCH 23/27] net/ena/base: make allocation macros thread-safe
[ upstream commit b14fcac035fd8514851c9140a4e26d765b61c532 ]
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")
Change-Id: Ib9207aaae4e5e7ecdf1a99a0f23a508a53af631d
Signed-off-by: Igor Chauskin <[email protected]>
Reviewed-by: Michal Krawczyk <[email protected]>
Reviewed-by: Guy Tzalik <[email protected]>
---
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 900ba1a6b0..ac2c281297 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -1,7 +1,7 @@
/*-
* BSD LICENSE
*
-* Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
+* Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -201,7 +201,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 { \
@@ -209,7 +209,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; \
@@ -234,7 +235,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 288e53265a..08e21c59b8 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -120,7 +120,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(tx_timeout),
--
2.20.1