[v4,07/31] net/ena/base: limit exponential backoff exp

Message ID 20240312180716.8515-8-shaibran@amazon.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/ena: v2.9.0 driver release |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Brandes, Shai March 12, 2024, 6:06 p.m. UTC
From: Shai Brandes <shaibran@amazon.com>

Limit the value of the exponent used for this backoff
at (1<<16) to prevent it from reaching to an excessive
value (1<<32) or potentially even overflowing.
In addition, for uniformity and readability purposes,
the min/max parameter in the calls of ENA_MIN32 and
ENA_MAX32 macros was changed to be first.

Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
---
 drivers/net/ena/base/ena_com.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Ferruh Yigit March 13, 2024, 3:58 p.m. UTC | #1
On 3/12/2024 6:06 PM, shaibran@amazon.com wrote:
> From: Shai Brandes <shaibran@amazon.com>
> 
> Limit the value of the exponent used for this backoff
> at (1<<16) to prevent it from reaching to an excessive
> value (1<<32) or potentially even overflowing.
> In addition, for uniformity and readability purposes,
> the min/max parameter in the calls of ENA_MIN32 and
> ENA_MAX32 macros was changed to be first.
> 
> Signed-off-by: Shai Brandes <shaibran@amazon.com>
> Reviewed-by: Amit Bernstein <amitbern@amazon.com>
> 

Fixes: 0c84e04824db ("net/ena/base: make delay exponential in polling
functions")
Cc: stable@dpdk.org
  

Patch

diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c
index 6953a1fa33..31c37b0ab3 100644
--- a/drivers/net/ena/base/ena_com.c
+++ b/drivers/net/ena/base/ena_com.c
@@ -34,6 +34,8 @@ 
 
 #define ENA_REGS_ADMIN_INTR_MASK 1
 
+#define ENA_MAX_BACKOFF_DELAY_EXP 16U
+
 #define ENA_MIN_ADMIN_POLL_US 100
 
 #define ENA_MAX_ADMIN_POLL_US 5000
@@ -545,8 +547,9 @@  static int ena_com_comp_status_to_errno(struct ena_com_admin_queue *admin_queue,
 
 static void ena_delay_exponential_backoff_us(u32 exp, u32 delay_us)
 {
+	exp = ENA_MIN32(ENA_MAX_BACKOFF_DELAY_EXP, exp);
 	delay_us = ENA_MAX32(ENA_MIN_ADMIN_POLL_US, delay_us);
-	delay_us = ENA_MIN32(delay_us * (1U << exp), ENA_MAX_ADMIN_POLL_US);
+	delay_us = ENA_MIN32(ENA_MAX_ADMIN_POLL_US, delay_us * (1U << exp));
 	ENA_USLEEP(delay_us);
 }