Skip to content

Commit ec3d7f5

Browse files
msanallayishaih
authored andcommitted
mlx5: Implement UAR fallback for td allocation
In mlx5_alloc_td(), check if blueflame is supported by examining ctx->bf_reg_size before attempting UAR allocation. When blueflame is not supported (bf_reg_size == 0), fallback to using the shared nc (non-cached) UAR instead of trying to allocate a dedicated UAR. This prevents unnecessary dedicated UAR allocation attempts on devices that don't support blueflame, while ensuring td allocation succeeds by using the available non-cached singleton UAR. In mlx5_dealloc_td(), only detach dedicated UARs by checking the singleton flag to avoid incorrectly freeing the shared nc_uar. Signed-off-by: Maher Sanalla <msanalla@nvidia.com> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
1 parent 1dc3e8d commit ec3d7f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

providers/mlx5/verbs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static void mlx5_detach_dedicated_uar(struct ibv_context *context, struct mlx5_b
448448

449449
struct ibv_td *mlx5_alloc_td(struct ibv_context *context, struct ibv_td_init_attr *init_attr)
450450
{
451+
struct mlx5_context *ctx = to_mctx(context);
451452
struct mlx5_td *td;
452453

453454
if (init_attr->comp_mask) {
@@ -461,7 +462,12 @@ struct ibv_td *mlx5_alloc_td(struct ibv_context *context, struct ibv_td_init_att
461462
return NULL;
462463
}
463464

464-
td->bf = mlx5_attach_dedicated_uar(context, 0);
465+
/* Check whether BlueFlame is supported on the device */
466+
if (ctx->bf_reg_size)
467+
td->bf = mlx5_attach_dedicated_uar(context, 0);
468+
else
469+
td->bf = ctx->nc_uar;
470+
465471
if (!td->bf) {
466472
free(td);
467473
return NULL;
@@ -481,7 +487,8 @@ int mlx5_dealloc_td(struct ibv_td *ib_td)
481487
if (atomic_load(&td->refcount) > 1)
482488
return EBUSY;
483489

484-
mlx5_detach_dedicated_uar(ib_td->context, td->bf);
490+
if (!td->bf->singleton)
491+
mlx5_detach_dedicated_uar(ib_td->context, td->bf);
485492
free(td);
486493

487494
return 0;

0 commit comments

Comments
 (0)