Skip to contentSkip to conversation

RDMA/mlx5: Fix bind QP error cleanup flow

PATCH Applied Leon Romanovsky 2 participants 4 messages Feb 20, 2025 – Feb 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/mlx5: Fix bind QP error cleanup flow

From: Patrisious Haddad <[email protected]>

When there is a failure during bind QP, the cleanup flow destroys the counter regardless if it is the one that created it or not, which is problematic since if it isn't the one that created it, that counter could still be in use.

Fix that by destroying the counter only if it was created during this call.

Fixes 45842fc627c7 ("IB/mlx5: Support statistic q counter configuration")
---
 drivers/infiniband/hw/mlx5/counters.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +6 -2
index 4f6c1968a2ee..81cfa74147a1 100644
@@ -546,6 +546,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
 				   struct ib_qp *qp)
 {
 	struct mlx5_ib_dev *dev = to_mdev(qp->device);
+	bool new = false;
 	int err;
 
 	if (!counter->id) {
@@ -560,6 +561,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
 			return err;
 		counter->id =
 			MLX5_GET(alloc_q_counter_out, out, counter_set_id);
+		new = true;
 	}
 
 	err = mlx5_ib_qp_set_counter(qp, counter);
@@ -569,8 +571,10 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
 	return 0;
 
 fail_set_counter:
-	mlx5_ib_counter_dealloc(counter);
-	counter->id = 0;
+	if (new) {
+		mlx5_ib_counter_dealloc(counter);
+		counter->id = 0;
+	}
 
 	return err;
 }
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Leon Romanovsky

From: Patrisious Haddad <[email protected]>

When there is a failure during bind QP, the cleanup flow destroys the counter regardless if it is the one that created it or not, which is problematic since if it isn't the one that created it, that counter could still be in use.

Fix that by destroying the counter only if it was created during this call.

Fixes 45842fc627c7 ("IB/mlx5: Support statistic q counter configuration")
---
  drivers/infiniband/hw/mlx5/counters.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +1 -0
index 4f6c1968a2ee..81cfa74147a1 100644
@@ -546,6 +546,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  				   struct ib_qp *qp)
  {
  	struct mlx5_ib_dev *dev = to_mdev(qp->device);
+	bool new = false;
  	int err;
 
  	if (!counter->id) {

drivers/infiniband/hw/mlx5/counters.c static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, · line 564

Quoted 4 lines
drivers/infiniband/hw/mlx5/counters.c +1 -0
@@ -560,6 +561,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  			return err;
  		counter->id =
  			MLX5_GET(alloc_q_counter_out, out, counter_set_id);
+		new = true;

It seems that there is no other better method except that a new bool variable is used. IMO, this method can fix this problem.

Zhu Yanjun

Quoted 16 lines
drivers/infiniband/hw/mlx5/counters.c +4 -2
  	}
 
  	err = mlx5_ib_qp_set_counter(qp, counter);
@@ -569,8 +571,10 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  	return 0;
 
  fail_set_counter:
-	mlx5_ib_counter_dealloc(counter);
-	counter->id = 0;
+	if (new) {
+		mlx5_ib_counter_dealloc(counter);
+		counter->id = 0;
+	}
 
  	return err;
  }
#2 lore raw
Quoted 37 lines · Zhu Yanjun
Quoted 29 lines · Leon Romanovsky

From: Patrisious Haddad <[email protected]>

When there is a failure during bind QP, the cleanup flow destroys the counter regardless if it is the one that created it or not, which is problematic since if it isn't the one that created it, that counter could still be in use.

Fix that by destroying the counter only if it was created during this call.

Fixes 45842fc627c7 ("IB/mlx5: Support statistic q counter configuration")
---
  drivers/infiniband/hw/mlx5/counters.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mlx5/counters.c +1 -0
index 4f6c1968a2ee..81cfa74147a1 100644
@@ -546,6 +546,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  				   struct ib_qp *qp)
  {
  	struct mlx5_ib_dev *dev = to_mdev(qp->device);
+	bool new = false;
  	int err;
  	if (!counter->id) {

drivers/infiniband/hw/mlx5/counters.c static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter, · line 564

Quoted 4 lines
drivers/infiniband/hw/mlx5/counters.c +1 -0
@@ -560,6 +561,7 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  			return err;
  		counter->id =
  			MLX5_GET(alloc_q_counter_out, out, counter_set_id);
+		new = true;

It seems that there is no other better method except that a new bool variable is used. IMO, this method can fix this problem.

Quoted 1 line

Thanks

Quoted 18 lines

Zhu Yanjun

Quoted 13 lines
drivers/infiniband/hw/mlx5/counters.c +4 -2
  	}
  	err = mlx5_ib_qp_set_counter(qp, counter);
@@ -569,8 +571,10 @@ static int mlx5_ib_counter_bind_qp(struct rdma_counter *counter,
  	return 0;
  fail_set_counter:
-	mlx5_ib_counter_dealloc(counter);
-	counter->id = 0;
+	if (new) {
+		mlx5_ib_counter_dealloc(counter);
+		counter->id = 0;
+	}
  	return err;
  }
author Applied
#3 lore raw
In reply to Leon Romanovsky
Quoted 8 lines · Leon Romanovsky

When there is a failure during bind QP, the cleanup flow destroys the counter regardless if it is the one that created it or not, which is problematic since if it isn't the one that created it, that counter could still be in use.

Fix that by destroying the counter only if it was created during this call.

[...]

Applied, thanks!

[1/1] RDMA/mlx5: Fix bind QP error cleanup flow

      https://git.kernel.org/rdma/rdma/c/e1a0bdbdfdf084

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>