DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory
@ 2021-07-06  8:57 David Marchand
  2021-07-06  9:36 ` Min Hu (Connor)
  2021-07-06 13:24 ` [dpdk-dev] [dpdk-stable] " Wang, Haiyue
  0 siblings, 2 replies; 5+ messages in thread
From: David Marchand @ 2021-07-06  8:57 UTC (permalink / raw)
  To: dev
  Cc: stable, 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

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 <david.marchand@redhat.com>
---
 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 <inttypes.h>
 
 #include <rte_common.h>
-#include <rte_random.h>
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 
@@ -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 <rte_cycles.h>
 #include <rte_spinlock.h>
 #include <rte_log.h>
-#include <rte_random.h>
 #include <rte_io.h>
 
 #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


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

* Re: [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory
  2021-07-06  8:57 [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory David Marchand
@ 2021-07-06  9:36 ` Min Hu (Connor)
  2021-07-06  9:49   ` David Marchand
  2021-07-06 13:24 ` [dpdk-dev] [dpdk-stable] " Wang, Haiyue
  1 sibling, 1 reply; 5+ messages in thread
From: Min Hu (Connor) @ 2021-07-06  9:36 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: stable, Jingjing Wu, Beilei Xing, Yisen Zhuang, Lijun Ou,
	Qiming Yang, Qi Zhang, Helin Zhang, Ferruh Yigit, Wenzhuo Lu,
	Huisong Li, Chunsong Feng, Wei Hu (Xavier),
	Hao Chen

acked.

在 2021/7/6 16:57, David Marchand 写道:
> 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 <david.marchand@redhat.com>
> ---
>   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 <inttypes.h>
>   
>   #include <rte_common.h>
> -#include <rte_random.h>
>   #include <rte_malloc.h>
>   #include <rte_memzone.h>
>   
> @@ -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 <rte_cycles.h>
>   #include <rte_spinlock.h>
>   #include <rte_log.h>
> -#include <rte_random.h>
>   #include <rte_io.h>
>   
>   #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)
> 

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

* Re: [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory
  2021-07-06  9:36 ` Min Hu (Connor)
@ 2021-07-06  9:49   ` David Marchand
  2021-07-06 10:37     ` Min Hu (Connor)
  0 siblings, 1 reply; 5+ messages in thread
From: David Marchand @ 2021-07-06  9:49 UTC (permalink / raw)
  To: Min Hu (Connor)
  Cc: dev, dpdk stable, Jingjing Wu, Beilei Xing, Yisen Zhuang,
	Lijun Ou, Qiming Yang, Qi Zhang, Helin Zhang, Ferruh Yigit,
	Wenzhuo Lu, Huisong Li, Chunsong Feng, Wei Hu (Xavier),
	Hao Chen

On Tue, Jul 6, 2021 at 11:36 AM Min Hu (Connor) <humin29@huawei.com> wrote:
>
> acked.

Thanks for the quick review, just translating this "acked" to:
Acked-by: Min Hu (Connor) <humin29@huawei.com>

For patchwork to catch it.


-- 
David Marchand


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

* Re: [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory
  2021-07-06  9:49   ` David Marchand
@ 2021-07-06 10:37     ` Min Hu (Connor)
  0 siblings, 0 replies; 5+ messages in thread
From: Min Hu (Connor) @ 2021-07-06 10:37 UTC (permalink / raw)
  To: David Marchand
  Cc: dev, dpdk stable, Jingjing Wu, Beilei Xing, Yisen Zhuang,
	Lijun Ou, Qiming Yang, Qi Zhang, Helin Zhang, Ferruh Yigit,
	Wenzhuo Lu, Huisong Li, Chunsong Feng, Wei Hu (Xavier),
	Hao Chen



在 2021/7/6 17:49, David Marchand 写道:
> On Tue, Jul 6, 2021 at 11:36 AM Min Hu (Connor) <humin29@huawei.com> wrote:
>>
>> acked.
> 
> Thanks for the quick review, just translating this "acked" to:
> Acked-by: Min Hu (Connor) <humin29@huawei.com>
> 
> For patchwork to catch it.
> 
OK, I will do it as you suggest in future.
> 

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

* Re: [dpdk-dev] [dpdk-stable] [PATCH] drivers: fix memzone allocations for DMA memory
  2021-07-06  8:57 [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory David Marchand
  2021-07-06  9:36 ` Min Hu (Connor)
@ 2021-07-06 13:24 ` Wang, Haiyue
  1 sibling, 0 replies; 5+ messages in thread
From: Wang, Haiyue @ 2021-07-06 13:24 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: stable, Wu, Jingjing, Xing, Beilei, Min Hu (Connor),
	Yisen Zhuang, Lijun Ou, Yang, Qiming, Zhang, Qi Z, Zhang, Helin,
	Yigit, Ferruh, Lu, Wenzhuo, Huisong Li, Chunsong Feng,
	Wei Hu (Xavier),
	Hao Chen

> -----Original Message-----
> From: stable <stable-bounces@dpdk.org> On Behalf Of David Marchand
> Sent: Tuesday, July 6, 2021 16:58
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Wu, Jingjing <jingjing.wu@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Min
> Hu (Connor) <humin29@huawei.com>; Yisen Zhuang <yisen.zhuang@huawei.com>; Lijun Ou
> <oulijun@huawei.com>; Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Zhang,
> Helin <helin.zhang@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Lu, Wenzhuo
> <wenzhuo.lu@intel.com>; Huisong Li <lihuisong@huawei.com>; Chunsong Feng <fengchunsong@huawei.com>;
> Wei Hu (Xavier) <xavier.huwei@huawei.com>; Hao Chen <chenhao164@huawei.com>
> Subject: [dpdk-stable] [PATCH] drivers: fix memzone allocations for DMA memory
> 
> 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 <david.marchand@redhat.com>
> ---
>  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(-)
> 

Acked-by: Haiyue Wang <haiyue.wang@intel.com>

> --
> 2.23.0


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

end of thread, other threads:[~2021-07-06 13:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06  8:57 [dpdk-dev] [PATCH] drivers: fix memzone allocations for DMA memory David Marchand
2021-07-06  9:36 ` Min Hu (Connor)
2021-07-06  9:49   ` David Marchand
2021-07-06 10:37     ` Min Hu (Connor)
2021-07-06 13:24 ` [dpdk-dev] [dpdk-stable] " Wang, Haiyue

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).