[PATCH net-next v1 1/4] net/mlx5: Don't free the ASO CQ if destroying it fails

From: Yuho Choi

Date: Fri Oct 16 2026 - 00:59:29 EST


mlx5_aso_destroy_cq() ignores the result of mlx5_core_destroy_cq() and
frees the CQ buffer and doorbell record anyway, and its callers then
free the struct mlx5_aso that embeds the CQ. If DESTROY_CQ fails, the
CQ may still exist in firmware and retain access to its buffer and
doorbell record. mlx5_core_destroy_cq() also returns early in that case,
without waiting for EQ handlers that may already hold a reference to
the CQ.

Return the error from mlx5_aso_destroy_cq() and keep both the buffer
and the struct mlx5_aso when it fails, as the regular mlx5_ib CQ destroy
path does. A device in internal error is not affected, since the mlx5
core reports success for DESTROY_CQ in that state.

Fixes: cdd04f4d4d71 ("net/mlx5: Add support to create SQ and CQ for ASO")
Assisted-by: LLM
Signed-off-by: Yuho Choi <oss.patchbox@xxxxxxxxx>
---
This was found with a static analysis tool from ongoing, not yet
published research, and confirmed by code inspection. It has not been
reproduced on hardware.

.../net/ethernet/mellanox/mlx5/core/lib/aso.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c
index 614cd57a40d74..6a9d31d539e9a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/aso.c
@@ -112,10 +112,14 @@ static int create_aso_cq(struct mlx5_aso_cq *cq, void *cqc_data)
return err;
}

-static void mlx5_aso_destroy_cq(struct mlx5_aso_cq *cq)
+static int mlx5_aso_destroy_cq(struct mlx5_aso_cq *cq)
{
- mlx5_core_destroy_cq(cq->mdev, &cq->mcq);
- mlx5_wq_destroy(&cq->wq_ctrl);
+ int err = mlx5_core_destroy_cq(cq->mdev, &cq->mcq);
+
+ /* The device may still access an undestroyed CQ's buffer; keep it. */
+ if (!err)
+ mlx5_wq_destroy(&cq->wq_ctrl);
+ return err;
}

static int mlx5_aso_create_cq(struct mlx5_core_dev *mdev, int numa_node,
@@ -326,7 +330,9 @@ struct mlx5_aso *mlx5_aso_create(struct mlx5_core_dev *mdev, u32 pdn)
return aso;

err_sq:
- mlx5_aso_destroy_cq(&aso->cq);
+ /* An undestroyed CQ may still be in use; keep the ASO that holds it. */
+ if (mlx5_aso_destroy_cq(&aso->cq))
+ return ERR_PTR(err);
err_cq:
kfree(aso);
return ERR_PTR(err);
@@ -335,7 +341,9 @@ struct mlx5_aso *mlx5_aso_create(struct mlx5_core_dev *mdev, u32 pdn)
void mlx5_aso_destroy(struct mlx5_aso *aso)
{
mlx5_aso_destroy_sq(aso);
- mlx5_aso_destroy_cq(&aso->cq);
+ /* An undestroyed CQ may still be in use; keep the ASO that holds it. */
+ if (mlx5_aso_destroy_cq(&aso->cq))
+ return;
kfree(aso);
}

--
2.43.0