diff mbox series

[v3,18/22] net/ena: move default RSS key to shared mem

Message ID 20210506142526.28245-19-mk@semihalf.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers show
Series net/ena: update ENA PMD to v2.3.0 | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michal Krawczyk May 6, 2021, 2:25 p.m. UTC
From: Stanislaw Kardach <kda@semihalf.com>

Make sure the same random generated RSS key is available to all ENA PMD
instances in all processes.

Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
Reviewed-by: Michal Krawczyk <mk@semihalf.com>
Reviewed-by: Igor Chauskin <igorch@amazon.com>
Reviewed-by: Shay Agroskin <shayagr@amazon.com>
---
 drivers/net/ena/ena_ethdev.c | 16 +++++-----------
 drivers/net/ena/ena_ethdev.h |  1 +
 2 files changed, 6 insertions(+), 11 deletions(-)

Comments

Stanislaw Kardach May 10, 2021, 8:27 a.m. UTC | #1
On Thu, May 06, 2021 at 04:25:22PM +0200, Michal Krawczyk wrote:
> From: Stanislaw Kardach <kda@semihalf.com>
> 
> Make sure the same random generated RSS key is available to all ENA PMD
> instances in all processes.
> 
> Signed-off-by: Stanislaw Kardach <kda@semihalf.com>
> Reviewed-by: Michal Krawczyk <mk@semihalf.com>
> Reviewed-by: Igor Chauskin <igorch@amazon.com>
> Reviewed-by: Shay Agroskin <shayagr@amazon.com>
> ---
>  drivers/net/ena/ena_ethdev.c | 16 +++++-----------
>  drivers/net/ena/ena_ethdev.h |  1 +
>  2 files changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
> index 0780e2fee2..5c365e1ab5 100644
> --- a/drivers/net/ena/ena_ethdev.c
> +++ b/drivers/net/ena/ena_ethdev.c
> @@ -276,19 +276,9 @@ static const struct eth_dev_ops ena_dev_ops = {
>  
>  void ena_rss_key_fill(void *key, size_t size)
>  {
> -	static bool key_generated;
> -	static uint8_t default_key[ENA_HASH_KEY_SIZE];
> -	size_t i;
> -
>  	RTE_ASSERT(size <= ENA_HASH_KEY_SIZE);
>  
> -	if (!key_generated) {
> -		for (i = 0; i < ENA_HASH_KEY_SIZE; ++i)
> -			default_key[i] = rte_rand() & 0xff;
> -		key_generated = true;
> -	}
> -
> -	rte_memcpy(key, default_key, size);
> +	rte_memcpy(key, ena_shared_data->default_key, size);
>  }
>  
>  static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
> @@ -1758,7 +1748,11 @@ static uint32_t ena_calc_max_io_queue_num(struct ena_com_dev *ena_dev,
>  
>  static void ena_prepare_shared_data(struct ena_shared_data *shared_data)
>  {
> +	size_t i;
> +
>  	memset(shared_data, 0, sizeof(*shared_data));
> +	for (i = 0; i < ENA_HASH_KEY_SIZE; ++i)
> +		shared_data->default_key[i] = rte_rand() & 0xff;
>  }
>  
>  static int ena_shared_data_init(void)
> diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h
> index e8858c6118..1f7383dce0 100644
> --- a/drivers/net/ena/ena_ethdev.h
> +++ b/drivers/net/ena/ena_ethdev.h
> @@ -209,6 +209,7 @@ struct ena_offloads {
>  
>  /* Holds data shared between all instances of ENA PMD. */
>  struct ena_shared_data {
> +	uint8_t default_key[ENA_HASH_KEY_SIZE];
Given Ferruh's comments on "[PATCH 17/22] net/ena: support SMP for mz
alloc counter" it is probably a better idea to have this default key
generated per-device and keep it in rte_eth_dev.data. This will allow to
eliminate the shared memory segment (freeing issues) and increase
entropy for the different devices.
>  	/* Each rte_memzone should have unique name.
>  	 * To satisfy it, count number of allocation and add it to name.
>  	 */
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c
index 0780e2fee2..5c365e1ab5 100644
--- a/drivers/net/ena/ena_ethdev.c
+++ b/drivers/net/ena/ena_ethdev.c
@@ -276,19 +276,9 @@  static const struct eth_dev_ops ena_dev_ops = {
 
 void ena_rss_key_fill(void *key, size_t size)
 {
-	static bool key_generated;
-	static uint8_t default_key[ENA_HASH_KEY_SIZE];
-	size_t i;
-
 	RTE_ASSERT(size <= ENA_HASH_KEY_SIZE);
 
-	if (!key_generated) {
-		for (i = 0; i < ENA_HASH_KEY_SIZE; ++i)
-			default_key[i] = rte_rand() & 0xff;
-		key_generated = true;
-	}
-
-	rte_memcpy(key, default_key, size);
+	rte_memcpy(key, ena_shared_data->default_key, size);
 }
 
 static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
@@ -1758,7 +1748,11 @@  static uint32_t ena_calc_max_io_queue_num(struct ena_com_dev *ena_dev,
 
 static void ena_prepare_shared_data(struct ena_shared_data *shared_data)
 {
+	size_t i;
+
 	memset(shared_data, 0, sizeof(*shared_data));
+	for (i = 0; i < ENA_HASH_KEY_SIZE; ++i)
+		shared_data->default_key[i] = rte_rand() & 0xff;
 }
 
 static int ena_shared_data_init(void)
diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h
index e8858c6118..1f7383dce0 100644
--- a/drivers/net/ena/ena_ethdev.h
+++ b/drivers/net/ena/ena_ethdev.h
@@ -209,6 +209,7 @@  struct ena_offloads {
 
 /* Holds data shared between all instances of ENA PMD. */
 struct ena_shared_data {
+	uint8_t default_key[ENA_HASH_KEY_SIZE];
 	/* Each rte_memzone should have unique name.
 	 * To satisfy it, count number of allocation and add it to name.
 	 */