[PATCH net 3/6] net/mlx5e: Fix misidentification of ASO CQE during poll loop

Tariq Toukan posted 6 patches 1 month, 2 weeks ago
[PATCH net 3/6] net/mlx5e: Fix misidentification of ASO CQE during poll loop
Posted by Tariq Toukan 1 month, 2 weeks ago
From: Gal Pressman <gal@nvidia.com>

The ASO completion poll loop uses usleep_range() which can sleep much
longer than requested due to scheduler latency. Under load, we witnessed
a 20ms+ delay until the process was rescheduled, causing the jiffies
based timeout to expire while the thread is sleeping.

The original do-while loop structure (poll, sleep, check timeout) would
exit without a final poll when waking after timeout, missing a CQE that
arrived during sleep.

Restructure the loop by moving the poll into the while condition,
ensuring we always poll after sleeping, catching CQEs that arrived
during that time.

Fixes: 739cfa34518e ("net/mlx5: Make ASO poll CQ usable in atomic context")
Fixes: 7e3fce82d945 ("net/mlx5e: Overcome slow response for first macsec ASO WQE")
Signed-off-by: Gal Pressman <gal@nvidia.com>
Reviewed-by: Jianbo Liu <jianbol@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c     | 8 +++-----
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 8 +++-----
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
index 7819fb297280..2ab618e11aad 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c
@@ -188,11 +188,9 @@ mlx5e_tc_meter_modify(struct mlx5_core_dev *mdev,
 
 	/* With newer FW, the wait for the first ASO WQE is more than 2us, put the wait 10ms. */
 	expires = jiffies + msecs_to_jiffies(10);
-	do {
-		err = mlx5_aso_poll_cq(aso, true);
-		if (err)
-			usleep_range(2, 10);
-	} while (err && time_is_after_jiffies(expires));
+	while ((err = mlx5_aso_poll_cq(aso, true)) &&
+	       time_is_after_jiffies(expires))
+		usleep_range(2, 10);
 	mutex_unlock(&flow_meters->aso_lock);
 
 	return err;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
index 528b04d4de41..2b3556fbfc42 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
@@ -1412,11 +1412,9 @@ static int macsec_aso_query(struct mlx5_core_dev *mdev, struct mlx5e_macsec *mac
 
 	mlx5_aso_post_wqe(maso, false, &aso_wqe->ctrl);
 	expires = jiffies + msecs_to_jiffies(10);
-	do {
-		err = mlx5_aso_poll_cq(maso, false);
-		if (err)
-			usleep_range(2, 10);
-	} while (err && time_is_after_jiffies(expires));
+	while ((err = mlx5_aso_poll_cq(maso, false)) &&
+	       time_is_after_jiffies(expires))
+		usleep_range(2, 10);
 
 	if (err)
 		goto err_out;
-- 
2.44.0
Re: [PATCH net 3/6] net/mlx5e: Fix misidentification of ASO CQE during poll loop
Posted by Jacob Keller 1 month, 2 weeks ago

On 2/12/2026 2:32 AM, Tariq Toukan wrote:
> From: Gal Pressman <gal@nvidia.com>
> 
> The ASO completion poll loop uses usleep_range() which can sleep much
> longer than requested due to scheduler latency. Under load, we witnessed
> a 20ms+ delay until the process was rescheduled, causing the jiffies
> based timeout to expire while the thread is sleeping.
> 
> The original do-while loop structure (poll, sleep, check timeout) would
> exit without a final poll when waking after timeout, missing a CQE that
> arrived during sleep.
> 
> Restructure the loop by moving the poll into the while condition,
> ensuring we always poll after sleeping, catching CQEs that arrived
> during that time.
> 

I would have re-written these to be based on poll_timeout_us() or 
read_poll_timeout().

Again as with previous patch, I don't know if that warrants a re-roll.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>