patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH 02/29] net/ena/base: make allocation macros thread-safe
       [not found] <20200327101823.12646-1-mk@semihalf.com>
@ 2020-03-27 10:17 ` Michal Krawczyk
  2020-03-27 14:54   ` [dpdk-stable] [dpdk-dev] " Stephen Hemminger
  2020-03-27 10:17 ` [dpdk-stable] [PATCH 03/29] net/ena/base: prevent allocation of 0-sized memory Michal Krawczyk
  2020-03-27 10:18 ` [dpdk-stable] [PATCH 15/29] net/ena: set IO ring size to the valid value Michal Krawczyk
  2 siblings, 1 reply; 5+ messages in thread
From: Michal Krawczyk @ 2020-03-27 10:17 UTC (permalink / raw)
  To: dev; +Cc: mw, mba, gtzalik, evgenys, igorch, stable, Michal Krawczyk

From: Igor Chauskin <igorch@amazon.com>

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 <igorch@amazon.com>
Reviewed-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Guy Tzalik <gtzalik@amazon.com>
---
 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 a8f8784a9f..cab38152a7 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-stable] [PATCH 03/29] net/ena/base: prevent allocation of 0-sized memory
       [not found] <20200327101823.12646-1-mk@semihalf.com>
  2020-03-27 10:17 ` [dpdk-stable] [PATCH 02/29] net/ena/base: make allocation macros thread-safe Michal Krawczyk
@ 2020-03-27 10:17 ` Michal Krawczyk
  2020-03-27 10:18 ` [dpdk-stable] [PATCH 15/29] net/ena: set IO ring size to the valid value Michal Krawczyk
  2 siblings, 0 replies; 5+ messages in thread
From: Michal Krawczyk @ 2020-03-27 10:17 UTC (permalink / raw)
  To: dev; +Cc: mw, mba, gtzalik, evgenys, igorch, stable, Michal Krawczyk

From: Igor Chauskin <igorch@amazon.com>

rte_memzone_reserve() will reserve the biggest contiguous memzone
available if received 0 as size param.

Fixes: 9ba7981ec992 ("ena: add communication layer for DPDK")
Cc: stable@dpdk.org

Signed-off-by: Igor Chauskin <igorch@amazon.com>
Reviewed-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Guy Tzalik <gtzalik@amazon.com>
---
 drivers/net/ena/base/ena_plat_dpdk.h | 29 ++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h
index 192bbaefcf..793ba8a957 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -184,15 +184,18 @@ extern rte_atomic32_t ena_alloc_cnt;
 
 #define ENA_MEM_ALLOC_COHERENT(dmadev, size, virt, phys, handle)	\
 	do {								\
-		const struct rte_memzone *mz;				\
-		char z_name[RTE_MEMZONE_NAMESIZE];			\
+		const struct rte_memzone *mz = NULL;			\
 		ENA_TOUCH(dmadev); ENA_TOUCH(handle);			\
-		snprintf(z_name, sizeof(z_name),			\
+		if (size > 0) {						\
+			char z_name[RTE_MEMZONE_NAMESIZE];		\
+			snprintf(z_name, sizeof(z_name),		\
 			 "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;						\
+			mz = rte_memzone_reserve(z_name, size,		\
+					SOCKET_ID_ANY,			\
+					RTE_MEMZONE_IOVA_CONTIG);	\
+			handle = mz;					\
+		}							\
 		if (mz == NULL) {					\
 			virt = NULL;					\
 			phys = 0;					\
@@ -210,15 +213,17 @@ extern rte_atomic32_t ena_alloc_cnt;
 #define ENA_MEM_ALLOC_COHERENT_NODE(					\
 	dmadev, size, virt, phys, mem_handle, node, dev_node)		\
 	do {								\
-		const struct rte_memzone *mz;				\
-		char z_name[RTE_MEMZONE_NAMESIZE];			\
+		const struct rte_memzone *mz = NULL;			\
 		ENA_TOUCH(dmadev); ENA_TOUCH(dev_node);			\
-		snprintf(z_name, sizeof(z_name),			\
+		if (size > 0) {						\
+			char z_name[RTE_MEMZONE_NAMESIZE];		\
+			snprintf(z_name, sizeof(z_name),		\
 			 "ena_alloc_%d",				\
-			 rte_atomic32_add_return(&ena_alloc_cnt, 1));	\
-		mz = rte_memzone_reserve(z_name, size, node,		\
+			 rte_atomic32_add_return(&ena_alloc_cnt, 1));   \
+			mz = rte_memzone_reserve(z_name, size, node,	\
 				RTE_MEMZONE_IOVA_CONTIG);		\
-		mem_handle = mz;					\
+			mem_handle = mz;				\
+		}							\
 		if (mz == NULL) {					\
 			virt = NULL;					\
 			phys = 0;					\
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-stable] [PATCH 15/29] net/ena: set IO ring size to the valid value
       [not found] <20200327101823.12646-1-mk@semihalf.com>
  2020-03-27 10:17 ` [dpdk-stable] [PATCH 02/29] net/ena/base: make allocation macros thread-safe Michal Krawczyk
  2020-03-27 10:17 ` [dpdk-stable] [PATCH 03/29] net/ena/base: prevent allocation of 0-sized memory Michal Krawczyk
@ 2020-03-27 10:18 ` Michal Krawczyk
  2 siblings, 0 replies; 5+ messages in thread
