Skip to content

Commit a0ffb4c

Browse files
MarkZhang81jgunthorpe
authored andcommitted
RDMA/mlx5: Use different doorbell memory for different processes
In a fork scenario, the parent and child can have same virtual address and also share the uverbs fd. That causes to the list_for_each_entry search return same doorbell physical page for all processes, even though that page has been COW' or copied. This patch takes the mm_struct into consideration during search, to make sure that VA's belonging to different processes are not intermixed. Resolves the malfunction of uverbs after fork in some specific cases. Fixes: e126ba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Link: https://lore.kernel.org/r/feacc23fe0bc6e1088c6824d5583798745e72405.1622726212.git.leonro@nvidia.com Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Mark Zhang <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent a3e74fb commit a0ffb4c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/infiniband/hw/mlx5/doorbell.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct mlx5_ib_user_db_page {
4141
struct ib_umem *umem;
4242
unsigned long user_virt;
4343
int refcnt;
44+
struct mm_struct *mm;
4445
};
4546

4647
int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context,
@@ -53,7 +54,8 @@ int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context,
5354
mutex_lock(&context->db_page_mutex);
5455

5556
list_for_each_entry(page, &context->db_page_list, list)
56-
if (page->user_virt == (virt & PAGE_MASK))
57+
if ((current->mm == page->mm) &&
58+
(page->user_virt == (virt & PAGE_MASK)))
5759
goto found;
5860

5961
page = kmalloc(sizeof(*page), GFP_KERNEL);
@@ -71,6 +73,8 @@ int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context,
7173
kfree(page);
7274
goto out;
7375
}
76+
mmgrab(current->mm);
77+
page->mm = current->mm;
7478

7579
list_add(&page->list, &context->db_page_list);
7680

@@ -91,6 +95,7 @@ void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db)
9195

9296
if (!--db->u.user_page->refcnt) {
9397
list_del(&db->u.user_page->list);
98+
mmdrop(db->u.user_page->mm);
9499
ib_umem_release(db->u.user_page->umem);
95100
kfree(db->u.user_page);
96101
}

0 commit comments

Comments
 (0)