Skip to content

Commit 0446cad

Browse files
committed
RDMA/odp: Provide ib_umem_odp_release() to undo the allocs
Now that there are allocator APIs that return the ib_umem_odp directly it should be freed through a umem_odp free'er as well. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 261dc53 commit 0446cad

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

drivers/infiniband/core/umem.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,6 @@ struct ib_umem *ib_umem_get(struct ib_udata *udata, unsigned long addr,
326326
}
327327
EXPORT_SYMBOL(ib_umem_get);
328328

329-
static void __ib_umem_release_tail(struct ib_umem *umem)
330-
{
331-
mmdrop(umem->owning_mm);
332-
if (umem->is_odp)
333-
kfree(to_ib_umem_odp(umem));
334-
else
335-
kfree(umem);
336-
}
337-
338329
/**
339330
* ib_umem_release - release memory pinned with ib_umem_get
340331
* @umem: umem struct to release
@@ -343,17 +334,14 @@ void ib_umem_release(struct ib_umem *umem)
343334
{
344335
if (!umem)
345336
return;
346-
347-
if (umem->is_odp) {
348-
ib_umem_odp_release(to_ib_umem_odp(umem));
349-
__ib_umem_release_tail(umem);
350-
return;
351-
}
337+
if (umem->is_odp)
338+
return ib_umem_odp_release(to_ib_umem_odp(umem));
352339

353340
__ib_umem_release(umem->context->device, umem, 1);
354341

355342
atomic64_sub(ib_umem_num_pages(umem), &umem->owning_mm->pinned_vm);
356-
__ib_umem_release_tail(umem);
343+
mmdrop(umem->owning_mm);
344+
kfree(umem);
357345
}
358346
EXPORT_SYMBOL(ib_umem_release);
359347

drivers/infiniband/core/umem_odp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ void ib_umem_odp_release(struct ib_umem_odp *umem_odp)
523523
vfree(umem_odp->page_list);
524524
}
525525
put_per_mm(umem_odp);
526+
mmdrop(umem_odp->umem.owning_mm);
527+
kfree(umem_odp);
526528
}
529+
EXPORT_SYMBOL(ib_umem_odp_release);
527530

528531
/*
529532
* Map for DMA and insert a single page into the on-demand paging page tables.

drivers/infiniband/hw/mlx5/mr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr)
16291629
* so that there will not be any invalidations in
16301630
* flight, looking at the *mr struct.
16311631
*/
1632-
ib_umem_release(umem);
1632+
ib_umem_odp_release(umem_odp);
16331633
atomic_sub(npages, &dev->mdev->priv.reg_pages);
16341634

16351635
/* Avoid double-freeing the umem. */

drivers/infiniband/hw/mlx5/odp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void mr_leaf_free_action(struct work_struct *work)
206206
mr->parent = NULL;
207207
synchronize_srcu(&mr->dev->mr_srcu);
208208

209-
ib_umem_release(&odp->umem);
209+
ib_umem_odp_release(odp);
210210
if (imr->live)
211211
mlx5_ib_update_xlt(imr, idx, 1, 0,
212212
MLX5_IB_UPD_XLT_INDIRECT |
@@ -472,7 +472,7 @@ static struct ib_umem_odp *implicit_mr_get_data(struct mlx5_ib_mr *mr,
472472
mr->access_flags);
473473
if (IS_ERR(mtt)) {
474474
mutex_unlock(&odp_mr->umem_mutex);
475-
ib_umem_release(&odp->umem);
475+
ib_umem_odp_release(odp);
476476
return ERR_CAST(mtt);
477477
}
478478

@@ -526,7 +526,7 @@ struct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,
526526

527527
imr = implicit_mr_alloc(&pd->ibpd, umem_odp, 1, access_flags);
528528
if (IS_ERR(imr)) {
529-
ib_umem_release(&umem_odp->umem);
529+
ib_umem_odp_release(umem_odp);
530530
return ERR_CAST(imr);
531531
}
532532

0 commit comments

Comments
 (0)