From: Michal Krawczyk @ 2020-03-27 10:18 UTC (permalink / raw)
  To: dev; +Cc: mw, mba, gtzalik, evgenys, igorch, Michal Krawczyk, stable

IO rings were configured with the maximum allowed size for the Tx/Rx
rings. However, the application could decide to create smaller rings.

This patch is using value stored in the ring instead of the value from
the adapter which is indicating the maximum allowed value.

Fixes: df238f84c0a2 ("net/ena: recreate HW IO rings on start and stop")
Cc: stable@dpdk.org

Signed-off-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Igor Chauskin <igorch@amazon.com>
Reviewed-by: Guy Tzalik <gtzalik@amazon.com>
---
 drivers/net/ena/ena_ethdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 4c1e4899d0..5f9a44ff71 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -1098,16 +1098,15 @@ static int ena_create_io_queue(struct ena_ring *ring)
 		ena_qid = ENA_IO_TXQ_IDX(ring->id);
 		ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX;
 		ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
-		ctx.queue_size = adapter->tx_ring_size;
 		for (i = 0; i < ring->ring_size; i++)
 			ring->empty_tx_reqs[i] = i;
 	} else {
 		ena_qid = ENA_IO_RXQ_IDX(ring->id);
 		ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX;
-		ctx.queue_size = adapter->rx_ring_size;
 		for (i = 0; i < ring->ring_size; i++)
 			ring->empty_rx_reqs[i] = i;
 	}
+	ctx.queue_size = ring->ring_size;
 	ctx.qid = ena_qid;
 	ctx.msix_vector = -1; /* interrupts not used */
 	ctx.numa_node = ring->numa_socket_id;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH 02/29] net/ena/base: make allocation macros thread-safe
  2020-03-27 10:17 ` [dpdk-stable] [PATCH 02/29] net/ena/base: make allocation macros thread-safe Michal Krawczyk
@ 2020-03-27 14:54   ` Stephen Hemminger
  2020-03-31  9:47     ` Michał Krawczyk
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2020-03-27 14:54 UTC (permalink / raw)
  To: Michal Krawczyk; +Cc: dev, mw, mba, gtzalik, evgenys, igorch, stable

On Fri, 27 Mar 2020 11:17:56 +0100
Michal Krawczyk <mk@semihalf.com> wrote:

> From: Igor Chauskin <igorch@amazon.com>
> 
> 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 <igorch@amazon.com>
> Reviewed-by: Michal Krawczyk <mk@semihalf.com>
> Reviewed-by: Guy Tzalik <gtzalik@amazon.com>

With DPDK all control operations are the device are supposed
to be single threaded by the caller. Do you have an allocation in
some datapath?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH 02/29] net/ena/base: make allocation macros thread-safe
  2020-03-27 14:54   ` [dpdk-stable] [dpdk-dev] " Stephen Hemminger
@ 2020-03-31  9:47     ` Michał Krawczyk
  0 siblings, 0 replies; 5+ messages in thread
From: Michał Krawczyk @ 2020-03-31  9:47 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, Marcin Wojtas, Maciej Bielski, Tzalik, Guy, Schmeilin,
	Evgeny, Chauskin, Igor, stable

pt., 27 mar 2020 o 15:54 Stephen Hemminger
<stephen@networkplumber.org> napisał(a):
>
> On Fri, 27 Mar 2020 11:17:56 +0100
> Michal Krawczyk <mk@semihalf.com> wrote:
>
> > From: Igor Chauskin <igorch@amazon.com>
> >
> > 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 <igorch@amazon.com>
> > Reviewed-by: Michal Krawczyk <mk@semihalf.com>
> > Reviewed-by: Guy Tzalik <gtzalik@amazon.com>
>
> With DPDK all control operations are the device are supposed
> to be single threaded by the caller. Do you have an allocation in
> some datapath?

Currently, there aren't any allocations on the datapath. But if you
don't mind, we would like to keep the atomics there for future
robustness.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-31  9:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200327101823.12646-1-mk@semihalf.com>
2020-03-27 10:17 ` [dpdk-stable] [PATCH 02/29] net/ena/base: make allocation macros thread-safe Michal Krawczyk
2020-03-27 14:54   ` [dpdk-stable] [dpdk-dev] " Stephen Hemminger
2020-03-31  9:47     ` Michał Krawczyk
2020-03-27 10:17 ` [dpdk-stable] [PATCH 03/29] net/ena/base: prevent allocation of 0-sized memory Michal Krawczyk
2020-03-27 10:18 ` [dpdk-stable] [PATCH 15/29] net/ena: set IO ring size to the valid value Michal Krawczyk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).